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