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 <string.h>
21 
22 #include <gegl.h>
23 #include <gtk/gtk.h>
24 
25 #include "libgimpwidgets/gimpwidgets.h"
26 
27 #include "actions-types.h"
28 
29 #include "config/gimpdisplayconfig.h"
30 #include "config/gimpguiconfig.h"
31 
32 #include "core/gimp.h"
33 #include "core/gimpcontainer.h"
34 
35 #include "widgets/gimpactiongroup.h"
36 #include "widgets/gimpdialogfactory.h"
37 #include "widgets/gimpsessioninfo.h"
38 #include "widgets/gimpwidgets-utils.h"
39 
40 #include "display/gimpdisplay.h"
41 #include "display/gimpdisplayshell.h"
42 
43 #include "dialogs/dialogs.h"
44 
45 #include "actions.h"
46 #include "dialogs-actions.h"
47 #include "windows-commands.h"
48 
49 #include "gimp-intl.h"
50 
51 
52 void
windows_hide_docks_cmd_callback(GimpAction * action,GVariant * value,gpointer data)53 windows_hide_docks_cmd_callback (GimpAction *action,
54                                  GVariant   *value,
55                                  gpointer    data)
56 {
57   Gimp     *gimp;
58   gboolean  active;
59   return_if_no_gimp (gimp, data);
60 
61   active = g_variant_get_boolean (value);
62 
63   if (active != GIMP_GUI_CONFIG (gimp->config)->hide_docks)
64     g_object_set (gimp->config,
65                   "hide-docks", active,
66                   NULL);
67 }
68 
69 void
windows_use_single_window_mode_cmd_callback(GimpAction * action,GVariant * value,gpointer data)70 windows_use_single_window_mode_cmd_callback (GimpAction *action,
71                                              GVariant   *value,
72                                              gpointer    data)
73 {
74   Gimp     *gimp;
75   gboolean  active;
76   return_if_no_gimp (gimp, data);
77 
78   active = g_variant_get_boolean (value);
79 
80   if (active != GIMP_GUI_CONFIG (gimp->config)->single_window_mode)
81     g_object_set (gimp->config,
82                   "single-window-mode", active,
83                   NULL);
84 }
85 
86 void
windows_show_tabs_cmd_callback(GimpAction * action,GVariant * value,gpointer data)87 windows_show_tabs_cmd_callback (GimpAction *action,
88                                 GVariant   *value,
89                                 gpointer    data)
90 {
91   Gimp     *gimp;
92   gboolean  active;
93   return_if_no_gimp (gimp, data);
94 
95   active = g_variant_get_boolean (value);
96 
97   if (active != GIMP_GUI_CONFIG (gimp->config)->show_tabs)
98     g_object_set (gimp->config,
99                   "show-tabs", active,
100                   NULL);
101 }
102 
103 
104 void
windows_set_tabs_position_cmd_callback(GimpAction * action,GVariant * value,gpointer data)105 windows_set_tabs_position_cmd_callback (GimpAction *action,
106                                         GVariant   *value,
107                                         gpointer    data)
108 {
109   Gimp         *gimp;
110   GimpPosition  position;
111   return_if_no_gimp (gimp, data);
112 
113   position = (GimpPosition) g_variant_get_int32 (value);
114 
115   if (position != GIMP_GUI_CONFIG (gimp->config)->tabs_position)
116     g_object_set (gimp->config,
117                   "tabs-position", position,
118                   NULL);
119 }
120 
121 void
windows_show_display_next_cmd_callback(GimpAction * action,GVariant * value,gpointer data)122 windows_show_display_next_cmd_callback (GimpAction *action,
123                                         GVariant   *value,
124                                         gpointer    data)
125 {
126   GimpDisplay *display;
127   Gimp        *gimp;
128   gint         index;
129   return_if_no_display (display, data);
130   return_if_no_gimp (gimp, data);
131 
132   index = gimp_container_get_child_index (gimp->displays,
133                                           GIMP_OBJECT (display));
134   index++;
135 
136   if (index >= gimp_container_get_n_children (gimp->displays))
137     index = 0;
138 
139   display = GIMP_DISPLAY (gimp_container_get_child_by_index (gimp->displays,
140                                                              index));
141   gimp_display_shell_present (gimp_display_get_shell (display));
142 }
143 
144 void
windows_show_display_previous_cmd_callback(GimpAction * action,GVariant * value,gpointer data)145 windows_show_display_previous_cmd_callback (GimpAction *action,
146                                             GVariant   *value,
147                                             gpointer    data)
148 {
149   GimpDisplay *display;
150   Gimp        *gimp;
151   gint         index;
152   return_if_no_display (display, data);
153   return_if_no_gimp (gimp, data);
154 
155   index = gimp_container_get_child_index (gimp->displays,
156                                           GIMP_OBJECT (display));
157   index--;
158 
159   if (index < 0)
160     index = gimp_container_get_n_children (gimp->displays) - 1;
161 
162   display = GIMP_DISPLAY (gimp_container_get_child_by_index (gimp->displays,
163                                                              index));
164   gimp_display_shell_present (gimp_display_get_shell (display));
165 }
166 
167 void
windows_show_display_cmd_callback(GimpAction * action,GVariant * value,gpointer data)168 windows_show_display_cmd_callback (GimpAction *action,
169                                    GVariant   *value,
170                                    gpointer    data)
171 {
172   GimpDisplay *display = g_object_get_data (G_OBJECT (action), "display");
173 
174   gimp_display_shell_present (gimp_display_get_shell (display));
175 }
176 
177 void
windows_show_dock_cmd_callback(GimpAction * action,GVariant * value,gpointer data)178 windows_show_dock_cmd_callback (GimpAction *action,
179                                 GVariant   *value,
180                                 gpointer    data)
181 {
182   GtkWindow *dock_window = g_object_get_data (G_OBJECT (action), "dock-window");
183 
184   gtk_window_present (dock_window);
185 }
186 
187 void
windows_open_recent_cmd_callback(GimpAction * action,GVariant * value,gpointer data)188 windows_open_recent_cmd_callback (GimpAction *action,
189                                   GVariant   *value,
190                                   gpointer    data)
191 {
192   GimpSessionInfo        *info;
193   GimpDialogFactoryEntry *entry;
194   Gimp                   *gimp;
195   GtkWidget              *widget;
196   return_if_no_gimp (gimp, data);
197   return_if_no_widget (widget, data);
198 
199   info  = g_object_get_data (G_OBJECT (action), "info");
200   entry = gimp_session_info_get_factory_entry (info);
201 
202   if (entry && strcmp ("gimp-toolbox-window", entry->identifier) == 0 &&
203       dialogs_actions_toolbox_exists (gimp))
204     {
205       gimp_message (gimp,
206                     G_OBJECT (action_data_get_widget (data)),
207                     GIMP_MESSAGE_WARNING,
208                     _("The chosen recent dock contains a toolbox. Please "
209                       "close the currently open toolbox and try again."));
210       return;
211     }
212 
213   g_object_ref (info);
214 
215   gimp_container_remove (global_recent_docks, GIMP_OBJECT (info));
216 
217   gimp_dialog_factory_add_session_info (gimp_dialog_factory_get_singleton (),
218                                         info);
219 
220   gimp_session_info_restore (info, gimp_dialog_factory_get_singleton (),
221                              gtk_widget_get_screen (widget),
222                              gimp_widget_get_monitor (widget));
223 
224   g_object_unref (info);
225 }
226