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/gimpbrushgenerated.h"
28 #include "core/gimpcontext.h"
29 
30 #include "widgets/gimpactiongroup.h"
31 #include "widgets/gimphelp-ids.h"
32 
33 #include "actions.h"
34 #include "brushes-actions.h"
35 #include "data-commands.h"
36 
37 #include "gimp-intl.h"
38 
39 
40 static const GimpActionEntry brushes_actions[] =
41 {
42   { "brushes-popup", GIMP_ICON_BRUSH,
43     NC_("brushes-action", "Brushes Menu"), NULL, NULL, NULL,
44     GIMP_HELP_BRUSH_DIALOG },
45 
46   { "brushes-open-as-image", GIMP_ICON_DOCUMENT_OPEN,
47     NC_("brushes-action", "_Open Brush as Image"), NULL,
48     NC_("brushes-action", "Open brush as image"),
49     data_open_as_image_cmd_callback,
50     GIMP_HELP_BRUSH_OPEN_AS_IMAGE },
51 
52   { "brushes-new", GIMP_ICON_DOCUMENT_NEW,
53     NC_("brushes-action", "_New Brush"), NULL,
54     NC_("brushes-action", "Create a new brush"),
55     data_new_cmd_callback,
56     GIMP_HELP_BRUSH_NEW },
57 
58   { "brushes-duplicate", GIMP_ICON_OBJECT_DUPLICATE,
59     NC_("brushes-action", "D_uplicate Brush"), NULL,
60     NC_("brushes-action", "Duplicate this brush"),
61     data_duplicate_cmd_callback,
62     GIMP_HELP_BRUSH_DUPLICATE },
63 
64   { "brushes-copy-location", GIMP_ICON_EDIT_COPY,
65     NC_("brushes-action", "Copy Brush _Location"), NULL,
66     NC_("brushes-action", "Copy brush file location to clipboard"),
67     data_copy_location_cmd_callback,
68     GIMP_HELP_BRUSH_COPY_LOCATION },
69 
70   { "brushes-show-in-file-manager", GIMP_ICON_FILE_MANAGER,
71     NC_("brushes-action", "Show in _File Manager"), NULL,
72     NC_("brushes-action", "Show brush file location in the file manager"),
73     data_show_in_file_manager_cmd_callback,
74     GIMP_HELP_BRUSH_SHOW_IN_FILE_MANAGER },
75 
76   { "brushes-delete", GIMP_ICON_EDIT_DELETE,
77     NC_("brushes-action", "_Delete Brush"), NULL,
78     NC_("brushes-action", "Delete this brush"),
79     data_delete_cmd_callback,
80     GIMP_HELP_BRUSH_DELETE },
81 
82   { "brushes-refresh", GIMP_ICON_VIEW_REFRESH,
83     NC_("brushes-action", "_Refresh Brushes"), NULL,
84     NC_("brushes-action", "Refresh brushes"),
85     data_refresh_cmd_callback,
86     GIMP_HELP_BRUSH_REFRESH }
87 };
88 
89 static const GimpStringActionEntry brushes_edit_actions[] =
90 {
91   { "brushes-edit", GIMP_ICON_EDIT,
92     NC_("brushes-action", "_Edit Brush..."), NULL,
93     NC_("brushes-action", "Edit this brush"),
94     "gimp-brush-editor",
95     GIMP_HELP_BRUSH_EDIT }
96 };
97 
98 
99 void
brushes_actions_setup(GimpActionGroup * group)100 brushes_actions_setup (GimpActionGroup *group)
101 {
102   gimp_action_group_add_actions (group, "brushes-action",
103                                  brushes_actions,
104                                  G_N_ELEMENTS (brushes_actions));
105 
106   gimp_action_group_add_string_actions (group, "brushes-action",
107                                         brushes_edit_actions,
108                                         G_N_ELEMENTS (brushes_edit_actions),
109                                         data_edit_cmd_callback);
110 }
111 
112 void
brushes_actions_update(GimpActionGroup * group,gpointer user_data)113 brushes_actions_update (GimpActionGroup *group,
114                         gpointer         user_data)
115 {
116   GimpContext *context = action_data_get_context (user_data);
117   GimpBrush   *brush   = NULL;
118   GimpData    *data    = NULL;
119   GFile       *file    = NULL;
120 
121   if (context)
122     {
123       brush = gimp_context_get_brush (context);
124 
125       if (action_data_sel_count (user_data) > 1)
126         {
127           brush = NULL;
128         }
129 
130       if (brush)
131         {
132           data = GIMP_DATA (brush);
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 ("brushes-edit",                 brush);
142   SET_SENSITIVE ("brushes-open-as-image",        file && ! GIMP_IS_BRUSH_GENERATED (brush));
143   SET_SENSITIVE ("brushes-duplicate",            brush && gimp_data_is_duplicatable (data));
144   SET_SENSITIVE ("brushes-copy-location",        file);
145   SET_SENSITIVE ("brushes-show-in-file-manager", file);
146   SET_SENSITIVE ("brushes-delete",               brush && gimp_data_is_deletable (data));
147 
148 #undef SET_SENSITIVE
149 }
150