Merge remote-tracking branch 'github/merge-requests/410'
[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 #include "keymap_template.c"
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 char *keyboard_map_hardcoded[][2] = {
876         {"Scroll","Left"},
877         {"FastScroll", "&lt;Shift&gt;Left"},
878         {"Left Border", "&lt;Primary&gt;Left"},
879         {"Left Border", "&lt;Primary&gt;&lt;Shift&gt;Left"},
880         {"Scroll", "Right"},
881         {"FastScroll", "&lt;Shift&gt;Right"},
882         {"Right Border", "&lt;Primary&gt;Right"},
883         {"Right Border", "&lt;Primary&gt;&lt;Shift&gt;Right"},
884         {"Scroll", "Up"},
885         {"FastScroll", "&lt;Shift&gt;Up"},
886         {"Uper Border", "&lt;Primary&gt;Up"},
887         {"Uper Border", "&lt;Primary&gt;&lt;Shift&gt;Up"},
888         {"Scroll", "Down"},
889         {"FastScroll", "&lt;Shift&gt;Down"},
890         {"Lower Border", "&lt;Primary&gt;Down"},
891         {"Lower Border", "&lt;Primary&gt;&lt;Shift&gt;Down"},
892         {"Next/Drag", "M1"},
893         {"FastDrag", "&lt;Shift&gt;M1"},
894         {"DnD Start", "M2"},
895         {"Menu", "M3"},
896         {"PrevImage", "MW4"},
897         {"NextImage", "MW5"},
898         {"ScrollUp", "&lt;Shift&gt;MW4"},
899         {"ScrollDown", "&lt;Shift&gt;MW5"},
900         {"ZoomIn", "&lt;Primary&gt;MW4"},
901         {"ZoomOut", "&lt;Primary&gt;MW5"},
902         {NULL, NULL}
903 };
904
905 static void layout_menu_foreach_func(
906                                         gpointer data,
907                                         const gchar *accel_path,
908                                         guint accel_key,
909                                         GdkModifierType accel_mods,
910                                         gboolean changed)
911 {
912         gchar *path, *name;
913         gchar *key_name, *menu_name;
914         gchar **subset_lt_arr, **subset_gt_arr;
915         gchar *subset_lt, *converted_name;
916         GPtrArray *array = data;
917
918         path = g_strescape(accel_path, NULL);
919         name = gtk_accelerator_name(accel_key, accel_mods);
920
921         menu_name = g_strdup(g_strrstr(path, "/")+1);
922
923         if (g_strrstr(name, ">"))
924                 {
925                 subset_lt_arr = g_strsplit_set(name,"<", 4);
926                 subset_lt = g_strjoinv("&lt;", subset_lt_arr);
927                 subset_gt_arr = g_strsplit_set(subset_lt,">", 4);
928                 converted_name = g_strjoinv("&gt;", subset_gt_arr);
929                 key_name = g_strdup(converted_name);
930
931                 g_free(converted_name);
932                 g_free(subset_lt);
933                 g_strfreev(subset_lt_arr);
934                 g_strfreev(subset_gt_arr);
935                 }
936         else
937                 key_name = g_strdup(name);
938
939         g_ptr_array_add(array, (gpointer)menu_name);
940         g_ptr_array_add(array, (gpointer)key_name);
941
942         g_free(name);
943         g_free(path);
944 }
945
946 static void layout_menu_kbd_map_cb(GtkAction *action, gpointer data)
947 {
948         LayoutWindow *lw = data;
949         gint fd = -1;
950         GPtrArray *array;
951         char * tmp_file;
952         GError *error = NULL;
953         GIOChannel *channel;
954         char **pre_key, **post_key;
955         char *key_name, *converted_line;
956         int keymap_index, index;
957
958         fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
959         if (error)
960                 {
961                 DEBUG_0("Keyboard Map - cannot create file:%s\n",error->message);
962                 g_error_free(error);
963                 }
964         else
965                 {
966                 array = g_ptr_array_new();
967
968                 gtk_accel_map_foreach(array, layout_menu_foreach_func);
969
970                 channel = g_io_channel_unix_new(fd);
971
972                 keymap_index = 0;
973                 while (keymap_template[keymap_index])
974                         {
975                         if (g_strrstr(keymap_template[keymap_index], ">key:"))
976                                 {
977                                 pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
978                                 post_key = g_strsplit(pre_key[1],"<",2);
979
980                                 index=0;
981                                 key_name = " ";
982                                 for (index=0; index < array->len-2; index=index+2)
983                                         {
984                                         if (!(g_ascii_strcasecmp(g_ptr_array_index(array,index+1), post_key[0])))
985                                                 {
986                                                 key_name = g_ptr_array_index(array,index+0);
987                                                 break;
988                                                 }
989                                         }
990
991                                 index=0;
992                                 while (keyboard_map_hardcoded[index][0])
993                                         {
994                                         if (!(g_strcmp0(keyboard_map_hardcoded[index][1], post_key[0])))
995                                                 {
996                                                 key_name = keyboard_map_hardcoded[index][0];
997                                                 break;
998                                                 }
999                                         index++;
1000                                         }
1001
1002                                 converted_line = g_strconcat(pre_key[0], ">", key_name, "<", post_key[1], "\n", NULL);
1003                                 g_io_channel_write_chars(channel, converted_line, -1, NULL, &error);
1004                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1005
1006                                 g_free(converted_line);
1007                                 g_strfreev(pre_key);
1008                                 g_strfreev(post_key);
1009                                 }
1010                         else
1011                                 {
1012                                 g_io_channel_write_chars(channel, keymap_template[keymap_index], -1, NULL, &error);
1013                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1014                                 g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
1015                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1016                                 }
1017                         keymap_index++;
1018                         }
1019
1020                 g_io_channel_flush(channel, &error);
1021                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1022                 g_io_channel_unref(channel);
1023
1024                 index=0;
1025                 for (index=0; index < array->len-2; index=index+2)
1026                         {
1027                         g_free(g_ptr_array_index(array,index));
1028                         g_free(g_ptr_array_index(array,index+1));
1029                         }
1030                 g_ptr_array_unref(array);
1031
1032                 view_window_new(file_data_new_simple(tmp_file));
1033                 g_free(tmp_file);
1034                 }
1035 }
1036
1037 static void layout_menu_about_cb(GtkAction *action, gpointer data)
1038 {
1039         LayoutWindow *lw = data;
1040
1041         layout_exit_fullscreen(lw);
1042         show_about_window();
1043 }
1044
1045 static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
1046 {
1047         LayoutWindow *lw = data;
1048
1049         layout_exit_fullscreen(lw);
1050         log_window_new();
1051 }
1052
1053
1054 /*
1055  *-----------------------------------------------------------------------------
1056  * select menu
1057  *-----------------------------------------------------------------------------
1058  */
1059
1060 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
1061 {
1062         LayoutWindow *lw = data;
1063
1064         layout_select_all(lw);
1065 }
1066
1067 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
1068 {
1069         LayoutWindow *lw = data;
1070
1071         layout_select_none(lw);
1072 }
1073
1074 static void layout_menu_invert_selection_cb(GtkAction *action, gpointer data)
1075 {
1076         LayoutWindow *lw = data;
1077
1078         layout_select_invert(lw);
1079 }
1080
1081 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
1082 {
1083         LayoutWindow *lw = data;
1084
1085         layout_marks_set(lw, gtk_toggle_action_get_active(action));
1086 }
1087
1088
1089 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
1090 {
1091         LayoutWindow *lw = data;
1092         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1093         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1094
1095         layout_selection_to_mark(lw, mark, STM_MODE_SET);
1096 }
1097
1098 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
1099 {
1100         LayoutWindow *lw = data;
1101         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1102         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1103
1104         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
1105 }
1106
1107 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
1108 {
1109         LayoutWindow *lw = data;
1110         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1111         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1112
1113         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
1114 }
1115
1116 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
1117 {
1118         LayoutWindow *lw = data;
1119         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1120         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1121
1122         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
1123 }
1124
1125 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
1126 {
1127         LayoutWindow *lw = data;
1128         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1129         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1130
1131         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
1132 }
1133
1134 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
1135 {
1136         LayoutWindow *lw = data;
1137         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1138         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1139
1140         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
1141 }
1142
1143 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
1144 {
1145         LayoutWindow *lw = data;
1146         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1147         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1148
1149         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
1150 }
1151
1152 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
1153 {
1154         LayoutWindow *lw = data;
1155         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1156         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1157
1158         layout_marks_set(lw, TRUE);
1159         layout_mark_filter_toggle(lw, mark);
1160 }
1161
1162
1163 /*
1164  *-----------------------------------------------------------------------------
1165  * go menu
1166  *-----------------------------------------------------------------------------
1167  */
1168
1169 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
1170 {
1171         LayoutWindow *lw = data;
1172         layout_image_first(lw);
1173 }
1174
1175 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
1176 {
1177         LayoutWindow *lw = data;
1178         layout_image_prev(lw);
1179 }
1180
1181 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
1182 {
1183         LayoutWindow *lw = data;
1184         layout_image_next(lw);
1185 }
1186
1187 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
1188 {
1189         LayoutWindow *lw = data;
1190         layout_image_last(lw);
1191 }
1192
1193 static void layout_menu_back_cb(GtkAction *action, gpointer data)
1194 {
1195         LayoutWindow *lw = data;
1196         FileData *dir_fd;
1197         gchar *path = NULL;
1198         GList *list = history_list_get_by_key("path_list");
1199         gint n = 0;
1200
1201         while (list)
1202                 {
1203                 if (n == 1) {
1204                         /* Previous path from history */
1205                         path = (gchar *)list->data;
1206                         break;
1207                 }
1208                 list = list->next;
1209                 n++;
1210                 }
1211
1212         if (!path) return;
1213
1214         /* Open previous path */
1215         dir_fd = file_data_new_dir(path);
1216         layout_set_fd(lw, dir_fd);
1217         file_data_unref(dir_fd);
1218 }
1219
1220 static void layout_menu_home_cb(GtkAction *action, gpointer data)
1221 {
1222         LayoutWindow *lw = data;
1223         const gchar *path;
1224
1225         if (lw->options.home_path && *lw->options.home_path)
1226                 path = lw->options.home_path;
1227         else
1228                 path = homedir();
1229
1230         if (path)
1231                 {
1232                 FileData *dir_fd = file_data_new_dir(path);
1233                 layout_set_fd(lw, dir_fd);
1234                 file_data_unref(dir_fd);
1235                 }
1236 }
1237
1238 static void layout_menu_up_cb(GtkAction *action, gpointer data)
1239 {
1240         LayoutWindow *lw = data;
1241         ViewDir *vd = lw->vd;
1242         gchar *path;
1243
1244         if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1245         path = remove_level_from_path(vd->dir_fd->path);
1246
1247         if (vd->select_func)
1248                 {
1249                 FileData *fd = file_data_new_dir(path);
1250                 vd->select_func(vd, fd, vd->select_data);
1251                 file_data_unref(fd);
1252                 }
1253
1254         g_free(path);
1255 }
1256
1257
1258 /*
1259  *-----------------------------------------------------------------------------
1260  * edit menu
1261  *-----------------------------------------------------------------------------
1262  */
1263
1264 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1265 {
1266         LayoutWindow *lw = data;
1267         const gchar *key = gtk_action_get_name(action);
1268
1269         if (!editor_window_flag_set(key))
1270                 layout_exit_fullscreen(lw);
1271
1272         file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1273 }
1274
1275
1276 static void layout_menu_metadata_write_cb(GtkAction *action, gpointer data)
1277 {
1278         metadata_write_queue_confirm(TRUE, NULL, NULL);
1279 }
1280
1281
1282 /*
1283  *-----------------------------------------------------------------------------
1284  * color profile button (and menu)
1285  *-----------------------------------------------------------------------------
1286  */
1287
1288 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1289 {
1290 #ifdef HAVE_LCMS
1291         LayoutWindow *lw = data;
1292
1293         if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1294
1295         layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1296         layout_util_sync_color(lw);
1297         layout_image_refresh(lw);
1298 #endif
1299 }
1300
1301 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1302 {
1303 #ifdef HAVE_LCMS
1304         LayoutWindow *lw = data;
1305         gint input;
1306         gboolean use_image;
1307
1308         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1309         if (use_image == gtk_toggle_action_get_active(action)) return;
1310         layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1311         layout_util_sync_color(lw);
1312         layout_image_refresh(lw);
1313 #endif
1314 }
1315
1316 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
1317 {
1318 #ifdef HAVE_LCMS
1319         LayoutWindow *lw = data;
1320         gint type;
1321         gint input;
1322         gboolean use_image;
1323
1324         type = gtk_radio_action_get_current_value(action);
1325         if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
1326
1327         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1328         if (type == input) return;
1329
1330         layout_image_color_profile_set(lw, type, use_image);
1331         layout_image_refresh(lw);
1332 #endif
1333 }
1334
1335
1336 /*
1337  *-----------------------------------------------------------------------------
1338  * recent menu
1339  *-----------------------------------------------------------------------------
1340  */
1341
1342 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
1343 {
1344         gint n;
1345         gchar *path;
1346
1347         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
1348
1349         path = g_list_nth_data(history_list_get_by_key("recent"), n);
1350
1351         if (!path) return;
1352
1353         /* make a copy of it */
1354         path = g_strdup(path);
1355         collection_window_new(path);
1356         g_free(path);
1357 }
1358
1359 static void layout_menu_recent_update(LayoutWindow *lw)
1360 {
1361         GtkWidget *menu;
1362         GtkWidget *recent;
1363         GtkWidget *item;
1364         GList *list;
1365         gint n;
1366
1367         if (!lw->ui_manager) return;
1368
1369         list = history_list_get_by_key("recent");
1370         n = 0;
1371
1372         menu = gtk_menu_new();
1373
1374         while (list)
1375                 {
1376                 const gchar *filename = filename_from_path((gchar *)list->data);
1377                 gchar *name;
1378                 gboolean free_name = FALSE;
1379
1380                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
1381                         {
1382                         name = remove_extension_from_path(filename);
1383                         free_name = TRUE;
1384                         }
1385                 else
1386                         {
1387                         name = (gchar *) filename;
1388                         }
1389
1390                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
1391                 if (free_name) g_free(name);
1392                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
1393                 list = list->next;
1394                 n++;
1395                 }
1396
1397         if (n == 0)
1398                 {
1399                 menu_item_add(menu, _("Empty"), NULL, NULL);
1400                 }
1401
1402         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
1403         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
1404         gtk_widget_set_sensitive(recent, (n != 0));
1405 }
1406
1407 void layout_recent_update_all(void)
1408 {
1409         GList *work;
1410
1411         work = layout_window_list;
1412         while (work)
1413                 {
1414                 LayoutWindow *lw = work->data;
1415                 work = work->next;
1416
1417                 layout_menu_recent_update(lw);
1418                 }
1419 }
1420
1421 void layout_recent_add_path(const gchar *path)
1422 {
1423         if (!path) return;
1424
1425         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
1426
1427         layout_recent_update_all();
1428 }
1429
1430 /*
1431  *-----------------------------------------------------------------------------
1432  * menu
1433  *-----------------------------------------------------------------------------
1434  */
1435
1436 #define CB G_CALLBACK
1437
1438 static GtkActionEntry menu_entries[] = {
1439   { "FileMenu",         NULL,                   N_("_File"),                            NULL,                   NULL,                                   NULL },
1440   { "GoMenu",           NULL,                   N_("_Go"),                              NULL,                   NULL,                                   NULL },
1441   { "EditMenu",         NULL,                   N_("_Edit"),                            NULL,                   NULL,                                   NULL },
1442   { "SelectMenu",       NULL,                   N_("_Select"),                          NULL,                   NULL,                                   NULL },
1443   { "OrientationMenu",  NULL,                   N_("_Orientation"),                     NULL,                   NULL,                                   NULL },
1444   { "ExternalMenu",     NULL,                   N_("E_xternal Editors"),                NULL,                   NULL,                                   NULL },
1445   { "PreferencesMenu",  NULL,                   N_("P_references"),                     NULL,                   NULL,                                   NULL },
1446   { "ViewMenu",         NULL,                   N_("_View"),                            NULL,                   NULL,                                   NULL },
1447   { "FileDirMenu",      NULL,                   N_("_Files and Folders"),               NULL,                   NULL,                                   NULL },
1448   { "ZoomMenu",         NULL,                   N_("_Zoom"),                            NULL,                   NULL,                                   NULL },
1449   { "ColorMenu",        NULL,                   N_("_Color Management"),                NULL,                   NULL,                                   NULL },
1450   { "ConnectZoomMenu",  NULL,                   N_("_Connected Zoom"),                  NULL,                   NULL,                                   NULL },
1451   { "SplitMenu",        NULL,                   N_("Spli_t"),                           NULL,                   NULL,                                   NULL },
1452   { "StereoMenu",       NULL,                   N_("Stere_o"),                          NULL,                   NULL,                                   NULL },
1453   { "OverlayMenu",      NULL,                   N_("Image _Overlay"),                   NULL,                   NULL,                                   NULL },
1454   { "HelpMenu",         NULL,                   N_("_Help"),                            NULL,                   NULL,                                   NULL },
1455
1456   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),                     "Home",                 N_("First Image"),                      CB(layout_menu_image_first_cb) },
1457   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "BackSpace",            N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1458   { "PrevImageAlt1",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "Page_Up",              N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1459   { "PrevImageAlt2",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "KP_Page_Up",           N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1460   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "space",                N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1461   { "NextImageAlt1",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "Page_Down",            N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1462   { "NextImageAlt2",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "KP_Page_Down",         N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1463   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),                      "End",                  N_("Last Image"),                       CB(layout_menu_image_last_cb) },
1464   { "Back",             GTK_STOCK_GO_BACK,      N_("_Back"),                            NULL,                   N_("Back"),                             CB(layout_menu_back_cb) },
1465   { "Home",             GTK_STOCK_HOME,         N_("_Home"),                            NULL,                   N_("Home"),                             CB(layout_menu_home_cb) },
1466   { "Up",               GTK_STOCK_GO_UP,        N_("_Up"),                              NULL,                   N_("Up"),                               CB(layout_menu_up_cb) },
1467
1468   { "NewWindow",        GTK_STOCK_NEW,          N_("New _window"),                      "<control>N",           N_("New window"),                       CB(layout_menu_new_window_cb) },
1469   { "NewCollection",    GTK_STOCK_INDEX,        N_("_New collection"),                  "C",                    N_("New collection"),                   CB(layout_menu_new_cb) },
1470   { "OpenCollection",   GTK_STOCK_OPEN,         N_("_Open collection..."),              "O",                    N_("Open collection..."),               CB(layout_menu_open_cb) },
1471   { "OpenRecent",       NULL,                   N_("Open recen_t"),                     NULL,                   N_("Open recent"),                      NULL },
1472   { "Search",           GTK_STOCK_FIND,         N_("_Search..."),                       "F3",                   N_("Search..."),                        CB(layout_menu_search_cb) },
1473   { "FindDupes",        GTK_STOCK_FIND,         N_("_Find duplicates..."),              "D",                    N_("Find duplicates..."),               CB(layout_menu_dupes_cb) },
1474   { "PanView",          NULL,                   N_("Pa_n view"),                        "<control>J",           N_("Pan view"),                         CB(layout_menu_pan_cb) },
1475   { "Print",            GTK_STOCK_PRINT,        N_("_Print..."),                        "<shift>P",             N_("Print..."),                         CB(layout_menu_print_cb) },
1476   { "NewFolder",        GTK_STOCK_DIRECTORY,    N_("N_ew folder..."),                   "<control>F",           N_("New folder..."),                    CB(layout_menu_dir_cb) },
1477   { "Copy",             GTK_STOCK_COPY,         N_("_Copy..."),                         "<control>C",           N_("Copy..."),                          CB(layout_menu_copy_cb) },
1478   { "Move",             NULL,                   N_("_Move..."),                         "<control>M",           N_("Move..."),                          CB(layout_menu_move_cb) },
1479   { "Rename",           NULL,                   N_("_Rename..."),                       "<control>R",           N_("Rename..."),                        CB(layout_menu_rename_cb) },
1480   { "Delete",           GTK_STOCK_DELETE,       N_("_Delete..."),                       "<control>D",           N_("Delete..."),                        CB(layout_menu_delete_cb) },
1481   { "DeleteAlt1",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "Delete",               N_("Delete..."),                        CB(layout_menu_delete_cb) },
1482   { "DeleteAlt2",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "KP_Delete",            N_("Delete..."),                        CB(layout_menu_delete_cb) },
1483   { "EnableGrouping",   NULL,                   N_("Enable file _grouping"),            NULL,                   N_("Enable file grouping"),             CB(layout_menu_enable_grouping_cb) },
1484   { "DisableGrouping",  NULL,                   N_("Disable file groupi_ng"),           NULL,                   N_("Disable file grouping"),            CB(layout_menu_disable_grouping_cb) },
1485   { "CopyPath",         NULL,                   N_("_Copy path to clipboard"),          NULL,                   N_("Copy path to clipboard"),           CB(layout_menu_copy_path_cb) },
1486   { "CloseWindow",      GTK_STOCK_CLOSE,        N_("C_lose window"),                    "<control>W",           N_("Close window"),                     CB(layout_menu_close_cb) },
1487   { "Quit",             GTK_STOCK_QUIT,         N_("_Quit"),                            "<control>Q",           N_("Quit"),                             CB(layout_menu_exit_cb) },
1488   { "RotateCW",         NULL,                   N_("_Rotate clockwise"),                "bracketright",         N_("Rotate clockwise"),                 CB(layout_menu_alter_90_cb) },
1489   { "RotateCCW",        NULL,                   N_("Rotate _counterclockwise"),         "bracketleft",          N_("Rotate counterclockwise"),          CB(layout_menu_alter_90cc_cb) },
1490   { "Rotate180",        NULL,                   N_("Rotate 1_80"),                      "<shift>R",             N_("Rotate 180"),                       CB(layout_menu_alter_180_cb) },
1491   { "Mirror",           NULL,                   N_("_Mirror"),                          "<shift>M",             N_("Mirror"),                           CB(layout_menu_alter_mirror_cb) },
1492   { "Flip",             NULL,                   N_("_Flip"),                            "<shift>F",             N_("Flip"),                             CB(layout_menu_alter_flip_cb) },
1493   { "AlterNone",        NULL,                   N_("_Original state"),                  "<shift>O",             N_("Original state"),                   CB(layout_menu_alter_none_cb) },
1494   { "SelectAll",        NULL,                   N_("Select _all"),                      "<control>A",           N_("Select all"),                       CB(layout_menu_select_all_cb) },
1495   { "SelectNone",       NULL,                   N_("Select _none"),                     "<control><shift>A",    N_("Select none"),                      CB(layout_menu_unselect_all_cb) },
1496   { "SelectInvert",     NULL,                   N_("_Invert Selection"),                "<control><shift>I",    N_("Invert Selection"),                 CB(layout_menu_invert_selection_cb) },
1497   { "Preferences",      GTK_STOCK_PREFERENCES,  N_("P_references..."),                  "<control>O",           N_("Preferences..."),                   CB(layout_menu_config_cb) },
1498   { "Editors",          GTK_STOCK_PREFERENCES,  N_("Configure _Editors..."),            NULL,                   N_("Configure Editors..."),             CB(layout_menu_editors_cb) },
1499   { "LayoutConfig",     GTK_STOCK_PREFERENCES,  N_("_Configure this window..."),        NULL,                   N_("Configure this window..."),         CB(layout_menu_layout_config_cb) },
1500   { "Maintenance",      NULL,                   N_("_Thumbnail maintenance..."),        NULL,                   N_("Thumbnail maintenance..."),         CB(layout_menu_remove_thumb_cb) },
1501   { "Wallpaper",        NULL,                   N_("Set as _wallpaper"),                NULL,                   N_("Set as wallpaper"),                 CB(layout_menu_wallpaper_cb) },
1502   { "SaveMetadata",     GTK_STOCK_SAVE,         N_("_Save metadata"),                   "<control>S",           N_("Save metadata"),                    CB(layout_menu_metadata_write_cb) },
1503   { "ZoomIn",           GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "equal",                N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1504   { "ZoomInAlt1",       GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "KP_Add",               N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1505   { "ZoomOut",          GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "minus",                N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1506   { "ZoomOutAlt1",      GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "KP_Subtract",          N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1507   { "Zoom100",          GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "Z",                    N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1508   { "Zoom100Alt1",      GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "KP_Divide",            N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1509   { "ZoomFit",          GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "X",                    N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1510   { "ZoomFitAlt1",      GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "KP_Multiply",          N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1511   { "ZoomFillHor",      NULL,                   N_("Fit _Horizontally"),                "H",                    N_("Fit Horizontally"),                 CB(layout_menu_zoom_fit_hor_cb) },
1512   { "ZoomFillVert",     NULL,                   N_("Fit _Vertically"),                  "W",                    N_("Fit Vertically"),                   CB(layout_menu_zoom_fit_vert_cb) },
1513   { "Zoom200",          NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Zoom 2:1"),                         CB(layout_menu_zoom_2_1_cb) },
1514   { "Zoom300",          NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Zoom 3:1"),                         CB(layout_menu_zoom_3_1_cb) },
1515   { "Zoom400",          NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Zoom 4:1"),                         CB(layout_menu_zoom_4_1_cb) },
1516   { "Zoom50",           NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Zoom 1:2"),                         CB(layout_menu_zoom_1_2_cb) },
1517   { "Zoom33",           NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Zoom 1:3"),                         CB(layout_menu_zoom_1_3_cb) },
1518   { "Zoom25",           NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Zoom 1:4"),                         CB(layout_menu_zoom_1_4_cb) },
1519   { "ConnectZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "plus",                 N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1520   { "ConnectZoomInAlt1",GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "<shift>KP_Add",        N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1521   { "ConnectZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "underscore",           N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1522   { "ConnectZoomOutAlt1",GTK_STOCK_ZOOM_OUT,    N_("Zoom _out"),                        "<shift>KP_Subtract",   N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1523   { "ConnectZoom100",   GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "<shift>Z",             N_("Connected Zoom 1:1"),               CB(layout_menu_connect_zoom_1_1_cb) },
1524   { "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) },
1525   { "ConnectZoomFit",   GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "<shift>X",             N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1526   { "ConnectZoomFitAlt1",GTK_STOCK_ZOOM_FIT,    N_("_Zoom to fit"),                     "<shift>KP_Multiply",   N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1527   { "ConnectZoomFillHor",NULL,                  N_("Fit _Horizontally"),                "<shift>H",             N_("Connected Fit Horizontally"),       CB(layout_menu_connect_zoom_fit_hor_cb) },
1528   { "ConnectZoomFillVert",NULL,                 N_("Fit _Vertically"),                  "<shift>W",             N_("Connected Fit Vertically"),         CB(layout_menu_connect_zoom_fit_vert_cb) },
1529   { "ConnectZoom200",   NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Connected Zoom 2:1"),               CB(layout_menu_connect_zoom_2_1_cb) },
1530   { "ConnectZoom300",   NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Connected Zoom 3:1"),               CB(layout_menu_connect_zoom_3_1_cb) },
1531   { "ConnectZoom400",   NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Connected Zoom 4:1"),               CB(layout_menu_connect_zoom_4_1_cb) },
1532   { "ConnectZoom50",    NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Connected Zoom 1:2"),               CB(layout_menu_connect_zoom_1_2_cb) },
1533   { "ConnectZoom33",    NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Connected Zoom 1:3"),               CB(layout_menu_connect_zoom_1_3_cb) },
1534   { "ConnectZoom25",    NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Connected Zoom 1:4"),               CB(layout_menu_connect_zoom_1_4_cb) },
1535   { "ViewInNewWindow",  NULL,                   N_("_View in new window"),              "<control>V",           N_("View in new window"),               CB(layout_menu_view_in_new_window_cb) },
1536   { "FullScreen",       GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1537   { "FullScreenAlt1",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "V",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1538   { "FullScreenAlt2",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F11",                  N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1539   { "Escape",           GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Escape",               N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1540   { "EscapeAlt1",       GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Q",                    N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1541   { "ImageOverlayCycle",NULL,                   N_("_Cycle through overlay modes"),     "I",                    N_("Cycle through Overlay modes"),      CB(layout_menu_overlay_toggle_cb) },
1542   { "HistogramChanCycle",NULL,                  N_("Cycle through histogram ch_annels"),"K",                    N_("Cycle through histogram channels"), CB(layout_menu_histogram_toggle_channel_cb) },
1543   { "HistogramModeCycle",NULL,                  N_("Cycle through histogram mo_des"),   "J",                    N_("Cycle through histogram modes"),    CB(layout_menu_histogram_toggle_mode_cb) },
1544   { "HideTools",        NULL,                   N_("_Hide file list"),                  "<control>H",           N_("Hide file list"),                   CB(layout_menu_hide_cb) },
1545   { "SlideShowPause",   GTK_STOCK_MEDIA_PAUSE,  N_("_Pause slideshow"),                 "P",                    N_("Pause slideshow"),                  CB(layout_menu_slideshow_pause_cb) },
1546   { "Refresh",          GTK_STOCK_REFRESH,      N_("_Refresh"),                         "R",                    N_("Refresh"),                          CB(layout_menu_refresh_cb) },
1547   { "HelpContents",     GTK_STOCK_HELP,         N_("_Contents"),                        "F1",                   N_("Contents"),                         CB(layout_menu_help_cb) },
1548   { "HelpShortcuts",    NULL,                   N_("_Keyboard shortcuts"),              NULL,                   N_("Keyboard shortcuts"),               CB(layout_menu_help_keys_cb) },
1549   { "HelpKbd",          NULL,                   N_("_Keyboard map"),                    NULL,                   N_("Keyboard map"),                     CB(layout_menu_kbd_map_cb) },
1550   { "HelpNotes",        NULL,                   N_("_Release notes"),                   NULL,                   N_("Release notes"),                    CB(layout_menu_notes_cb) },
1551   { "About",            GTK_STOCK_ABOUT,        N_("_About"),                           NULL,                   N_("About"),                            CB(layout_menu_about_cb) },
1552   { "LogWindow",        NULL,                   N_("_Log Window"),                      NULL,                   N_("Log Window"),                       CB(layout_menu_log_window_cb) },
1553   { "ExifWin",          NULL,                   N_("_Exif window"),                     "<control>E",           N_("Exif window"),                      CB(layout_menu_bar_exif_cb) },
1554   { "StereoCycle",      NULL,                   N_("_Cycle through stereo modes"),      NULL,                   N_("Cycle through stereo modes"),       CB(layout_menu_stereo_mode_next_cb) },
1555
1556 };
1557
1558 static GtkToggleActionEntry menu_toggle_entries[] = {
1559   { "Thumbnails",       PIXBUF_INLINE_ICON_THUMB,N_("Show _Thumbnails"),                "T",                    N_("Show Thumbnails"),                  CB(layout_menu_thumb_cb),        FALSE },
1560   { "ShowMarks",        NULL,                   N_("Show _Marks"),                      "M",                    N_("Show Marks"),                       CB(layout_menu_marks_cb),        FALSE  },
1561   { "ShowInfoPixel",    GTK_STOCK_COLOR_PICKER, N_("Pi_xel Info"),                      NULL,                   N_("Show Pixel Info"),                  CB(layout_menu_info_pixel_cb),   FALSE  },
1562   { "FloatTools",       PIXBUF_INLINE_ICON_FLOAT,N_("_Float file list"),                "L",                    N_("Float file list"),                  CB(layout_menu_float_cb),        FALSE  },
1563   { "HideToolbar",      NULL,                   N_("Hide tool_bar"),                    NULL,                   N_("Hide toolbar"),                     CB(layout_menu_toolbar_cb),      FALSE  },
1564   { "SBar",             NULL,                   N_("_Info sidebar"),                    "<control>K",           N_("Info sidebar"),                     CB(layout_menu_bar_cb),          FALSE  },
1565   { "SBarSort",         NULL,                   N_("Sort _manager"),                    "<shift>S",             N_("Sort manager"),                     CB(layout_menu_bar_sort_cb),     FALSE  },
1566   { "SlideShow",        GTK_STOCK_MEDIA_PLAY,   N_("Toggle _slideshow"),                "S",                    N_("Toggle slideshow"),                 CB(layout_menu_slideshow_cb),    FALSE  },
1567   { "UseColorProfiles", GTK_STOCK_SELECT_COLOR, N_("Use _color profiles"),              NULL,                   N_("Use color profiles"),               CB(layout_color_menu_enable_cb), FALSE},
1568   { "UseImageProfile",  NULL,                   N_("Use profile from _image"),          NULL,                   N_("Use profile from image"),           CB(layout_color_menu_use_image_cb), FALSE},
1569   { "Grayscale",        NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
1570   { "ImageOverlay",     NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
1571   { "ImageHistogram",   NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
1572 };
1573
1574 static GtkRadioActionEntry menu_radio_entries[] = {
1575   { "ViewList",         NULL,                   N_("Image _List"),                      "<control>L",           N_("View Images as List"),              FILEVIEW_LIST },
1576   { "ViewIcons",        NULL,                   N_("I_cons"),                           "<control>I",           N_("View Images as Icons"),             FILEVIEW_ICON }
1577 };
1578
1579 static GtkRadioActionEntry menu_view_dir_radio_entries[] = {
1580   { "FolderList",       NULL,                   N_("Folder Li_st"),                     "<meta>L",              N_("View Folders as List"),             DIRVIEW_LIST },
1581   { "FolderTree",       NULL,                   N_("Folder T_ree"),                     "<control>T",           N_("View Folders as Tree"),             DIRVIEW_TREE },
1582 };
1583
1584 static GtkRadioActionEntry menu_split_radio_entries[] = {
1585   { "SplitHorizontal",  NULL,                   N_("_Horizontal"),                      "E",                    N_("Split Horizontal"),                 SPLIT_HOR },
1586   { "SplitVertical",    NULL,                   N_("_Vertical"),                        "U",                    N_("Split Vertical"),                           SPLIT_VERT },
1587   { "SplitQuad",        NULL,                   N_("_Quad"),                            NULL,                   N_("Split Quad"),                               SPLIT_QUAD },
1588   { "SplitSingle",      NULL,                   N_("_Single"),                          "Y",                    N_("Split Single"),                             SPLIT_NONE }
1589 };
1590
1591 static GtkRadioActionEntry menu_color_radio_entries[] = {
1592   { "ColorProfile0",    NULL,                   N_("Input _0: sRGB"),                   NULL,                   N_("Input 0: sRGB"),                    COLOR_PROFILE_SRGB },
1593   { "ColorProfile1",    NULL,                   N_("Input _1: AdobeRGB compatible"),    NULL,                   N_("Input 1: AdobeRGB compatible"),     COLOR_PROFILE_ADOBERGB },
1594   { "ColorProfile2",    NULL,                   N_("Input _2"),                         NULL,                   N_("Input 2"),                          COLOR_PROFILE_FILE },
1595   { "ColorProfile3",    NULL,                   N_("Input _3"),                         NULL,                   N_("Input 3"),                          COLOR_PROFILE_FILE + 1 },
1596   { "ColorProfile4",    NULL,                   N_("Input _4"),                         NULL,                   N_("Input 4"),                          COLOR_PROFILE_FILE + 2 },
1597   { "ColorProfile5",    NULL,                   N_("Input _5"),                         NULL,                   N_("Input 5"),                          COLOR_PROFILE_FILE + 3 }
1598 };
1599
1600 static GtkRadioActionEntry menu_histogram_channel[] = {
1601   { "HistogramChanR",   NULL,                   N_("Histogram on _Red"),                NULL,                   N_("Histogram on Red"),         HCHAN_R },
1602   { "HistogramChanG",   NULL,                   N_("Histogram on _Green"),              NULL,                   N_("Histogram on Green"),       HCHAN_G },
1603   { "HistogramChanB",   NULL,                   N_("Histogram on _Blue"),               NULL,                   N_("Histogram on Blue"),        HCHAN_B },
1604   { "HistogramChanRGB", NULL,                   N_("_Histogram on RGB"),                        NULL,                   N_("Histogram on RGB"),         HCHAN_RGB },
1605   { "HistogramChanV",   NULL,                   N_("Histogram on _Value"),              NULL,                   N_("Histogram on Value"),       HCHAN_MAX }
1606 };
1607
1608 static GtkRadioActionEntry menu_histogram_mode[] = {
1609   { "HistogramModeLin", NULL,                   N_("Li_near Histogram"),                NULL,                   N_("Linear Histogram"),         0 },
1610   { "HistogramModeLog", NULL,                   N_("_Log Histogram"),                   NULL,                   N_("Log Histogram"),            1 },
1611 };
1612
1613 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
1614   { "StereoAuto",       NULL,                   N_("_Auto"),                            NULL,                   N_("Stereo Auto"),              STEREO_PIXBUF_DEFAULT },
1615   { "StereoSBS",        NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      STEREO_PIXBUF_SBS },
1616   { "StereoCross",      NULL,                   N_("_Cross"),                           NULL,                   N_("Stereo Cross"),             STEREO_PIXBUF_CROSS },
1617   { "StereoOff",        NULL,                   N_("_Off"),                             NULL,                   N_("Stereo Off"),               STEREO_PIXBUF_NONE }
1618 };
1619
1620
1621 #undef CB
1622
1623 static const gchar *menu_ui_description =
1624 "<ui>"
1625 "  <menubar name='MainMenu'>"
1626 "    <menu action='FileMenu'>"
1627 "      <menuitem action='NewWindow'/>"
1628 "      <menuitem action='NewCollection'/>"
1629 "      <menuitem action='OpenCollection'/>"
1630 "      <menuitem action='OpenRecent'/>"
1631 "      <placeholder name='OpenSection'/>"
1632 "      <separator/>"
1633 "      <menuitem action='Search'/>"
1634 "      <menuitem action='FindDupes'/>"
1635 "      <placeholder name='SearchSection'/>"
1636 "      <separator/>"
1637 "      <menuitem action='Print'/>"
1638 "      <placeholder name='PrintSection'/>"
1639 "      <separator/>"
1640 "      <menuitem action='NewFolder'/>"
1641 "      <menuitem action='Copy'/>"
1642 "      <menuitem action='Move'/>"
1643 "      <menuitem action='Rename'/>"
1644 "      <menuitem action='Delete'/>"
1645 "      <placeholder name='FileOpsSection'/>"
1646 "      <separator/>"
1647 "      <placeholder name='QuitSection'/>"
1648 "      <menuitem action='CloseWindow'/>"
1649 "      <menuitem action='Quit'/>"
1650 "      <separator/>"
1651 "    </menu>"
1652 "    <menu action='GoMenu'>"
1653 "      <menuitem action='FirstImage'/>"
1654 "      <menuitem action='PrevImage'/>"
1655 "      <menuitem action='NextImage'/>"
1656 "      <menuitem action='LastImage'/>"
1657 "      <separator/>"
1658 "      <menuitem action='Back'/>"
1659 "      <menuitem action='Up'/>"
1660 "      <menuitem action='Home'/>"
1661 "      <separator/>"
1662 "    </menu>"
1663 "    <menu action='SelectMenu'>"
1664 "      <menuitem action='SelectAll'/>"
1665 "      <menuitem action='SelectNone'/>"
1666 "      <menuitem action='SelectInvert'/>"
1667 "      <placeholder name='SelectSection'/>"
1668 "      <separator/>"
1669 "      <menuitem action='CopyPath'/>"
1670 "      <placeholder name='ClipboardSection'/>"
1671 "      <separator/>"
1672 "      <menuitem action='ShowMarks'/>"
1673 "      <placeholder name='MarksSection'/>"
1674 "      <separator/>"
1675 "    </menu>"
1676 "    <menu action='EditMenu'>"
1677 "      <menu action='ExternalMenu'>"
1678 "      </menu>"
1679 "      <placeholder name='EditSection'/>"
1680 "      <separator/>"
1681 "      <menu action='OrientationMenu'>"
1682 "        <menuitem action='RotateCW'/>"
1683 "        <menuitem action='RotateCCW'/>"
1684 "        <menuitem action='Rotate180'/>"
1685 "        <menuitem action='Mirror'/>"
1686 "        <menuitem action='Flip'/>"
1687 "        <menuitem action='AlterNone'/>"
1688 "      </menu>"
1689 "      <menuitem action='SaveMetadata'/>"
1690 "      <placeholder name='PropertiesSection'/>"
1691 "      <separator/>"
1692 "        <menu action='PreferencesMenu'>"
1693 "        <menuitem action='Preferences'/>"
1694 "        <menuitem action='Editors'/>"
1695 "        <menuitem action='LayoutConfig'/>"
1696 "        <menuitem action='Maintenance'/>"
1697 "      </menu>"
1698 "      <placeholder name='PreferencesSection'/>"
1699 "      <separator/>"
1700 "      <menuitem action='Wallpaper'/>"
1701 "      <separator/>"
1702 "    </menu>"
1703 "    <menu action='ViewMenu'>"
1704 "      <menuitem action='ViewInNewWindow'/>"
1705 "      <menuitem action='PanView'/>"
1706 "      <menuitem action='ExifWin'/>"
1707 "      <placeholder name='WindowSection'/>"
1708 "      <separator/>"
1709 "      <menu action='FileDirMenu'>"
1710 "        <menuitem action='FolderList'/>"
1711 "        <menuitem action='FolderTree'/>"
1712 "        <placeholder name='FolderSection'/>"
1713 "        <separator/>"
1714 "        <menuitem action='ViewList'/>"
1715 "        <menuitem action='ViewIcons'/>"
1716 "        <menuitem action='Thumbnails'/>"
1717 "        <placeholder name='ListSection'/>"
1718 "        <separator/>"
1719 "        <menuitem action='FloatTools'/>"
1720 "        <menuitem action='HideTools'/>"
1721 "        <menuitem action='HideToolbar'/>"
1722 "      </menu>"
1723 "      <placeholder name='DirSection'/>"
1724 "      <separator/>"
1725 "      <menu action='ZoomMenu'>"
1726 "        <menu action='ConnectZoomMenu'>"
1727 "          <menuitem action='ConnectZoomIn'/>"
1728 "          <menuitem action='ConnectZoomOut'/>"
1729 "          <menuitem action='ConnectZoomFit'/>"
1730 "          <menuitem action='ConnectZoomFillHor'/>"
1731 "          <menuitem action='ConnectZoomFillVert'/>"
1732 "          <menuitem action='ConnectZoom100'/>"
1733 "          <menuitem action='ConnectZoom200'/>"
1734 "          <menuitem action='ConnectZoom300'/>"
1735 "          <menuitem action='ConnectZoom400'/>"
1736 "          <menuitem action='ConnectZoom50'/>"
1737 "          <menuitem action='ConnectZoom33'/>"
1738 "          <menuitem action='ConnectZoom25'/>"
1739 "        </menu>"
1740 "        <menuitem action='ZoomIn'/>"
1741 "        <menuitem action='ZoomOut'/>"
1742 "        <menuitem action='ZoomFit'/>"
1743 "        <menuitem action='ZoomFillHor'/>"
1744 "        <menuitem action='ZoomFillVert'/>"
1745 "        <menuitem action='Zoom100'/>"
1746 "        <menuitem action='Zoom200'/>"
1747 "        <menuitem action='Zoom300'/>"
1748 "        <menuitem action='Zoom400'/>"
1749 "        <menuitem action='Zoom50'/>"
1750 "        <menuitem action='Zoom33'/>"
1751 "        <menuitem action='Zoom25'/>"
1752 "      </menu>"
1753 "      <menu action='SplitMenu'>"
1754 "        <menuitem action='SplitHorizontal'/>"
1755 "        <menuitem action='SplitVertical'/>"
1756 "        <menuitem action='SplitQuad'/>"
1757 "        <menuitem action='SplitSingle'/>"
1758 "      </menu>"
1759 "      <menu action='StereoMenu'>"
1760 "        <menuitem action='StereoAuto'/>"
1761 "        <menuitem action='StereoSBS'/>"
1762 "        <menuitem action='StereoCross'/>"
1763 "        <menuitem action='StereoOff'/>"
1764 "        <separator/>"
1765 "        <menuitem action='StereoCycle'/>"
1766 "      </menu>"
1767 "      <menu action='ColorMenu'>"
1768 "        <menuitem action='UseColorProfiles'/>"
1769 "        <menuitem action='UseImageProfile'/>"
1770 "        <menuitem action='ColorProfile0'/>"
1771 "        <menuitem action='ColorProfile1'/>"
1772 "        <menuitem action='ColorProfile2'/>"
1773 "        <menuitem action='ColorProfile3'/>"
1774 "        <menuitem action='ColorProfile4'/>"
1775 "        <menuitem action='ColorProfile5'/>"
1776 "        <separator/>"
1777 "        <menuitem action='Grayscale'/>"
1778 "      </menu>"
1779 "      <menu action='OverlayMenu'>"
1780 "        <menuitem action='ImageOverlay'/>"
1781 "        <menuitem action='ImageHistogram'/>"
1782 "        <menuitem action='ImageOverlayCycle'/>"
1783 "        <separator/>"
1784 "        <menuitem action='HistogramChanR'/>"
1785 "        <menuitem action='HistogramChanG'/>"
1786 "        <menuitem action='HistogramChanB'/>"
1787 "        <menuitem action='HistogramChanRGB'/>"
1788 "        <menuitem action='HistogramChanV'/>"
1789 "        <menuitem action='HistogramChanCycle'/>"
1790 "        <separator/>"
1791 "        <menuitem action='HistogramModeLin'/>"
1792 "        <menuitem action='HistogramModeLog'/>"
1793 "        <menuitem action='HistogramModeCycle'/>"
1794 "      </menu>"
1795 "      <menuitem action='FullScreen'/>"
1796 "      <placeholder name='ViewSection'/>"
1797 "      <separator/>"
1798 "      <menuitem action='SBar'/>"
1799 "      <menuitem action='SBarSort'/>"
1800 "      <menuitem action='ShowInfoPixel'/>"
1801 "      <placeholder name='ToolsSection'/>"
1802 "      <separator/>"
1803 "      <menuitem action='SlideShow'/>"
1804 "      <menuitem action='SlideShowPause'/>"
1805 "      <menuitem action='Refresh'/>"
1806 "      <placeholder name='SlideShowSection'/>"
1807 "      <separator/>"
1808 "    </menu>"
1809 "    <menu action='HelpMenu'>"
1810 "      <separator/>"
1811 "      <menuitem action='HelpContents'/>"
1812 "      <menuitem action='HelpShortcuts'/>"
1813 "      <menuitem action='HelpKbd'/>"
1814 "      <menuitem action='HelpNotes'/>"
1815 "      <placeholder name='HelpSection'/>"
1816 "      <separator/>"
1817 "      <menuitem action='About'/>"
1818 "      <separator/>"
1819 "      <menuitem action='LogWindow'/>"
1820 "      <separator/>"
1821 "    </menu>"
1822 "  </menubar>"
1823 "  <toolbar name='ToolBar'>"
1824 "    <toolitem action='Thumbnails'/>"
1825 "    <toolitem action='Back'/>"
1826 "    <toolitem action='Up'/>"
1827 "    <toolitem action='Home'/>"
1828 "    <toolitem action='Refresh'/>"
1829 "    <toolitem action='ZoomIn'/>"
1830 "    <toolitem action='ZoomOut'/>"
1831 "    <toolitem action='ZoomFit'/>"
1832 "    <toolitem action='Zoom100'/>"
1833 "    <toolitem action='Preferences'/>"
1834 "    <toolitem action='FloatTools'/>"
1835 "  </toolbar>"
1836 "  <toolbar name='StatusBar'>"
1837 "    <toolitem action='ShowInfoPixel'/>"
1838 "    <toolitem action='UseColorProfiles'/>"
1839 "    <toolitem action='SaveMetadata'/>"
1840 "  </toolbar>"
1841 "<accelerator action='PrevImageAlt1'/>"
1842 "<accelerator action='PrevImageAlt2'/>"
1843 "<accelerator action='NextImageAlt1'/>"
1844 "<accelerator action='NextImageAlt2'/>"
1845 "<accelerator action='DeleteAlt1'/>"
1846 "<accelerator action='DeleteAlt2'/>"
1847 "<accelerator action='FullScreenAlt1'/>"
1848 "<accelerator action='FullScreenAlt2'/>"
1849 "<accelerator action='Escape'/>"
1850 "<accelerator action='EscapeAlt1'/>"
1851
1852 "<accelerator action='ZoomInAlt1'/>"
1853 "<accelerator action='ZoomOutAlt1'/>"
1854 "<accelerator action='Zoom100Alt1'/>"
1855 "<accelerator action='ZoomFitAlt1'/>"
1856
1857 "<accelerator action='ConnectZoomInAlt1'/>"
1858 "<accelerator action='ConnectZoomOutAlt1'/>"
1859 "<accelerator action='ConnectZoom100Alt1'/>"
1860 "<accelerator action='ConnectZoomFitAlt1'/>"
1861 "</ui>";
1862
1863 static gchar *menu_translate(const gchar *path, gpointer data)
1864 {
1865         return (gchar *)(_(path));
1866 }
1867
1868 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl,
1869                                       gchar *label_tmpl, gchar *accel_tmpl, gchar *tooltip_tmpl, GCallback cb)
1870 {
1871         gchar name[50];
1872         gchar label[100];
1873         gchar accel[50];
1874         gchar tooltip[100];
1875         GtkActionEntry entry = { name, NULL, label, accel, tooltip, cb };
1876         GtkAction *action;
1877
1878         g_snprintf(name, sizeof(name), name_tmpl, mark);
1879         g_snprintf(label, sizeof(label), label_tmpl, mark);
1880
1881         if (accel_tmpl)
1882                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
1883         else
1884                 entry.accelerator = NULL;
1885
1886         if (tooltip_tmpl)
1887                 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
1888         else
1889                 entry.tooltip = NULL;
1890
1891         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
1892         action = gtk_action_group_get_action(lw->action_group, name);
1893         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark));
1894 }
1895
1896 static void layout_actions_setup_marks(LayoutWindow *lw)
1897 {
1898         gint mark;
1899         GError *error;
1900         GString *desc = g_string_new(
1901                                 "<ui>"
1902                                 "  <menubar name='MainMenu'>"
1903                                 "    <menu action='SelectMenu'>");
1904
1905         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1906                 {
1907                 layout_actions_setup_mark(lw, mark, "Mark%d",           _("Mark _%d"), NULL, NULL, NULL);
1908                 layout_actions_setup_mark(lw, mark, "SetMark%d",        _("_Set mark %d"),                      NULL,           _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
1909                 layout_actions_setup_mark(lw, mark, "ResetMark%d",      _("_Reset mark %d"),                    NULL,           _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
1910                 layout_actions_setup_mark(lw, mark, "ToggleMark%d",     _("_Toggle mark %d"),                   "%d",           _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1911                 layout_actions_setup_mark(lw, mark, "ToggleMark%dAlt1", _("_Toggle mark %d"),                   "KP_%d",        _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1912                 layout_actions_setup_mark(lw, mark, "SelectMark%d",     _("Se_lect mark %d"),                   "<control>%d",  _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1913                 layout_actions_setup_mark(lw, mark, "SelectMark%dAlt1", _("_Select mark %d"),                   "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1914                 layout_actions_setup_mark(lw, mark, "AddMark%d",        _("_Add mark %d"),                      NULL,           _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
1915                 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));
1916                 layout_actions_setup_mark(lw, mark, "UnselMark%d",      _("_Unselect mark %d"),                 NULL,           _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
1917                 layout_actions_setup_mark(lw, mark, "FilterMark%d",     _("_Filter mark %d"),                   NULL,           _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
1918
1919                 g_string_append_printf(desc,
1920                                 "      <menu action='Mark%d'>"
1921                                 "        <menuitem action='ToggleMark%d'/>"
1922                                 "        <menuitem action='SetMark%d'/>"
1923                                 "        <menuitem action='ResetMark%d'/>"
1924                                 "        <separator/>"
1925                                 "        <menuitem action='SelectMark%d'/>"
1926                                 "        <menuitem action='AddMark%d'/>"
1927                                 "        <menuitem action='IntMark%d'/>"
1928                                 "        <menuitem action='UnselMark%d'/>"
1929                                 "        <separator/>"
1930                                 "        <menuitem action='FilterMark%d'/>"
1931                                 "      </menu>",
1932                                 mark, mark, mark, mark, mark, mark, mark, mark, mark);
1933                 }
1934
1935         g_string_append(desc,
1936                                 "    </menu>"
1937                                 "  </menubar>");
1938         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1939                 {
1940                 g_string_append_printf(desc,
1941                                 "<accelerator action='ToggleMark%dAlt1'/>"
1942                                 "<accelerator action='SelectMark%dAlt1'/>",
1943                                 mark, mark);
1944                 }
1945         g_string_append(desc,   "</ui>" );
1946
1947         error = NULL;
1948         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
1949                 {
1950                 g_message("building menus failed: %s", error->message);
1951                 g_error_free(error);
1952                 exit(EXIT_FAILURE);
1953                 }
1954         g_string_free(desc, TRUE);
1955 }
1956
1957 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
1958 {
1959         gchar **split = g_strsplit(editor->menu_path, "/", 0);
1960         gint i = 0;
1961         GList *ret = NULL;
1962
1963         if (split[0] == NULL)
1964                 {
1965                 g_strfreev(split);
1966                 return NULL;
1967                 }
1968
1969         while (split[i])
1970                 {
1971                 ret = g_list_prepend(ret, g_strdup(split[i]));
1972                 i++;
1973                 }
1974
1975         g_strfreev(split);
1976
1977         ret = g_list_prepend(ret, g_strdup(editor->key));
1978
1979         return g_list_reverse(ret);
1980 }
1981
1982 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
1983 {
1984         gint to_open, to_close, i;
1985         while (path && old_path && strcmp((gchar *)path->data, (gchar *)old_path->data) == 0)
1986                 {
1987                 path = path->next;
1988                 old_path = old_path->next;
1989                 }
1990         to_open = g_list_length(path) - 1;
1991         to_close = g_list_length(old_path) - 1;
1992
1993         if (to_close > 0)
1994                 {
1995                 old_path = g_list_last(old_path);
1996                 old_path = old_path->prev;
1997                 }
1998
1999         for (i =  0; i < to_close; i++)
2000                 {
2001                 gchar *name = old_path->data;
2002                 if (g_str_has_suffix(name, "Section"))
2003                         {
2004                         g_string_append(desc,   "      </placeholder>");
2005                         }
2006                 else if (g_str_has_suffix(name, "Menu"))
2007                         {
2008                         g_string_append(desc,   "    </menu>");
2009                         }
2010                 else
2011                         {
2012                         g_warning("invalid menu path item %s", name);
2013                         }
2014                 old_path = old_path->prev;
2015                 }
2016
2017         for (i =  0; i < to_open; i++)
2018                 {
2019                 gchar *name = path->data;
2020                 if (g_str_has_suffix(name, "Section"))
2021                         {
2022                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
2023                         }
2024                 else if (g_str_has_suffix(name, "Menu"))
2025                         {
2026                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
2027                         }
2028                 else
2029                         {
2030                         g_warning("invalid menu path item %s", name);
2031                         }
2032                 path = path->next;
2033                 }
2034
2035         if (path)
2036                 g_string_append_printf(desc, "      <menuitem action='%s'/>", (gchar *)path->data);
2037 }
2038
2039 static void layout_actions_setup_editors(LayoutWindow *lw)
2040 {
2041         GError *error;
2042         GList *editors_list;
2043         GList *work;
2044         GList *old_path;
2045         GString *desc;
2046
2047         if (lw->ui_editors_id)
2048                 {
2049                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
2050                 }
2051
2052         if (lw->action_group_editors)
2053                 {
2054                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
2055                 g_object_unref(lw->action_group_editors);
2056                 }
2057         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
2058         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
2059
2060         /* lw->action_group_editors contains translated entries, no translate func is required */
2061         desc = g_string_new(
2062                                 "<ui>"
2063                                 "  <menubar name='MainMenu'>");
2064
2065         editors_list = editor_list_get();
2066
2067         old_path = NULL;
2068         work = editors_list;
2069         while (work)
2070                 {
2071                 GList *path;
2072                 EditorDescription *editor = work->data;
2073                 GtkActionEntry entry = { editor->key,
2074                                          NULL,
2075                                          editor->name,
2076                                          editor->hotkey,
2077                                          editor->comment ? editor->comment : editor->name,
2078                                          G_CALLBACK(layout_menu_edit_cb) };
2079
2080                 if (editor->icon)
2081                         {
2082                         entry.stock_id = editor->key;
2083                         }
2084                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
2085
2086                 path = layout_actions_editor_menu_path(editor);
2087                 layout_actions_editor_add(desc, path, old_path);
2088
2089                 string_list_free(old_path);
2090                 old_path = path;
2091                 work = work->next;
2092                 }
2093
2094         layout_actions_editor_add(desc, NULL, old_path);
2095         string_list_free(old_path);
2096
2097         g_string_append(desc,   "  </menubar>"
2098                                 "</ui>" );
2099
2100         error = NULL;
2101
2102         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
2103         if (!lw->ui_editors_id)
2104                 {
2105                 g_message("building menus failed: %s", error->message);
2106                 g_error_free(error);
2107                 exit(EXIT_FAILURE);
2108                 }
2109         g_string_free(desc, TRUE);
2110         g_list_free(editors_list);
2111 }
2112
2113 void layout_actions_setup(LayoutWindow *lw)
2114 {
2115         GError *error;
2116         gint i;
2117
2118         DEBUG_1("%s layout_actions_setup: start", get_exec_time());
2119         if (lw->ui_manager) return;
2120
2121         lw->action_group = gtk_action_group_new("MenuActions");
2122         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
2123
2124         gtk_action_group_add_actions(lw->action_group,
2125                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
2126         gtk_action_group_add_toggle_actions(lw->action_group,
2127                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
2128         gtk_action_group_add_radio_actions(lw->action_group,
2129                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
2130                                            0, G_CALLBACK(layout_menu_list_cb), lw);
2131         gtk_action_group_add_radio_actions(lw->action_group,
2132                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
2133                                            0, G_CALLBACK(layout_menu_split_cb), lw);
2134         gtk_action_group_add_radio_actions(lw->action_group,
2135                                            menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
2136                                            0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);
2137         gtk_action_group_add_radio_actions(lw->action_group,
2138                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
2139                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
2140         gtk_action_group_add_radio_actions(lw->action_group,
2141                                            menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
2142                                            0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
2143         gtk_action_group_add_radio_actions(lw->action_group,
2144                                            menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
2145                                            0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
2146         gtk_action_group_add_radio_actions(lw->action_group,
2147                                            menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
2148                                            0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
2149
2150
2151         lw->ui_manager = gtk_ui_manager_new();
2152         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
2153         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
2154
2155         DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
2156         error = NULL;
2157         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
2158                 {
2159                 g_message("building menus failed: %s", error->message);
2160                 g_error_free(error);
2161                 exit(EXIT_FAILURE);
2162                 }
2163
2164         DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
2165         layout_actions_setup_marks(lw);
2166
2167         DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
2168         layout_actions_setup_editors(lw);
2169
2170         DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
2171         layout_util_status_update_write(lw);
2172
2173         DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
2174         layout_actions_add_window(lw, lw->window);
2175         DEBUG_1("%s layout_actions_setup: end", get_exec_time());
2176 }
2177
2178 static gint layout_editors_reload_idle_id = -1;
2179 static GList *layout_editors_desktop_files = NULL;
2180
2181 static gboolean layout_editors_reload_idle_cb(gpointer data)
2182 {
2183         if (!layout_editors_desktop_files)
2184                 {
2185                 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
2186                 layout_editors_desktop_files = editor_get_desktop_files();
2187                 return TRUE;
2188                 }
2189
2190         editor_read_desktop_file(layout_editors_desktop_files->data);
2191         g_free(layout_editors_desktop_files->data);
2192         layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
2193
2194
2195         if (!layout_editors_desktop_files)
2196                 {
2197                 GList *work;
2198                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
2199                 editor_table_finish();
2200
2201                 work = layout_window_list;
2202                 while (work)
2203                         {
2204                         LayoutWindow *lw = work->data;
2205                         work = work->next;
2206                         layout_actions_setup_editors(lw);
2207                         }
2208
2209                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
2210
2211                 layout_editors_reload_idle_id = -1;
2212                 return FALSE;
2213                 }
2214         return TRUE;
2215 }
2216
2217 void layout_editors_reload_start(void)
2218 {
2219         DEBUG_1("%s layout_editors_reload_start", get_exec_time());
2220
2221         if (layout_editors_reload_idle_id != -1)
2222                 {
2223                 g_source_remove(layout_editors_reload_idle_id);
2224                 string_list_free(layout_editors_desktop_files);
2225                 }
2226
2227         editor_table_clear();
2228         layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL);
2229 }
2230
2231 void layout_editors_reload_finish(void)
2232 {
2233         if (layout_editors_reload_idle_id != -1)
2234                 {
2235                 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
2236                 g_source_remove(layout_editors_reload_idle_id);
2237                 while (layout_editors_reload_idle_id != -1)
2238                         {
2239                         layout_editors_reload_idle_cb(NULL);
2240                         }
2241                 }
2242 }
2243
2244 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
2245 {
2246         GtkAccelGroup *group;
2247
2248         if (!lw->ui_manager) return;
2249
2250         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
2251         gtk_window_add_accel_group(GTK_WINDOW(window), group);
2252 }
2253
2254 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
2255 {
2256         if (lw->menu_bar) return lw->menu_bar;
2257         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
2258         g_object_ref(lw->menu_bar);
2259         return lw->menu_bar;
2260 }
2261
2262 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
2263 {
2264         if (lw->toolbar[type]) return lw->toolbar[type];
2265         switch (type)
2266                 {
2267                 case TOOLBAR_MAIN:
2268                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar");
2269                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_SMALL_TOOLBAR);
2270                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2271                         break;
2272                 case TOOLBAR_STATUS:
2273                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/StatusBar");
2274                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_MENU);
2275                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2276                         gtk_toolbar_set_show_arrow(GTK_TOOLBAR(lw->toolbar[type]), FALSE);
2277                         break;
2278                 default:
2279                         break;
2280                 }
2281         g_object_ref(lw->toolbar[type]);
2282         return lw->toolbar[type];
2283 }
2284
2285 /*
2286  *-----------------------------------------------------------------------------
2287  * misc
2288  *-----------------------------------------------------------------------------
2289  */
2290
2291 void layout_util_status_update_write(LayoutWindow *lw)
2292 {
2293         GtkAction *action;
2294         gint n = metadata_queue_length();
2295         action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
2296         gtk_action_set_sensitive(action, n > 0);
2297         if (n > 0)
2298                 {
2299                 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
2300                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2301                 g_free(buf);
2302                 }
2303         else
2304                 {
2305                 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
2306                 }
2307 }
2308
2309 void layout_util_status_update_write_all(void)
2310 {
2311         GList *work;
2312
2313         work = layout_window_list;
2314         while (work)
2315                 {
2316                 LayoutWindow *lw = work->data;
2317                 work = work->next;
2318
2319                 layout_util_status_update_write(lw);
2320                 }
2321 }
2322
2323 static gchar *layout_color_name_parse(const gchar *name)
2324 {
2325         if (!name || !*name) return g_strdup(_("Empty"));
2326         return g_strdelimit(g_strdup(name), "_", '-');
2327 }
2328
2329 void layout_util_sync_color(LayoutWindow *lw)
2330 {
2331         GtkAction *action;
2332         gint input = 0;
2333         gboolean use_color;
2334         gboolean use_image = FALSE;
2335         gint i;
2336         gchar action_name[15];
2337         gchar *image_profile;
2338         gchar *screen_profile;
2339
2340
2341         if (!lw->action_group) return;
2342         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
2343
2344         use_color = layout_image_color_profile_get_use(lw);
2345
2346         action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
2347 #ifdef HAVE_LCMS
2348         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
2349         if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
2350                 {
2351                 gchar *buf;
2352                 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
2353                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2354                 g_free(image_profile);
2355                 g_free(screen_profile);
2356                 g_free(buf);
2357                 }
2358         else
2359                 {
2360                 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
2361                 }
2362 #else
2363         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
2364         gtk_action_set_sensitive(action, FALSE);
2365         g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
2366 #endif
2367
2368         action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
2369         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
2370         gtk_action_set_sensitive(action, use_color);
2371
2372         for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
2373                 {
2374                 sprintf(action_name, "ColorProfile%d", i);
2375                 action = gtk_action_group_get_action(lw->action_group, action_name);
2376
2377                 if (i >= COLOR_PROFILE_FILE)
2378                         {
2379                         const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
2380                         const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
2381                         gchar *end;
2382                         gchar *buf;
2383
2384                         if (!name || !name[0]) name = filename_from_path(file);
2385
2386                         end = layout_color_name_parse(name);
2387                         buf = g_strdup_printf(_("Input _%d: %s"), i, end);
2388                         g_free(end);
2389
2390                         g_object_set(G_OBJECT(action), "label", buf, NULL);
2391                         g_free(buf);
2392
2393                         gtk_action_set_visible(action, file && file[0]);
2394                         }
2395
2396                 gtk_action_set_sensitive(action, !use_image);
2397                 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
2398                 }
2399
2400         action = gtk_action_group_get_action(lw->action_group, "Grayscale");
2401         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
2402 }
2403
2404 static void layout_util_sync_views(LayoutWindow *lw)
2405 {
2406         GtkAction *action;
2407         OsdShowFlags osd_flags = image_osd_get(lw->image);
2408
2409         if (!lw->action_group) return;
2410
2411         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
2412         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
2413
2414         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
2415         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
2416
2417         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
2418         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
2419
2420         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
2421         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
2422
2423         action = gtk_action_group_get_action(lw->action_group, "SBar");
2424         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
2425
2426         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
2427         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
2428
2429         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
2430         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
2431
2432         action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
2433         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
2434
2435         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
2436         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
2437
2438         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
2439         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
2440
2441         action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
2442         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
2443
2444         action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
2445         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
2446
2447         if (osd_flags & OSD_SHOW_HISTOGRAM)
2448                 {
2449                 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
2450                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
2451
2452                 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
2453                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
2454                 }
2455
2456         action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
2457         gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
2458
2459         action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
2460         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
2461
2462         layout_util_sync_color(lw);
2463 }
2464
2465 void layout_util_sync_thumb(LayoutWindow *lw)
2466 {
2467         GtkAction *action;
2468
2469         if (!lw->action_group) return;
2470
2471         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
2472         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
2473         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
2474 }
2475
2476 void layout_util_sync(LayoutWindow *lw)
2477 {
2478         layout_util_sync_views(lw);
2479         layout_util_sync_thumb(lw);
2480         layout_menu_recent_update(lw);
2481 //      layout_menu_edit_update(lw);
2482 }
2483
2484
2485 /*
2486  *-----------------------------------------------------------------------------
2487  * sidebars
2488  *-----------------------------------------------------------------------------
2489  */
2490
2491 static gboolean layout_bar_enabled(LayoutWindow *lw)
2492 {
2493         return lw->bar && gtk_widget_get_visible(lw->bar);
2494 }
2495
2496 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
2497 {
2498         LayoutWindow *lw = data;
2499
2500         lw->bar = NULL;
2501 /*
2502     do not call layout_util_sync_views(lw) here
2503     this is called either when whole layout is destroyed - no need for update
2504     or when the bar is replaced - sync is called by upper function at the end of whole operation
2505
2506 */
2507 }
2508
2509 static void layout_bar_set_default(LayoutWindow *lw)
2510 {
2511         GtkWidget *bar;
2512
2513         if (!lw->utility_box) return;
2514
2515         bar = bar_new(lw);
2516
2517         layout_bar_set(lw, bar);
2518
2519         bar_populate_default(bar);
2520 }
2521
2522 static void layout_bar_close(LayoutWindow *lw)
2523 {
2524         if (lw->bar)
2525                 {
2526                 bar_close(lw->bar);
2527                 lw->bar = NULL;
2528                 }
2529 }
2530
2531
2532 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
2533 {
2534         if (!lw->utility_box) return;
2535
2536         layout_bar_close(lw); /* if any */
2537
2538         if (!bar) return;
2539         lw->bar = bar;
2540
2541         g_signal_connect(G_OBJECT(lw->bar), "destroy",
2542                          G_CALLBACK(layout_bar_destroyed), lw);
2543
2544
2545 //      gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
2546         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
2547
2548         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2549 }
2550
2551
2552 void layout_bar_toggle(LayoutWindow *lw)
2553 {
2554         if (layout_bar_enabled(lw))
2555                 {
2556                 gtk_widget_hide(lw->bar);
2557                 }
2558         else
2559                 {
2560                 if (!lw->bar)
2561                         {
2562                         layout_bar_set_default(lw);
2563                         }
2564                 gtk_widget_show(lw->bar);
2565                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
2566                 }
2567         layout_util_sync_views(lw);
2568 }
2569
2570 static void layout_bar_new_image(LayoutWindow *lw)
2571 {
2572         if (!layout_bar_enabled(lw)) return;
2573
2574         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2575 }
2576
2577 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
2578 {
2579         if (!layout_bar_enabled(lw)) return;
2580
2581         bar_notify_selection(lw->bar, count);
2582 }
2583
2584 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
2585 {
2586         return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
2587 }
2588
2589
2590 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
2591 {
2592         LayoutWindow *lw = data;
2593
2594         lw->bar_sort = NULL;
2595
2596 /*
2597     do not call layout_util_sync_views(lw) here
2598     this is called either when whole layout is destroyed - no need for update
2599     or when the bar is replaced - sync is called by upper function at the end of whole operation
2600
2601 */
2602 }
2603
2604 static void layout_bar_sort_set_default(LayoutWindow *lw)
2605 {
2606         GtkWidget *bar;
2607
2608         if (!lw->utility_box) return;
2609
2610         bar = bar_sort_new_default(lw);
2611
2612         layout_bar_sort_set(lw, bar);
2613 }
2614
2615 static void layout_bar_sort_close(LayoutWindow *lw)
2616 {
2617         if (lw->bar_sort)
2618                 {
2619                 bar_sort_close(lw->bar_sort);
2620                 lw->bar_sort = NULL;
2621                 }
2622 }
2623
2624 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
2625 {
2626         if (!lw->utility_box) return;
2627
2628         layout_bar_sort_close(lw); /* if any */
2629
2630         if (!bar) return;
2631         lw->bar_sort = bar;
2632
2633         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
2634                          G_CALLBACK(layout_bar_sort_destroyed), lw);
2635
2636         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
2637 }
2638
2639 void layout_bar_sort_toggle(LayoutWindow *lw)
2640 {
2641         if (layout_bar_sort_enabled(lw))
2642                 {
2643                 gtk_widget_hide(lw->bar_sort);
2644                 }
2645         else
2646                 {
2647                 if (!lw->bar_sort)
2648                         {
2649                         layout_bar_sort_set_default(lw);
2650                         }
2651                 gtk_widget_show(lw->bar_sort);
2652                 }
2653         layout_util_sync_views(lw);
2654 }
2655
2656 void layout_bars_new_image(LayoutWindow *lw)
2657 {
2658         layout_bar_new_image(lw);
2659
2660         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2661
2662         /* this should be called here to handle the metadata edited in bars */
2663         if (options->metadata.confirm_on_image_change)
2664                 metadata_write_queue_confirm(FALSE, NULL, NULL);
2665 }
2666
2667 void layout_bars_new_selection(LayoutWindow *lw, gint count)
2668 {
2669         layout_bar_new_selection(lw, count);
2670 }
2671
2672 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
2673 {
2674         if (lw->utility_box) return lw->utility_box;
2675         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
2676         lw->utility_paned = gtk_hpaned_new();
2677         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
2678
2679         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
2680         gtk_widget_show(lw->utility_paned);
2681
2682         gtk_widget_show(image);
2683
2684         g_object_ref(lw->utility_box);
2685         return lw->utility_box;
2686 }
2687
2688 void layout_bars_close(LayoutWindow *lw)
2689 {
2690         layout_bar_sort_close(lw);
2691         layout_bar_close(lw);
2692 }
2693
2694 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
2695 {
2696         LayoutWindow *lw = data;
2697         lw->exif_window = NULL;
2698 }
2699
2700 void layout_exif_window_new(LayoutWindow *lw)
2701 {
2702         if (lw->exif_window) return;
2703
2704         lw->exif_window = advanced_exif_new();
2705         if (!lw->exif_window) return;
2706         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
2707                          G_CALLBACK(layout_exif_window_destroy), lw);
2708         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2709 }
2710
2711 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */