Mercurial > geeqie
annotate src/menu.c @ 927:d27b4184ceb8
Minor tidy up and optimization.
author | zas_ |
---|---|
date | Fri, 25 Jul 2008 06:35:35 +0000 |
parents | fa8f7d7396cf |
children | 1646720364cf |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "menu.h" |
1 | 16 |
9 | 17 #include "cache_maint.h" |
18 #include "collect.h" | |
19 #include "collect-dlg.h" | |
20 #include "dupe.h" | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
21 #include "editors.h" |
586 | 22 #include "filedata.h" |
9 | 23 #include "img-view.h" |
24 #include "preferences.h" | |
25 #include "slideshow.h" | |
26 #include "utilops.h" | |
27 #include "ui_fileops.h" | |
28 #include "ui_tabcomp.h" | |
29 #include "ui_menu.h" | |
30 | |
31 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data, | |
32 GtkAccelGroup *accel_group); | |
1 | 33 |
34 /* | |
35 *----------------------------------------------------------------------------- | |
9 | 36 * menu utils |
1 | 37 *----------------------------------------------------------------------------- |
442 | 38 */ |
1 | 39 |
9 | 40 static GtkWidget *add_menu_item(GtkWidget *menu, gchar *label, GtkAccelGroup *accel_group, |
41 guint accel_key, guint accel_mods, GCallback func, gpointer data) | |
1 | 42 { |
43 GtkWidget *item; | |
44 | |
45 item = gtk_menu_item_new_with_label(label); | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
46 gtk_widget_add_accelerator(item, "activate", accel_group, accel_key, accel_mods, GTK_ACCEL_VISIBLE); |
9 | 47 g_signal_connect(G_OBJECT(item), "activate", func, data); |
48 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
1 | 49 gtk_widget_show(item); |
9 | 50 |
51 return item; | |
1 | 52 } |
53 | |
9 | 54 gpointer submenu_item_get_data(GtkWidget *menu) |
1 | 55 { |
9 | 56 if (!menu->parent || !GTK_IS_MENU(menu->parent)) return NULL; |
1 | 57 |
9 | 58 return g_object_get_data(G_OBJECT(menu->parent), "submenu_data"); |
1 | 59 } |
60 | |
61 /* | |
62 *----------------------------------------------------------------------------- | |
9 | 63 * edit menu |
1 | 64 *----------------------------------------------------------------------------- |
442 | 65 */ |
1 | 66 |
9 | 67 static void add_edit_items(GtkWidget *menu, GCallback func, GtkAccelGroup *accel_grp) |
1 | 68 { |
69 gint i; | |
570
0da87187d5fb
Do not show Copy, Move, Rename, Delete, New Folder external commands
zas_
parents:
512
diff
changeset
|
70 |
0da87187d5fb
Do not show Copy, Move, Rename, Delete, New Folder external commands
zas_
parents:
512
diff
changeset
|
71 for (i = 0; i < GQ_EDITOR_GENERIC_SLOTS; i++) |
1 | 72 { |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
73 gchar *text; |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
74 const gchar *name = editor_get_name(i); |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
75 |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
76 if (!name) continue; |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
77 |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
78 text = g_strdup_printf(_("_%d %s..."), i, name); |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
79 if (accel_grp) |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
80 add_menu_item(menu, text, accel_grp, i + 49, GDK_CONTROL_MASK, func, GINT_TO_POINTER(i)); |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
81 else |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
82 menu_item_add(menu, text, func, GINT_TO_POINTER(i)); |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
83 g_free(text); |
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
84 |
1 | 85 } |
86 } | |
87 | |
9 | 88 GtkWidget *submenu_add_edit(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data) |
1 | 89 { |
9 | 90 GtkWidget *item; |
91 GtkWidget *submenu; | |
1 | 92 |
9 | 93 item = menu_item_add(menu, _("_Edit"), NULL, NULL); |
1 | 94 |
9 | 95 submenu = gtk_menu_new(); |
96 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
97 add_edit_items(submenu, func, NULL); | |
1 | 98 |
9 | 99 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); |
1 | 100 |
9 | 101 if (menu_item) *menu_item = item; |
1 | 102 |
9 | 103 return submenu; |
1 | 104 } |
105 | |
106 /* | |
107 *----------------------------------------------------------------------------- | |
9 | 108 * sorting |
1 | 109 *----------------------------------------------------------------------------- |
9 | 110 */ |
1 | 111 |
9 | 112 gchar *sort_type_get_text(SortType method) |
1 | 113 { |
9 | 114 switch (method) |
115 { | |
116 case SORT_SIZE: | |
117 return _("Sort by size"); | |
118 break; | |
119 case SORT_TIME: | |
120 return _("Sort by date"); | |
121 break; | |
122 case SORT_NONE: | |
123 return _("Unsorted"); | |
124 break; | |
125 case SORT_PATH: | |
126 return _("Sort by path"); | |
127 break; | |
128 case SORT_NUMBER: | |
129 return _("Sort by number"); | |
130 break; | |
131 case SORT_NAME: | |
132 default: | |
133 return _("Sort by name"); | |
134 break; | |
135 } | |
1 | 136 |
9 | 137 return ""; |
138 } | |
1 | 139 |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
140 static GtkWidget *submenu_add_sort_item(GtkWidget *menu, GtkWidget *parent, |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
141 GCallback func, SortType type, |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
142 gint show_current, SortType show_type) |
9 | 143 { |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
144 GtkWidget *item; |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
145 |
9 | 146 if (show_current) |
147 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
148 item = menu_item_add_radio(menu, parent, |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
149 sort_type_get_text(type), (type == show_type), |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
150 func, GINT_TO_POINTER((gint)type)); |
9 | 151 } |
152 else | |
153 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
154 item = menu_item_add(menu, sort_type_get_text(type), |
120 | 155 func, GINT_TO_POINTER((gint)type)); |
9 | 156 } |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
157 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
158 return item; |
9 | 159 } |
1 | 160 |
9 | 161 GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data, |
162 gint include_none, gint include_path, | |
163 gint show_current, SortType type) | |
164 { | |
165 GtkWidget *submenu; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
166 GtkWidget *parent; |
1 | 167 |
9 | 168 submenu = gtk_menu_new(); |
169 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
170 | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
171 parent = submenu_add_sort_item(submenu, NULL, func, SORT_NAME, show_current, type); |
9 | 172 #ifdef HAVE_STRVERSCMP |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
173 submenu_add_sort_item(submenu, parent, func, SORT_NUMBER, show_current, type); |
9 | 174 #endif |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
175 submenu_add_sort_item(submenu, parent, func, SORT_TIME, show_current, type); |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
176 submenu_add_sort_item(submenu, parent, func, SORT_SIZE, show_current, type); |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
177 if (include_path) submenu_add_sort_item(submenu, parent, func, SORT_PATH, show_current, type); |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
178 if (include_none) submenu_add_sort_item(submenu, parent, func, SORT_NONE, show_current, type); |
9 | 179 |
180 if (menu) | |
181 { | |
182 GtkWidget *item; | |
183 | |
184 item = menu_item_add(menu, _("Sort"), NULL, NULL); | |
185 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
186 return item; | |
187 } | |
188 | |
189 return submenu; | |
1 | 190 } |
191 | |
192 /* | |
193 *----------------------------------------------------------------------------- | |
9 | 194 * altering |
1 | 195 *----------------------------------------------------------------------------- |
9 | 196 */ |
1 | 197 |
9 | 198 gchar *alter_type_get_text(AlterType type) |
1 | 199 { |
9 | 200 switch (type) |
1 | 201 { |
9 | 202 case ALTER_ROTATE_90: |
203 return _("_Rotate clockwise"); | |
204 break; | |
205 case ALTER_ROTATE_90_CC: | |
206 return _("Rotate _counterclockwise"); | |
207 break; | |
208 case ALTER_ROTATE_180: | |
209 return _("Rotate _180"); | |
210 break; | |
211 case ALTER_MIRROR: | |
212 return _("_Mirror"); | |
213 break; | |
214 case ALTER_FLIP: | |
215 return _("_Flip"); | |
216 break; | |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
217 case ALTER_DESATURATE: |
398
c4080362d619
image post-processing (rotation and color management) moved to
nadvornik
parents:
318
diff
changeset
|
218 return _("Toggle _grayscale"); |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
219 break; |
439 | 220 case ALTER_NONE: |
221 return _("_Original state"); | |
222 break; | |
9 | 223 default: |
224 break; | |
225 } | |
226 | |
227 return ""; | |
228 } | |
229 | |
230 static void submenu_add_alter_item(GtkWidget *menu, GCallback func, AlterType type, | |
231 GtkAccelGroup *accel_group, guint accel_key, guint accel_mods) | |
232 { | |
233 if (accel_group) | |
234 { | |
235 add_menu_item(menu, alter_type_get_text(type), accel_group, | |
236 accel_key, accel_mods, func, GINT_TO_POINTER((gint)type)); | |
442 | 237 |
9 | 238 } |
239 else | |
240 { | |
241 menu_item_add(menu, alter_type_get_text(type), func, GINT_TO_POINTER((gint)type)); | |
1 | 242 } |
243 } | |
244 | |
9 | 245 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data, |
246 GtkAccelGroup *accel_group) | |
1 | 247 { |
9 | 248 GtkWidget *submenu; |
1 | 249 |
9 | 250 submenu = gtk_menu_new(); |
251 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
1 | 252 |
9 | 253 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90, accel_group, ']', 0); |
254 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90_CC, accel_group, '[', 0); | |
255 submenu_add_alter_item(submenu, func, ALTER_ROTATE_180, accel_group, 'R', GDK_SHIFT_MASK); | |
256 submenu_add_alter_item(submenu, func, ALTER_MIRROR, accel_group, 'M', GDK_SHIFT_MASK); | |
257 submenu_add_alter_item(submenu, func, ALTER_FLIP, accel_group, 'F', GDK_SHIFT_MASK); | |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
258 submenu_add_alter_item(submenu, func, ALTER_DESATURATE, accel_group, 'G', GDK_SHIFT_MASK); |
439 | 259 submenu_add_alter_item(submenu, func, ALTER_NONE, accel_group, 'O', GDK_SHIFT_MASK); |
1 | 260 |
9 | 261 if (menu) |
262 { | |
263 GtkWidget *item; | |
1 | 264 |
9 | 265 item = menu_item_add(menu, _("_Adjust"), NULL, NULL); |
266 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
267 return item; | |
268 } | |
269 | |
270 return submenu; | |
1 | 271 } |
272 | |
9 | 273 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data) |
1 | 274 { |
9 | 275 return real_submenu_add_alter(menu, func, data, NULL); |
1 | 276 } |