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