1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22 
23 #include "libgimpwidgets/gimpwidgets.h"
24 
25 #include "actions-types.h"
26 
27 #include "core/gimpcontext.h"
28 #include "core/gimpdata.h"
29 
30 #include "widgets/gimpactiongroup.h"
31 #include "widgets/gimphelp-ids.h"
32 
33 #include "actions.h"
34 #include "data-commands.h"
35 #include "patterns-actions.h"
36 
37 #include "gimp-intl.h"
38 
39 
40 static const GimpActionEntry patterns_actions[] =
41 {
42   { "patterns-popup", GIMP_ICON_PATTERN,
43     NC_("patterns-action", "Patterns Menu"), NULL, NULL, NULL,
44     GIMP_HELP_PATTERN_DIALOG },
45 
46   { "patterns-open-as-image", GIMP_ICON_DOCUMENT_OPEN,
47     NC_("patterns-action", "_Open Pattern as Image"), NULL,
48     NC_("patterns-action", "Open this pattern as an image"),
49     data_open_as_image_cmd_callback,
50     GIMP_HELP_PATTERN_OPEN_AS_IMAGE },
51 
52   { "patterns-new", GIMP_ICON_DOCUMENT_NEW,
53     NC_("patterns-action", "_New Pattern"), NULL,
54     NC_("patterns-action", "Create a new pattern"),
55     data_new_cmd_callback,
56     GIMP_HELP_PATTERN_NEW },
57 
58   { "patterns-duplicate", GIMP_ICON_OBJECT_DUPLICATE,
59     NC_("patterns-action", "D_uplicate Pattern"), NULL,
60     NC_("patterns-action", "Duplicate this pattern"),
61     data_duplicate_cmd_callback,
62     GIMP_HELP_PATTERN_DUPLICATE },
63 
64   { "patterns-copy-location", GIMP_ICON_EDIT_COPY,
65     NC_("patterns-action", "Copy Pattern _Location"), NULL,
66     NC_("patterns-action", "Copy pattern file location to clipboard"),
67     data_copy_location_cmd_callback,
68     GIMP_HELP_PATTERN_COPY_LOCATION },
69 
70   { "patterns-show-in-file-manager", GIMP_ICON_FILE_MANAGER,
71     NC_("patterns-action", "Show in _File Manager"), NULL,
72     NC_("patterns-action", "Show pattern file location in the file manager"),
73     data_show_in_file_manager_cmd_callback,
74     GIMP_HELP_PATTERN_SHOW_IN_FILE_MANAGER },
75 
76   { "patterns-delete", GIMP_ICON_EDIT_DELETE,
77     NC_("patterns-action", "_Delete Pattern"), NULL,
78     NC_("patterns-action", "Delete this pattern"),
79     data_delete_cmd_callback,
80     GIMP_HELP_PATTERN_DELETE },
81 
82   { "patterns-refresh", GIMP_ICON_VIEW_REFRESH,
83     NC_("patterns-action", "_Refresh Patterns"), NULL,
84     NC_("patterns-action", "Refresh patterns"),
85     data_refresh_cmd_callback,
86     GIMP_HELP_PATTERN_REFRESH }
87 };
88 
89 static const GimpStringActionEntry patterns_edit_actions[] =
90 {
91   { "patterns-edit", GIMP_ICON_EDIT,
92     NC_("patterns-action", "_Edit Pattern..."), NULL,
93     NC_("patterns-action", "Edit pattern"),
94     "gimp-pattern-editor",
95     GIMP_HELP_PATTERN_EDIT }
96 };
97 
98 
99 void
patterns_actions_setup(GimpActionGroup * group)100 patterns_actions_setup (GimpActionGroup *group)
101 {
102   gimp_action_group_add_actions (group, "patterns-action",
103                                  patterns_actions,
104                                  G_N_ELEMENTS (patterns_actions));
105 
106   gimp_action_group_add_string_actions (group, "patterns-action",
107                                         patterns_edit_actions,
108                                         G_N_ELEMENTS (patterns_edit_actions),
109                                         data_edit_cmd_callback);
110 }
111 
112 void
patterns_actions_update(GimpActionGroup * group,gpointer user_data)113 patterns_actions_update (GimpActionGroup *group,
114                          gpointer         user_data)
115 {
116   GimpContext *context = action_data_get_context (user_data);
117   GimpPattern *pattern = NULL;
118   GimpData    *data    = NULL;
119   GFile       *file    = NULL;
120 
121   if (context)
122     {
123       pattern = gimp_context_get_pattern (context);
124 
125       if (action_data_sel_count (user_data) > 1)
126         {
127           pattern = NULL;
128         }
129 
130       if (pattern)
131         {
132           data = GIMP_DATA (pattern);
133 
134           file = gimp_data_get_file (data);
135         }
136     }
137 
138 #define SET_SENSITIVE(action,condition) \
139         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
140 
141   SET_SENSITIVE ("patterns-edit",                 pattern && FALSE);
142   SET_SENSITIVE ("patterns-open-as-image",        file);
143   SET_SENSITIVE ("patterns-duplicate",            pattern && gimp_data_is_duplicatable (data));
144   SET_SENSITIVE ("patterns-copy-location",        file);
145   SET_SENSITIVE ("patterns-show-in-file-manager", file);
146   SET_SENSITIVE ("patterns-delete",               pattern && gimp_data_is_deletable (data));
147 
148 #undef SET_SENSITIVE
149 }
150