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