Remove some leftover from toolbar rc entries
[geeqie.git] / src / layout_util.c
1 /*
2  * Geeqie
3  * (C) 2004 John Ellis
4  * Copyright (C) 2008 - 2012 The Geeqie Team
5  *
6  * Author: John Ellis
7  *
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!
11  */
12
13
14 #include "main.h"
15 #include "layout_util.h"
16
17 #include "advanced_exif.h"
18 #include "bar_sort.h"
19 #include "bar.h"
20 #include "cache_maint.h"
21 #include "collect.h"
22 #include "collect-dlg.h"
23 #include "compat.h"
24 #include "color-man.h"
25 #include "dupe.h"
26 #include "editors.h"
27 #include "filedata.h"
28 #include "history_list.h"
29 #include "image-overlay.h"
30 #include "histogram.h"
31 #include "img-view.h"
32 #include "layout_image.h"
33 #include "logwindow.h"
34 #include "misc.h"
35 #include "pan-view.h"
36 #include "pixbuf_util.h"
37 #include "preferences.h"
38 #include "print.h"
39 #include "search.h"
40 #include "ui_fileops.h"
41 #include "ui_menu.h"
42 #include "ui_misc.h"
43 #include "ui_tabcomp.h"
44 #include "utilops.h"
45 #include "view_dir.h"
46 #include "window.h"
47 #include "metadata.h"
48 #include "desktop_file.h"
49
50 #include <gdk/gdkkeysyms.h> /* for keyboard values */
51
52
53 #define MENU_EDIT_ACTION_OFFSET 16
54
55 static gboolean layout_bar_enabled(LayoutWindow *lw);
56 static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
57 static void layout_util_sync_views(LayoutWindow *lw);
58
59 /*
60  *-----------------------------------------------------------------------------
61  * keyboard handler
62  *-----------------------------------------------------------------------------
63  */
64
65 static guint tree_key_overrides[] = {
66         GDK_KEY_Page_Up,        GDK_KEY_KP_Page_Up,
67         GDK_KEY_Page_Down,      GDK_KEY_KP_Page_Down,
68         GDK_KEY_Home,   GDK_KEY_KP_Home,
69         GDK_KEY_End,    GDK_KEY_KP_End
70 };
71
72 static gboolean layout_key_match(guint keyval)
73 {
74         guint i;
75
76         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
77                 {
78                 if (keyval == tree_key_overrides[i]) return TRUE;
79                 }
80
81         return FALSE;
82 }
83
84 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
85 {
86         LayoutWindow *lw = data;
87         GtkWidget *focused;
88         gboolean stop_signal = FALSE;
89         gint x = 0;
90         gint y = 0;
91
92         if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
93                 {
94                 if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
95                         {
96                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
97                         }
98
99                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
100                  * so when the some widgets have focus, give them priority (HACK)
101                  */
102                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
103                         {
104                         return TRUE;
105                         }
106                 }
107         if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
108             !layout_key_match(event->keyval) &&
109             gtk_widget_event(lw->vd->view, (GdkEvent *)event))
110                 {
111                 return TRUE;
112                 }
113         if (lw->bar &&
114             bar_event(lw->bar, (GdkEvent *)event))
115                 {
116                 return TRUE;
117                 }
118
119         focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
120         if (lw->image &&
121             ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
122                 {
123                 stop_signal = TRUE;
124                 switch (event->keyval)
125                         {
126                         case GDK_KEY_Left: case GDK_KEY_KP_Left:
127                                 x -= 1;
128                                 break;
129                         case GDK_KEY_Right: case GDK_KEY_KP_Right:
130                                 x += 1;
131                                 break;
132                         case GDK_KEY_Up: case GDK_KEY_KP_Up:
133                                 y -= 1;
134                                 break;
135                         case GDK_KEY_Down: case GDK_KEY_KP_Down:
136                                 y += 1;
137                                 break;
138                         default:
139                                 stop_signal = FALSE;
140                                 break;
141                         }
142
143                 if (!stop_signal &&
144                     !(event->state & GDK_CONTROL_MASK))
145                         {
146                         stop_signal = TRUE;
147                         switch (event->keyval)
148                                 {
149                                 case GDK_KEY_Menu:
150                                         layout_image_menu_popup(lw);
151                                         break;
152                                 default:
153                                         stop_signal = FALSE;
154                                         break;
155                                 }
156                         }
157                 }
158
159         if (x != 0 || y!= 0)
160                 {
161                 keyboard_scroll_calc(&x, &y, event);
162                 layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK));
163                 }
164
165         return stop_signal;
166 }
167
168 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
169 {
170         g_signal_connect(G_OBJECT(window), "key_press_event",
171                          G_CALLBACK(layout_key_press_cb), lw);
172 }
173
174 /*
175  *-----------------------------------------------------------------------------
176  * menu callbacks
177  *-----------------------------------------------------------------------------
178  */
179
180
181 static GtkWidget *layout_window(LayoutWindow *lw)
182 {
183         return lw->full_screen ? lw->full_screen->window : lw->window;
184 }
185
186 static void layout_exit_fullscreen(LayoutWindow *lw)
187 {
188         if (!lw->full_screen) return;
189         layout_image_full_screen_stop(lw);
190 }
191
192 static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
193 {
194         LayoutWindow *lw = data;
195         LayoutWindow *nw;
196         LayoutOptions lop;
197         gboolean tmp = options->save_window_positions;
198         options->save_window_positions = FALSE; /* let the windowmanager decide for the first time */
199
200         layout_exit_fullscreen(lw);
201
202         layout_sync_options_with_current_state(lw);
203         lop = lw->options; /* we can copy it directly, no strings are modified */
204
205         lop.id = NULL; /* get a new id */
206         nw = layout_new(NULL, &lop);
207         layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
208         layout_set_fd(nw, lw->dir_fd);
209         options->save_window_positions = tmp;
210 }
211
212 static void layout_menu_new_cb(GtkAction *action, gpointer data)
213 {
214         LayoutWindow *lw = data;
215
216         layout_exit_fullscreen(lw);
217         collection_window_new(NULL);
218 }
219
220 static void layout_menu_open_cb(GtkAction *action, gpointer data)
221 {
222         LayoutWindow *lw = data;
223
224         layout_exit_fullscreen(lw);
225         collection_dialog_load(NULL);
226 }
227
228 static void layout_menu_search_cb(GtkAction *action, gpointer data)
229 {
230         LayoutWindow *lw = data;
231
232         layout_exit_fullscreen(lw);
233         search_new(lw->dir_fd, layout_image_get_fd(lw));
234 }
235
236 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
237 {
238         LayoutWindow *lw = data;
239
240         layout_exit_fullscreen(lw);
241         dupe_window_new(DUPE_MATCH_NAME);
242 }
243
244 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
245 {
246         LayoutWindow *lw = data;
247
248         layout_exit_fullscreen(lw);
249         pan_window_new(lw->dir_fd);
250 }
251
252 static void layout_menu_print_cb(GtkAction *action, gpointer data)
253 {
254         LayoutWindow *lw = data;
255
256         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
257 }
258
259 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
260 {
261         LayoutWindow *lw = data;
262
263         if (lw->vd) vd_new_folder(lw->vd, lw->dir_fd);
264 }
265
266 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
267 {
268         LayoutWindow *lw = data;
269
270         file_util_copy(NULL, layout_selection_list(lw), NULL, layout_window(lw));
271 }
272
273 static void layout_menu_copy_path_cb(GtkAction *action, gpointer data)
274 {
275         LayoutWindow *lw = data;
276
277         file_util_copy_path_list_to_clipboard(layout_selection_list(lw));
278 }
279
280 static void layout_menu_move_cb(GtkAction *action, gpointer data)
281 {
282         LayoutWindow *lw = data;
283
284         file_util_move(NULL, layout_selection_list(lw), NULL, layout_window(lw));
285 }
286
287 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
288 {
289         LayoutWindow *lw = data;
290
291         file_util_rename(NULL, layout_selection_list(lw), layout_window(lw));
292 }
293
294 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
295 {
296         LayoutWindow *lw = data;
297
298         file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
299 }
300
301 static void layout_menu_disable_grouping_cb(GtkAction *action, gpointer data)
302 {
303         LayoutWindow *lw = data;
304
305         file_data_disable_grouping_list(layout_selection_list(lw), TRUE);
306 }
307
308 static void layout_menu_enable_grouping_cb(GtkAction *action, gpointer data)
309 {
310         LayoutWindow *lw = data;
311
312         file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
313 }
314
315 static void layout_menu_close_cb(GtkAction *action, gpointer data)
316 {
317         LayoutWindow *lw = data;
318
319         layout_exit_fullscreen(lw);
320         layout_close(lw);
321 }
322
323 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
324 {
325         exit_program();
326 }
327
328 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
329 {
330         LayoutWindow *lw = data;
331
332         layout_image_alter_orientation(lw, ALTER_ROTATE_90);
333 }
334
335 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
336 {
337         LayoutWindow *lw = data;
338
339         layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
340 }
341
342 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
343 {
344         LayoutWindow *lw = data;
345
346         layout_image_alter_orientation(lw, ALTER_ROTATE_180);
347 }
348
349 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
350 {
351         LayoutWindow *lw = data;
352
353         layout_image_alter_orientation(lw, ALTER_MIRROR);
354 }
355
356 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
357 {
358         LayoutWindow *lw = data;
359
360         layout_image_alter_orientation(lw, ALTER_FLIP);
361 }
362
363 static void layout_menu_alter_desaturate_cb(GtkToggleAction *action, gpointer data)
364 {
365         LayoutWindow *lw = data;
366
367         layout_image_set_desaturate(lw, gtk_toggle_action_get_active(action));
368 }
369
370 static void layout_menu_alter_none_cb(GtkAction *action, gpointer data)
371 {
372         LayoutWindow *lw = data;
373
374         layout_image_alter_orientation(lw, ALTER_NONE);
375 }
376
377 static void layout_menu_config_cb(GtkAction *action, gpointer data)
378 {
379         LayoutWindow *lw = data;
380
381         layout_exit_fullscreen(lw);
382         show_config_window();
383 }
384
385 static void layout_menu_editors_cb(GtkAction *action, gpointer data)
386 {
387         LayoutWindow *lw = data;
388
389         layout_exit_fullscreen(lw);
390         show_editor_list_window();
391 }
392
393 static void layout_menu_layout_config_cb(GtkAction *action, gpointer data)
394 {
395         LayoutWindow *lw = data;
396
397         layout_exit_fullscreen(lw);
398         layout_show_config_window(lw);
399 }
400
401 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
402 {
403         LayoutWindow *lw = data;
404
405         layout_exit_fullscreen(lw);
406         cache_manager_show();
407 }
408
409 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
410 {
411         LayoutWindow *lw = data;
412
413         layout_image_to_root(lw);
414 }
415
416 /* single window zoom */
417 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
418 {
419         LayoutWindow *lw = data;
420
421         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
422 }
423
424 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
425 {
426         LayoutWindow *lw = data;
427
428         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
429 }
430
431 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
432 {
433         LayoutWindow *lw = data;
434
435         layout_image_zoom_set(lw, 1.0, FALSE);
436 }
437
438 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
439 {
440         LayoutWindow *lw = data;
441
442         layout_image_zoom_set(lw, 0.0, FALSE);
443 }
444
445 static void layout_menu_zoom_fit_hor_cb(GtkAction *action, gpointer data)
446 {
447         LayoutWindow *lw = data;
448
449         layout_image_zoom_set_fill_geometry(lw, FALSE, FALSE);
450 }
451
452 static void layout_menu_zoom_fit_vert_cb(GtkAction *action, gpointer data)
453 {
454         LayoutWindow *lw = data;
455
456         layout_image_zoom_set_fill_geometry(lw, TRUE, FALSE);
457 }
458
459 static void layout_menu_zoom_2_1_cb(GtkAction *action, gpointer data)
460 {
461         LayoutWindow *lw = data;
462
463         layout_image_zoom_set(lw, 2.0, FALSE);
464 }
465
466 static void layout_menu_zoom_3_1_cb(GtkAction *action, gpointer data)
467 {
468         LayoutWindow *lw = data;
469
470         layout_image_zoom_set(lw, 3.0, FALSE);
471 }
472 static void layout_menu_zoom_4_1_cb(GtkAction *action, gpointer data)
473 {
474         LayoutWindow *lw = data;
475
476         layout_image_zoom_set(lw, 4.0, FALSE);
477 }
478
479 static void layout_menu_zoom_1_2_cb(GtkAction *action, gpointer data)
480 {
481         LayoutWindow *lw = data;
482
483         layout_image_zoom_set(lw, -2.0, FALSE);
484 }
485
486 static void layout_menu_zoom_1_3_cb(GtkAction *action, gpointer data)
487 {
488         LayoutWindow *lw = data;
489
490         layout_image_zoom_set(lw, -3.0, FALSE);
491 }
492
493 static void layout_menu_zoom_1_4_cb(GtkAction *action, gpointer data)
494 {
495         LayoutWindow *lw = data;
496
497         layout_image_zoom_set(lw, -4.0, FALSE);
498 }
499
500 /* connected zoom */
501 static void layout_menu_connect_zoom_in_cb(GtkAction *action, gpointer data)
502 {
503         LayoutWindow *lw = data;
504
505         layout_image_zoom_adjust(lw, get_zoom_increment(), TRUE);
506 }
507
508 static void layout_menu_connect_zoom_out_cb(GtkAction *action, gpointer data)
509 {
510         LayoutWindow *lw = data;
511
512         layout_image_zoom_adjust(lw, -get_zoom_increment(), TRUE);
513 }
514
515 static void layout_menu_connect_zoom_1_1_cb(GtkAction *action, gpointer data)
516 {
517         LayoutWindow *lw = data;
518
519         layout_image_zoom_set(lw, 1.0, TRUE);
520 }
521
522 static void layout_menu_connect_zoom_fit_cb(GtkAction *action, gpointer data)
523 {
524         LayoutWindow *lw = data;
525
526         layout_image_zoom_set(lw, 0.0, TRUE);
527 }
528
529 static void layout_menu_connect_zoom_fit_hor_cb(GtkAction *action, gpointer data)
530 {
531         LayoutWindow *lw = data;
532
533         layout_image_zoom_set_fill_geometry(lw, FALSE, TRUE);
534 }
535
536 static void layout_menu_connect_zoom_fit_vert_cb(GtkAction *action, gpointer data)
537 {
538         LayoutWindow *lw = data;
539
540         layout_image_zoom_set_fill_geometry(lw, TRUE, TRUE);
541 }
542
543 static void layout_menu_connect_zoom_2_1_cb(GtkAction *action, gpointer data)
544 {
545         LayoutWindow *lw = data;
546
547         layout_image_zoom_set(lw, 2.0, TRUE);
548 }
549
550 static void layout_menu_connect_zoom_3_1_cb(GtkAction *action, gpointer data)
551 {
552         LayoutWindow *lw = data;
553
554         layout_image_zoom_set(lw, 3.0, TRUE);
555 }
556 static void layout_menu_connect_zoom_4_1_cb(GtkAction *action, gpointer data)
557 {
558         LayoutWindow *lw = data;
559
560         layout_image_zoom_set(lw, 4.0, TRUE);
561 }
562
563 static void layout_menu_connect_zoom_1_2_cb(GtkAction *action, gpointer data)
564 {
565         LayoutWindow *lw = data;
566
567         layout_image_zoom_set(lw, -2.0, TRUE);
568 }
569
570 static void layout_menu_connect_zoom_1_3_cb(GtkAction *action, gpointer data)
571 {
572         LayoutWindow *lw = data;
573
574         layout_image_zoom_set(lw, -3.0, TRUE);
575 }
576
577 static void layout_menu_connect_zoom_1_4_cb(GtkAction *action, gpointer data)
578 {
579         LayoutWindow *lw = data;
580
581         layout_image_zoom_set(lw, -4.0, TRUE);
582 }
583
584
585 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
586 {
587         LayoutWindow *lw = data;
588         ImageSplitMode mode;
589
590         layout_exit_fullscreen(lw);
591         mode = gtk_radio_action_get_current_value(action);
592         layout_split_change(lw, mode);
593 }
594
595
596 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
597 {
598         LayoutWindow *lw = data;
599
600         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
601 }
602
603
604 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
605 {
606         LayoutWindow *lw = data;
607
608         layout_exit_fullscreen(lw);
609         layout_views_set(lw, lw->options.dir_view_type, (FileViewType) gtk_radio_action_get_current_value(action));
610 }
611
612 static void layout_menu_view_dir_as_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
613 {
614         LayoutWindow *lw = data;
615
616         layout_exit_fullscreen(lw);
617         layout_views_set(lw, (DirViewType) gtk_radio_action_get_current_value(action), lw->options.file_view_type);
618 }
619
620 static void layout_menu_view_in_new_window_cb(GtkAction *action, gpointer data)
621 {
622         LayoutWindow *lw = data;
623
624         layout_exit_fullscreen(lw);
625         view_window_new(layout_image_get_fd(lw));
626 }
627
628 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
629 {
630         LayoutWindow *lw = data;
631
632         layout_image_full_screen_toggle(lw);
633 }
634
635 static void layout_menu_escape_cb(GtkAction *action, gpointer data)
636 {
637         LayoutWindow *lw = data;
638
639         layout_exit_fullscreen(lw);
640 }
641
642 static void layout_menu_overlay_toggle_cb(GtkAction *action, gpointer data)
643 {
644         LayoutWindow *lw = data;
645
646         image_osd_toggle(lw->image);
647         layout_util_sync_views(lw);
648 }
649
650
651 static void layout_menu_overlay_cb(GtkToggleAction *action, gpointer data)
652 {
653         LayoutWindow *lw = data;
654
655         if (gtk_toggle_action_get_active(action))
656                 {
657                 OsdShowFlags flags = image_osd_get(lw->image);
658
659                 if ((flags | OSD_SHOW_INFO | OSD_SHOW_STATUS) != flags)
660                         image_osd_set(lw->image, flags | OSD_SHOW_INFO | OSD_SHOW_STATUS);
661                 }
662         else
663                 {
664                 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
665
666                 image_osd_set(lw->image, OSD_SHOW_NOTHING);
667                 gtk_toggle_action_set_active(histogram_action, FALSE); /* this calls layout_menu_histogram_cb */
668                 }
669 }
670
671 static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
672 {
673         LayoutWindow *lw = data;
674
675         if (gtk_toggle_action_get_active(action))
676                 {
677                 image_osd_set(lw->image, OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_HISTOGRAM);
678                 layout_util_sync_views(lw); /* show the overlay state, default channel and mode in the menu */
679                 }
680         else
681                 {
682                 OsdShowFlags flags = image_osd_get(lw->image);
683                 if (flags & OSD_SHOW_HISTOGRAM)
684                         image_osd_set(lw->image, flags & ~OSD_SHOW_HISTOGRAM);
685                 }
686 }
687
688 static void layout_menu_histogram_toggle_channel_cb(GtkAction *action, gpointer data)
689 {
690         LayoutWindow *lw = data;
691
692         image_osd_histogram_toggle_channel(lw->image);
693         layout_util_sync_views(lw);
694 }
695
696 static void layout_menu_histogram_toggle_mode_cb(GtkAction *action, gpointer data)
697 {
698         LayoutWindow *lw = data;
699
700         image_osd_histogram_toggle_mode(lw->image);
701         layout_util_sync_views(lw);
702 }
703
704 static void layout_menu_histogram_channel_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
705 {
706         LayoutWindow *lw = data;
707         gint channel = gtk_radio_action_get_current_value(action);
708         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
709
710         if (channel < 0 || channel >= HCHAN_COUNT) return;
711
712         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
713         image_osd_histogram_set_channel(lw->image, channel);
714 }
715
716 static void layout_menu_histogram_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
717 {
718         LayoutWindow *lw = data;
719         gint mode = gtk_radio_action_get_current_value(action);
720         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
721
722         if (mode < 0 || mode > 1) return;
723
724         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
725         image_osd_histogram_set_mode(lw->image, mode);
726 }
727
728 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
729 {
730         LayoutWindow *lw = data;
731
732         layout_refresh(lw);
733 }
734
735 static void layout_menu_bar_exif_cb(GtkAction *action, gpointer data)
736 {
737         LayoutWindow *lw = data;
738
739         layout_exit_fullscreen(lw);
740         layout_exif_window_new(lw);
741 }
742
743 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
744 {
745         LayoutWindow *lw = data;
746
747         if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return;
748
749         layout_exit_fullscreen(lw);
750         layout_tools_float_toggle(lw);
751 }
752
753 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
754 {
755         LayoutWindow *lw = data;
756
757         layout_exit_fullscreen(lw);
758         layout_tools_hide_toggle(lw);
759 }
760
761 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
762 {
763         LayoutWindow *lw = data;
764
765         if (lw->options.toolbar_hidden == gtk_toggle_action_get_active(action)) return;
766
767         layout_exit_fullscreen(lw);
768         layout_toolbar_toggle(lw);
769 }
770
771 static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
772 {
773         LayoutWindow *lw = data;
774
775         if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
776
777         layout_exit_fullscreen(lw);
778         layout_info_pixel_set(lw, !lw->options.show_info_pixel);
779 }
780
781 /* NOTE: these callbacks are called also from layout_util_sync_views */
782 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
783 {
784         LayoutWindow *lw = data;
785
786         if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
787
788         layout_exit_fullscreen(lw);
789         layout_bar_toggle(lw);
790 }
791
792 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
793 {
794         LayoutWindow *lw = data;
795
796         if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
797
798         layout_exit_fullscreen(lw);
799         layout_bar_sort_toggle(lw);
800 }
801
802 static void layout_menu_slideshow_cb(GtkToggleAction *action, gpointer data)
803 {
804         LayoutWindow *lw = data;
805
806         if (layout_image_slideshow_active(lw) == gtk_toggle_action_get_active(action)) return;
807         layout_image_slideshow_toggle(lw);
808 }
809
810 static void layout_menu_slideshow_pause_cb(GtkAction *action, gpointer data)
811 {
812         LayoutWindow *lw = data;
813
814         layout_image_slideshow_pause_toggle(lw);
815 }
816
817
818 static void layout_menu_stereo_mode_next_cb(GtkAction *action, gpointer data)
819 {
820         LayoutWindow *lw = data;
821         gint mode = layout_image_stereo_pixbuf_get(lw);
822
823         /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
824         mode = mode % 3 + 1;
825
826         GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
827         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
828
829         /*
830         this is called via fallback in layout_menu_stereo_mode_cb
831         layout_image_stereo_pixbuf_set(lw, mode);
832         */
833
834 }
835
836 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
837 {
838         LayoutWindow *lw = data;
839         gint mode = gtk_radio_action_get_current_value(action);
840         layout_image_stereo_pixbuf_set(lw, mode);
841 }
842
843 static void layout_menu_help_cb(GtkAction *action, gpointer data)
844 {
845         LayoutWindow *lw = data;
846
847         layout_exit_fullscreen(lw);
848         help_window_show("html_contents");
849 }
850
851 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
852 {
853         LayoutWindow *lw = data;
854
855         layout_exit_fullscreen(lw);
856         help_window_show("documentation");
857 }
858
859 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
860 {
861         LayoutWindow *lw = data;
862
863         layout_exit_fullscreen(lw);
864         help_window_show("release_notes");
865 }
866
867 static void layout_menu_about_cb(GtkAction *action, gpointer data)
868 {
869         LayoutWindow *lw = data;
870
871         layout_exit_fullscreen(lw);
872         show_about_window();
873 }
874
875 static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
876 {
877         LayoutWindow *lw = data;
878
879         layout_exit_fullscreen(lw);
880         log_window_new();
881 }
882
883
884 /*
885  *-----------------------------------------------------------------------------
886  * select menu
887  *-----------------------------------------------------------------------------
888  */
889
890 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
891 {
892         LayoutWindow *lw = data;
893
894         layout_select_all(lw);
895 }
896
897 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
898 {
899         LayoutWindow *lw = data;
900
901         layout_select_none(lw);
902 }
903
904 static void layout_menu_invert_selection_cb(GtkAction *action, gpointer data)
905 {
906         LayoutWindow *lw = data;
907
908         layout_select_invert(lw);
909 }
910
911 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
912 {
913         LayoutWindow *lw = data;
914
915         layout_marks_set(lw, gtk_toggle_action_get_active(action));
916 }
917
918
919 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
920 {
921         LayoutWindow *lw = data;
922         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
923         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
924
925         layout_selection_to_mark(lw, mark, STM_MODE_SET);
926 }
927
928 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
929 {
930         LayoutWindow *lw = data;
931         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
932         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
933
934         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
935 }
936
937 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
938 {
939         LayoutWindow *lw = data;
940         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
941         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
942
943         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
944 }
945
946 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
947 {
948         LayoutWindow *lw = data;
949         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
950         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
951
952         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
953 }
954
955 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
956 {
957         LayoutWindow *lw = data;
958         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
959         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
960
961         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
962 }
963
964 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
965 {
966         LayoutWindow *lw = data;
967         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
968         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
969
970         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
971 }
972
973 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
974 {
975         LayoutWindow *lw = data;
976         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
977         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
978
979         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
980 }
981
982 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
983 {
984         LayoutWindow *lw = data;
985         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
986         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
987
988         layout_marks_set(lw, TRUE);
989         layout_mark_filter_toggle(lw, mark);
990 }
991
992
993 /*
994  *-----------------------------------------------------------------------------
995  * go menu
996  *-----------------------------------------------------------------------------
997  */
998
999 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
1000 {
1001         LayoutWindow *lw = data;
1002         layout_image_first(lw);
1003 }
1004
1005 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
1006 {
1007         LayoutWindow *lw = data;
1008         layout_image_prev(lw);
1009 }
1010
1011 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
1012 {
1013         LayoutWindow *lw = data;
1014         layout_image_next(lw);
1015 }
1016
1017 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
1018 {
1019         LayoutWindow *lw = data;
1020         layout_image_last(lw);
1021 }
1022
1023 static void layout_menu_back_cb(GtkAction *action, gpointer data)
1024 {
1025         LayoutWindow *lw = data;
1026         FileData *dir_fd;
1027         gchar *path = NULL;
1028         GList *list = history_list_get_by_key("path_list");
1029         gint n = 0;
1030
1031         while (list)
1032                 {
1033                 if (n == 1) {
1034                         /* Previous path from history */
1035                         path = (gchar *)list->data;
1036                         break;
1037                 }
1038                 list = list->next;
1039                 n++;
1040                 }
1041
1042         if (!path) return;
1043
1044         /* Open previous path */
1045         dir_fd = file_data_new_dir(path);
1046         layout_set_fd(lw, dir_fd);
1047         file_data_unref(dir_fd);
1048 }
1049
1050 static void layout_menu_home_cb(GtkAction *action, gpointer data)
1051 {
1052         LayoutWindow *lw = data;
1053         const gchar *path;
1054
1055         if (lw->options.home_path && *lw->options.home_path)
1056                 path = lw->options.home_path;
1057         else
1058                 path = homedir();
1059
1060         if (path)
1061                 {
1062                 FileData *dir_fd = file_data_new_dir(path);
1063                 layout_set_fd(lw, dir_fd);
1064                 file_data_unref(dir_fd);
1065                 }
1066 }
1067
1068 static void layout_menu_up_cb(GtkAction *action, gpointer data)
1069 {
1070         LayoutWindow *lw = data;
1071         ViewDir *vd = lw->vd;
1072         gchar *path;
1073
1074         if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1075         path = remove_level_from_path(vd->dir_fd->path);
1076
1077         if (vd->select_func)
1078                 {
1079                 FileData *fd = file_data_new_dir(path);
1080                 vd->select_func(vd, fd, vd->select_data);
1081                 file_data_unref(fd);
1082                 }
1083
1084         g_free(path);
1085 }
1086
1087
1088 /*
1089  *-----------------------------------------------------------------------------
1090  * edit menu
1091  *-----------------------------------------------------------------------------
1092  */
1093
1094 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1095 {
1096         LayoutWindow *lw = data;
1097         const gchar *key = gtk_action_get_name(action);
1098
1099         if (!editor_window_flag_set(key))
1100                 layout_exit_fullscreen(lw);
1101
1102         file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1103 }
1104
1105
1106 static void layout_menu_metadata_write_cb(GtkAction *action, gpointer data)
1107 {
1108         metadata_write_queue_confirm(TRUE, NULL, NULL);
1109 }
1110
1111
1112 /*
1113  *-----------------------------------------------------------------------------
1114  * color profile button (and menu)
1115  *-----------------------------------------------------------------------------
1116  */
1117
1118 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1119 {
1120 #ifdef HAVE_LCMS
1121         LayoutWindow *lw = data;
1122
1123         if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1124
1125         layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1126         layout_util_sync_color(lw);
1127         layout_image_refresh(lw);
1128 #endif
1129 }
1130
1131 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1132 {
1133 #ifdef HAVE_LCMS
1134         LayoutWindow *lw = data;
1135         gint input;
1136         gboolean use_image;
1137
1138         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1139         if (use_image == gtk_toggle_action_get_active(action)) return;
1140         layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1141         layout_util_sync_color(lw);
1142         layout_image_refresh(lw);
1143 #endif
1144 }
1145
1146 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
1147 {
1148 #ifdef HAVE_LCMS
1149         LayoutWindow *lw = data;
1150         gint type;
1151         gint input;
1152         gboolean use_image;
1153
1154         type = gtk_radio_action_get_current_value(action);
1155         if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
1156
1157         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1158         if (type == input) return;
1159
1160         layout_image_color_profile_set(lw, type, use_image);
1161         layout_image_refresh(lw);
1162 #endif
1163 }
1164
1165
1166 /*
1167  *-----------------------------------------------------------------------------
1168  * recent menu
1169  *-----------------------------------------------------------------------------
1170  */
1171
1172 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
1173 {
1174         gint n;
1175         gchar *path;
1176
1177         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
1178
1179         path = g_list_nth_data(history_list_get_by_key("recent"), n);
1180
1181         if (!path) return;
1182
1183         /* make a copy of it */
1184         path = g_strdup(path);
1185         collection_window_new(path);
1186         g_free(path);
1187 }
1188
1189 static void layout_menu_recent_update(LayoutWindow *lw)
1190 {
1191         GtkWidget *menu;
1192         GtkWidget *recent;
1193         GtkWidget *item;
1194         GList *list;
1195         gint n;
1196
1197         if (!lw->ui_manager) return;
1198
1199         list = history_list_get_by_key("recent");
1200         n = 0;
1201
1202         menu = gtk_menu_new();
1203
1204         while (list)
1205                 {
1206                 const gchar *filename = filename_from_path((gchar *)list->data);
1207                 gchar *name;
1208                 gboolean free_name = FALSE;
1209
1210                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
1211                         {
1212                         name = remove_extension_from_path(filename);
1213                         free_name = TRUE;
1214                         }
1215                 else
1216                         {
1217                         name = (gchar *) filename;
1218                         }
1219
1220                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
1221                 if (free_name) g_free(name);
1222                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
1223                 list = list->next;
1224                 n++;
1225                 }
1226
1227         if (n == 0)
1228                 {
1229                 menu_item_add(menu, _("Empty"), NULL, NULL);
1230                 }
1231
1232         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
1233         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
1234         gtk_widget_set_sensitive(recent, (n != 0));
1235 }
1236
1237 void layout_recent_update_all(void)
1238 {
1239         GList *work;
1240
1241         work = layout_window_list;
1242         while (work)
1243                 {
1244                 LayoutWindow *lw = work->data;
1245                 work = work->next;
1246
1247                 layout_menu_recent_update(lw);
1248                 }
1249 }
1250
1251 void layout_recent_add_path(const gchar *path)
1252 {
1253         if (!path) return;
1254
1255         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
1256
1257         layout_recent_update_all();
1258 }
1259
1260 /*
1261  *-----------------------------------------------------------------------------
1262  * menu
1263  *-----------------------------------------------------------------------------
1264  */
1265
1266 #define CB G_CALLBACK
1267
1268 static GtkActionEntry menu_entries[] = {
1269   { "FileMenu",         NULL,                   N_("_File"),                            NULL,                   NULL,                                   NULL },
1270   { "GoMenu",           NULL,                   N_("_Go"),                              NULL,                   NULL,                                   NULL },
1271   { "EditMenu",         NULL,                   N_("_Edit"),                            NULL,                   NULL,                                   NULL },
1272   { "SelectMenu",       NULL,                   N_("_Select"),                          NULL,                   NULL,                                   NULL },
1273   { "OrientationMenu",  NULL,                   N_("_Orientation"),                     NULL,                   NULL,                                   NULL },
1274   { "ExternalMenu",     NULL,                   N_("E_xternal Editors"),                NULL,                   NULL,                                   NULL },
1275   { "PreferencesMenu",  NULL,                   N_("P_references"),                     NULL,                   NULL,                                   NULL },
1276   { "ViewMenu",         NULL,                   N_("_View"),                            NULL,                   NULL,                                   NULL },
1277   { "FileDirMenu",      NULL,                   N_("_Files and Folders"),               NULL,                   NULL,                                   NULL },
1278   { "ZoomMenu",         NULL,                   N_("_Zoom"),                            NULL,                   NULL,                                   NULL },
1279   { "ColorMenu",        NULL,                   N_("_Color Management"),                NULL,                   NULL,                                   NULL },
1280   { "ConnectZoomMenu",  NULL,                   N_("_Connected Zoom"),                  NULL,                   NULL,                                   NULL },
1281   { "SplitMenu",        NULL,                   N_("Spli_t"),                           NULL,                   NULL,                                   NULL },
1282   { "StereoMenu",       NULL,                   N_("Stere_o"),                          NULL,                   NULL,                                   NULL },
1283   { "OverlayMenu",      NULL,                   N_("Image _Overlay"),                   NULL,                   NULL,                                   NULL },
1284   { "HelpMenu",         NULL,                   N_("_Help"),                            NULL,                   NULL,                                   NULL },
1285
1286   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),                     "Home",                 N_("First Image"),                      CB(layout_menu_image_first_cb) },
1287   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "BackSpace",            N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1288   { "PrevImageAlt1",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "Page_Up",              N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1289   { "PrevImageAlt2",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "KP_Page_Up",           N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1290   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "space",                N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1291   { "NextImageAlt1",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "Page_Down",            N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1292   { "NextImageAlt2",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "KP_Page_Down",         N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1293   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),                      "End",                  N_("Last Image"),                       CB(layout_menu_image_last_cb) },
1294   { "Back",             GTK_STOCK_GO_BACK,      N_("_Back"),                            NULL,                   N_("Back"),                             CB(layout_menu_back_cb) },
1295   { "Home",             GTK_STOCK_HOME,         N_("_Home"),                            NULL,                   N_("Home"),                             CB(layout_menu_home_cb) },
1296   { "Up",               GTK_STOCK_GO_UP,        N_("_Up"),                              NULL,                   N_("Up"),                               CB(layout_menu_up_cb) },
1297
1298   { "NewWindow",        GTK_STOCK_NEW,          N_("New _window"),                      "<control>N",           N_("New window"),                       CB(layout_menu_new_window_cb) },
1299   { "NewCollection",    GTK_STOCK_INDEX,        N_("_New collection"),                  "C",                    N_("New collection"),                   CB(layout_menu_new_cb) },
1300   { "OpenCollection",   GTK_STOCK_OPEN,         N_("_Open collection..."),              "O",                    N_("Open collection..."),               CB(layout_menu_open_cb) },
1301   { "OpenRecent",       NULL,                   N_("Open recen_t"),                     NULL,                   N_("Open recent"),                      NULL },
1302   { "Search",           GTK_STOCK_FIND,         N_("_Search..."),                       "F3",                   N_("Search..."),                        CB(layout_menu_search_cb) },
1303   { "FindDupes",        GTK_STOCK_FIND,         N_("_Find duplicates..."),              "D",                    N_("Find duplicates..."),               CB(layout_menu_dupes_cb) },
1304   { "PanView",          NULL,                   N_("Pa_n view"),                        "<control>J",           N_("Pan view"),                         CB(layout_menu_pan_cb) },
1305   { "Print",            GTK_STOCK_PRINT,        N_("_Print..."),                        "<shift>P",             N_("Print..."),                         CB(layout_menu_print_cb) },
1306   { "NewFolder",        GTK_STOCK_DIRECTORY,    N_("N_ew folder..."),                   "<control>F",           N_("New folder..."),                    CB(layout_menu_dir_cb) },
1307   { "Copy",             GTK_STOCK_COPY,         N_("_Copy..."),                         "<control>C",           N_("Copy..."),                          CB(layout_menu_copy_cb) },
1308   { "Move",             NULL,                   N_("_Move..."),                         "<control>M",           N_("Move..."),                          CB(layout_menu_move_cb) },
1309   { "Rename",           NULL,                   N_("_Rename..."),                       "<control>R",           N_("Rename..."),                        CB(layout_menu_rename_cb) },
1310   { "Delete",           GTK_STOCK_DELETE,       N_("_Delete..."),                       "<control>D",           N_("Delete..."),                        CB(layout_menu_delete_cb) },
1311   { "DeleteAlt1",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "Delete",               N_("Delete..."),                        CB(layout_menu_delete_cb) },
1312   { "DeleteAlt2",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "KP_Delete",            N_("Delete..."),                        CB(layout_menu_delete_cb) },
1313   { "EnableGrouping",   NULL,                   N_("Enable file _grouping"),            NULL,                   N_("Enable file grouping"),             CB(layout_menu_enable_grouping_cb) },
1314   { "DisableGrouping",  NULL,                   N_("Disable file groupi_ng"),           NULL,                   N_("Disable file grouping"),            CB(layout_menu_disable_grouping_cb) },
1315   { "CopyPath",         NULL,                   N_("_Copy path to clipboard"),          NULL,                   N_("Copy path to clipboard"),           CB(layout_menu_copy_path_cb) },
1316   { "CloseWindow",      GTK_STOCK_CLOSE,        N_("C_lose window"),                    "<control>W",           N_("Close window"),                     CB(layout_menu_close_cb) },
1317   { "Quit",             GTK_STOCK_QUIT,         N_("_Quit"),                            "<control>Q",           N_("Quit"),                             CB(layout_menu_exit_cb) },
1318   { "RotateCW",         NULL,                   N_("_Rotate clockwise"),                "bracketright",         N_("Rotate clockwise"),                 CB(layout_menu_alter_90_cb) },
1319   { "RotateCCW",        NULL,                   N_("Rotate _counterclockwise"),         "bracketleft",          N_("Rotate counterclockwise"),          CB(layout_menu_alter_90cc_cb) },
1320   { "Rotate180",        NULL,                   N_("Rotate 1_80"),                      "<shift>R",             N_("Rotate 180"),                       CB(layout_menu_alter_180_cb) },
1321   { "Mirror",           NULL,                   N_("_Mirror"),                          "<shift>M",             N_("Mirror"),                           CB(layout_menu_alter_mirror_cb) },
1322   { "Flip",             NULL,                   N_("_Flip"),                            "<shift>F",             N_("Flip"),                             CB(layout_menu_alter_flip_cb) },
1323   { "AlterNone",        NULL,                   N_("_Original state"),                  "<shift>O",             N_("Original state"),                   CB(layout_menu_alter_none_cb) },
1324   { "SelectAll",        NULL,                   N_("Select _all"),                      "<control>A",           N_("Select all"),                       CB(layout_menu_select_all_cb) },
1325   { "SelectNone",       NULL,                   N_("Select _none"),                     "<control><shift>A",    N_("Select none"),                      CB(layout_menu_unselect_all_cb) },
1326   { "SelectInvert",     NULL,                   N_("_Invert Selection"),                "<control><shift>I",    N_("Invert Selection"),                 CB(layout_menu_invert_selection_cb) },
1327   { "Preferences",      GTK_STOCK_PREFERENCES,  N_("P_references..."),                  "<control>O",           N_("Preferences..."),                   CB(layout_menu_config_cb) },
1328   { "Editors",          GTK_STOCK_PREFERENCES,  N_("Configure _Editors..."),            NULL,                   N_("Configure Editors..."),             CB(layout_menu_editors_cb) },
1329   { "LayoutConfig",     GTK_STOCK_PREFERENCES,  N_("_Configure this window..."),        NULL,                   N_("Configure this window..."),         CB(layout_menu_layout_config_cb) },
1330   { "Maintenance",      NULL,                   N_("_Thumbnail maintenance..."),        NULL,                   N_("Thumbnail maintenance..."),         CB(layout_menu_remove_thumb_cb) },
1331   { "Wallpaper",        NULL,                   N_("Set as _wallpaper"),                NULL,                   N_("Set as wallpaper"),                 CB(layout_menu_wallpaper_cb) },
1332   { "SaveMetadata",     GTK_STOCK_SAVE,         N_("_Save metadata"),                   "<control>S",           N_("Save metadata"),                    CB(layout_menu_metadata_write_cb) },
1333   { "ZoomIn",           GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "equal",                N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1334   { "ZoomInAlt1",       GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "KP_Add",               N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1335   { "ZoomOut",          GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "minus",                N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1336   { "ZoomOutAlt1",      GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "KP_Subtract",          N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1337   { "Zoom100",          GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "Z",                    N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1338   { "Zoom100Alt1",      GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "KP_Divide",            N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1339   { "ZoomFit",          GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "X",                    N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1340   { "ZoomFitAlt1",      GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "KP_Multiply",          N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1341   { "ZoomFillHor",      NULL,                   N_("Fit _Horizontally"),                "H",                    N_("Fit Horizontally"),                 CB(layout_menu_zoom_fit_hor_cb) },
1342   { "ZoomFillVert",     NULL,                   N_("Fit _Vertically"),                  "W",                    N_("Fit Vertically"),                   CB(layout_menu_zoom_fit_vert_cb) },
1343   { "Zoom200",          NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Zoom 2:1"),                         CB(layout_menu_zoom_2_1_cb) },
1344   { "Zoom300",          NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Zoom 3:1"),                         CB(layout_menu_zoom_3_1_cb) },
1345   { "Zoom400",          NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Zoom 4:1"),                         CB(layout_menu_zoom_4_1_cb) },
1346   { "Zoom50",           NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Zoom 1:2"),                         CB(layout_menu_zoom_1_2_cb) },
1347   { "Zoom33",           NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Zoom 1:3"),                         CB(layout_menu_zoom_1_3_cb) },
1348   { "Zoom25",           NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Zoom 1:4"),                         CB(layout_menu_zoom_1_4_cb) },
1349   { "ConnectZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "plus",                 N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1350   { "ConnectZoomInAlt1",GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "<shift>KP_Add",        N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1351   { "ConnectZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "underscore",           N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1352   { "ConnectZoomOutAlt1",GTK_STOCK_ZOOM_OUT,    N_("Zoom _out"),                        "<shift>KP_Subtract",   N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1353   { "ConnectZoom100",   GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "<shift>Z",             N_("Connected Zoom 1:1"),               CB(layout_menu_connect_zoom_1_1_cb) },
1354   { "ConnectZoom100Alt1",GTK_STOCK_ZOOM_100,    N_("Zoom _1:1"),                        "<shift>KP_Divide",     N_("Connected Zoom 1:1"),               CB(layout_menu_connect_zoom_1_1_cb) },
1355   { "ConnectZoomFit",   GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "<shift>X",             N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1356   { "ConnectZoomFitAlt1",GTK_STOCK_ZOOM_FIT,    N_("_Zoom to fit"),                     "<shift>KP_Multiply",   N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1357   { "ConnectZoomFillHor",NULL,                  N_("Fit _Horizontally"),                "<shift>H",             N_("Connected Fit Horizontally"),       CB(layout_menu_connect_zoom_fit_hor_cb) },
1358   { "ConnectZoomFillVert",NULL,                 N_("Fit _Vertically"),                  "<shift>W",             N_("Connected Fit Vertically"),         CB(layout_menu_connect_zoom_fit_vert_cb) },
1359   { "ConnectZoom200",   NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Connected Zoom 2:1"),               CB(layout_menu_connect_zoom_2_1_cb) },
1360   { "ConnectZoom300",   NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Connected Zoom 3:1"),               CB(layout_menu_connect_zoom_3_1_cb) },
1361   { "ConnectZoom400",   NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Connected Zoom 4:1"),               CB(layout_menu_connect_zoom_4_1_cb) },
1362   { "ConnectZoom50",    NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Connected Zoom 1:2"),               CB(layout_menu_connect_zoom_1_2_cb) },
1363   { "ConnectZoom33",    NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Connected Zoom 1:3"),               CB(layout_menu_connect_zoom_1_3_cb) },
1364   { "ConnectZoom25",    NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Connected Zoom 1:4"),               CB(layout_menu_connect_zoom_1_4_cb) },
1365   { "ViewInNewWindow",  NULL,                   N_("_View in new window"),              "<control>V",           N_("View in new window"),               CB(layout_menu_view_in_new_window_cb) },
1366   { "FullScreen",       GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1367   { "FullScreenAlt1",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "V",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1368   { "FullScreenAlt2",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F11",                  N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1369   { "Escape",           GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Escape",               N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1370   { "EscapeAlt1",       GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Q",                    N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1371   { "ImageOverlayCycle",NULL,                   N_("_Cycle through overlay modes"),     "I",                    N_("Cycle through Overlay modes"),      CB(layout_menu_overlay_toggle_cb) },
1372   { "HistogramChanCycle",NULL,                  N_("Cycle through histogram ch_annels"),"K",                    N_("Cycle through histogram channels"), CB(layout_menu_histogram_toggle_channel_cb) },
1373   { "HistogramModeCycle",NULL,                  N_("Cycle through histogram mo_des"),   "J",                    N_("Cycle through histogram modes"),    CB(layout_menu_histogram_toggle_mode_cb) },
1374   { "HideTools",        NULL,                   N_("_Hide file list"),                  "<control>H",           N_("Hide file list"),                   CB(layout_menu_hide_cb) },
1375   { "SlideShowPause",   GTK_STOCK_MEDIA_PAUSE,  N_("_Pause slideshow"),                 "P",                    N_("Pause slideshow"),                  CB(layout_menu_slideshow_pause_cb) },
1376   { "Refresh",          GTK_STOCK_REFRESH,      N_("_Refresh"),                         "R",                    N_("Refresh"),                          CB(layout_menu_refresh_cb) },
1377   { "HelpContents",     GTK_STOCK_HELP,         N_("_Contents"),                        "F1",                   N_("Contents"),                         CB(layout_menu_help_cb) },
1378   { "HelpShortcuts",    NULL,                   N_("_Keyboard shortcuts"),              NULL,                   N_("Keyboard shortcuts"),               CB(layout_menu_help_keys_cb) },
1379   { "HelpNotes",        NULL,                   N_("_Release notes"),                   NULL,                   N_("Release notes"),                    CB(layout_menu_notes_cb) },
1380   { "About",            GTK_STOCK_ABOUT,        N_("_About"),                           NULL,                   N_("About"),                            CB(layout_menu_about_cb) },
1381   { "LogWindow",        NULL,                   N_("_Log Window"),                      NULL,                   N_("Log Window"),                       CB(layout_menu_log_window_cb) },
1382   { "ExifWin",          NULL,                   N_("_Exif window"),                     "<control>E",           N_("Exif window"),                      CB(layout_menu_bar_exif_cb) },
1383   { "StereoCycle",      NULL,                   N_("_Cycle through stereo modes"),      NULL,                   N_("Cycle through stereo modes"),       CB(layout_menu_stereo_mode_next_cb) },
1384
1385 };
1386
1387 static GtkToggleActionEntry menu_toggle_entries[] = {
1388   { "Thumbnails",       PIXBUF_INLINE_ICON_THUMB,N_("Show _Thumbnails"),                "T",                    N_("Show Thumbnails"),                  CB(layout_menu_thumb_cb),        FALSE },
1389   { "ShowMarks",        NULL,                   N_("Show _Marks"),                      "M",                    N_("Show Marks"),                       CB(layout_menu_marks_cb),        FALSE  },
1390   { "ShowInfoPixel",    GTK_STOCK_COLOR_PICKER, N_("Pi_xel Info"),                      NULL,                   N_("Show Pixel Info"),                  CB(layout_menu_info_pixel_cb),   FALSE  },
1391   { "FloatTools",       PIXBUF_INLINE_ICON_FLOAT,N_("_Float file list"),                "L",                    N_("Float file list"),                  CB(layout_menu_float_cb),        FALSE  },
1392   { "HideToolbar",      NULL,                   N_("Hide tool_bar"),                    NULL,                   N_("Hide toolbar"),                     CB(layout_menu_toolbar_cb),      FALSE  },
1393   { "SBar",             NULL,                   N_("_Info sidebar"),                    "<control>K",           N_("Info sidebar"),                     CB(layout_menu_bar_cb),          FALSE  },
1394   { "SBarSort",         NULL,                   N_("Sort _manager"),                    "<shift>S",             N_("Sort manager"),                     CB(layout_menu_bar_sort_cb),     FALSE  },
1395   { "SlideShow",        GTK_STOCK_MEDIA_PLAY,   N_("Toggle _slideshow"),                "S",                    N_("Toggle slideshow"),                 CB(layout_menu_slideshow_cb),    FALSE  },
1396   { "UseColorProfiles", GTK_STOCK_SELECT_COLOR, N_("Use _color profiles"),              NULL,                   N_("Use color profiles"),               CB(layout_color_menu_enable_cb), FALSE},
1397   { "UseImageProfile",  NULL,                   N_("Use profile from _image"),          NULL,                   N_("Use profile from image"),           CB(layout_color_menu_use_image_cb), FALSE},
1398   { "Grayscale",        NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
1399   { "ImageOverlay",     NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
1400   { "ImageHistogram",   NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
1401 };
1402
1403 static GtkRadioActionEntry menu_radio_entries[] = {
1404   { "ViewList",         NULL,                   N_("Image _List"),                      "<control>L",           N_("View Images as List"),              FILEVIEW_LIST },
1405   { "ViewIcons",        NULL,                   N_("I_cons"),                           "<control>I",           N_("View Images as Icons"),             FILEVIEW_ICON }
1406 };
1407
1408 static GtkRadioActionEntry menu_view_dir_radio_entries[] = {
1409   { "FolderList",       NULL,                   N_("Folder Li_st"),                     "<meta>L",              N_("View Folders as List"),             DIRVIEW_LIST },
1410   { "FolderTree",       NULL,                   N_("Folder T_ree"),                     "<control>T",           N_("View Folders as Tree"),             DIRVIEW_TREE },
1411 };
1412
1413 static GtkRadioActionEntry menu_split_radio_entries[] = {
1414   { "SplitHorizontal",  NULL,                   N_("_Horizontal"),                      "E",                    N_("Split Horizontal"),                 SPLIT_HOR },
1415   { "SplitVertical",    NULL,                   N_("_Vertical"),                        "U",                    N_("Split Vertical"),                           SPLIT_VERT },
1416   { "SplitQuad",        NULL,                   N_("_Quad"),                            NULL,                   N_("Split Quad"),                               SPLIT_QUAD },
1417   { "SplitSingle",      NULL,                   N_("_Single"),                          "Y",                    N_("Split Single"),                             SPLIT_NONE }
1418 };
1419
1420 static GtkRadioActionEntry menu_color_radio_entries[] = {
1421   { "ColorProfile0",    NULL,                   N_("Input _0: sRGB"),                   NULL,                   N_("Input 0: sRGB"),                    COLOR_PROFILE_SRGB },
1422   { "ColorProfile1",    NULL,                   N_("Input _1: AdobeRGB compatible"),    NULL,                   N_("Input 1: AdobeRGB compatible"),     COLOR_PROFILE_ADOBERGB },
1423   { "ColorProfile2",    NULL,                   N_("Input _2"),                         NULL,                   N_("Input 2"),                          COLOR_PROFILE_FILE },
1424   { "ColorProfile3",    NULL,                   N_("Input _3"),                         NULL,                   N_("Input 3"),                          COLOR_PROFILE_FILE + 1 },
1425   { "ColorProfile4",    NULL,                   N_("Input _4"),                         NULL,                   N_("Input 4"),                          COLOR_PROFILE_FILE + 2 },
1426   { "ColorProfile5",    NULL,                   N_("Input _5"),                         NULL,                   N_("Input 5"),                          COLOR_PROFILE_FILE + 3 }
1427 };
1428
1429 static GtkRadioActionEntry menu_histogram_channel[] = {
1430   { "HistogramChanR",   NULL,                   N_("Histogram on _Red"),                NULL,                   N_("Histogram on Red"),         HCHAN_R },
1431   { "HistogramChanG",   NULL,                   N_("Histogram on _Green"),              NULL,                   N_("Histogram on Green"),       HCHAN_G },
1432   { "HistogramChanB",   NULL,                   N_("Histogram on _Blue"),               NULL,                   N_("Histogram on Blue"),        HCHAN_B },
1433   { "HistogramChanRGB", NULL,                   N_("_Histogram on RGB"),                        NULL,                   N_("Histogram on RGB"),         HCHAN_RGB },
1434   { "HistogramChanV",   NULL,                   N_("Histogram on _Value"),              NULL,                   N_("Histogram on Value"),       HCHAN_MAX }
1435 };
1436
1437 static GtkRadioActionEntry menu_histogram_mode[] = {
1438   { "HistogramModeLin", NULL,                   N_("Li_near Histogram"),                NULL,                   N_("Linear Histogram"),         0 },
1439   { "HistogramModeLog", NULL,                   N_("_Log Histogram"),                   NULL,                   N_("Log Histogram"),            1 },
1440 };
1441
1442 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
1443   { "StereoAuto",       NULL,                   N_("_Auto"),                            NULL,                   N_("Stereo Auto"),              STEREO_PIXBUF_DEFAULT },
1444   { "StereoSBS",        NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      STEREO_PIXBUF_SBS },
1445   { "StereoCross",      NULL,                   N_("_Cross"),                           NULL,                   N_("Stereo Cross"),             STEREO_PIXBUF_CROSS },
1446   { "StereoOff",        NULL,                   N_("_Off"),                             NULL,                   N_("Stereo Off"),               STEREO_PIXBUF_NONE }
1447 };
1448
1449
1450 #undef CB
1451
1452 static const gchar *menu_ui_description =
1453 "<ui>"
1454 "  <menubar name='MainMenu'>"
1455 "    <menu action='FileMenu'>"
1456 "      <menuitem action='NewWindow'/>"
1457 "      <menuitem action='NewCollection'/>"
1458 "      <menuitem action='OpenCollection'/>"
1459 "      <menuitem action='OpenRecent'/>"
1460 "      <placeholder name='OpenSection'/>"
1461 "      <separator/>"
1462 "      <menuitem action='Search'/>"
1463 "      <menuitem action='FindDupes'/>"
1464 "      <placeholder name='SearchSection'/>"
1465 "      <separator/>"
1466 "      <menuitem action='Print'/>"
1467 "      <placeholder name='PrintSection'/>"
1468 "      <separator/>"
1469 "      <menuitem action='NewFolder'/>"
1470 "      <menuitem action='Copy'/>"
1471 "      <menuitem action='Move'/>"
1472 "      <menuitem action='Rename'/>"
1473 "      <menuitem action='Delete'/>"
1474 "      <placeholder name='FileOpsSection'/>"
1475 "      <separator/>"
1476 "      <placeholder name='QuitSection'/>"
1477 "      <menuitem action='CloseWindow'/>"
1478 "      <menuitem action='Quit'/>"
1479 "      <separator/>"
1480 "    </menu>"
1481 "    <menu action='GoMenu'>"
1482 "      <menuitem action='FirstImage'/>"
1483 "      <menuitem action='PrevImage'/>"
1484 "      <menuitem action='NextImage'/>"
1485 "      <menuitem action='LastImage'/>"
1486 "      <separator/>"
1487 "      <menuitem action='Back'/>"
1488 "      <menuitem action='Up'/>"
1489 "      <menuitem action='Home'/>"
1490 "      <separator/>"
1491 "    </menu>"
1492 "    <menu action='SelectMenu'>"
1493 "      <menuitem action='SelectAll'/>"
1494 "      <menuitem action='SelectNone'/>"
1495 "      <menuitem action='SelectInvert'/>"
1496 "      <placeholder name='SelectSection'/>"
1497 "      <separator/>"
1498 "      <menuitem action='CopyPath'/>"
1499 "      <placeholder name='ClipboardSection'/>"
1500 "      <separator/>"
1501 "      <menuitem action='ShowMarks'/>"
1502 "      <placeholder name='MarksSection'/>"
1503 "      <separator/>"
1504 "    </menu>"
1505 "    <menu action='EditMenu'>"
1506 "      <menu action='ExternalMenu'>"
1507 "      </menu>"
1508 "      <placeholder name='EditSection'/>"
1509 "      <separator/>"
1510 "      <menu action='OrientationMenu'>"
1511 "        <menuitem action='RotateCW'/>"
1512 "        <menuitem action='RotateCCW'/>"
1513 "        <menuitem action='Rotate180'/>"
1514 "        <menuitem action='Mirror'/>"
1515 "        <menuitem action='Flip'/>"
1516 "        <menuitem action='AlterNone'/>"
1517 "      </menu>"
1518 "      <menuitem action='SaveMetadata'/>"
1519 "      <placeholder name='PropertiesSection'/>"
1520 "      <separator/>"
1521 "        <menu action='PreferencesMenu'>"
1522 "        <menuitem action='Preferences'/>"
1523 "        <menuitem action='Editors'/>"
1524 "        <menuitem action='LayoutConfig'/>"
1525 "        <menuitem action='Maintenance'/>"
1526 "      </menu>"
1527 "      <placeholder name='PreferencesSection'/>"
1528 "      <separator/>"
1529 "      <menuitem action='Wallpaper'/>"
1530 "      <separator/>"
1531 "    </menu>"
1532 "    <menu action='ViewMenu'>"
1533 "      <menuitem action='ViewInNewWindow'/>"
1534 "      <menuitem action='PanView'/>"
1535 "      <menuitem action='ExifWin'/>"
1536 "      <placeholder name='WindowSection'/>"
1537 "      <separator/>"
1538 "      <menu action='FileDirMenu'>"
1539 "        <menuitem action='FolderList'/>"
1540 "        <menuitem action='FolderTree'/>"
1541 "        <placeholder name='FolderSection'/>"
1542 "        <separator/>"
1543 "        <menuitem action='ViewList'/>"
1544 "        <menuitem action='ViewIcons'/>"
1545 "        <menuitem action='Thumbnails'/>"
1546 "        <placeholder name='ListSection'/>"
1547 "        <separator/>"
1548 "        <menuitem action='FloatTools'/>"
1549 "        <menuitem action='HideTools'/>"
1550 "        <menuitem action='HideToolbar'/>"
1551 "      </menu>"
1552 "      <placeholder name='DirSection'/>"
1553 "      <separator/>"
1554 "      <menu action='ZoomMenu'>"
1555 "        <menu action='ConnectZoomMenu'>"
1556 "          <menuitem action='ConnectZoomIn'/>"
1557 "          <menuitem action='ConnectZoomOut'/>"
1558 "          <menuitem action='ConnectZoomFit'/>"
1559 "          <menuitem action='ConnectZoomFillHor'/>"
1560 "          <menuitem action='ConnectZoomFillVert'/>"
1561 "          <menuitem action='ConnectZoom100'/>"
1562 "          <menuitem action='ConnectZoom200'/>"
1563 "          <menuitem action='ConnectZoom300'/>"
1564 "          <menuitem action='ConnectZoom400'/>"
1565 "          <menuitem action='ConnectZoom50'/>"
1566 "          <menuitem action='ConnectZoom33'/>"
1567 "          <menuitem action='ConnectZoom25'/>"
1568 "        </menu>"
1569 "        <menuitem action='ZoomIn'/>"
1570 "        <menuitem action='ZoomOut'/>"
1571 "        <menuitem action='ZoomFit'/>"
1572 "        <menuitem action='ZoomFillHor'/>"
1573 "        <menuitem action='ZoomFillVert'/>"
1574 "        <menuitem action='Zoom100'/>"
1575 "        <menuitem action='Zoom200'/>"
1576 "        <menuitem action='Zoom300'/>"
1577 "        <menuitem action='Zoom400'/>"
1578 "        <menuitem action='Zoom50'/>"
1579 "        <menuitem action='Zoom33'/>"
1580 "        <menuitem action='Zoom25'/>"
1581 "      </menu>"
1582 "      <menu action='SplitMenu'>"
1583 "        <menuitem action='SplitHorizontal'/>"
1584 "        <menuitem action='SplitVertical'/>"
1585 "        <menuitem action='SplitQuad'/>"
1586 "        <menuitem action='SplitSingle'/>"
1587 "      </menu>"
1588 "      <menu action='StereoMenu'>"
1589 "        <menuitem action='StereoAuto'/>"
1590 "        <menuitem action='StereoSBS'/>"
1591 "        <menuitem action='StereoCross'/>"
1592 "        <menuitem action='StereoOff'/>"
1593 "        <separator/>"
1594 "        <menuitem action='StereoCycle'/>"
1595 "      </menu>"
1596 "      <menu action='ColorMenu'>"
1597 "        <menuitem action='UseColorProfiles'/>"
1598 "        <menuitem action='UseImageProfile'/>"
1599 "        <menuitem action='ColorProfile0'/>"
1600 "        <menuitem action='ColorProfile1'/>"
1601 "        <menuitem action='ColorProfile2'/>"
1602 "        <menuitem action='ColorProfile3'/>"
1603 "        <menuitem action='ColorProfile4'/>"
1604 "        <menuitem action='ColorProfile5'/>"
1605 "        <separator/>"
1606 "        <menuitem action='Grayscale'/>"
1607 "      </menu>"
1608 "      <menu action='OverlayMenu'>"
1609 "        <menuitem action='ImageOverlay'/>"
1610 "        <menuitem action='ImageHistogram'/>"
1611 "        <menuitem action='ImageOverlayCycle'/>"
1612 "        <separator/>"
1613 "        <menuitem action='HistogramChanR'/>"
1614 "        <menuitem action='HistogramChanG'/>"
1615 "        <menuitem action='HistogramChanB'/>"
1616 "        <menuitem action='HistogramChanRGB'/>"
1617 "        <menuitem action='HistogramChanV'/>"
1618 "        <menuitem action='HistogramChanCycle'/>"
1619 "        <separator/>"
1620 "        <menuitem action='HistogramModeLin'/>"
1621 "        <menuitem action='HistogramModeLog'/>"
1622 "        <menuitem action='HistogramModeCycle'/>"
1623 "      </menu>"
1624 "      <menuitem action='FullScreen'/>"
1625 "      <placeholder name='ViewSection'/>"
1626 "      <separator/>"
1627 "      <menuitem action='SBar'/>"
1628 "      <menuitem action='SBarSort'/>"
1629 "      <menuitem action='ShowInfoPixel'/>"
1630 "      <placeholder name='ToolsSection'/>"
1631 "      <separator/>"
1632 "      <menuitem action='SlideShow'/>"
1633 "      <menuitem action='SlideShowPause'/>"
1634 "      <menuitem action='Refresh'/>"
1635 "      <placeholder name='SlideShowSection'/>"
1636 "      <separator/>"
1637 "    </menu>"
1638 "    <menu action='HelpMenu'>"
1639 "      <separator/>"
1640 "      <menuitem action='HelpContents'/>"
1641 "      <menuitem action='HelpShortcuts'/>"
1642 "      <menuitem action='HelpNotes'/>"
1643 "      <placeholder name='HelpSection'/>"
1644 "      <separator/>"
1645 "      <menuitem action='About'/>"
1646 "      <separator/>"
1647 "      <menuitem action='LogWindow'/>"
1648 "      <separator/>"
1649 "    </menu>"
1650 "  </menubar>"
1651 "  <toolbar name='ToolBar'>"
1652 "    <toolitem action='Thumbnails'/>"
1653 "    <toolitem action='Back'/>"
1654 "    <toolitem action='Up'/>"
1655 "    <toolitem action='Home'/>"
1656 "    <toolitem action='Refresh'/>"
1657 "    <toolitem action='ZoomIn'/>"
1658 "    <toolitem action='ZoomOut'/>"
1659 "    <toolitem action='ZoomFit'/>"
1660 "    <toolitem action='Zoom100'/>"
1661 "    <toolitem action='Preferences'/>"
1662 "    <toolitem action='FloatTools'/>"
1663 "  </toolbar>"
1664 "  <toolbar name='StatusBar'>"
1665 "    <toolitem action='ShowInfoPixel'/>"
1666 "    <toolitem action='UseColorProfiles'/>"
1667 "    <toolitem action='SaveMetadata'/>"
1668 "  </toolbar>"
1669 "<accelerator action='PrevImageAlt1'/>"
1670 "<accelerator action='PrevImageAlt2'/>"
1671 "<accelerator action='NextImageAlt1'/>"
1672 "<accelerator action='NextImageAlt2'/>"
1673 "<accelerator action='DeleteAlt1'/>"
1674 "<accelerator action='DeleteAlt2'/>"
1675 "<accelerator action='FullScreenAlt1'/>"
1676 "<accelerator action='FullScreenAlt2'/>"
1677 "<accelerator action='Escape'/>"
1678 "<accelerator action='EscapeAlt1'/>"
1679
1680 "<accelerator action='ZoomInAlt1'/>"
1681 "<accelerator action='ZoomOutAlt1'/>"
1682 "<accelerator action='Zoom100Alt1'/>"
1683 "<accelerator action='ZoomFitAlt1'/>"
1684
1685 "<accelerator action='ConnectZoomInAlt1'/>"
1686 "<accelerator action='ConnectZoomOutAlt1'/>"
1687 "<accelerator action='ConnectZoom100Alt1'/>"
1688 "<accelerator action='ConnectZoomFitAlt1'/>"
1689 "</ui>";
1690
1691 static gchar *menu_translate(const gchar *path, gpointer data)
1692 {
1693         return (gchar *)(_(path));
1694 }
1695
1696 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl,
1697                                       gchar *label_tmpl, gchar *accel_tmpl, gchar *tooltip_tmpl, GCallback cb)
1698 {
1699         gchar name[50];
1700         gchar label[100];
1701         gchar accel[50];
1702         gchar tooltip[100];
1703         GtkActionEntry entry = { name, NULL, label, accel, tooltip, cb };
1704         GtkAction *action;
1705
1706         g_snprintf(name, sizeof(name), name_tmpl, mark);
1707         g_snprintf(label, sizeof(label), label_tmpl, mark);
1708
1709         if (accel_tmpl)
1710                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
1711         else
1712                 entry.accelerator = NULL;
1713
1714         if (tooltip_tmpl)
1715                 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
1716         else
1717                 entry.tooltip = NULL;
1718
1719         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
1720         action = gtk_action_group_get_action(lw->action_group, name);
1721         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark));
1722 }
1723
1724 static void layout_actions_setup_marks(LayoutWindow *lw)
1725 {
1726         gint mark;
1727         GError *error;
1728         GString *desc = g_string_new(
1729                                 "<ui>"
1730                                 "  <menubar name='MainMenu'>"
1731                                 "    <menu action='SelectMenu'>");
1732
1733         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1734                 {
1735                 layout_actions_setup_mark(lw, mark, "Mark%d",           _("Mark _%d"), NULL, NULL, NULL);
1736                 layout_actions_setup_mark(lw, mark, "SetMark%d",        _("_Set mark %d"),                      NULL,           _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
1737                 layout_actions_setup_mark(lw, mark, "ResetMark%d",      _("_Reset mark %d"),                    NULL,           _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
1738                 layout_actions_setup_mark(lw, mark, "ToggleMark%d",     _("_Toggle mark %d"),                   "%d",           _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1739                 layout_actions_setup_mark(lw, mark, "ToggleMark%dAlt1", _("_Toggle mark %d"),                   "KP_%d",        _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1740                 layout_actions_setup_mark(lw, mark, "SelectMark%d",     _("Se_lect mark %d"),                   "<control>%d",  _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1741                 layout_actions_setup_mark(lw, mark, "SelectMark%dAlt1", _("_Select mark %d"),                   "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1742                 layout_actions_setup_mark(lw, mark, "AddMark%d",        _("_Add mark %d"),                      NULL,           _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
1743                 layout_actions_setup_mark(lw, mark, "IntMark%d",        _("_Intersection with mark %d"),        NULL,           _("Intersection with mark %d"), G_CALLBACK(layout_menu_sel_mark_and_cb));
1744                 layout_actions_setup_mark(lw, mark, "UnselMark%d",      _("_Unselect mark %d"),                 NULL,           _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
1745                 layout_actions_setup_mark(lw, mark, "FilterMark%d",     _("_Filter mark %d"),                   NULL,           _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
1746
1747                 g_string_append_printf(desc,
1748                                 "      <menu action='Mark%d'>"
1749                                 "        <menuitem action='ToggleMark%d'/>"
1750                                 "        <menuitem action='SetMark%d'/>"
1751                                 "        <menuitem action='ResetMark%d'/>"
1752                                 "        <separator/>"
1753                                 "        <menuitem action='SelectMark%d'/>"
1754                                 "        <menuitem action='AddMark%d'/>"
1755                                 "        <menuitem action='IntMark%d'/>"
1756                                 "        <menuitem action='UnselMark%d'/>"
1757                                 "        <separator/>"
1758                                 "        <menuitem action='FilterMark%d'/>"
1759                                 "      </menu>",
1760                                 mark, mark, mark, mark, mark, mark, mark, mark, mark);
1761                 }
1762
1763         g_string_append(desc,
1764                                 "    </menu>"
1765                                 "  </menubar>");
1766         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1767                 {
1768                 g_string_append_printf(desc,
1769                                 "<accelerator action='ToggleMark%dAlt1'/>"
1770                                 "<accelerator action='SelectMark%dAlt1'/>",
1771                                 mark, mark);
1772                 }
1773         g_string_append(desc,   "</ui>" );
1774
1775         error = NULL;
1776         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
1777                 {
1778                 g_message("building menus failed: %s", error->message);
1779                 g_error_free(error);
1780                 exit(EXIT_FAILURE);
1781                 }
1782         g_string_free(desc, TRUE);
1783 }
1784
1785 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
1786 {
1787         gchar **split = g_strsplit(editor->menu_path, "/", 0);
1788         gint i = 0;
1789         GList *ret = NULL;
1790
1791         if (split[0] == NULL)
1792                 {
1793                 g_strfreev(split);
1794                 return NULL;
1795                 }
1796
1797         while (split[i])
1798                 {
1799                 ret = g_list_prepend(ret, g_strdup(split[i]));
1800                 i++;
1801                 }
1802
1803         g_strfreev(split);
1804
1805         ret = g_list_prepend(ret, g_strdup(editor->key));
1806
1807         return g_list_reverse(ret);
1808 }
1809
1810 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
1811 {
1812         gint to_open, to_close, i;
1813         while (path && old_path && strcmp((gchar *)path->data, (gchar *)old_path->data) == 0)
1814                 {
1815                 path = path->next;
1816                 old_path = old_path->next;
1817                 }
1818         to_open = g_list_length(path) - 1;
1819         to_close = g_list_length(old_path) - 1;
1820
1821         if (to_close > 0)
1822                 {
1823                 old_path = g_list_last(old_path);
1824                 old_path = old_path->prev;
1825                 }
1826
1827         for (i =  0; i < to_close; i++)
1828                 {
1829                 gchar *name = old_path->data;
1830                 if (g_str_has_suffix(name, "Section"))
1831                         {
1832                         g_string_append(desc,   "      </placeholder>");
1833                         }
1834                 else if (g_str_has_suffix(name, "Menu"))
1835                         {
1836                         g_string_append(desc,   "    </menu>");
1837                         }
1838                 else
1839                         {
1840                         g_warning("invalid menu path item %s", name);
1841                         }
1842                 old_path = old_path->prev;
1843                 }
1844
1845         for (i =  0; i < to_open; i++)
1846                 {
1847                 gchar *name = path->data;
1848                 if (g_str_has_suffix(name, "Section"))
1849                         {
1850                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
1851                         }
1852                 else if (g_str_has_suffix(name, "Menu"))
1853                         {
1854                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
1855                         }
1856                 else
1857                         {
1858                         g_warning("invalid menu path item %s", name);
1859                         }
1860                 path = path->next;
1861                 }
1862
1863         if (path)
1864                 g_string_append_printf(desc, "      <menuitem action='%s'/>", (gchar *)path->data);
1865 }
1866
1867 static void layout_actions_setup_editors(LayoutWindow *lw)
1868 {
1869         GError *error;
1870         GList *editors_list;
1871         GList *work;
1872         GList *old_path;
1873         GString *desc;
1874
1875         if (lw->ui_editors_id)
1876                 {
1877                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
1878                 }
1879
1880         if (lw->action_group_editors)
1881                 {
1882                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
1883                 g_object_unref(lw->action_group_editors);
1884                 }
1885         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
1886         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
1887
1888         /* lw->action_group_editors contains translated entries, no translate func is required */
1889         desc = g_string_new(
1890                                 "<ui>"
1891                                 "  <menubar name='MainMenu'>");
1892
1893         editors_list = editor_list_get();
1894
1895         old_path = NULL;
1896         work = editors_list;
1897         while (work)
1898                 {
1899                 GList *path;
1900                 EditorDescription *editor = work->data;
1901                 GtkActionEntry entry = { editor->key,
1902                                          NULL,
1903                                          editor->name,
1904                                          editor->hotkey,
1905                                          editor->comment ? editor->comment : editor->name,
1906                                          G_CALLBACK(layout_menu_edit_cb) };
1907
1908                 if (editor->icon)
1909                         {
1910                         entry.stock_id = editor->key;
1911                         }
1912                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
1913
1914                 path = layout_actions_editor_menu_path(editor);
1915                 layout_actions_editor_add(desc, path, old_path);
1916
1917                 string_list_free(old_path);
1918                 old_path = path;
1919                 work = work->next;
1920                 }
1921
1922         layout_actions_editor_add(desc, NULL, old_path);
1923         string_list_free(old_path);
1924
1925         g_string_append(desc,   "  </menubar>"
1926                                 "</ui>" );
1927
1928         error = NULL;
1929
1930         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
1931         if (!lw->ui_editors_id)
1932                 {
1933                 g_message("building menus failed: %s", error->message);
1934                 g_error_free(error);
1935                 exit(EXIT_FAILURE);
1936                 }
1937         g_string_free(desc, TRUE);
1938         g_list_free(editors_list);
1939 }
1940
1941 void layout_actions_setup(LayoutWindow *lw)
1942 {
1943         GError *error;
1944         gint i;
1945
1946         DEBUG_1("%s layout_actions_setup: start", get_exec_time());
1947         if (lw->ui_manager) return;
1948
1949         lw->action_group = gtk_action_group_new("MenuActions");
1950         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
1951
1952         gtk_action_group_add_actions(lw->action_group,
1953                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
1954         gtk_action_group_add_toggle_actions(lw->action_group,
1955                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
1956         gtk_action_group_add_radio_actions(lw->action_group,
1957                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
1958                                            0, G_CALLBACK(layout_menu_list_cb), lw);
1959         gtk_action_group_add_radio_actions(lw->action_group,
1960                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
1961                                            0, G_CALLBACK(layout_menu_split_cb), lw);
1962         gtk_action_group_add_radio_actions(lw->action_group,
1963                                            menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
1964                                            0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);
1965         gtk_action_group_add_radio_actions(lw->action_group,
1966                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
1967                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
1968         gtk_action_group_add_radio_actions(lw->action_group,
1969                                            menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
1970                                            0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
1971         gtk_action_group_add_radio_actions(lw->action_group,
1972                                            menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
1973                                            0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
1974         gtk_action_group_add_radio_actions(lw->action_group,
1975                                            menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
1976                                            0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
1977
1978
1979         lw->ui_manager = gtk_ui_manager_new();
1980         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
1981         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
1982
1983         DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
1984         error = NULL;
1985         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
1986                 {
1987                 g_message("building menus failed: %s", error->message);
1988                 g_error_free(error);
1989                 exit(EXIT_FAILURE);
1990                 }
1991
1992         DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
1993         layout_actions_setup_marks(lw);
1994
1995         DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
1996         layout_actions_setup_editors(lw);
1997
1998         DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
1999         layout_util_status_update_write(lw);
2000
2001         DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
2002         layout_actions_add_window(lw, lw->window);
2003         DEBUG_1("%s layout_actions_setup: end", get_exec_time());
2004 }
2005
2006 static gint layout_editors_reload_idle_id = -1;
2007 static GList *layout_editors_desktop_files = NULL;
2008
2009 static gboolean layout_editors_reload_idle_cb(gpointer data)
2010 {
2011         if (!layout_editors_desktop_files)
2012                 {
2013                 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
2014                 layout_editors_desktop_files = editor_get_desktop_files();
2015                 return TRUE;
2016                 }
2017
2018         editor_read_desktop_file(layout_editors_desktop_files->data);
2019         g_free(layout_editors_desktop_files->data);
2020         layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
2021
2022
2023         if (!layout_editors_desktop_files)
2024                 {
2025                 GList *work;
2026                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
2027                 editor_table_finish();
2028
2029                 work = layout_window_list;
2030                 while (work)
2031                         {
2032                         LayoutWindow *lw = work->data;
2033                         work = work->next;
2034                         layout_actions_setup_editors(lw);
2035                         }
2036
2037                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
2038
2039                 layout_editors_reload_idle_id = -1;
2040                 return FALSE;
2041                 }
2042         return TRUE;
2043 }
2044
2045 void layout_editors_reload_start(void)
2046 {
2047         DEBUG_1("%s layout_editors_reload_start", get_exec_time());
2048
2049         if (layout_editors_reload_idle_id != -1)
2050                 {
2051                 g_source_remove(layout_editors_reload_idle_id);
2052                 string_list_free(layout_editors_desktop_files);
2053                 }
2054
2055         editor_table_clear();
2056         layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL);
2057 }
2058
2059 void layout_editors_reload_finish(void)
2060 {
2061         if (layout_editors_reload_idle_id != -1)
2062                 {
2063                 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
2064                 g_source_remove(layout_editors_reload_idle_id);
2065                 while (layout_editors_reload_idle_id != -1)
2066                         {
2067                         layout_editors_reload_idle_cb(NULL);
2068                         }
2069                 }
2070 }
2071
2072 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
2073 {
2074         GtkAccelGroup *group;
2075
2076         if (!lw->ui_manager) return;
2077
2078         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
2079         gtk_window_add_accel_group(GTK_WINDOW(window), group);
2080 }
2081
2082 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
2083 {
2084         if (lw->menu_bar) return lw->menu_bar;
2085         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
2086         g_object_ref(lw->menu_bar);
2087         return lw->menu_bar;
2088 }
2089
2090 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
2091 {
2092         if (lw->toolbar[type]) return lw->toolbar[type];
2093         switch (type)
2094                 {
2095                 case TOOLBAR_MAIN:
2096                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar");
2097                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_SMALL_TOOLBAR);
2098                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2099                         break;
2100                 case TOOLBAR_STATUS:
2101                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/StatusBar");
2102                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_MENU);
2103                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2104                         gtk_toolbar_set_show_arrow(GTK_TOOLBAR(lw->toolbar[type]), FALSE);
2105                         break;
2106                 default:
2107                         break;
2108                 }
2109         g_object_ref(lw->toolbar[type]);
2110         return lw->toolbar[type];
2111 }
2112
2113 /*
2114  *-----------------------------------------------------------------------------
2115  * misc
2116  *-----------------------------------------------------------------------------
2117  */
2118
2119 void layout_util_status_update_write(LayoutWindow *lw)
2120 {
2121         GtkAction *action;
2122         gint n = metadata_queue_length();
2123         action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
2124         gtk_action_set_sensitive(action, n > 0);
2125         if (n > 0)
2126                 {
2127                 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
2128                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2129                 g_free(buf);
2130                 }
2131         else
2132                 {
2133                 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
2134                 }
2135 }
2136
2137 void layout_util_status_update_write_all(void)
2138 {
2139         GList *work;
2140
2141         work = layout_window_list;
2142         while (work)
2143                 {
2144                 LayoutWindow *lw = work->data;
2145                 work = work->next;
2146
2147                 layout_util_status_update_write(lw);
2148                 }
2149 }
2150
2151 static gchar *layout_color_name_parse(const gchar *name)
2152 {
2153         if (!name || !*name) return g_strdup(_("Empty"));
2154         return g_strdelimit(g_strdup(name), "_", '-');
2155 }
2156
2157 void layout_util_sync_color(LayoutWindow *lw)
2158 {
2159         GtkAction *action;
2160         gint input = 0;
2161         gboolean use_color;
2162         gboolean use_image = FALSE;
2163         gint i;
2164         gchar action_name[15];
2165         gchar *image_profile;
2166         gchar *screen_profile;
2167
2168
2169         if (!lw->action_group) return;
2170         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
2171
2172         use_color = layout_image_color_profile_get_use(lw);
2173
2174         action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
2175 #ifdef HAVE_LCMS
2176         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
2177         if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
2178                 {
2179                 gchar *buf;
2180                 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
2181                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2182                 g_free(image_profile);
2183                 g_free(screen_profile);
2184                 g_free(buf);
2185                 }
2186         else
2187                 {
2188                 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
2189                 }
2190 #else
2191         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
2192         gtk_action_set_sensitive(action, FALSE);
2193         g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
2194 #endif
2195
2196         action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
2197         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
2198         gtk_action_set_sensitive(action, use_color);
2199
2200         for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
2201                 {
2202                 sprintf(action_name, "ColorProfile%d", i);
2203                 action = gtk_action_group_get_action(lw->action_group, action_name);
2204
2205                 if (i >= COLOR_PROFILE_FILE)
2206                         {
2207                         const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
2208                         const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
2209                         gchar *end;
2210                         gchar *buf;
2211
2212                         if (!name || !name[0]) name = filename_from_path(file);
2213
2214                         end = layout_color_name_parse(name);
2215                         buf = g_strdup_printf(_("Input _%d: %s"), i, end);
2216                         g_free(end);
2217
2218                         g_object_set(G_OBJECT(action), "label", buf, NULL);
2219                         g_free(buf);
2220
2221                         gtk_action_set_visible(action, file && file[0]);
2222                         }
2223
2224                 gtk_action_set_sensitive(action, !use_image);
2225                 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
2226                 }
2227
2228         action = gtk_action_group_get_action(lw->action_group, "Grayscale");
2229         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
2230 }
2231
2232 static void layout_util_sync_views(LayoutWindow *lw)
2233 {
2234         GtkAction *action;
2235         OsdShowFlags osd_flags = image_osd_get(lw->image);
2236
2237         if (!lw->action_group) return;
2238
2239         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
2240         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
2241
2242         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
2243         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
2244
2245         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
2246         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
2247
2248         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
2249         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
2250
2251         action = gtk_action_group_get_action(lw->action_group, "SBar");
2252         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
2253
2254         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
2255         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
2256
2257         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
2258         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
2259
2260         action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
2261         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
2262
2263         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
2264         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
2265
2266         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
2267         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
2268
2269         action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
2270         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
2271
2272         action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
2273         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
2274
2275         if (osd_flags & OSD_SHOW_HISTOGRAM)
2276                 {
2277                 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
2278                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
2279
2280                 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
2281                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
2282                 }
2283
2284         action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
2285         gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
2286
2287         action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
2288         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
2289
2290         layout_util_sync_color(lw);
2291 }
2292
2293 void layout_util_sync_thumb(LayoutWindow *lw)
2294 {
2295         GtkAction *action;
2296
2297         if (!lw->action_group) return;
2298
2299         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
2300         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
2301         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
2302 }
2303
2304 void layout_util_sync(LayoutWindow *lw)
2305 {
2306         layout_util_sync_views(lw);
2307         layout_util_sync_thumb(lw);
2308         layout_menu_recent_update(lw);
2309 //      layout_menu_edit_update(lw);
2310 }
2311
2312
2313 /*
2314  *-----------------------------------------------------------------------------
2315  * sidebars
2316  *-----------------------------------------------------------------------------
2317  */
2318
2319 static gboolean layout_bar_enabled(LayoutWindow *lw)
2320 {
2321         return lw->bar && gtk_widget_get_visible(lw->bar);
2322 }
2323
2324 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
2325 {
2326         LayoutWindow *lw = data;
2327
2328         lw->bar = NULL;
2329 /*
2330     do not call layout_util_sync_views(lw) here
2331     this is called either when whole layout is destroyed - no need for update
2332     or when the bar is replaced - sync is called by upper function at the end of whole operation
2333
2334 */
2335 }
2336
2337 static void layout_bar_set_default(LayoutWindow *lw)
2338 {
2339         GtkWidget *bar;
2340
2341         if (!lw->utility_box) return;
2342
2343         bar = bar_new(lw);
2344
2345         layout_bar_set(lw, bar);
2346
2347         bar_populate_default(bar);
2348 }
2349
2350 static void layout_bar_close(LayoutWindow *lw)
2351 {
2352         if (lw->bar)
2353                 {
2354                 bar_close(lw->bar);
2355                 lw->bar = NULL;
2356                 }
2357 }
2358
2359
2360 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
2361 {
2362         if (!lw->utility_box) return;
2363
2364         layout_bar_close(lw); /* if any */
2365
2366         if (!bar) return;
2367         lw->bar = bar;
2368
2369         g_signal_connect(G_OBJECT(lw->bar), "destroy",
2370                          G_CALLBACK(layout_bar_destroyed), lw);
2371
2372
2373 //      gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
2374         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
2375
2376         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2377 }
2378
2379
2380 void layout_bar_toggle(LayoutWindow *lw)
2381 {
2382         if (layout_bar_enabled(lw))
2383                 {
2384                 gtk_widget_hide(lw->bar);
2385                 }
2386         else
2387                 {
2388                 if (!lw->bar)
2389                         {
2390                         layout_bar_set_default(lw);
2391                         }
2392                 gtk_widget_show(lw->bar);
2393                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
2394                 }
2395         layout_util_sync_views(lw);
2396 }
2397
2398 static void layout_bar_new_image(LayoutWindow *lw)
2399 {
2400         if (!layout_bar_enabled(lw)) return;
2401
2402         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2403 }
2404
2405 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
2406 {
2407         if (!layout_bar_enabled(lw)) return;
2408
2409         bar_notify_selection(lw->bar, count);
2410 }
2411
2412 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
2413 {
2414         return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
2415 }
2416
2417
2418 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
2419 {
2420         LayoutWindow *lw = data;
2421
2422         lw->bar_sort = NULL;
2423
2424 /*
2425     do not call layout_util_sync_views(lw) here
2426     this is called either when whole layout is destroyed - no need for update
2427     or when the bar is replaced - sync is called by upper function at the end of whole operation
2428
2429 */
2430 }
2431
2432 static void layout_bar_sort_set_default(LayoutWindow *lw)
2433 {
2434         GtkWidget *bar;
2435
2436         if (!lw->utility_box) return;
2437
2438         bar = bar_sort_new_default(lw);
2439
2440         layout_bar_sort_set(lw, bar);
2441 }
2442
2443 static void layout_bar_sort_close(LayoutWindow *lw)
2444 {
2445         if (lw->bar_sort)
2446                 {
2447                 bar_sort_close(lw->bar_sort);
2448                 lw->bar_sort = NULL;
2449                 }
2450 }
2451
2452 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
2453 {
2454         if (!lw->utility_box) return;
2455
2456         layout_bar_sort_close(lw); /* if any */
2457
2458         if (!bar) return;
2459         lw->bar_sort = bar;
2460
2461         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
2462                          G_CALLBACK(layout_bar_sort_destroyed), lw);
2463
2464         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
2465 }
2466
2467 void layout_bar_sort_toggle(LayoutWindow *lw)
2468 {
2469         if (layout_bar_sort_enabled(lw))
2470                 {
2471                 gtk_widget_hide(lw->bar_sort);
2472                 }
2473         else
2474                 {
2475                 if (!lw->bar_sort)
2476                         {
2477                         layout_bar_sort_set_default(lw);
2478                         }
2479                 gtk_widget_show(lw->bar_sort);
2480                 }
2481         layout_util_sync_views(lw);
2482 }
2483
2484 void layout_bars_new_image(LayoutWindow *lw)
2485 {
2486         layout_bar_new_image(lw);
2487
2488         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2489
2490         /* this should be called here to handle the metadata edited in bars */
2491         if (options->metadata.confirm_on_image_change)
2492                 metadata_write_queue_confirm(FALSE, NULL, NULL);
2493 }
2494
2495 void layout_bars_new_selection(LayoutWindow *lw, gint count)
2496 {
2497         layout_bar_new_selection(lw, count);
2498 }
2499
2500 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
2501 {
2502         if (lw->utility_box) return lw->utility_box;
2503         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
2504         lw->utility_paned = gtk_hpaned_new();
2505         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
2506
2507         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
2508         gtk_widget_show(lw->utility_paned);
2509
2510         gtk_widget_show(image);
2511
2512         g_object_ref(lw->utility_box);
2513         return lw->utility_box;
2514 }
2515
2516 void layout_bars_close(LayoutWindow *lw)
2517 {
2518         layout_bar_sort_close(lw);
2519         layout_bar_close(lw);
2520 }
2521
2522 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
2523 {
2524         LayoutWindow *lw = data;
2525         lw->exif_window = NULL;
2526 }
2527
2528 void layout_exif_window_new(LayoutWindow *lw)
2529 {
2530         if (lw->exif_window) return;
2531
2532         lw->exif_window = advanced_exif_new();
2533         if (!lw->exif_window) return;
2534         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
2535                          G_CALLBACK(layout_exif_window_destroy), lw);
2536         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2537 }
2538
2539 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */