1
|
1 /*
|
9
|
2 * GQview
|
|
3 * (C) 2004 John Ellis
|
1
|
4 *
|
|
5 * Author: John Ellis
|
|
6 *
|
9
|
7 * This software is released under the GNU General Public License (GNU GPL).
|
|
8 * Please read the included file COPYING for more information.
|
|
9 * This software comes with no warranty of any kind, use at your own risk!
|
1
|
10 */
|
|
11
|
|
12
|
9
|
13 #include "gqview.h"
|
|
14 #include "menu.h"
|
1
|
15
|
9
|
16 #include "cache_maint.h"
|
|
17 #include "collect.h"
|
|
18 #include "collect-dlg.h"
|
|
19 #include "dupe.h"
|
|
20 #include "filelist.h"
|
|
21 #include "img-view.h"
|
|
22 #include "preferences.h"
|
|
23 #include "slideshow.h"
|
|
24 #include "utilops.h"
|
|
25 #include "ui_fileops.h"
|
|
26 #include "ui_tabcomp.h"
|
|
27 #include "ui_menu.h"
|
|
28
|
|
29 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data,
|
|
30 GtkAccelGroup *accel_group);
|
1
|
31
|
|
32 /*
|
|
33 *-----------------------------------------------------------------------------
|
9
|
34 * menu utils
|
1
|
35 *-----------------------------------------------------------------------------
|
|
36 */
|
|
37
|
9
|
38 static GtkWidget *add_menu_item(GtkWidget *menu, gchar *label, GtkAccelGroup *accel_group,
|
|
39 guint accel_key, guint accel_mods, GCallback func, gpointer data)
|
1
|
40 {
|
|
41 GtkWidget *item;
|
|
42
|
|
43 item = gtk_menu_item_new_with_label(label);
|
|
44 gtk_widget_add_accelerator (item, "activate", accel_group, accel_key, accel_mods, GTK_ACCEL_VISIBLE);
|
9
|
45 g_signal_connect(G_OBJECT(item), "activate", func, data);
|
|
46 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
1
|
47 gtk_widget_show(item);
|
9
|
48
|
|
49 return item;
|
1
|
50 }
|
|
51
|
9
|
52 gpointer submenu_item_get_data(GtkWidget *menu)
|
1
|
53 {
|
9
|
54 if (!menu->parent || !GTK_IS_MENU(menu->parent)) return NULL;
|
1
|
55
|
9
|
56 return g_object_get_data(G_OBJECT(menu->parent), "submenu_data");
|
1
|
57 }
|
|
58
|
|
59 /*
|
|
60 *-----------------------------------------------------------------------------
|
9
|
61 * edit menu
|
1
|
62 *-----------------------------------------------------------------------------
|
|
63 */
|
|
64
|
9
|
65 static void add_edit_items(GtkWidget *menu, GCallback func, GtkAccelGroup *accel_grp)
|
1
|
66 {
|
|
67 gint i;
|
9
|
68 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
|
1
|
69 {
|
|
70 if (editor_command[i] && strlen(editor_command[i]) > 0)
|
|
71 {
|
|
72 gchar *text;
|
|
73 if (editor_name[i] && strlen(editor_name[i]) > 0)
|
|
74 text = g_strdup_printf(_("in %s..."), editor_name[i]);
|
|
75 else
|
|
76 text = g_strdup(_("in (unknown)..."));
|
|
77 if (accel_grp)
|
|
78 add_menu_item(menu, text, accel_grp, i + 49, GDK_CONTROL_MASK, func, GINT_TO_POINTER(i));
|
|
79 else
|
9
|
80 menu_item_add_simple(menu, text, func, GINT_TO_POINTER(i));
|
1
|
81 g_free(text);
|
|
82 }
|
|
83 }
|
|
84 }
|
|
85
|
9
|
86 GtkWidget *submenu_add_edit(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data)
|
1
|
87 {
|
9
|
88 GtkWidget *item;
|
|
89 GtkWidget *submenu;
|
1
|
90
|
9
|
91 item = menu_item_add(menu, _("_Edit"), NULL, NULL);
|
1
|
92
|
9
|
93 submenu = gtk_menu_new();
|
|
94 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
|
|
95 add_edit_items(submenu, func, NULL);
|
1
|
96
|
9
|
97 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
|
1
|
98
|
9
|
99 if (menu_item) *menu_item = item;
|
1
|
100
|
9
|
101 return submenu;
|
1
|
102 }
|
|
103
|
|
104 /*
|
|
105 *-----------------------------------------------------------------------------
|
9
|
106 * sorting
|
1
|
107 *-----------------------------------------------------------------------------
|
9
|
108 */
|
1
|
109
|
9
|
110 gchar *sort_type_get_text(SortType method)
|
1
|
111 {
|
9
|
112 switch (method)
|
|
113 {
|
|
114 case SORT_SIZE:
|
|
115 return _("Sort by size");
|
|
116 break;
|
|
117 case SORT_TIME:
|
|
118 return _("Sort by date");
|
|
119 break;
|
|
120 case SORT_NONE:
|
|
121 return _("Unsorted");
|
|
122 break;
|
|
123 case SORT_PATH:
|
|
124 return _("Sort by path");
|
|
125 break;
|
|
126 case SORT_NUMBER:
|
|
127 return _("Sort by number");
|
|
128 break;
|
|
129 case SORT_NAME:
|
|
130 default:
|
|
131 return _("Sort by name");
|
|
132 break;
|
|
133 }
|
1
|
134
|
9
|
135 return "";
|
|
136 }
|
1
|
137
|
9
|
138 static void submenu_add_sort_item(GtkWidget *menu, GCallback func, SortType type,
|
|
139 gint show_current, SortType show_type)
|
|
140 {
|
|
141 if (show_current)
|
|
142 {
|
|
143 menu_item_add_check(menu, sort_type_get_text(type), (type == show_type),
|
|
144 func, GINT_TO_POINTER((gint)type));
|
|
145 }
|
|
146 else
|
|
147 {
|
|
148 menu_item_add(menu, sort_type_get_text(type),
|
|
149 func, GINT_TO_POINTER((gint)type));
|
|
150 }
|
|
151 }
|
1
|
152
|
9
|
153 GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data,
|
|
154 gint include_none, gint include_path,
|
|
155 gint show_current, SortType type)
|
|
156 {
|
|
157 GtkWidget *submenu;
|
1
|
158
|
9
|
159 submenu = gtk_menu_new();
|
|
160 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
|
|
161
|
|
162 submenu_add_sort_item(submenu, func, SORT_NAME, show_current, type);
|
|
163 #ifdef HAVE_STRVERSCMP
|
|
164 submenu_add_sort_item(submenu, func, SORT_NUMBER, show_current, type);
|
|
165 #endif
|
|
166 submenu_add_sort_item(submenu, func, SORT_TIME, show_current, type);
|
|
167 submenu_add_sort_item(submenu, func, SORT_SIZE, show_current, type);
|
|
168 if (include_path) submenu_add_sort_item(submenu, func, SORT_PATH, show_current, type);
|
|
169 if (include_none) submenu_add_sort_item(submenu, func, SORT_NONE, show_current, type);
|
|
170
|
|
171 if (menu)
|
|
172 {
|
|
173 GtkWidget *item;
|
|
174
|
|
175 item = menu_item_add(menu, _("Sort"), NULL, NULL);
|
|
176 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
|
|
177 return item;
|
|
178 }
|
|
179
|
|
180 return submenu;
|
1
|
181 }
|
|
182
|
|
183 /*
|
|
184 *-----------------------------------------------------------------------------
|
9
|
185 * altering
|
1
|
186 *-----------------------------------------------------------------------------
|
9
|
187 */
|
1
|
188
|
9
|
189 gchar *alter_type_get_text(AlterType type)
|
1
|
190 {
|
9
|
191 switch (type)
|
1
|
192 {
|
9
|
193 case ALTER_ROTATE_90:
|
|
194 return _("_Rotate clockwise");
|
|
195 break;
|
|
196 case ALTER_ROTATE_90_CC:
|
|
197 return _("Rotate _counterclockwise");
|
|
198 break;
|
|
199 case ALTER_ROTATE_180:
|
|
200 return _("Rotate _180");
|
|
201 break;
|
|
202 case ALTER_MIRROR:
|
|
203 return _("_Mirror");
|
|
204 break;
|
|
205 case ALTER_FLIP:
|
|
206 return _("_Flip");
|
|
207 break;
|
|
208 default:
|
|
209 break;
|
|
210 }
|
|
211
|
|
212 return "";
|
|
213 }
|
|
214
|
|
215 static void submenu_add_alter_item(GtkWidget *menu, GCallback func, AlterType type,
|
|
216 GtkAccelGroup *accel_group, guint accel_key, guint accel_mods)
|
|
217 {
|
|
218 if (accel_group)
|
|
219 {
|
|
220 add_menu_item(menu, alter_type_get_text(type), accel_group,
|
|
221 accel_key, accel_mods, func, GINT_TO_POINTER((gint)type));
|
|
222
|
|
223 }
|
|
224 else
|
|
225 {
|
|
226 menu_item_add(menu, alter_type_get_text(type), func, GINT_TO_POINTER((gint)type));
|
1
|
227 }
|
|
228 }
|
|
229
|
9
|
230 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data,
|
|
231 GtkAccelGroup *accel_group)
|
1
|
232 {
|
9
|
233 GtkWidget *submenu;
|
1
|
234
|
9
|
235 submenu = gtk_menu_new();
|
|
236 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
|
1
|
237
|
9
|
238 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90, accel_group, ']', 0);
|
|
239 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90_CC, accel_group, '[', 0);
|
|
240 submenu_add_alter_item(submenu, func, ALTER_ROTATE_180, accel_group, 'R', GDK_SHIFT_MASK);
|
|
241 submenu_add_alter_item(submenu, func, ALTER_MIRROR, accel_group, 'M', GDK_SHIFT_MASK);
|
|
242 submenu_add_alter_item(submenu, func, ALTER_FLIP, accel_group, 'F', GDK_SHIFT_MASK);
|
1
|
243
|
9
|
244 if (menu)
|
|
245 {
|
|
246 GtkWidget *item;
|
1
|
247
|
9
|
248 item = menu_item_add(menu, _("_Adjust"), NULL, NULL);
|
|
249 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
|
|
250 return item;
|
|
251 }
|
|
252
|
|
253 return submenu;
|
1
|
254 }
|
|
255
|
9
|
256 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data)
|
1
|
257 {
|
9
|
258 return real_submenu_add_alter(menu, func, data, NULL);
|
1
|
259 }
|
|
260
|
|
261
|