Mercurial > geeqie
annotate src/menu.c @ 1398:9e7aed6ba6bd
Display icons in edit contextual menu.
author | zas_ |
---|---|
date | Sun, 08 Mar 2009 14:27:19 +0000 |
parents | a0bd58a6535f |
children | 67573155210c |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 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" |
1398 | 24 #include "pixbuf_util.h" |
9 | 25 #include "preferences.h" |
26 #include "slideshow.h" | |
27 #include "utilops.h" | |
28 #include "ui_fileops.h" | |
29 #include "ui_tabcomp.h" | |
30 #include "ui_menu.h" | |
31 | |
32 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data, | |
33 GtkAccelGroup *accel_group); | |
1 | 34 |
35 /* | |
36 *----------------------------------------------------------------------------- | |
9 | 37 * menu utils |
1 | 38 *----------------------------------------------------------------------------- |
442 | 39 */ |
1 | 40 |
9 | 41 static GtkWidget *add_menu_item(GtkWidget *menu, gchar *label, GtkAccelGroup *accel_group, |
42 guint accel_key, guint accel_mods, GCallback func, gpointer data) | |
1 | 43 { |
44 GtkWidget *item; | |
45 | |
46 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
|
47 gtk_widget_add_accelerator(item, "activate", accel_group, accel_key, accel_mods, GTK_ACCEL_VISIBLE); |
9 | 48 g_signal_connect(G_OBJECT(item), "activate", func, data); |
49 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
1 | 50 gtk_widget_show(item); |
9 | 51 |
52 return item; | |
1 | 53 } |
54 | |
9 | 55 gpointer submenu_item_get_data(GtkWidget *menu) |
1 | 56 { |
9 | 57 if (!menu->parent || !GTK_IS_MENU(menu->parent)) return NULL; |
1 | 58 |
9 | 59 return g_object_get_data(G_OBJECT(menu->parent), "submenu_data"); |
1 | 60 } |
61 | |
62 /* | |
63 *----------------------------------------------------------------------------- | |
9 | 64 * edit menu |
1 | 65 *----------------------------------------------------------------------------- |
442 | 66 */ |
1 | 67 |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
68 static void add_edit_items(GtkWidget *menu, GCallback func, GList *fd_list) |
1 | 69 { |
1272 | 70 GList *editors_list = editor_list_get(); |
71 GList *work = editors_list; | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
72 |
1272 | 73 while (work) |
74 { | |
75 const EditorDescription *editor = work->data; | |
76 work = work->next; | |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
77 gboolean active = TRUE; |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
78 |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
79 if (fd_list) |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
80 { |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
81 gint flags = editor_command_parse(editor, fd_list, NULL); |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
82 if ((flags & EDITOR_ERROR_MASK) != 0) |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
83 active = FALSE; |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
84 } |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
85 |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
86 if (active) |
1398 | 87 { |
88 const gchar *stock_id = NULL; | |
89 if (editor->icon && register_theme_icon_as_stock(editor->key, editor->icon)) | |
90 stock_id = editor->key; | |
91 | |
92 menu_item_add_stock(menu, editor->name, stock_id, func, editor->key); | |
93 } | |
1272 | 94 } |
95 | |
96 g_list_free(editors_list); | |
97 } | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
98 |
1 | 99 |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
100 GtkWidget *submenu_add_edit(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data, GList *fd_list) |
1 | 101 { |
9 | 102 GtkWidget *item; |
103 GtkWidget *submenu; | |
1 | 104 |
9 | 105 item = menu_item_add(menu, _("_Edit"), NULL, NULL); |
1 | 106 |
9 | 107 submenu = gtk_menu_new(); |
108 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
109 add_edit_items(submenu, func, fd_list); |
1 | 110 |
9 | 111 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); |
1 | 112 |
9 | 113 if (menu_item) *menu_item = item; |
1 | 114 |
9 | 115 return submenu; |
1 | 116 } |
117 | |
118 /* | |
119 *----------------------------------------------------------------------------- | |
9 | 120 * sorting |
1 | 121 *----------------------------------------------------------------------------- |
9 | 122 */ |
1 | 123 |
9 | 124 gchar *sort_type_get_text(SortType method) |
1 | 125 { |
9 | 126 switch (method) |
127 { | |
128 case SORT_SIZE: | |
129 return _("Sort by size"); | |
130 break; | |
131 case SORT_TIME: | |
132 return _("Sort by date"); | |
133 break; | |
134 case SORT_NONE: | |
135 return _("Unsorted"); | |
136 break; | |
137 case SORT_PATH: | |
138 return _("Sort by path"); | |
139 break; | |
140 case SORT_NUMBER: | |
141 return _("Sort by number"); | |
142 break; | |
143 case SORT_NAME: | |
144 default: | |
145 return _("Sort by name"); | |
146 break; | |
147 } | |
1 | 148 |
9 | 149 return ""; |
150 } | |
1 | 151 |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
152 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
|
153 GCallback func, SortType type, |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
154 gint show_current, SortType show_type) |
9 | 155 { |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
156 GtkWidget *item; |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
157 |
9 | 158 if (show_current) |
159 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
160 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
|
161 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
|
162 func, GINT_TO_POINTER((gint)type)); |
9 | 163 } |
164 else | |
165 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
166 item = menu_item_add(menu, sort_type_get_text(type), |
120 | 167 func, GINT_TO_POINTER((gint)type)); |
9 | 168 } |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
169 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
170 return item; |
9 | 171 } |
1 | 172 |
9 | 173 GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data, |
174 gint include_none, gint include_path, | |
175 gint show_current, SortType type) | |
176 { | |
177 GtkWidget *submenu; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
178 GtkWidget *parent; |
1 | 179 |
9 | 180 submenu = gtk_menu_new(); |
181 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
182 | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
183 parent = submenu_add_sort_item(submenu, NULL, func, SORT_NAME, show_current, type); |
9 | 184 #ifdef HAVE_STRVERSCMP |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
185 submenu_add_sort_item(submenu, parent, func, SORT_NUMBER, show_current, type); |
9 | 186 #endif |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 if (include_none) submenu_add_sort_item(submenu, parent, func, SORT_NONE, show_current, type); |
9 | 191 |
192 if (menu) | |
193 { | |
194 GtkWidget *item; | |
195 | |
196 item = menu_item_add(menu, _("Sort"), NULL, NULL); | |
197 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
198 return item; | |
199 } | |
200 | |
201 return submenu; | |
1 | 202 } |
203 | |
204 /* | |
205 *----------------------------------------------------------------------------- | |
9 | 206 * altering |
1 | 207 *----------------------------------------------------------------------------- |
9 | 208 */ |
1 | 209 |
9 | 210 gchar *alter_type_get_text(AlterType type) |
1 | 211 { |
9 | 212 switch (type) |
1 | 213 { |
9 | 214 case ALTER_ROTATE_90: |
215 return _("_Rotate clockwise"); | |
216 break; | |
217 case ALTER_ROTATE_90_CC: | |
218 return _("Rotate _counterclockwise"); | |
219 break; | |
220 case ALTER_ROTATE_180: | |
221 return _("Rotate _180"); | |
222 break; | |
223 case ALTER_MIRROR: | |
224 return _("_Mirror"); | |
225 break; | |
226 case ALTER_FLIP: | |
227 return _("_Flip"); | |
228 break; | |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
229 case ALTER_DESATURATE: |
398
c4080362d619
image post-processing (rotation and color management) moved to
nadvornik
parents:
318
diff
changeset
|
230 return _("Toggle _grayscale"); |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
231 break; |
439 | 232 case ALTER_NONE: |
233 return _("_Original state"); | |
234 break; | |
9 | 235 default: |
236 break; | |
237 } | |
238 | |
239 return ""; | |
240 } | |
241 | |
242 static void submenu_add_alter_item(GtkWidget *menu, GCallback func, AlterType type, | |
243 GtkAccelGroup *accel_group, guint accel_key, guint accel_mods) | |
244 { | |
245 if (accel_group) | |
246 { | |
247 add_menu_item(menu, alter_type_get_text(type), accel_group, | |
248 accel_key, accel_mods, func, GINT_TO_POINTER((gint)type)); | |
442 | 249 |
9 | 250 } |
251 else | |
252 { | |
253 menu_item_add(menu, alter_type_get_text(type), func, GINT_TO_POINTER((gint)type)); | |
1 | 254 } |
255 } | |
256 | |
9 | 257 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data, |
258 GtkAccelGroup *accel_group) | |
1 | 259 { |
9 | 260 GtkWidget *submenu; |
1 | 261 |
9 | 262 submenu = gtk_menu_new(); |
263 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
1 | 264 |
9 | 265 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90, accel_group, ']', 0); |
266 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90_CC, accel_group, '[', 0); | |
267 submenu_add_alter_item(submenu, func, ALTER_ROTATE_180, accel_group, 'R', GDK_SHIFT_MASK); | |
268 submenu_add_alter_item(submenu, func, ALTER_MIRROR, accel_group, 'M', GDK_SHIFT_MASK); | |
269 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
|
270 submenu_add_alter_item(submenu, func, ALTER_DESATURATE, accel_group, 'G', GDK_SHIFT_MASK); |
439 | 271 submenu_add_alter_item(submenu, func, ALTER_NONE, accel_group, 'O', GDK_SHIFT_MASK); |
1 | 272 |
9 | 273 if (menu) |
274 { | |
275 GtkWidget *item; | |
1 | 276 |
9 | 277 item = menu_item_add(menu, _("_Adjust"), NULL, NULL); |
278 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
279 return item; | |
280 } | |
281 | |
282 return submenu; | |
1 | 283 } |
284 | |
9 | 285 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data) |
1 | 286 { |
9 | 287 return real_submenu_add_alter(menu, func, data, NULL); |
1 | 288 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
731
diff
changeset
|
289 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |