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