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