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 "widgets/gimpactiongroup.h"
28 #include "widgets/gimpdockwindow.h"
29 #include "widgets/gimphelp-ids.h"
30 #include "widgets/gimpmenudock.h"
31 
32 #include "display/gimpimagewindow.h"
33 
34 #include "actions.h"
35 #include "dock-actions.h"
36 #include "dock-commands.h"
37 #include "window-actions.h"
38 #include "window-commands.h"
39 
40 #include "gimp-intl.h"
41 
42 
43 static const GimpActionEntry dock_actions[] =
44 {
45   { "dock-move-to-screen-menu", GIMP_ICON_WINDOW_MOVE_TO_SCREEN,
46     NC_("dock-action", "M_ove to Screen"), NULL, NULL, NULL,
47     GIMP_HELP_DOCK_CHANGE_SCREEN },
48 
49   { "dock-close", GIMP_ICON_WINDOW_CLOSE,
50     NC_("dock-action", "Close Dock"), "", NULL,
51     window_close_cmd_callback,
52     GIMP_HELP_DOCK_CLOSE },
53 
54   { "dock-open-display", NULL,
55     NC_("dock-action", "_Open Display..."), NULL,
56     NC_("dock-action", "Connect to another display"),
57     window_open_display_cmd_callback,
58     NULL }
59 };
60 
61 static const GimpToggleActionEntry dock_toggle_actions[] =
62 {
63   { "dock-show-image-menu", NULL,
64     NC_("dock-action", "_Show Image Selection"), NULL, NULL,
65     dock_toggle_image_menu_cmd_callback,
66     TRUE,
67     GIMP_HELP_DOCK_IMAGE_MENU },
68 
69   { "dock-auto-follow-active", NULL,
70     NC_("dock-action", "Auto _Follow Active Image"), NULL, NULL,
71     dock_toggle_auto_cmd_callback,
72     TRUE,
73     GIMP_HELP_DOCK_AUTO_BUTTON }
74 };
75 
76 
77 void
dock_actions_setup(GimpActionGroup * group)78 dock_actions_setup (GimpActionGroup *group)
79 {
80   gimp_action_group_add_actions (group, "dock-action",
81                                  dock_actions,
82                                  G_N_ELEMENTS (dock_actions));
83 
84   gimp_action_group_add_toggle_actions (group, "dock-action",
85                                         dock_toggle_actions,
86                                         G_N_ELEMENTS (dock_toggle_actions));
87 
88   window_actions_setup (group, GIMP_HELP_DOCK_CHANGE_SCREEN);
89 }
90 
91 void
dock_actions_update(GimpActionGroup * group,gpointer data)92 dock_actions_update (GimpActionGroup *group,
93                      gpointer         data)
94 {
95   GtkWidget *widget   = action_data_get_widget (data);
96   GtkWidget *toplevel = NULL;
97 
98   if (widget)
99     toplevel = gtk_widget_get_toplevel (widget);
100 
101 #define SET_ACTIVE(action,active) \
102         gimp_action_group_set_action_active (group, action, (active) != 0)
103 #define SET_VISIBLE(action,active) \
104         gimp_action_group_set_action_visible (group, action, (active) != 0)
105 
106   if (GIMP_IS_DOCK_WINDOW (toplevel))
107     {
108       GimpDockWindow *dock_window = GIMP_DOCK_WINDOW (toplevel);
109       gboolean show_image_menu = ! gimp_dock_window_has_toolbox (dock_window);
110 
111       if (show_image_menu)
112         {
113           SET_VISIBLE ("dock-show-image-menu",    TRUE);
114           SET_VISIBLE ("dock-auto-follow-active", TRUE);
115 
116           SET_ACTIVE ("dock-show-image-menu",
117                       gimp_dock_window_get_show_image_menu (dock_window));
118           SET_ACTIVE ("dock-auto-follow-active",
119                       gimp_dock_window_get_auto_follow_active (dock_window));
120         }
121       else
122         {
123           SET_VISIBLE ("dock-show-image-menu",    FALSE);
124           SET_VISIBLE ("dock-auto-follow-active", FALSE);
125         }
126 
127       /*  update the window actions only in the context of their
128        *  own window (not in the context of some display or NULL)
129        *  (see view-actions.c)
130        */
131       window_actions_update (group, toplevel);
132     }
133   else if (GIMP_IS_IMAGE_WINDOW (toplevel))
134     {
135       SET_VISIBLE ("dock-show-image-menu",    FALSE);
136       SET_VISIBLE ("dock-auto-follow-active", FALSE);
137     }
138 
139 #undef SET_ACTIVE
140 #undef SET_VISIBLE
141 }
142