Mercurial > geeqie
annotate src/menu.c @ 1518:4eed0789a828
optimized sidecar file check
author | nadvornik |
---|---|
date | Mon, 06 Apr 2009 19:09:55 +0000 |
parents | b106af9689db |
children | 3d9f5c078521 |
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 */ |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
67 static void edit_item_destroy_cb(GtkWidget *widget, gpointer data) |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
68 { |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
69 g_free(data); |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
70 } |
1 | 71 |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
72 static void add_edit_items(GtkWidget *menu, GCallback func, GList *fd_list) |
1 | 73 { |
1272 | 74 GList *editors_list = editor_list_get(); |
75 GList *work = editors_list; | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
76 |
1272 | 77 while (work) |
78 { | |
79 const EditorDescription *editor = work->data; | |
80 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
|
81 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
|
82 |
1400
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1398
diff
changeset
|
83 if (fd_list && EDITOR_ERRORS(editor_command_parse(editor, fd_list, NULL))) |
67573155210c
Add helper macros EDITOR_ERRORS() and EDITOR_ERRORS_BUT_SKIPPED() to clean up the code a bit. Minor tidy up.
zas_
parents:
1398
diff
changeset
|
84 active = FALSE; |
1397
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 { |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
88 GtkWidget *item; |
1398 | 89 const gchar *stock_id = NULL; |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
90 gchar *key = g_strdup(editor->key); |
1398 | 91 |
1413
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
92 if (editor->icon && register_theme_icon_as_stock(key, editor->icon)) |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
93 stock_id = key; |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
94 |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
95 item = menu_item_add_stock(menu, editor->name, stock_id, func, key); |
3bc4967aaa57
Use dynamic allocation for editor key passed to various callbacks.
zas_
parents:
1400
diff
changeset
|
96 g_signal_connect(G_OBJECT(item), "destroy", G_CALLBACK(edit_item_destroy_cb), key); |
1398 | 97 } |
1272 | 98 } |
99 | |
100 g_list_free(editors_list); | |
101 } | |
731
fa8f7d7396cf
Introduce an helper function that returns the name of an editor.
zas_
parents:
730
diff
changeset
|
102 |
1 | 103 |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1284
diff
changeset
|
104 GtkWidget *submenu_add_edit(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data, GList *fd_list) |
1 | 105 { |
9 | 106 GtkWidget *item; |
107 GtkWidget *submenu; | |
1 | 108 |
9 | 109 item = menu_item_add(menu, _("_Edit"), NULL, NULL); |
1 | 110 |
9 | 111 submenu = gtk_menu_new(); |
112 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
|
113 add_edit_items(submenu, func, fd_list); |
1 | 114 |
9 | 115 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); |
1 | 116 |
9 | 117 if (menu_item) *menu_item = item; |
1 | 118 |
9 | 119 return submenu; |
1 | 120 } |
121 | |
122 /* | |
123 *----------------------------------------------------------------------------- | |
9 | 124 * sorting |
1 | 125 *----------------------------------------------------------------------------- |
9 | 126 */ |
1 | 127 |
9 | 128 gchar *sort_type_get_text(SortType method) |
1 | 129 { |
9 | 130 switch (method) |
131 { | |
132 case SORT_SIZE: | |
133 return _("Sort by size"); | |
134 break; | |
135 case SORT_TIME: | |
136 return _("Sort by date"); | |
137 break; | |
138 case SORT_NONE: | |
139 return _("Unsorted"); | |
140 break; | |
141 case SORT_PATH: | |
142 return _("Sort by path"); | |
143 break; | |
144 case SORT_NUMBER: | |
145 return _("Sort by number"); | |
146 break; | |
147 case SORT_NAME: | |
148 default: | |
149 return _("Sort by name"); | |
150 break; | |
151 } | |
1 | 152 |
9 | 153 return ""; |
154 } | |
1 | 155 |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
156 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
|
157 GCallback func, SortType type, |
1434 | 158 gboolean show_current, SortType show_type) |
9 | 159 { |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
160 GtkWidget *item; |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
161 |
9 | 162 if (show_current) |
163 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
164 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
|
165 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
|
166 func, GINT_TO_POINTER((gint)type)); |
9 | 167 } |
168 else | |
169 { | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
170 item = menu_item_add(menu, sort_type_get_text(type), |
120 | 171 func, GINT_TO_POINTER((gint)type)); |
9 | 172 } |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
173 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
174 return item; |
9 | 175 } |
1 | 176 |
9 | 177 GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data, |
1434 | 178 gboolean include_none, gboolean include_path, |
179 gboolean show_current, SortType type) | |
9 | 180 { |
181 GtkWidget *submenu; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
182 GtkWidget *parent; |
1 | 183 |
9 | 184 submenu = gtk_menu_new(); |
185 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
186 | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
187 parent = submenu_add_sort_item(submenu, NULL, func, SORT_NAME, show_current, type); |
9 | 188 #ifdef HAVE_STRVERSCMP |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
189 submenu_add_sort_item(submenu, parent, func, SORT_NUMBER, show_current, type); |
9 | 190 #endif |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
82
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 if (include_none) submenu_add_sort_item(submenu, parent, func, SORT_NONE, show_current, type); |
9 | 195 |
196 if (menu) | |
197 { | |
198 GtkWidget *item; | |
199 | |
200 item = menu_item_add(menu, _("Sort"), NULL, NULL); | |
201 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
202 return item; | |
203 } | |
204 | |
205 return submenu; | |
1 | 206 } |
207 | |
208 /* | |
209 *----------------------------------------------------------------------------- | |
9 | 210 * altering |
1 | 211 *----------------------------------------------------------------------------- |
9 | 212 */ |
1 | 213 |
9 | 214 gchar *alter_type_get_text(AlterType type) |
1 | 215 { |
9 | 216 switch (type) |
1 | 217 { |
9 | 218 case ALTER_ROTATE_90: |
219 return _("_Rotate clockwise"); | |
220 break; | |
221 case ALTER_ROTATE_90_CC: | |
222 return _("Rotate _counterclockwise"); | |
223 break; | |
224 case ALTER_ROTATE_180: | |
225 return _("Rotate _180"); | |
226 break; | |
227 case ALTER_MIRROR: | |
228 return _("_Mirror"); | |
229 break; | |
230 case ALTER_FLIP: | |
231 return _("_Flip"); | |
232 break; | |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
233 case ALTER_DESATURATE: |
398
c4080362d619
image post-processing (rotation and color management) moved to
nadvornik
parents:
318
diff
changeset
|
234 return _("Toggle _grayscale"); |
82
a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
235 break; |
439 | 236 case ALTER_NONE: |
237 return _("_Original state"); | |
238 break; | |
9 | 239 default: |
240 break; | |
241 } | |
242 | |
243 return ""; | |
244 } | |
245 | |
246 static void submenu_add_alter_item(GtkWidget *menu, GCallback func, AlterType type, | |
247 GtkAccelGroup *accel_group, guint accel_key, guint accel_mods) | |
248 { | |
249 if (accel_group) | |
250 { | |
251 add_menu_item(menu, alter_type_get_text(type), accel_group, | |
252 accel_key, accel_mods, func, GINT_TO_POINTER((gint)type)); | |
442 | 253 |
9 | 254 } |
255 else | |
256 { | |
257 menu_item_add(menu, alter_type_get_text(type), func, GINT_TO_POINTER((gint)type)); | |
1 | 258 } |
259 } | |
260 | |
9 | 261 static GtkWidget *real_submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data, |
262 GtkAccelGroup *accel_group) | |
1 | 263 { |
9 | 264 GtkWidget *submenu; |
1 | 265 |
9 | 266 submenu = gtk_menu_new(); |
267 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
1 | 268 |
9 | 269 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90, accel_group, ']', 0); |
270 submenu_add_alter_item(submenu, func, ALTER_ROTATE_90_CC, accel_group, '[', 0); | |
271 submenu_add_alter_item(submenu, func, ALTER_ROTATE_180, accel_group, 'R', GDK_SHIFT_MASK); | |
272 submenu_add_alter_item(submenu, func, ALTER_MIRROR, accel_group, 'M', GDK_SHIFT_MASK); | |
273 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
|
274 submenu_add_alter_item(submenu, func, ALTER_DESATURATE, accel_group, 'G', GDK_SHIFT_MASK); |
439 | 275 submenu_add_alter_item(submenu, func, ALTER_NONE, accel_group, 'O', GDK_SHIFT_MASK); |
1 | 276 |
9 | 277 if (menu) |
278 { | |
279 GtkWidget *item; | |
1 | 280 |
9 | 281 item = menu_item_add(menu, _("_Adjust"), NULL, NULL); |
282 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
283 return item; | |
284 } | |
285 | |
286 return submenu; | |
1 | 287 } |
288 | |
9 | 289 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data) |
1 | 290 { |
9 | 291 return real_submenu_add_alter(menu, func, data, NULL); |
1 | 292 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
731
diff
changeset
|
293 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |