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