Mercurial > geeqie
annotate src/menu.c @ 1807:3a2aff957816
Allow scrollview to grow when generic dialog is resized (ie. Metadata write ? dialog). Do not force scrollbar if not needed.
author | zas_ |
---|---|
date | Sat, 27 Feb 2010 23:31:07 +0000 |
parents | 956aab097ea7 |
children |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1802 | 4 * Copyright (C) 2008 - 2010 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 |
1742 | 83 if (fd_list && EDITOR_ERRORS(editor_command_parse(editor, fd_list, FALSE, NULL))) |
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
|
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 |
1667 | 156 static GtkWidget *submenu_add_sort_item(GtkWidget *menu, |
113
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 { | |
1667 | 164 item = menu_item_add_radio(menu, |
165 sort_type_get_text(type), GINT_TO_POINTER((gint)type), (type == show_type), | |
113
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; | |
1 | 182 |
9 | 183 submenu = gtk_menu_new(); |
184 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); | |
185 | |
1667 | 186 submenu_add_sort_item(submenu, func, SORT_NAME, show_current, type); |
9 | 187 #ifdef HAVE_STRVERSCMP |
1667 | 188 submenu_add_sort_item(submenu, func, SORT_NUMBER, show_current, type); |
9 | 189 #endif |
1667 | 190 submenu_add_sort_item(submenu, func, SORT_TIME, show_current, type); |
191 submenu_add_sort_item(submenu, func, SORT_SIZE, show_current, type); | |
192 if (include_path) submenu_add_sort_item(submenu, func, SORT_PATH, show_current, type); | |
193 if (include_none) submenu_add_sort_item(submenu, func, SORT_NONE, show_current, type); | |
9 | 194 |
195 if (menu) | |
196 { | |
197 GtkWidget *item; | |
198 | |
199 item = menu_item_add(menu, _("Sort"), NULL, NULL); | |
200 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
201 return item; | |
202 } | |
203 | |
204 return submenu; | |
1 | 205 } |
206 | |
207 /* | |
208 *----------------------------------------------------------------------------- | |
9 | 209 * altering |
1 | 210 *----------------------------------------------------------------------------- |
9 | 211 */ |
1 | 212 |
9 | 213 gchar *alter_type_get_text(AlterType type) |
1 | 214 { |
9 | 215 switch (type) |
1 | 216 { |
9 | 217 case ALTER_ROTATE_90: |
218 return _("_Rotate clockwise"); | |
219 break; | |
220 case ALTER_ROTATE_90_CC: | |
221 return _("Rotate _counterclockwise"); | |
222 break; | |
223 case ALTER_ROTATE_180: | |
224 return _("Rotate _180"); | |
225 break; | |
226 case ALTER_MIRROR: | |
227 return _("_Mirror"); | |
228 break; | |
229 case ALTER_FLIP: | |
230 return _("_Flip"); | |
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); | |
439 | 270 submenu_add_alter_item(submenu, func, ALTER_NONE, accel_group, 'O', GDK_SHIFT_MASK); |
1 | 271 |
9 | 272 if (menu) |
273 { | |
274 GtkWidget *item; | |
1 | 275 |
1566 | 276 item = menu_item_add(menu, _("_Orientation"), NULL, NULL); |
9 | 277 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); |
278 return item; | |
279 } | |
280 | |
281 return submenu; | |
1 | 282 } |
283 | |
9 | 284 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data) |
1 | 285 { |
9 | 286 return real_submenu_add_alter(menu, func, data, NULL); |
1 | 287 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
731
diff
changeset
|
288 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |