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