Context-sensitve help
[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 "rcfile.h"
48 #include "search.h"
49 #include "slideshow.h"
50 #include "ui_fileops.h"
51 #include "ui_menu.h"
52 #include "ui_misc.h"
53 #include "ui_tabcomp.h"
54 #include "utilops.h"
55 #include "view_dir.h"
56 #include "view_file.h"
57 #include "window.h"
58 #include "metadata.h"
59 #include "desktop_file.h"
60
61 #include <gdk/gdkkeysyms.h> /* for keyboard values */
62 #include "keymap_template.c"
63
64 #define MENU_EDIT_ACTION_OFFSET 16
65 #define FILE_COLUMN_POINTER 0
66
67 static gboolean layout_bar_enabled(LayoutWindow *lw);
68 static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
69 static void layout_bars_hide_toggle(LayoutWindow *lw);
70 static void layout_util_sync_views(LayoutWindow *lw);
71
72 /*
73  *-----------------------------------------------------------------------------
74  * keyboard handler
75  *-----------------------------------------------------------------------------
76  */
77
78 static guint tree_key_overrides[] = {
79         GDK_KEY_Page_Up,        GDK_KEY_KP_Page_Up,
80         GDK_KEY_Page_Down,      GDK_KEY_KP_Page_Down,
81         GDK_KEY_Home,   GDK_KEY_KP_Home,
82         GDK_KEY_End,    GDK_KEY_KP_End
83 };
84
85 static gboolean layout_key_match(guint keyval)
86 {
87         guint i;
88
89         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
90                 {
91                 if (keyval == tree_key_overrides[i]) return TRUE;
92                 }
93
94         return FALSE;
95 }
96
97 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
98 {
99         LayoutWindow *lw = data;
100         GtkWidget *focused;
101         gboolean stop_signal = FALSE;
102         gint x = 0;
103         gint y = 0;
104
105         if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
106                 {
107                 if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
108                         {
109                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
110                         }
111
112                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
113                  * so when the some widgets have focus, give them priority (HACK)
114                  */
115                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
116                         {
117                         return TRUE;
118                         }
119                 }
120         if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
121             !layout_key_match(event->keyval) &&
122             gtk_widget_event(lw->vd->view, (GdkEvent *)event))
123                 {
124                 return TRUE;
125                 }
126         if (lw->bar &&
127             bar_event(lw->bar, (GdkEvent *)event))
128                 {
129                 return TRUE;
130                 }
131
132         focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
133         if (lw->image &&
134             ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
135                 {
136                 stop_signal = TRUE;
137                 switch (event->keyval)
138                         {
139                         case GDK_KEY_Left: case GDK_KEY_KP_Left:
140                                 x -= 1;
141                                 break;
142                         case GDK_KEY_Right: case GDK_KEY_KP_Right:
143                                 x += 1;
144                                 break;
145                         case GDK_KEY_Up: case GDK_KEY_KP_Up:
146                                 y -= 1;
147                                 break;
148                         case GDK_KEY_Down: case GDK_KEY_KP_Down:
149                                 y += 1;
150                                 break;
151                         default:
152                                 stop_signal = FALSE;
153                                 break;
154                         }
155
156                 if (!stop_signal &&
157                     !(event->state & GDK_CONTROL_MASK))
158                         {
159                         stop_signal = TRUE;
160                         switch (event->keyval)
161                                 {
162                                 case GDK_KEY_Menu:
163                                         layout_image_menu_popup(lw);
164                                         break;
165                                 default:
166                                         stop_signal = FALSE;
167                                         break;
168                                 }
169                         }
170                 }
171
172         if (x != 0 || y!= 0)
173                 {
174                 keyboard_scroll_calc(&x, &y, event);
175                 layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK));
176                 }
177
178         return stop_signal;
179 }
180
181 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
182 {
183         g_signal_connect(G_OBJECT(window), "key_press_event",
184                          G_CALLBACK(layout_key_press_cb), lw);
185 }
186
187 /*
188  *-----------------------------------------------------------------------------
189  * menu callbacks
190  *-----------------------------------------------------------------------------
191  */
192
193
194 static GtkWidget *layout_window(LayoutWindow *lw)
195 {
196         return lw->full_screen ? lw->full_screen->window : lw->window;
197 }
198
199 static void layout_exit_fullscreen(LayoutWindow *lw)
200 {
201         if (!lw->full_screen) return;
202         layout_image_full_screen_stop(lw);
203 }
204
205 static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
206 {
207         LayoutWindow *lw = data;
208         LayoutWindow *nw;
209         LayoutOptions lop;
210         gboolean tmp = options->save_window_positions;
211
212         if (!options->use_saved_window_positions_for_new_windows)
213                 options->save_window_positions = FALSE; /* let the windowmanager decide for the first time */
214
215         layout_exit_fullscreen(lw);
216
217         layout_sync_options_with_current_state(lw);
218         lop = lw->options; /* we can copy it directly, no strings are modified */
219
220         lop.id = NULL; /* get a new id */
221         nw = layout_new(NULL, &lop);
222         layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
223         layout_set_fd(nw, lw->dir_fd);
224         options->save_window_positions = tmp;
225 }
226
227 static void layout_menu_new_cb(GtkAction *action, gpointer data)
228 {
229         LayoutWindow *lw = data;
230
231         layout_exit_fullscreen(lw);
232         collection_window_new(NULL);
233 }
234
235 static void layout_menu_open_cb(GtkAction *action, gpointer data)
236 {
237         LayoutWindow *lw = data;
238
239         layout_exit_fullscreen(lw);
240         collection_dialog_load(NULL);
241 }
242
243 static void layout_menu_search_cb(GtkAction *action, gpointer data)
244 {
245         LayoutWindow *lw = data;
246
247         layout_exit_fullscreen(lw);
248         search_new(lw->dir_fd, layout_image_get_fd(lw));
249 }
250
251 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
252 {
253         LayoutWindow *lw = data;
254
255         layout_exit_fullscreen(lw);
256         dupe_window_new();
257 }
258
259 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
260 {
261         LayoutWindow *lw = data;
262
263         layout_exit_fullscreen(lw);
264         pan_window_new(lw->dir_fd);
265 }
266
267 static void layout_menu_print_cb(GtkAction *action, gpointer data)
268 {
269         LayoutWindow *lw = data;
270
271         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
272 }
273
274 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
275 {
276         LayoutWindow *lw = data;
277
278         if (lw->vd) vd_new_folder(lw->vd, lw->dir_fd);
279 }
280
281 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
282 {
283         LayoutWindow *lw = data;
284
285         file_util_copy(NULL, layout_selection_list(lw), NULL, layout_window(lw));
286 }
287
288 static void layout_menu_copy_path_cb(GtkAction *action, gpointer data)
289 {
290         LayoutWindow *lw = data;
291
292         file_util_copy_path_list_to_clipboard(layout_selection_list(lw), TRUE);
293 }
294
295 static void layout_menu_copy_path_unquoted_cb(GtkAction *action, gpointer data)
296 {
297         LayoutWindow *lw = data;
298
299         file_util_copy_path_list_to_clipboard(layout_selection_list(lw), FALSE);
300 }
301
302 static void layout_menu_move_cb(GtkAction *action, gpointer data)
303 {
304         LayoutWindow *lw = data;
305
306         file_util_move(NULL, layout_selection_list(lw), NULL, layout_window(lw));
307 }
308
309 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
310 {
311         LayoutWindow *lw = data;
312
313         file_util_rename(NULL, layout_selection_list(lw), layout_window(lw));
314 }
315
316 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
317 {
318         LayoutWindow *lw = data;
319
320         file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
321 }
322
323 static void layout_menu_delete_key_cb(GtkAction *action, gpointer data)
324 {
325         LayoutWindow *lw = data;
326
327         if (options->file_ops.enable_delete_key)
328                 {
329                 file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
330                 }
331 }
332
333 static void layout_menu_disable_grouping_cb(GtkAction *action, gpointer data)
334 {
335         LayoutWindow *lw = data;
336
337         file_data_disable_grouping_list(layout_selection_list(lw), TRUE);
338 }
339
340 static void layout_menu_enable_grouping_cb(GtkAction *action, gpointer data)
341 {
342         LayoutWindow *lw = data;
343
344         file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
345 }
346
347 static void layout_menu_close_cb(GtkAction *action, gpointer data)
348 {
349         LayoutWindow *lw = data;
350
351         layout_exit_fullscreen(lw);
352         layout_close(lw);
353 }
354
355 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
356 {
357         exit_program();
358 }
359
360 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
361 {
362         LayoutWindow *lw = data;
363
364         layout_image_alter_orientation(lw, ALTER_ROTATE_90);
365 }
366
367 static void layout_menu_rating_0_cb(GtkAction *action, gpointer data)
368 {
369         LayoutWindow *lw = data;
370
371         layout_image_rating(lw, "0");
372 }
373
374 static void layout_menu_rating_1_cb(GtkAction *action, gpointer data)
375 {
376         LayoutWindow *lw = data;
377
378         layout_image_rating(lw, "1");
379 }
380
381 static void layout_menu_rating_2_cb(GtkAction *action, gpointer data)
382 {
383         LayoutWindow *lw = data;
384
385         layout_image_rating(lw, "2");
386 }
387
388 static void layout_menu_rating_3_cb(GtkAction *action, gpointer data)
389 {
390         LayoutWindow *lw = data;
391
392         layout_image_rating(lw, "3");
393 }
394
395 static void layout_menu_rating_4_cb(GtkAction *action, gpointer data)
396 {
397         LayoutWindow *lw = data;
398
399         layout_image_rating(lw, "4");
400 }
401
402 static void layout_menu_rating_5_cb(GtkAction *action, gpointer data)
403 {
404         LayoutWindow *lw = data;
405
406         layout_image_rating(lw, "5");
407 }
408
409 static void layout_menu_rating_m1_cb(GtkAction *action, gpointer data)
410 {
411         LayoutWindow *lw = data;
412
413         layout_image_rating(lw, "-1");
414 }
415
416 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
417 {
418         LayoutWindow *lw = data;
419
420         layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
421 }
422
423 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
424 {
425         LayoutWindow *lw = data;
426
427         layout_image_alter_orientation(lw, ALTER_ROTATE_180);
428 }
429
430 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
431 {
432         LayoutWindow *lw = data;
433
434         layout_image_alter_orientation(lw, ALTER_MIRROR);
435 }
436
437 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
438 {
439         LayoutWindow *lw = data;
440
441         layout_image_alter_orientation(lw, ALTER_FLIP);
442 }
443
444 static void layout_menu_alter_desaturate_cb(GtkToggleAction *action, gpointer data)
445 {
446         LayoutWindow *lw = data;
447
448         layout_image_set_desaturate(lw, gtk_toggle_action_get_active(action));
449 }
450
451 static void layout_menu_alter_none_cb(GtkAction *action, gpointer data)
452 {
453         LayoutWindow *lw = data;
454
455         layout_image_alter_orientation(lw, ALTER_NONE);
456 }
457
458 static void layout_menu_exif_rotate_cb(GtkToggleAction *action, gpointer data)
459 {
460         LayoutWindow *lw = data;
461
462         options->image.exif_rotate_enable = gtk_toggle_action_get_active(action);
463         layout_image_reset_orientation(lw);
464 }
465
466 static void layout_menu_write_rotate(GtkToggleAction *action, gpointer data, gboolean keep_date)
467 {
468         LayoutWindow *lw = data;
469         GtkTreeModel *store;
470         GList *work;
471         GtkTreeSelection *selection;
472         GtkTreePath *tpath;
473         FileData *fd_n;
474         GtkTreeIter iter;
475         gchar *rotation;
476         gchar *command;
477         gint run_result;
478         GenericDialog *gd;
479         GString *message;
480
481         if (!layout_valid(&lw)) return;
482
483         if (!lw || !lw->vf) return;
484
485         if (lw->vf->type == FILEVIEW_ICON)
486                 {
487                 if (!VFICON(lw->vf)->selection) return;
488                 work = VFICON(lw->vf)->selection;
489                 }
490         else
491                 {
492                 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
493                 work = gtk_tree_selection_get_selected_rows(selection, &store);
494                 }
495
496         while (work)
497                 {
498                 if (lw->vf->type == FILEVIEW_ICON)
499                         {
500                         fd_n = work->data;
501                         work = work->next;
502                         }
503                 else
504                         {
505                         tpath = work->data;
506                         gtk_tree_model_get_iter(store, &iter, tpath);
507                         gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
508                         work = work->next;
509                         }
510
511                 rotation = g_strdup_printf("%d", fd_n->user_orientation);
512                 command = g_strconcat(GQ_BIN_DIR, "/geeqie-rotate -r ", rotation,
513                                                                                                         keep_date ? " -t " : " ", fd_n->path, NULL);
514
515                 run_result = WEXITSTATUS(runcmd(command));
516                 if (!run_result)
517                         {
518                         fd_n->user_orientation = 0;
519                         }
520                 else
521                         {
522                         message = g_string_new("");
523                         message = g_string_append(message, _("Operation failed:\n"));
524
525                         if (run_result == 3)
526                                 message = g_string_append(message, _("Cannot create tmp file"));
527                         else
528                                 {
529                                 message = g_string_append(message, _("File: "));
530                                 message = g_string_append(message, fd_n->name);
531                                 }
532
533                         gd = generic_dialog_new(_("Image orientation"),
534                         "Image orientation", NULL, TRUE, NULL, NULL);
535                         generic_dialog_add_message(gd, GTK_STOCK_DIALOG_ERROR,
536                         "Image orientation", message->str, TRUE);
537                         generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, NULL, TRUE);
538
539                         gtk_widget_show(gd->dialog);
540
541                         g_string_free(message, TRUE);
542                         }
543
544                 g_free(rotation);
545                 g_free(command);
546                 }
547 }
548
549 static void layout_menu_write_rotate_keep_date_cb(GtkToggleAction *action, gpointer data)
550 {
551         layout_menu_write_rotate(action, data, TRUE);
552 }
553
554 static void layout_menu_write_rotate_cb(GtkToggleAction *action, gpointer data)
555 {
556         layout_menu_write_rotate(action, data, FALSE);
557 }
558
559 static void layout_menu_config_cb(GtkAction *action, gpointer data)
560 {
561         LayoutWindow *lw = data;
562
563         layout_exit_fullscreen(lw);
564         show_config_window();
565 }
566
567 static void layout_menu_editors_cb(GtkAction *action, gpointer data)
568 {
569         LayoutWindow *lw = data;
570
571         layout_exit_fullscreen(lw);
572         show_editor_list_window();
573 }
574
575 static void layout_menu_layout_config_cb(GtkAction *action, gpointer data)
576 {
577         LayoutWindow *lw = data;
578
579         layout_exit_fullscreen(lw);
580         layout_show_config_window(lw);
581 }
582
583 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
584 {
585         LayoutWindow *lw = data;
586
587         layout_exit_fullscreen(lw);
588         cache_manager_show();
589 }
590
591 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
592 {
593         LayoutWindow *lw = data;
594
595         layout_image_to_root(lw);
596 }
597
598 /* single window zoom */
599 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
600 {
601         LayoutWindow *lw = data;
602
603         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
604 }
605
606 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
607 {
608         LayoutWindow *lw = data;
609
610         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
611 }
612
613 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
614 {
615         LayoutWindow *lw = data;
616
617         layout_image_zoom_set(lw, 1.0, FALSE);
618 }
619
620 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
621 {
622         LayoutWindow *lw = data;
623
624         layout_image_zoom_set(lw, 0.0, FALSE);
625 }
626
627 static void layout_menu_zoom_fit_hor_cb(GtkAction *action, gpointer data)
628 {
629         LayoutWindow *lw = data;
630
631         layout_image_zoom_set_fill_geometry(lw, FALSE, FALSE);
632 }
633
634 static void layout_menu_zoom_fit_vert_cb(GtkAction *action, gpointer data)
635 {
636         LayoutWindow *lw = data;
637
638         layout_image_zoom_set_fill_geometry(lw, TRUE, FALSE);
639 }
640
641 static void layout_menu_zoom_2_1_cb(GtkAction *action, gpointer data)
642 {
643         LayoutWindow *lw = data;
644
645         layout_image_zoom_set(lw, 2.0, FALSE);
646 }
647
648 static void layout_menu_zoom_3_1_cb(GtkAction *action, gpointer data)
649 {
650         LayoutWindow *lw = data;
651
652         layout_image_zoom_set(lw, 3.0, FALSE);
653 }
654 static void layout_menu_zoom_4_1_cb(GtkAction *action, gpointer data)
655 {
656         LayoutWindow *lw = data;
657
658         layout_image_zoom_set(lw, 4.0, FALSE);
659 }
660
661 static void layout_menu_zoom_1_2_cb(GtkAction *action, gpointer data)
662 {
663         LayoutWindow *lw = data;
664
665         layout_image_zoom_set(lw, -2.0, FALSE);
666 }
667
668 static void layout_menu_zoom_1_3_cb(GtkAction *action, gpointer data)
669 {
670         LayoutWindow *lw = data;
671
672         layout_image_zoom_set(lw, -3.0, FALSE);
673 }
674
675 static void layout_menu_zoom_1_4_cb(GtkAction *action, gpointer data)
676 {
677         LayoutWindow *lw = data;
678
679         layout_image_zoom_set(lw, -4.0, FALSE);
680 }
681
682 /* connected zoom */
683 static void layout_menu_connect_zoom_in_cb(GtkAction *action, gpointer data)
684 {
685         LayoutWindow *lw = data;
686
687         layout_image_zoom_adjust(lw, get_zoom_increment(), TRUE);
688 }
689
690 static void layout_menu_connect_zoom_out_cb(GtkAction *action, gpointer data)
691 {
692         LayoutWindow *lw = data;
693
694         layout_image_zoom_adjust(lw, -get_zoom_increment(), TRUE);
695 }
696
697 static void layout_menu_connect_zoom_1_1_cb(GtkAction *action, gpointer data)
698 {
699         LayoutWindow *lw = data;
700
701         layout_image_zoom_set(lw, 1.0, TRUE);
702 }
703
704 static void layout_menu_connect_zoom_fit_cb(GtkAction *action, gpointer data)
705 {
706         LayoutWindow *lw = data;
707
708         layout_image_zoom_set(lw, 0.0, TRUE);
709 }
710
711 static void layout_menu_connect_zoom_fit_hor_cb(GtkAction *action, gpointer data)
712 {
713         LayoutWindow *lw = data;
714
715         layout_image_zoom_set_fill_geometry(lw, FALSE, TRUE);
716 }
717
718 static void layout_menu_connect_zoom_fit_vert_cb(GtkAction *action, gpointer data)
719 {
720         LayoutWindow *lw = data;
721
722         layout_image_zoom_set_fill_geometry(lw, TRUE, TRUE);
723 }
724
725 static void layout_menu_connect_zoom_2_1_cb(GtkAction *action, gpointer data)
726 {
727         LayoutWindow *lw = data;
728
729         layout_image_zoom_set(lw, 2.0, TRUE);
730 }
731
732 static void layout_menu_connect_zoom_3_1_cb(GtkAction *action, gpointer data)
733 {
734         LayoutWindow *lw = data;
735
736         layout_image_zoom_set(lw, 3.0, TRUE);
737 }
738 static void layout_menu_connect_zoom_4_1_cb(GtkAction *action, gpointer data)
739 {
740         LayoutWindow *lw = data;
741
742         layout_image_zoom_set(lw, 4.0, TRUE);
743 }
744
745 static void layout_menu_connect_zoom_1_2_cb(GtkAction *action, gpointer data)
746 {
747         LayoutWindow *lw = data;
748
749         layout_image_zoom_set(lw, -2.0, TRUE);
750 }
751
752 static void layout_menu_connect_zoom_1_3_cb(GtkAction *action, gpointer data)
753 {
754         LayoutWindow *lw = data;
755
756         layout_image_zoom_set(lw, -3.0, TRUE);
757 }
758
759 static void layout_menu_connect_zoom_1_4_cb(GtkAction *action, gpointer data)
760 {
761         LayoutWindow *lw = data;
762
763         layout_image_zoom_set(lw, -4.0, TRUE);
764 }
765
766
767 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
768 {
769         LayoutWindow *lw = data;
770         ImageSplitMode mode;
771
772         layout_exit_fullscreen(lw);
773         mode = gtk_radio_action_get_current_value(action);
774         layout_split_change(lw, mode);
775 }
776
777
778 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
779 {
780         LayoutWindow *lw = data;
781
782         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
783 }
784
785
786 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
787 {
788         LayoutWindow *lw = data;
789
790         layout_exit_fullscreen(lw);
791         layout_views_set(lw, lw->options.dir_view_type, (FileViewType) gtk_radio_action_get_current_value(action));
792 }
793
794 static void layout_menu_view_dir_as_cb(GtkToggleAction *action,  gpointer data)
795 {
796         LayoutWindow *lw = data;
797
798         layout_exit_fullscreen(lw);
799
800         if (gtk_toggle_action_get_active(action))
801                 {
802                 layout_views_set(lw, DIRVIEW_TREE, lw->options.file_view_type);
803                 }
804         else
805                 {
806                 layout_views_set(lw, DIRVIEW_LIST, lw->options.file_view_type);
807                 }
808 }
809
810 static void layout_menu_view_in_new_window_cb(GtkAction *action, gpointer data)
811 {
812         LayoutWindow *lw = data;
813
814         layout_exit_fullscreen(lw);
815         view_window_new(layout_image_get_fd(lw));
816 }
817
818 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
819 {
820         LayoutWindow *lw = data;
821
822         layout_image_full_screen_toggle(lw);
823 }
824
825 static void layout_menu_escape_cb(GtkAction *action, gpointer data)
826 {
827         LayoutWindow *lw = data;
828
829         layout_exit_fullscreen(lw);
830 }
831
832 static void layout_menu_overlay_toggle_cb(GtkAction *action, gpointer data)
833 {
834         LayoutWindow *lw = data;
835
836         image_osd_toggle(lw->image);
837         layout_util_sync_views(lw);
838 }
839
840
841 static void layout_menu_overlay_cb(GtkToggleAction *action, gpointer data)
842 {
843         LayoutWindow *lw = data;
844
845         if (gtk_toggle_action_get_active(action))
846                 {
847                 OsdShowFlags flags = image_osd_get(lw->image);
848
849                 if ((flags | OSD_SHOW_INFO | OSD_SHOW_STATUS) != flags)
850                         image_osd_set(lw->image, flags | OSD_SHOW_INFO | OSD_SHOW_STATUS);
851                 }
852         else
853                 {
854                 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
855
856                 image_osd_set(lw->image, OSD_SHOW_NOTHING);
857                 gtk_toggle_action_set_active(histogram_action, FALSE); /* this calls layout_menu_histogram_cb */
858                 }
859 }
860
861 static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
862 {
863         LayoutWindow *lw = data;
864
865         if (gtk_toggle_action_get_active(action))
866                 {
867                 image_osd_set(lw->image, OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_HISTOGRAM);
868                 layout_util_sync_views(lw); /* show the overlay state, default channel and mode in the menu */
869                 }
870         else
871                 {
872                 OsdShowFlags flags = image_osd_get(lw->image);
873                 if (flags & OSD_SHOW_HISTOGRAM)
874                         image_osd_set(lw->image, flags & ~OSD_SHOW_HISTOGRAM);
875                 }
876 }
877
878 static void layout_menu_animate_cb(GtkToggleAction *action, gpointer data)
879 {
880         LayoutWindow *lw = data;
881
882         if (lw->options.animate == gtk_toggle_action_get_active(action)) return;
883         layout_image_animate_toggle(lw);
884 }
885
886 static void layout_menu_rectangular_selection_cb(GtkToggleAction *action, gpointer data)
887 {
888         options->collections.rectangular_selection = gtk_toggle_action_get_active(action);
889 }
890
891 static void layout_menu_histogram_toggle_channel_cb(GtkAction *action, gpointer data)
892 {
893         LayoutWindow *lw = data;
894
895         image_osd_histogram_toggle_channel(lw->image);
896         layout_util_sync_views(lw);
897 }
898
899 static void layout_menu_histogram_toggle_mode_cb(GtkAction *action, gpointer data)
900 {
901         LayoutWindow *lw = data;
902
903         image_osd_histogram_toggle_mode(lw->image);
904         layout_util_sync_views(lw);
905 }
906
907 static void layout_menu_histogram_channel_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
908 {
909         LayoutWindow *lw = data;
910         gint channel = gtk_radio_action_get_current_value(action);
911         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
912
913         if (channel < 0 || channel >= HCHAN_COUNT) return;
914
915         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
916         image_osd_histogram_set_channel(lw->image, channel);
917 }
918
919 static void layout_menu_histogram_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
920 {
921         LayoutWindow *lw = data;
922         gint mode = gtk_radio_action_get_current_value(action);
923         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
924
925         if (mode < 0 || mode > 1) return;
926
927         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
928         image_osd_histogram_set_mode(lw->image, mode);
929 }
930
931 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
932 {
933         LayoutWindow *lw = data;
934
935         layout_refresh(lw);
936 }
937
938 static void layout_menu_bar_exif_cb(GtkAction *action, gpointer data)
939 {
940         LayoutWindow *lw = data;
941
942         layout_exit_fullscreen(lw);
943         layout_exif_window_new(lw);
944 }
945
946 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
947 {
948         LayoutWindow *lw = data;
949
950         if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return;
951
952         layout_exit_fullscreen(lw);
953         layout_tools_float_toggle(lw);
954 }
955
956 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
957 {
958         LayoutWindow *lw = data;
959
960         layout_exit_fullscreen(lw);
961         layout_tools_hide_toggle(lw);
962 }
963
964 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
965 {
966         LayoutWindow *lw = data;
967
968         if (lw->options.toolbar_hidden == gtk_toggle_action_get_active(action)) return;
969
970         layout_exit_fullscreen(lw);
971         layout_toolbar_toggle(lw);
972 }
973
974 static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
975 {
976         LayoutWindow *lw = data;
977
978         if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
979
980         layout_exit_fullscreen(lw);
981         layout_info_pixel_set(lw, !lw->options.show_info_pixel);
982 }
983
984 /* NOTE: these callbacks are called also from layout_util_sync_views */
985 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
986 {
987         LayoutWindow *lw = data;
988
989         if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
990
991         layout_exit_fullscreen(lw);
992         layout_bar_toggle(lw);
993 }
994
995 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
996 {
997         LayoutWindow *lw = data;
998
999         if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
1000
1001         layout_exit_fullscreen(lw);
1002         layout_bar_sort_toggle(lw);
1003 }
1004
1005 static void layout_menu_hide_bars_cb(GtkToggleAction *action, gpointer data)
1006 {
1007         LayoutWindow *lw = data;
1008
1009         layout_bars_hide_toggle(lw);
1010 }
1011
1012 static void layout_menu_slideshow_cb(GtkToggleAction *action, gpointer data)
1013 {
1014         LayoutWindow *lw = data;
1015
1016         if (layout_image_slideshow_active(lw) == gtk_toggle_action_get_active(action)) return;
1017         layout_image_slideshow_toggle(lw);
1018 }
1019
1020 static void layout_menu_slideshow_pause_cb(GtkAction *action, gpointer data)
1021 {
1022         LayoutWindow *lw = data;
1023
1024         layout_image_slideshow_pause_toggle(lw);
1025 }
1026
1027 static void layout_menu_slideshow_slower_cb(GtkAction *action, gpointer data)
1028 {
1029         options->slideshow.delay = options->slideshow.delay + 5;
1030         if (options->slideshow.delay > SLIDESHOW_MAX_SECONDS)
1031                 options->slideshow.delay = SLIDESHOW_MAX_SECONDS;
1032 }
1033
1034 static void layout_menu_slideshow_faster_cb(GtkAction *action, gpointer data)
1035 {
1036         options->slideshow.delay = options->slideshow.delay - 5;
1037         if (options->slideshow.delay < SLIDESHOW_MIN_SECONDS * 10)
1038                 options->slideshow.delay = SLIDESHOW_MIN_SECONDS * 10;
1039 }
1040
1041
1042 static void layout_menu_stereo_mode_next_cb(GtkAction *action, gpointer data)
1043 {
1044         LayoutWindow *lw = data;
1045         gint mode = layout_image_stereo_pixbuf_get(lw);
1046
1047         /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
1048         mode = mode % 3 + 1;
1049
1050         GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
1051         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
1052
1053         /*
1054         this is called via fallback in layout_menu_stereo_mode_cb
1055         layout_image_stereo_pixbuf_set(lw, mode);
1056         */
1057
1058 }
1059
1060 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
1061 {
1062         LayoutWindow *lw = data;
1063         gint mode = gtk_radio_action_get_current_value(action);
1064         layout_image_stereo_pixbuf_set(lw, mode);
1065 }
1066
1067 static void layout_menu_help_cb(GtkAction *action, gpointer data)
1068 {
1069         LayoutWindow *lw = data;
1070
1071         layout_exit_fullscreen(lw);
1072         help_window_show("index.html");
1073 }
1074
1075 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
1076 {
1077         LayoutWindow *lw = data;
1078
1079         layout_exit_fullscreen(lw);
1080         help_window_show("GuideReferenceKeyboardShortcuts.html");
1081 }
1082
1083 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
1084 {
1085         LayoutWindow *lw = data;
1086
1087         layout_exit_fullscreen(lw);
1088         help_window_show("release_notes");
1089 }
1090
1091 static void layout_menu_changelog_cb(GtkAction *action, gpointer data)
1092 {
1093         LayoutWindow *lw = data;
1094
1095         layout_exit_fullscreen(lw);
1096         help_window_show("changelog");
1097 }
1098
1099 static char *keyboard_map_hardcoded[][2] = {
1100         {"Scroll","Left"},
1101         {"FastScroll", "&lt;Shift&gt;Left"},
1102         {"Left Border", "&lt;Primary&gt;Left"},
1103         {"Left Border", "&lt;Primary&gt;&lt;Shift&gt;Left"},
1104         {"Scroll", "Right"},
1105         {"FastScroll", "&lt;Shift&gt;Right"},
1106         {"Right Border", "&lt;Primary&gt;Right"},
1107         {"Right Border", "&lt;Primary&gt;&lt;Shift&gt;Right"},
1108         {"Scroll", "Up"},
1109         {"FastScroll", "&lt;Shift&gt;Up"},
1110         {"Uper Border", "&lt;Primary&gt;Up"},
1111         {"Uper Border", "&lt;Primary&gt;&lt;Shift&gt;Up"},
1112         {"Scroll", "Down"},
1113         {"FastScroll", "&lt;Shift&gt;Down"},
1114         {"Lower Border", "&lt;Primary&gt;Down"},
1115         {"Lower Border", "&lt;Primary&gt;&lt;Shift&gt;Down"},
1116         {"Next/Drag", "M1"},
1117         {"FastDrag", "&lt;Shift&gt;M1"},
1118         {"DnD Start", "M2"},
1119         {"Menu", "M3"},
1120         {"PrevImage", "MW4"},
1121         {"NextImage", "MW5"},
1122         {"ScrollUp", "&lt;Shift&gt;MW4"},
1123         {"ScrollDown", "&lt;Shift&gt;MW5"},
1124         {"ZoomIn", "&lt;Primary&gt;MW4"},
1125         {"ZoomOut", "&lt;Primary&gt;MW5"},
1126         {NULL, NULL}
1127 };
1128
1129 static void layout_menu_foreach_func(
1130                                         gpointer data,
1131                                         const gchar *accel_path,
1132                                         guint accel_key,
1133                                         GdkModifierType accel_mods,
1134                                         gboolean changed)
1135 {
1136         gchar *path, *name;
1137         gchar *key_name, *menu_name;
1138         gchar **subset_lt_arr, **subset_gt_arr;
1139         gchar *subset_lt, *converted_name;
1140         GPtrArray *array = data;
1141
1142         path = g_strescape(accel_path, NULL);
1143         name = gtk_accelerator_name(accel_key, accel_mods);
1144
1145         menu_name = g_strdup(g_strrstr(path, "/")+1);
1146
1147         if (g_strrstr(name, ">"))
1148                 {
1149                 subset_lt_arr = g_strsplit_set(name,"<", 4);
1150                 subset_lt = g_strjoinv("&lt;", subset_lt_arr);
1151                 subset_gt_arr = g_strsplit_set(subset_lt,">", 4);
1152                 converted_name = g_strjoinv("&gt;", subset_gt_arr);
1153                 key_name = g_strdup(converted_name);
1154
1155                 g_free(converted_name);
1156                 g_free(subset_lt);
1157                 g_strfreev(subset_lt_arr);
1158                 g_strfreev(subset_gt_arr);
1159                 }
1160         else
1161                 key_name = g_strdup(name);
1162
1163         g_ptr_array_add(array, (gpointer)menu_name);
1164         g_ptr_array_add(array, (gpointer)key_name);
1165
1166         g_free(name);
1167         g_free(path);
1168 }
1169
1170 static void layout_menu_kbd_map_cb(GtkAction *action, gpointer data)
1171 {
1172         gint fd = -1;
1173         GPtrArray *array;
1174         char * tmp_file;
1175         GError *error = NULL;
1176         GIOChannel *channel;
1177         char **pre_key, **post_key;
1178         char *key_name, *converted_line;
1179         int keymap_index, index;
1180
1181         fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
1182         if (error)
1183                 {
1184                 log_printf("Error: Keyboard Map - cannot create file:%s\n",error->message);
1185                 g_error_free(error);
1186                 }
1187         else
1188                 {
1189                 array = g_ptr_array_new();
1190
1191                 gtk_accel_map_foreach(array, layout_menu_foreach_func);
1192
1193                 channel = g_io_channel_unix_new(fd);
1194
1195                 keymap_index = 0;
1196                 while (keymap_template[keymap_index])
1197                         {
1198                         if (g_strrstr(keymap_template[keymap_index], ">key:"))
1199                                 {
1200                                 pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
1201                                 post_key = g_strsplit(pre_key[1],"<",2);
1202
1203                                 index=0;
1204                                 key_name = " ";
1205                                 for (index=0; index < array->len-2; index=index+2)
1206                                         {
1207                                         if (!(g_ascii_strcasecmp(g_ptr_array_index(array,index+1), post_key[0])))
1208                                                 {
1209                                                 key_name = g_ptr_array_index(array,index+0);
1210                                                 break;
1211                                                 }
1212                                         }
1213
1214                                 index=0;
1215                                 while (keyboard_map_hardcoded[index][0])
1216                                         {
1217                                         if (!(g_strcmp0(keyboard_map_hardcoded[index][1], post_key[0])))
1218                                                 {
1219                                                 key_name = keyboard_map_hardcoded[index][0];
1220                                                 break;
1221                                                 }
1222                                         index++;
1223                                         }
1224
1225                                 converted_line = g_strconcat(pre_key[0], ">", key_name, "<", post_key[1], "\n", NULL);
1226                                 g_io_channel_write_chars(channel, converted_line, -1, NULL, &error);
1227                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1228
1229                                 g_free(converted_line);
1230                                 g_strfreev(pre_key);
1231                                 g_strfreev(post_key);
1232                                 }
1233                         else
1234                                 {
1235                                 g_io_channel_write_chars(channel, keymap_template[keymap_index], -1, NULL, &error);
1236                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1237                                 g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
1238                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1239                                 }
1240                         keymap_index++;
1241                         }
1242
1243                 g_io_channel_flush(channel, &error);
1244                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1245                 g_io_channel_unref(channel);
1246
1247                 index=0;
1248                 for (index=0; index < array->len-2; index=index+2)
1249                         {
1250                         g_free(g_ptr_array_index(array,index));
1251                         g_free(g_ptr_array_index(array,index+1));
1252                         }
1253                 g_ptr_array_unref(array);
1254
1255                 view_window_new(file_data_new_simple(tmp_file));
1256                 g_free(tmp_file);
1257                 }
1258 }
1259
1260 static void layout_menu_about_cb(GtkAction *action, gpointer data)
1261 {
1262         LayoutWindow *lw = data;
1263
1264         layout_exit_fullscreen(lw);
1265         show_about_window(lw);
1266 }
1267
1268 static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
1269 {
1270         LayoutWindow *lw = data;
1271
1272         layout_exit_fullscreen(lw);
1273         log_window_new(lw);
1274 }
1275
1276
1277 /*
1278  *-----------------------------------------------------------------------------
1279  * select menu
1280  *-----------------------------------------------------------------------------
1281  */
1282
1283 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
1284 {
1285         LayoutWindow *lw = data;
1286
1287         layout_select_all(lw);
1288 }
1289
1290 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
1291 {
1292         LayoutWindow *lw = data;
1293
1294         layout_select_none(lw);
1295 }
1296
1297 static void layout_menu_invert_selection_cb(GtkAction *action, gpointer data)
1298 {
1299         LayoutWindow *lw = data;
1300
1301         layout_select_invert(lw);
1302 }
1303
1304 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
1305 {
1306         LayoutWindow *lw = data;
1307
1308         layout_marks_set(lw, gtk_toggle_action_get_active(action));
1309 }
1310
1311
1312 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
1313 {
1314         LayoutWindow *lw = data;
1315         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1316         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1317
1318         layout_selection_to_mark(lw, mark, STM_MODE_SET);
1319 }
1320
1321 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
1322 {
1323         LayoutWindow *lw = data;
1324         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1325         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1326
1327         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
1328 }
1329
1330 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
1331 {
1332         LayoutWindow *lw = data;
1333         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1334         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1335
1336         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
1337 }
1338
1339 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
1340 {
1341         LayoutWindow *lw = data;
1342         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1343         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1344
1345         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
1346 }
1347
1348 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
1349 {
1350         LayoutWindow *lw = data;
1351         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1352         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1353
1354         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
1355 }
1356
1357 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
1358 {
1359         LayoutWindow *lw = data;
1360         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1361         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1362
1363         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
1364 }
1365
1366 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
1367 {
1368         LayoutWindow *lw = data;
1369         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1370         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1371
1372         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
1373 }
1374
1375 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
1376 {
1377         LayoutWindow *lw = data;
1378         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1379         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1380
1381         layout_marks_set(lw, TRUE);
1382         layout_mark_filter_toggle(lw, mark);
1383 }
1384
1385
1386 /*
1387  *-----------------------------------------------------------------------------
1388  * go menu
1389  *-----------------------------------------------------------------------------
1390  */
1391
1392 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
1393 {
1394         LayoutWindow *lw = data;
1395         layout_image_first(lw);
1396 }
1397
1398 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
1399 {
1400         LayoutWindow *lw = data;
1401         layout_image_prev(lw);
1402 }
1403
1404 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
1405 {
1406         LayoutWindow *lw = data;
1407         layout_image_next(lw);
1408 }
1409
1410 static void layout_menu_split_pane_next_cb(GtkAction *action, gpointer data)
1411 {
1412         LayoutWindow *lw = data;
1413         gint active_frame;
1414
1415         active_frame = lw->active_split_image;
1416
1417         if (active_frame < MAX_SPLIT_IMAGES-1 && lw->split_images[active_frame+1] )
1418                 {
1419                 active_frame++;
1420                 }
1421         else
1422                 {
1423                 active_frame = 0;
1424                 }
1425         layout_image_activate(lw, active_frame, FALSE);
1426 }
1427
1428 static void layout_menu_split_pane_prev_cb(GtkAction *action, gpointer data)
1429 {
1430         LayoutWindow *lw = data;
1431         gint active_frame;
1432
1433         active_frame = lw->active_split_image;
1434
1435         if (active_frame >=1 && lw->split_images[active_frame-1] )
1436                 {
1437                 active_frame--;
1438                 }
1439         else
1440                 {
1441                 active_frame = MAX_SPLIT_IMAGES-1;
1442                 while (!lw->split_images[active_frame])
1443                         {
1444                         active_frame--;
1445                         }
1446                 }
1447         layout_image_activate(lw, active_frame, FALSE);
1448 }
1449
1450 static void layout_menu_split_pane_updown_cb(GtkAction *action, gpointer data)
1451 {
1452         LayoutWindow *lw = data;
1453         gint active_frame;
1454
1455         active_frame = lw->active_split_image;
1456
1457         if (lw->split_images[MAX_SPLIT_IMAGES-1] )
1458                 {
1459                 active_frame = active_frame ^ 2;
1460                 }
1461         else
1462                 {
1463                 active_frame = active_frame ^ 1;
1464                 }
1465         layout_image_activate(lw, active_frame, FALSE);
1466 }
1467
1468 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
1469 {
1470         LayoutWindow *lw = data;
1471         layout_image_last(lw);
1472 }
1473
1474 static void layout_menu_back_cb(GtkAction *action, gpointer data)
1475 {
1476         LayoutWindow *lw = data;
1477         FileData *dir_fd;
1478
1479         /* Obtain previous path */
1480         dir_fd = file_data_new_dir(history_chain_back());
1481         layout_set_fd(lw, dir_fd);
1482         file_data_unref(dir_fd);
1483 }
1484
1485 static void layout_menu_forward_cb(GtkAction *action, gpointer data)
1486 {
1487         LayoutWindow *lw = data;
1488         FileData *dir_fd;
1489
1490         /* Obtain next path */
1491         dir_fd = file_data_new_dir(history_chain_forward());
1492         layout_set_fd(lw, dir_fd);
1493         file_data_unref(dir_fd);
1494 }
1495
1496 static void layout_menu_home_cb(GtkAction *action, gpointer data)
1497 {
1498         LayoutWindow *lw = data;
1499         const gchar *path;
1500
1501         if (lw->options.home_path && *lw->options.home_path)
1502                 path = lw->options.home_path;
1503         else
1504                 path = homedir();
1505
1506         if (path)
1507                 {
1508                 FileData *dir_fd = file_data_new_dir(path);
1509                 layout_set_fd(lw, dir_fd);
1510                 file_data_unref(dir_fd);
1511                 }
1512 }
1513
1514 static void layout_menu_up_cb(GtkAction *action, gpointer data)
1515 {
1516         LayoutWindow *lw = data;
1517         ViewDir *vd = lw->vd;
1518         gchar *path;
1519
1520         if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1521         path = remove_level_from_path(vd->dir_fd->path);
1522
1523         if (vd->select_func)
1524                 {
1525                 FileData *fd = file_data_new_dir(path);
1526                 vd->select_func(vd, fd, vd->select_data);
1527                 file_data_unref(fd);
1528                 }
1529
1530         g_free(path);
1531 }
1532
1533
1534 /*
1535  *-----------------------------------------------------------------------------
1536  * edit menu
1537  *-----------------------------------------------------------------------------
1538  */
1539
1540 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1541 {
1542         LayoutWindow *lw = data;
1543         const gchar *key = gtk_action_get_name(action);
1544
1545         if (!editor_window_flag_set(key))
1546                 layout_exit_fullscreen(lw);
1547
1548         file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1549 }
1550
1551
1552 static void layout_menu_metadata_write_cb(GtkAction *action, gpointer data)
1553 {
1554         metadata_write_queue_confirm(TRUE, NULL, NULL);
1555 }
1556
1557
1558 /*
1559  *-----------------------------------------------------------------------------
1560  * color profile button (and menu)
1561  *-----------------------------------------------------------------------------
1562  */
1563
1564 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1565 {
1566 #ifdef HAVE_LCMS
1567         LayoutWindow *lw = data;
1568
1569         if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1570
1571         layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1572         layout_util_sync_color(lw);
1573         layout_image_refresh(lw);
1574 #endif
1575 }
1576
1577 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1578 {
1579 #ifdef HAVE_LCMS
1580         LayoutWindow *lw = data;
1581         gint input;
1582         gboolean use_image;
1583
1584         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1585         if (use_image == gtk_toggle_action_get_active(action)) return;
1586         layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1587         layout_util_sync_color(lw);
1588         layout_image_refresh(lw);
1589 #endif
1590 }
1591
1592 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
1593 {
1594 #ifdef HAVE_LCMS
1595         LayoutWindow *lw = data;
1596         gint type;
1597         gint input;
1598         gboolean use_image;
1599
1600         type = gtk_radio_action_get_current_value(action);
1601         if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
1602
1603         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1604         if (type == input) return;
1605
1606         layout_image_color_profile_set(lw, type, use_image);
1607         layout_image_refresh(lw);
1608 #endif
1609 }
1610
1611
1612 /*
1613  *-----------------------------------------------------------------------------
1614  * recent menu
1615  *-----------------------------------------------------------------------------
1616  */
1617
1618 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
1619 {
1620         gint n;
1621         gchar *path;
1622
1623         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
1624
1625         path = g_list_nth_data(history_list_get_by_key("recent"), n);
1626
1627         if (!path) return;
1628
1629         /* make a copy of it */
1630         path = g_strdup(path);
1631         collection_window_new(path);
1632         g_free(path);
1633 }
1634
1635 static void layout_menu_recent_update(LayoutWindow *lw)
1636 {
1637         GtkWidget *menu;
1638         GtkWidget *recent;
1639         GtkWidget *item;
1640         GList *list;
1641         gint n;
1642
1643         if (!lw->ui_manager) return;
1644
1645         list = history_list_get_by_key("recent");
1646         n = 0;
1647
1648         menu = gtk_menu_new();
1649
1650         while (list)
1651                 {
1652                 const gchar *filename = filename_from_path((gchar *)list->data);
1653                 gchar *name;
1654                 gboolean free_name = FALSE;
1655
1656                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
1657                         {
1658                         name = remove_extension_from_path(filename);
1659                         free_name = TRUE;
1660                         }
1661                 else
1662                         {
1663                         name = (gchar *) filename;
1664                         }
1665
1666                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
1667                 if (free_name) g_free(name);
1668                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
1669                 list = list->next;
1670                 n++;
1671                 }
1672
1673         if (n == 0)
1674                 {
1675                 menu_item_add(menu, _("Empty"), NULL, NULL);
1676                 }
1677
1678         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
1679         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
1680         gtk_widget_set_sensitive(recent, (n != 0));
1681 }
1682
1683 void layout_recent_update_all(void)
1684 {
1685         GList *work;
1686
1687         work = layout_window_list;
1688         while (work)
1689                 {
1690                 LayoutWindow *lw = work->data;
1691                 work = work->next;
1692
1693                 layout_menu_recent_update(lw);
1694                 }
1695 }
1696
1697 void layout_recent_add_path(const gchar *path)
1698 {
1699         if (!path) return;
1700
1701         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
1702
1703         layout_recent_update_all();
1704 }
1705
1706 /*
1707  *-----------------------------------------------------------------------------
1708  * menu
1709  *-----------------------------------------------------------------------------
1710  */
1711
1712 #define CB G_CALLBACK
1713
1714 static GtkActionEntry menu_entries[] = {
1715   { "FileMenu",         NULL,                   N_("_File"),                            NULL,                   NULL,                                   NULL },
1716   { "GoMenu",           NULL,                   N_("_Go"),                              NULL,                   NULL,                                   NULL },
1717   { "EditMenu",         NULL,                   N_("_Edit"),                            NULL,                   NULL,                                   NULL },
1718   { "SelectMenu",       NULL,                   N_("_Select"),                          NULL,                   NULL,                                   NULL },
1719   { "OrientationMenu",  NULL,                   N_("_Orientation"),                     NULL,                   NULL,                                   NULL },
1720   { "RatingMenu",       NULL,                   N_("_Rating"),                                  NULL,                   NULL,                                   NULL },
1721   { "PreferencesMenu",  NULL,                   N_("P_references"),                     NULL,                   NULL,                                   NULL },
1722   { "ViewMenu",         NULL,                   N_("_View"),                            NULL,                   NULL,                                   NULL },
1723   { "FileDirMenu",      NULL,                   N_("_Files and Folders"),               NULL,                   NULL,                                   NULL },
1724   { "ZoomMenu",         NULL,                   N_("_Zoom"),                            NULL,                   NULL,                                   NULL },
1725   { "ColorMenu",        NULL,                   N_("_Color Management"),                NULL,                   NULL,                                   NULL },
1726   { "ConnectZoomMenu",  NULL,                   N_("_Connected Zoom"),                  NULL,                   NULL,                                   NULL },
1727   { "SplitMenu",        NULL,                   N_("Spli_t"),                           NULL,                   NULL,                                   NULL },
1728   { "StereoMenu",       NULL,                   N_("Stere_o"),                          NULL,                   NULL,                                   NULL },
1729   { "OverlayMenu",      NULL,                   N_("Image _Overlay"),                   NULL,                   NULL,                                   NULL },
1730   { "PluginsMenu",      NULL,                   N_("_Plugins"),                         NULL,                   NULL,                                   NULL },
1731   { "HelpMenu",         NULL,                   N_("_Help"),                            NULL,                   NULL,                                   NULL },
1732
1733   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),                     "Home",                 N_("First Image"),                      CB(layout_menu_image_first_cb) },
1734   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "BackSpace",            N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1735   { "PrevImageAlt1",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "Page_Up",              N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1736   { "PrevImageAlt2",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "KP_Page_Up",           N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1737   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "space",                N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1738   { "NextImageAlt1",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "Page_Down",            N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1739   { "NextImageAlt2",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "KP_Page_Down",         N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1740   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),                      "End",                  N_("Last Image"),                       CB(layout_menu_image_last_cb) },
1741   { "Back",             GTK_STOCK_GO_BACK,      N_("_Back"),                            NULL,                   N_("Back"),                             CB(layout_menu_back_cb) },
1742   { "Forward",  GTK_STOCK_GO_FORWARD,   N_("_Forward"),                 NULL,                   N_("Forward"),                          CB(layout_menu_forward_cb) },
1743   { "Home",             GTK_STOCK_HOME,         N_("_Home"),                            NULL,                   N_("Home"),                             CB(layout_menu_home_cb) },
1744   { "Up",               GTK_STOCK_GO_UP,        N_("_Up"),                              NULL,                   N_("Up"),                               CB(layout_menu_up_cb) },
1745
1746   { "NewWindow",        GTK_STOCK_NEW,          N_("New _window"),                      "<control>N",           N_("New window"),                       CB(layout_menu_new_window_cb) },
1747   { "NewCollection",    GTK_STOCK_INDEX,        N_("_New collection"),                  "C",                    N_("New collection"),                   CB(layout_menu_new_cb) },
1748   { "OpenCollection",   GTK_STOCK_OPEN,         N_("_Open collection..."),              "O",                    N_("Open collection..."),               CB(layout_menu_open_cb) },
1749   { "OpenRecent",       NULL,                   N_("Open recen_t"),                     NULL,                   N_("Open recent"),                      NULL },
1750   { "Search",           GTK_STOCK_FIND,         N_("_Search..."),                       "F3",                   N_("Search..."),                        CB(layout_menu_search_cb) },
1751   { "FindDupes",        GTK_STOCK_FIND,         N_("_Find duplicates..."),              "D",                    N_("Find duplicates..."),               CB(layout_menu_dupes_cb) },
1752   { "PanView",          GTK_STOCK_FILE,                 N_("Pa_n view"),                        "<control>J",           N_("Pan view"),                         CB(layout_menu_pan_cb) },
1753   { "Print",            GTK_STOCK_PRINT,        N_("_Print..."),                        "<shift>P",             N_("Print..."),                         CB(layout_menu_print_cb) },
1754   { "NewFolder",        GTK_STOCK_DIRECTORY,    N_("N_ew folder..."),                   "<control>F",           N_("New folder..."),                    CB(layout_menu_dir_cb) },
1755   { "Copy",             GTK_STOCK_COPY,         N_("_Copy..."),                         "<control>C",           N_("Copy..."),                          CB(layout_menu_copy_cb) },
1756   { "Move",             NULL,                   N_("_Move..."),                         "<control>M",           N_("Move..."),                          CB(layout_menu_move_cb) },
1757   { "Rename",           NULL,                   N_("_Rename..."),                       "<control>R",           N_("Rename..."),                        CB(layout_menu_rename_cb) },
1758   { "Delete",           GTK_STOCK_DELETE,       N_("_Delete..."),                       "<control>D",           N_("Delete..."),                        CB(layout_menu_delete_cb) },
1759   { "DeleteAlt1",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "Delete",               N_("Delete..."),                        CB(layout_menu_delete_key_cb) },
1760   { "DeleteAlt2",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "KP_Delete",            N_("Delete..."),                        CB(layout_menu_delete_key_cb) },
1761   { "EnableGrouping",   NULL,                   N_("Enable file _grouping"),            NULL,                   N_("Enable file grouping"),             CB(layout_menu_enable_grouping_cb) },
1762   { "DisableGrouping",  NULL,                   N_("Disable file groupi_ng"),           NULL,                   N_("Disable file grouping"),            CB(layout_menu_disable_grouping_cb) },
1763   { "CopyPath",         NULL,                   N_("_Copy path to clipboard"),          NULL,                   N_("Copy path to clipboard"),           CB(layout_menu_copy_path_cb) },
1764   { "CopyPathUnquoted",         NULL,                   N_("_Copy path unquoted to clipboard"),         NULL,                   N_("Copy path unquoted to clipboard"),          CB(layout_menu_copy_path_unquoted_cb) },
1765   { "CloseWindow",      GTK_STOCK_CLOSE,        N_("C_lose window"),                    "<control>W",           N_("Close window"),                     CB(layout_menu_close_cb) },
1766   { "Quit",             GTK_STOCK_QUIT,         N_("_Quit"),                            "<control>Q",           N_("Quit"),                             CB(layout_menu_exit_cb) },
1767   { "RotateCW",         NULL,                   N_("_Rotate clockwise"),                "bracketright",         N_("Rotate clockwise"),                 CB(layout_menu_alter_90_cb) },
1768   { "Rating0",          NULL,                   N_("_Rating 0"),        "<alt>KP_0",    N_("Rating 0"),                 CB(layout_menu_rating_0_cb) },
1769   { "Rating1",          NULL,                   N_("_Rating 1"),        "<alt>KP_1",    N_("Rating 1"),                 CB(layout_menu_rating_1_cb) },
1770   { "Rating2",          NULL,                   N_("_Rating 2"),        "<alt>KP_2",    N_("Rating 2"),                 CB(layout_menu_rating_2_cb) },
1771   { "Rating3",          NULL,                   N_("_Rating 3"),        "<alt>KP_3",    N_("Rating 3"),                 CB(layout_menu_rating_3_cb) },
1772   { "Rating4",          NULL,                   N_("_Rating 4"),        "<alt>KP_4",    N_("Rating 4"),                 CB(layout_menu_rating_4_cb) },
1773   { "Rating5",          NULL,                   N_("_Rating 5"),        "<alt>KP_5",    N_("Rating 5"),                 CB(layout_menu_rating_5_cb) },
1774   { "RatingM1",         NULL,                   N_("_Rating -1"),       "<alt>KP_Subtract",     N_("Rating -1"),        CB(layout_menu_rating_m1_cb) },
1775   { "RotateCCW",        NULL,                   N_("Rotate _counterclockwise"),         "bracketleft",          N_("Rotate counterclockwise"),          CB(layout_menu_alter_90cc_cb) },
1776   { "Rotate180",        NULL,                   N_("Rotate 1_80"),                      "<shift>R",             N_("Rotate 180"),                       CB(layout_menu_alter_180_cb) },
1777   { "Mirror",           NULL,                   N_("_Mirror"),                          "<shift>M",             N_("Mirror"),                           CB(layout_menu_alter_mirror_cb) },
1778   { "Flip",             NULL,                   N_("_Flip"),                            "<shift>F",             N_("Flip"),                             CB(layout_menu_alter_flip_cb) },
1779   { "AlterNone",        NULL,                   N_("_Original state"),                  "<shift>O",             N_("Original state"),                   CB(layout_menu_alter_none_cb) },
1780   { "SelectAll",        NULL,                   N_("Select _all"),                      "<control>A",           N_("Select all"),                       CB(layout_menu_select_all_cb) },
1781   { "SelectNone",       NULL,                   N_("Select _none"),                     "<control><shift>A",    N_("Select none"),                      CB(layout_menu_unselect_all_cb) },
1782   { "SelectInvert",     NULL,                   N_("_Invert Selection"),                "<control><shift>I",    N_("Invert Selection"),                 CB(layout_menu_invert_selection_cb) },
1783   { "Preferences",      GTK_STOCK_PREFERENCES,  N_("P_references..."),                  "<control>O",           N_("Preferences..."),                   CB(layout_menu_config_cb) },
1784   { "Plugins",          GTK_STOCK_PREFERENCES,  N_("Configure _Plugins..."),            NULL,                   N_("Configure Plugins..."),             CB(layout_menu_editors_cb) },
1785   { "LayoutConfig",     GTK_STOCK_PREFERENCES,  N_("_Configure this window..."),        NULL,                   N_("Configure this window..."),         CB(layout_menu_layout_config_cb) },
1786   { "Maintenance",      GTK_STOCK_FILE,                 N_("_Thumbnail maintenance..."),        NULL,                   N_("Thumbnail maintenance..."),         CB(layout_menu_remove_thumb_cb) },
1787   { "Wallpaper",        NULL,                   N_("Set as _wallpaper"),                NULL,                   N_("Set as wallpaper"),                 CB(layout_menu_wallpaper_cb) },
1788   { "SaveMetadata",     GTK_STOCK_SAVE,         N_("_Save metadata"),                   "<control>S",           N_("Save metadata"),                    CB(layout_menu_metadata_write_cb) },
1789   { "ZoomIn",           GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "equal",                N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1790   { "ZoomInAlt1",       GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "KP_Add",               N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1791   { "ZoomOut",          GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "minus",                N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1792   { "ZoomOutAlt1",      GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "KP_Subtract",          N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1793   { "Zoom100",          GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "Z",                    N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1794   { "Zoom100Alt1",      GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "KP_Divide",            N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1795   { "ZoomFit",          GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "X",                    N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1796   { "ZoomFitAlt1",      GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "KP_Multiply",          N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1797   { "ZoomFillHor",      GTK_STOCK_FILE,                 N_("Fit _Horizontally"),                "H",                    N_("Fit Horizontally"),                 CB(layout_menu_zoom_fit_hor_cb) },
1798   { "ZoomFillVert",     GTK_STOCK_FILE,                 N_("Fit _Vertically"),                  "W",                    N_("Fit Vertically"),                   CB(layout_menu_zoom_fit_vert_cb) },
1799   { "Zoom200",          GTK_STOCK_FILE,                 N_("Zoom _2:1"),                        NULL,                   N_("Zoom 2:1"),                         CB(layout_menu_zoom_2_1_cb) },
1800   { "Zoom300",          GTK_STOCK_FILE,                 N_("Zoom _3:1"),                        NULL,                   N_("Zoom 3:1"),                         CB(layout_menu_zoom_3_1_cb) },
1801   { "Zoom400",          GTK_STOCK_FILE,                 N_("Zoom _4:1"),                        NULL,                   N_("Zoom 4:1"),                         CB(layout_menu_zoom_4_1_cb) },
1802   { "Zoom50",           GTK_STOCK_FILE,                 N_("Zoom 1:2"),                         NULL,                   N_("Zoom 1:2"),                         CB(layout_menu_zoom_1_2_cb) },
1803   { "Zoom33",           GTK_STOCK_FILE,                 N_("Zoom 1:3"),                         NULL,                   N_("Zoom 1:3"),                         CB(layout_menu_zoom_1_3_cb) },
1804   { "Zoom25",           GTK_STOCK_FILE,                 N_("Zoom 1:4"),                         NULL,                   N_("Zoom 1:4"),                         CB(layout_menu_zoom_1_4_cb) },
1805   { "ConnectZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "plus",                 N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1806   { "ConnectZoomInAlt1",GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "<shift>KP_Add",        N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1807   { "ConnectZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "underscore",           N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1808   { "ConnectZoomOutAlt1",GTK_STOCK_ZOOM_OUT,    N_("Zoom _out"),                        "<shift>KP_Subtract",   N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1809   { "ConnectZoom100",   GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "<shift>Z",             N_("Connected Zoom 1:1"),               CB(layout_menu_connect_zoom_1_1_cb) },
1810   { "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) },
1811   { "ConnectZoomFit",   GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "<shift>X",             N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1812   { "ConnectZoomFitAlt1",GTK_STOCK_ZOOM_FIT,    N_("_Zoom to fit"),                     "<shift>KP_Multiply",   N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1813   { "ConnectZoomFillHor",NULL,                  N_("Fit _Horizontally"),                "<shift>H",             N_("Connected Fit Horizontally"),       CB(layout_menu_connect_zoom_fit_hor_cb) },
1814   { "ConnectZoomFillVert",NULL,                 N_("Fit _Vertically"),                  "<shift>W",             N_("Connected Fit Vertically"),         CB(layout_menu_connect_zoom_fit_vert_cb) },
1815   { "ConnectZoom200",   NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Connected Zoom 2:1"),               CB(layout_menu_connect_zoom_2_1_cb) },
1816   { "ConnectZoom300",   NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Connected Zoom 3:1"),               CB(layout_menu_connect_zoom_3_1_cb) },
1817   { "ConnectZoom400",   NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Connected Zoom 4:1"),               CB(layout_menu_connect_zoom_4_1_cb) },
1818   { "ConnectZoom50",    NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Connected Zoom 1:2"),               CB(layout_menu_connect_zoom_1_2_cb) },
1819   { "ConnectZoom33",    NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Connected Zoom 1:3"),               CB(layout_menu_connect_zoom_1_3_cb) },
1820   { "ConnectZoom25",    NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Connected Zoom 1:4"),               CB(layout_menu_connect_zoom_1_4_cb) },
1821   { "ViewInNewWindow",  NULL,                   N_("_View in new window"),              "<control>V",           N_("View in new window"),               CB(layout_menu_view_in_new_window_cb) },
1822   { "FullScreen",       GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1823   { "FullScreenAlt1",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "V",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1824   { "FullScreenAlt2",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F11",                  N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1825   { "Escape",           GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Escape",               N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1826   { "EscapeAlt1",       GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Q",                    N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1827   { "ImageOverlayCycle",NULL,                   N_("_Cycle through overlay modes"),     "I",                    N_("Cycle through Overlay modes"),      CB(layout_menu_overlay_toggle_cb) },
1828   { "HistogramChanCycle",NULL,                  N_("Cycle through histogram ch_annels"),"K",                    N_("Cycle through histogram channels"), CB(layout_menu_histogram_toggle_channel_cb) },
1829   { "HistogramModeCycle",NULL,                  N_("Cycle through histogram mo_des"),   "J",                    N_("Cycle through histogram modes"),    CB(layout_menu_histogram_toggle_mode_cb) },
1830   { "HideTools",        GTK_STOCK_FILE,                 N_("_Hide file list"),                  "<control>H",           N_("Hide file list"),                   CB(layout_menu_hide_cb) },
1831   { "SlideShowPause",   GTK_STOCK_MEDIA_PAUSE,  N_("_Pause slideshow"),                 "P",                    N_("Pause slideshow"),                  CB(layout_menu_slideshow_pause_cb) },
1832   { "SlideShowFaster",  GTK_STOCK_FILE, N_("Faster"),           "<control>KP_Add",                      N_("Faster"),                   CB(layout_menu_slideshow_faster_cb) },
1833   { "SlideShowSlower",  GTK_STOCK_FILE, N_("Slower"),           "<control>KP_Subtract",                 N_("Slower"),                   CB(layout_menu_slideshow_slower_cb) },
1834   { "Refresh",          GTK_STOCK_REFRESH,      N_("_Refresh"),                         "R",                    N_("Refresh"),                          CB(layout_menu_refresh_cb) },
1835   { "HelpContents",     GTK_STOCK_HELP,         N_("_Contents"),                        "F1",                   N_("Contents"),                         CB(layout_menu_help_cb) },
1836   { "HelpShortcuts",    NULL,                   N_("_Keyboard shortcuts"),              NULL,                   N_("Keyboard shortcuts"),               CB(layout_menu_help_keys_cb) },
1837   { "HelpKbd",          NULL,                   N_("_Keyboard map"),                    NULL,                   N_("Keyboard map"),                     CB(layout_menu_kbd_map_cb) },
1838   { "HelpNotes",        NULL,                   N_("_Release notes"),                   NULL,                   N_("Release notes"),                    CB(layout_menu_notes_cb) },
1839   { "HelpChangeLog",    NULL,                   N_("_ChangeLog"),                       NULL,                   N_("ChangeLog notes"),                  CB(layout_menu_changelog_cb) },
1840   { "About",            GTK_STOCK_ABOUT,        N_("_About"),                           NULL,                   N_("About"),                            CB(layout_menu_about_cb) },
1841   { "LogWindow",        NULL,                   N_("_Log Window"),                      NULL,                   N_("Log Window"),                       CB(layout_menu_log_window_cb) },
1842   { "ExifWin",          GTK_STOCK_FILE,                 N_("_Exif window"),                     "<control>E",           N_("Exif window"),                      CB(layout_menu_bar_exif_cb) },
1843   { "StereoCycle",      NULL,                   N_("_Cycle through stereo modes"),      NULL,                   N_("Cycle through stereo modes"),       CB(layout_menu_stereo_mode_next_cb) },
1844   { "SplitNextPane",    NULL,                   N_("_Next Pane"),       "<alt>Right",                   N_("Next Pane"),        CB(layout_menu_split_pane_next_cb) },
1845   { "SplitPreviousPane",        NULL,                   N_("_Previous Pane"),   "<alt>Left",                    N_("Previous Pane"),    CB(layout_menu_split_pane_prev_cb) },
1846   { "SplitUpPane",      NULL,                   N_("_Up Pane"), "<alt>Up",                      N_("Up Pane"),  CB(layout_menu_split_pane_updown_cb) },
1847   { "SplitDownPane",    NULL,                   N_("_Down Pane"),       "<alt>Down",                    N_("Down Pane"),        CB(layout_menu_split_pane_updown_cb) },
1848   { "WriteRotation",    NULL,                   N_("_Write orientation to file"),               NULL,           N_("Write orientation to file"),                        CB(layout_menu_write_rotate_cb) },
1849   { "WriteRotationKeepDate",    NULL,                   N_("_Write orientation to file (preserve timestamp)"),                  NULL,           N_("Write orientation to file (preserve timestamp)"),                   CB(layout_menu_write_rotate_keep_date_cb) },
1850
1851 };
1852
1853 static GtkToggleActionEntry menu_toggle_entries[] = {
1854   { "Thumbnails",       PIXBUF_INLINE_ICON_THUMB,N_("Show _Thumbnails"),                "T",                    N_("Show Thumbnails"),                  CB(layout_menu_thumb_cb),        FALSE },
1855   { "ShowMarks",        GTK_STOCK_FILE,                 N_("Show _Marks"),                      "M",                    N_("Show Marks"),                       CB(layout_menu_marks_cb),        FALSE  },
1856   { "ShowInfoPixel",    GTK_STOCK_COLOR_PICKER, N_("Pi_xel Info"),                      NULL,                   N_("Show Pixel Info"),                  CB(layout_menu_info_pixel_cb),   FALSE  },
1857   { "FloatTools",       PIXBUF_INLINE_ICON_FLOAT,N_("_Float file list"),                "L",                    N_("Float file list"),                  CB(layout_menu_float_cb),        FALSE  },
1858   { "HideToolbar",      NULL,                   N_("Hide tool_bar"),                    NULL,                   N_("Hide toolbar"),                     CB(layout_menu_toolbar_cb),      FALSE  },
1859   { "SBar",             GTK_STOCK_FILE,                 N_("_Info sidebar"),                    "<control>K",           N_("Info sidebar"),                     CB(layout_menu_bar_cb),          FALSE  },
1860   { "SBarSort",         GTK_STOCK_FILE,                 N_("Sort _manager"),                    "<shift>S",             N_("Sort manager"),                     CB(layout_menu_bar_sort_cb),     FALSE  },
1861   { "HideBars",         NULL,                   N_("Hide Bars"),                        "grave",                N_("Hide Bars"),                        CB(layout_menu_hide_bars_cb),    FALSE  },
1862   { "SlideShow",        GTK_STOCK_MEDIA_PLAY,   N_("Toggle _slideshow"),                "S",                    N_("Toggle slideshow"),                 CB(layout_menu_slideshow_cb),    FALSE  },
1863   { "UseColorProfiles", GTK_STOCK_SELECT_COLOR, N_("Use _color profiles"),              NULL,                   N_("Use color profiles"),               CB(layout_color_menu_enable_cb), FALSE},
1864   { "UseImageProfile",  NULL,                   N_("Use profile from _image"),          NULL,                   N_("Use profile from image"),           CB(layout_color_menu_use_image_cb), FALSE},
1865   { "Grayscale",        NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
1866   { "ImageOverlay",     NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
1867   { "ImageHistogram",   NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
1868   { "RectangularSelection",     NULL,                   N_("Rectangular Selection"),                    "<alt>R",                       N_("Rectangular Selection"),                    CB(layout_menu_rectangular_selection_cb),        FALSE },
1869   { "Animate",  NULL,   N_("GIF _animation"),           "A",                    N_("Toggle GIF animation"),                     CB(layout_menu_animate_cb),      FALSE  },
1870   { "ExifRotate",       GTK_STOCK_ORIENTATION_PORTRAIT,                 N_("_Exif rotate"),             "<alt>X",               N_("Exif rotate"),                      CB(layout_menu_exif_rotate_cb), FALSE },
1871 };
1872
1873 static GtkRadioActionEntry menu_radio_entries[] = {
1874   { "ViewList",         NULL,                   N_("Image _List"),                      "<control>L",           N_("View Images as List"),              FILEVIEW_LIST },
1875   { "ViewIcons",        NULL,                   N_("I_cons"),                           "<control>I",           N_("View Images as Icons"),             FILEVIEW_ICON }
1876 };
1877
1878 static GtkToggleActionEntry menu_view_dir_toggle_entries[] = {
1879   { "FolderTree",       NULL,                   N_("T_oggle Folder View"),                      "<control>T",           N_("Toggle Folders View"),              CB(layout_menu_view_dir_as_cb),FALSE },
1880 };
1881
1882 static GtkRadioActionEntry menu_split_radio_entries[] = {
1883   { "SplitHorizontal",  NULL,                   N_("_Horizontal"),                      "E",                    N_("Split Horizontal"),                 SPLIT_HOR },
1884   { "SplitVertical",    NULL,                   N_("_Vertical"),                        "U",                    N_("Split Vertical"),                           SPLIT_VERT },
1885   { "SplitQuad",        NULL,                   N_("_Quad"),                            NULL,                   N_("Split Quad"),                               SPLIT_QUAD },
1886   { "SplitSingle",      NULL,                   N_("_Single"),                          "Y",                    N_("Split Single"),                             SPLIT_NONE }
1887 };
1888
1889 static GtkRadioActionEntry menu_color_radio_entries[] = {
1890   { "ColorProfile0",    NULL,                   N_("Input _0: sRGB"),                   NULL,                   N_("Input 0: sRGB"),                    COLOR_PROFILE_SRGB },
1891   { "ColorProfile1",    NULL,                   N_("Input _1: AdobeRGB compatible"),    NULL,                   N_("Input 1: AdobeRGB compatible"),     COLOR_PROFILE_ADOBERGB },
1892   { "ColorProfile2",    NULL,                   N_("Input _2"),                         NULL,                   N_("Input 2"),                          COLOR_PROFILE_FILE },
1893   { "ColorProfile3",    NULL,                   N_("Input _3"),                         NULL,                   N_("Input 3"),                          COLOR_PROFILE_FILE + 1 },
1894   { "ColorProfile4",    NULL,                   N_("Input _4"),                         NULL,                   N_("Input 4"),                          COLOR_PROFILE_FILE + 2 },
1895   { "ColorProfile5",    NULL,                   N_("Input _5"),                         NULL,                   N_("Input 5"),                          COLOR_PROFILE_FILE + 3 }
1896 };
1897
1898 static GtkRadioActionEntry menu_histogram_channel[] = {
1899   { "HistogramChanR",   NULL,                   N_("Histogram on _Red"),                NULL,                   N_("Histogram on Red"),         HCHAN_R },
1900   { "HistogramChanG",   NULL,                   N_("Histogram on _Green"),              NULL,                   N_("Histogram on Green"),       HCHAN_G },
1901   { "HistogramChanB",   NULL,                   N_("Histogram on _Blue"),               NULL,                   N_("Histogram on Blue"),        HCHAN_B },
1902   { "HistogramChanRGB", NULL,                   N_("_Histogram on RGB"),                        NULL,                   N_("Histogram on RGB"),         HCHAN_RGB },
1903   { "HistogramChanV",   NULL,                   N_("Histogram on _Value"),              NULL,                   N_("Histogram on Value"),       HCHAN_MAX }
1904 };
1905
1906 static GtkRadioActionEntry menu_histogram_mode[] = {
1907   { "HistogramModeLin", NULL,                   N_("Li_near Histogram"),                NULL,                   N_("Linear Histogram"),         0 },
1908   { "HistogramModeLog", NULL,                   N_("_Log Histogram"),                   NULL,                   N_("Log Histogram"),            1 },
1909 };
1910
1911 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
1912   { "StereoAuto",       NULL,                   N_("_Auto"),                            NULL,                   N_("Stereo Auto"),              STEREO_PIXBUF_DEFAULT },
1913   { "StereoSBS",        NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      STEREO_PIXBUF_SBS },
1914   { "StereoCross",      NULL,                   N_("_Cross"),                           NULL,                   N_("Stereo Cross"),             STEREO_PIXBUF_CROSS },
1915   { "StereoOff",        NULL,                   N_("_Off"),                             NULL,                   N_("Stereo Off"),               STEREO_PIXBUF_NONE }
1916 };
1917
1918
1919 #undef CB
1920
1921 static const gchar *menu_ui_description =
1922 "<ui>"
1923 "  <menubar name='MainMenu'>"
1924 "    <menu action='FileMenu'>"
1925 "      <menuitem action='NewWindow'/>"
1926 "      <menuitem action='NewCollection'/>"
1927 "      <menuitem action='OpenCollection'/>"
1928 "      <menuitem action='OpenRecent'/>"
1929 "      <placeholder name='OpenSection'/>"
1930 "      <separator/>"
1931 "      <menuitem action='Search'/>"
1932 "      <menuitem action='FindDupes'/>"
1933 "      <placeholder name='SearchSection'/>"
1934 "      <separator/>"
1935 "      <menuitem action='Print'/>"
1936 "      <placeholder name='PrintSection'/>"
1937 "      <separator/>"
1938 "      <menuitem action='NewFolder'/>"
1939 "      <menuitem action='Copy'/>"
1940 "      <menuitem action='Move'/>"
1941 "      <menuitem action='Rename'/>"
1942 "      <menuitem action='Delete'/>"
1943 "      <placeholder name='FileOpsSection'/>"
1944 "      <separator/>"
1945 "      <placeholder name='QuitSection'/>"
1946 "      <menuitem action='CloseWindow'/>"
1947 "      <menuitem action='Quit'/>"
1948 "      <separator/>"
1949 "    </menu>"
1950 "    <menu action='GoMenu'>"
1951 "      <menuitem action='FirstImage'/>"
1952 "      <menuitem action='PrevImage'/>"
1953 "      <menuitem action='NextImage'/>"
1954 "      <menuitem action='LastImage'/>"
1955 "      <separator/>"
1956 "      <menuitem action='Back'/>"
1957 "      <menuitem action='Forward'/>"
1958 "      <menuitem action='Up'/>"
1959 "      <menuitem action='Home'/>"
1960 "      <separator/>"
1961 "    </menu>"
1962 "    <menu action='SelectMenu'>"
1963 "      <menuitem action='SelectAll'/>"
1964 "      <menuitem action='SelectNone'/>"
1965 "      <menuitem action='SelectInvert'/>"
1966 "      <menuitem action='RectangularSelection'/>"
1967 "      <placeholder name='SelectSection'/>"
1968 "      <separator/>"
1969 "      <menuitem action='CopyPath'/>"
1970 "      <menuitem action='CopyPathUnquoted'/>"
1971 "      <placeholder name='ClipboardSection'/>"
1972 "      <separator/>"
1973 "      <menuitem action='ShowMarks'/>"
1974 "      <placeholder name='MarksSection'/>"
1975 "      <separator/>"
1976 "    </menu>"
1977 "    <menu action='EditMenu'>"
1978 "      <placeholder name='EditSection'/>"
1979 "      <separator/>"
1980 "      <menu action='OrientationMenu'>"
1981 "        <menuitem action='RotateCW'/>"
1982 "        <menuitem action='RotateCCW'/>"
1983 "        <menuitem action='Rotate180'/>"
1984 "        <menuitem action='Mirror'/>"
1985 "        <menuitem action='Flip'/>"
1986 "        <menuitem action='AlterNone'/>"
1987 "        <separator/>"
1988 "        <menuitem action='ExifRotate'/>"
1989 "        <separator/>"
1990 "        <menuitem action='WriteRotation'/>"
1991 "        <menuitem action='WriteRotationKeepDate'/>"
1992 "        <separator/>"
1993 "      </menu>"
1994 "      <menu action='RatingMenu'>"
1995 "        <menuitem action='Rating0'/>"
1996 "        <menuitem action='Rating1'/>"
1997 "        <menuitem action='Rating2'/>"
1998 "        <menuitem action='Rating3'/>"
1999 "        <menuitem action='Rating4'/>"
2000 "        <menuitem action='Rating5'/>"
2001 "        <menuitem action='RatingM1'/>"
2002 "        <separator/>"
2003 "      </menu>"
2004 "      <menuitem action='SaveMetadata'/>"
2005 "      <placeholder name='PropertiesSection'/>"
2006 "      <separator/>"
2007 "      <menuitem action='Preferences'/>"
2008 "      <menuitem action='Plugins'/>"
2009 "      <menuitem action='LayoutConfig'/>"
2010 "      <menuitem action='Maintenance'/>"
2011 "      <placeholder name='PreferencesSection'/>"
2012 "      <separator/>"
2013 #if !GTK_CHECK_VERSION(3,0,0)
2014 "      <menuitem action='Wallpaper'/>"
2015 #endif
2016 "      <separator/>"
2017 "    </menu>"
2018 "    <menu action='PluginsMenu'>"
2019 "    </menu>"
2020 "    <menu action='ViewMenu'>"
2021 "      <menuitem action='ViewInNewWindow'/>"
2022 "      <menuitem action='PanView'/>"
2023 "      <menuitem action='ExifWin'/>"
2024 "      <placeholder name='WindowSection'/>"
2025 "      <separator/>"
2026 "      <menu action='FileDirMenu'>"
2027 "        <menuitem action='FolderTree'/>"
2028 "        <placeholder name='FolderSection'/>"
2029 "        <separator/>"
2030 "        <menuitem action='ViewList'/>"
2031 "        <menuitem action='ViewIcons'/>"
2032 "        <menuitem action='Thumbnails'/>"
2033 "        <placeholder name='ListSection'/>"
2034 "        <separator/>"
2035 "        <menuitem action='FloatTools'/>"
2036 "        <menuitem action='HideTools'/>"
2037 "        <menuitem action='HideToolbar'/>"
2038 "      </menu>"
2039 "      <placeholder name='DirSection'/>"
2040 "      <separator/>"
2041 "      <menu action='ZoomMenu'>"
2042 "        <menu action='ConnectZoomMenu'>"
2043 "          <menuitem action='ConnectZoomIn'/>"
2044 "          <menuitem action='ConnectZoomOut'/>"
2045 "          <menuitem action='ConnectZoomFit'/>"
2046 "          <menuitem action='ConnectZoomFillHor'/>"
2047 "          <menuitem action='ConnectZoomFillVert'/>"
2048 "          <menuitem action='ConnectZoom100'/>"
2049 "          <menuitem action='ConnectZoom200'/>"
2050 "          <menuitem action='ConnectZoom300'/>"
2051 "          <menuitem action='ConnectZoom400'/>"
2052 "          <menuitem action='ConnectZoom50'/>"
2053 "          <menuitem action='ConnectZoom33'/>"
2054 "          <menuitem action='ConnectZoom25'/>"
2055 "        </menu>"
2056 "        <menuitem action='ZoomIn'/>"
2057 "        <menuitem action='ZoomOut'/>"
2058 "        <menuitem action='ZoomFit'/>"
2059 "        <menuitem action='ZoomFillHor'/>"
2060 "        <menuitem action='ZoomFillVert'/>"
2061 "        <menuitem action='Zoom100'/>"
2062 "        <menuitem action='Zoom200'/>"
2063 "        <menuitem action='Zoom300'/>"
2064 "        <menuitem action='Zoom400'/>"
2065 "        <menuitem action='Zoom50'/>"
2066 "        <menuitem action='Zoom33'/>"
2067 "        <menuitem action='Zoom25'/>"
2068 "      </menu>"
2069 "      <menu action='SplitMenu'>"
2070 "        <menuitem action='SplitHorizontal'/>"
2071 "        <menuitem action='SplitVertical'/>"
2072 "        <menuitem action='SplitQuad'/>"
2073 "        <menuitem action='SplitSingle'/>"
2074 "        <separator/>"
2075 "        <menuitem action='SplitNextPane'/>"
2076 "        <menuitem action='SplitPreviousPane'/>"
2077 "        <menuitem action='SplitUpPane'/>"
2078 "        <menuitem action='SplitDownPane'/>"
2079 "      </menu>"
2080 "      <menu action='StereoMenu'>"
2081 "        <menuitem action='StereoAuto'/>"
2082 "        <menuitem action='StereoSBS'/>"
2083 "        <menuitem action='StereoCross'/>"
2084 "        <menuitem action='StereoOff'/>"
2085 "        <separator/>"
2086 "        <menuitem action='StereoCycle'/>"
2087 "      </menu>"
2088 "      <menu action='ColorMenu'>"
2089 "        <menuitem action='UseColorProfiles'/>"
2090 "        <menuitem action='UseImageProfile'/>"
2091 "        <menuitem action='ColorProfile0'/>"
2092 "        <menuitem action='ColorProfile1'/>"
2093 "        <menuitem action='ColorProfile2'/>"
2094 "        <menuitem action='ColorProfile3'/>"
2095 "        <menuitem action='ColorProfile4'/>"
2096 "        <menuitem action='ColorProfile5'/>"
2097 "        <separator/>"
2098 "        <menuitem action='Grayscale'/>"
2099 "      </menu>"
2100 "      <menu action='OverlayMenu'>"
2101 "        <menuitem action='ImageOverlay'/>"
2102 "        <menuitem action='ImageHistogram'/>"
2103 "        <menuitem action='ImageOverlayCycle'/>"
2104 "        <separator/>"
2105 "        <menuitem action='HistogramChanR'/>"
2106 "        <menuitem action='HistogramChanG'/>"
2107 "        <menuitem action='HistogramChanB'/>"
2108 "        <menuitem action='HistogramChanRGB'/>"
2109 "        <menuitem action='HistogramChanV'/>"
2110 "        <menuitem action='HistogramChanCycle'/>"
2111 "        <separator/>"
2112 "        <menuitem action='HistogramModeLin'/>"
2113 "        <menuitem action='HistogramModeLog'/>"
2114 "        <menuitem action='HistogramModeCycle'/>"
2115 "      </menu>"
2116 "      <menuitem action='FullScreen'/>"
2117 "      <placeholder name='ViewSection'/>"
2118 "      <separator/>"
2119 "      <menuitem action='SBar'/>"
2120 "      <menuitem action='SBarSort'/>"
2121 "      <menuitem action='HideBars'/>"
2122 "      <menuitem action='ShowInfoPixel'/>"
2123 "      <placeholder name='ToolsSection'/>"
2124 "      <separator/>"
2125 "      <menuitem action='Animate'/>"
2126 "      <menuitem action='SlideShow'/>"
2127 "      <menuitem action='SlideShowPause'/>"
2128 "      <menuitem action='SlideShowFaster'/>"
2129 "      <menuitem action='SlideShowSlower'/>"
2130 "      <separator/>"
2131 "      <menuitem action='Refresh'/>"
2132 "      <placeholder name='SlideShowSection'/>"
2133 "      <separator/>"
2134 "    </menu>"
2135 "    <menu action='HelpMenu'>"
2136 "      <separator/>"
2137 "      <menuitem action='HelpContents'/>"
2138 "      <menuitem action='HelpShortcuts'/>"
2139 "      <menuitem action='HelpKbd'/>"
2140 "      <menuitem action='HelpNotes'/>"
2141 "      <menuitem action='HelpChangeLog'/>"
2142 "      <placeholder name='HelpSection'/>"
2143 "      <separator/>"
2144 "      <menuitem action='About'/>"
2145 "      <separator/>"
2146 "      <menuitem action='LogWindow'/>"
2147 "      <separator/>"
2148 "    </menu>"
2149 "  </menubar>"
2150 "  <toolbar name='ToolBar'>"
2151 "  </toolbar>"
2152 "  <toolbar name='StatusBar'>"
2153 "    <toolitem action='ExifRotate'/>"
2154 "    <toolitem action='ShowInfoPixel'/>"
2155 "    <toolitem action='UseColorProfiles'/>"
2156 "    <toolitem action='SaveMetadata'/>"
2157 "  </toolbar>"
2158 "<accelerator action='PrevImageAlt1'/>"
2159 "<accelerator action='PrevImageAlt2'/>"
2160 "<accelerator action='NextImageAlt1'/>"
2161 "<accelerator action='NextImageAlt2'/>"
2162 "<accelerator action='DeleteAlt1'/>"
2163 "<accelerator action='DeleteAlt2'/>"
2164 "<accelerator action='FullScreenAlt1'/>"
2165 "<accelerator action='FullScreenAlt2'/>"
2166 "<accelerator action='Escape'/>"
2167 "<accelerator action='EscapeAlt1'/>"
2168
2169 "<accelerator action='ZoomInAlt1'/>"
2170 "<accelerator action='ZoomOutAlt1'/>"
2171 "<accelerator action='Zoom100Alt1'/>"
2172 "<accelerator action='ZoomFitAlt1'/>"
2173
2174 "<accelerator action='ConnectZoomInAlt1'/>"
2175 "<accelerator action='ConnectZoomOutAlt1'/>"
2176 "<accelerator action='ConnectZoom100Alt1'/>"
2177 "<accelerator action='ConnectZoomFitAlt1'/>"
2178 "</ui>";
2179
2180 static gchar *menu_translate(const gchar *path, gpointer data)
2181 {
2182         return (gchar *)(_(path));
2183 }
2184
2185 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl,
2186                                       gchar *label_tmpl, gchar *accel_tmpl, gchar *tooltip_tmpl, GCallback cb)
2187 {
2188         gchar name[50];
2189         gchar label[100];
2190         gchar accel[50];
2191         gchar tooltip[100];
2192         GtkActionEntry entry = { name, NULL, label, accel, tooltip, cb };
2193         GtkAction *action;
2194
2195         g_snprintf(name, sizeof(name), name_tmpl, mark);
2196         g_snprintf(label, sizeof(label), label_tmpl, mark);
2197
2198         if (accel_tmpl)
2199                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
2200         else
2201                 entry.accelerator = NULL;
2202
2203         if (tooltip_tmpl)
2204                 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
2205         else
2206                 entry.tooltip = NULL;
2207
2208         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
2209         action = gtk_action_group_get_action(lw->action_group, name);
2210         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark > 0 ? mark : 10));
2211 }
2212
2213 static void layout_actions_setup_marks(LayoutWindow *lw)
2214 {
2215         gint mark;
2216         GError *error;
2217         GString *desc = g_string_new(
2218                                 "<ui>"
2219                                 "  <menubar name='MainMenu'>"
2220                                 "    <menu action='SelectMenu'>");
2221
2222         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
2223                 {
2224                 gint i = (mark < 10 ? mark : 0);
2225
2226                 layout_actions_setup_mark(lw, i, "Mark%d",              _("Mark _%d"), NULL, NULL, NULL);
2227                 layout_actions_setup_mark(lw, i, "SetMark%d",   _("_Set mark %d"),                      NULL,           _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
2228                 layout_actions_setup_mark(lw, i, "ResetMark%d", _("_Reset mark %d"),                    NULL,           _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
2229                 layout_actions_setup_mark(lw, i, "ToggleMark%d",        _("_Toggle mark %d"),                   "%d",           _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2230                 layout_actions_setup_mark(lw, i, "ToggleMark%dAlt1",    _("_Toggle mark %d"),                   "KP_%d",        _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2231                 layout_actions_setup_mark(lw, i, "SelectMark%d",        _("Se_lect mark %d"),                   "<control>%d",  _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2232                 layout_actions_setup_mark(lw, i, "SelectMark%dAlt1",    _("_Select mark %d"),                   "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2233                 layout_actions_setup_mark(lw, i, "AddMark%d",   _("_Add mark %d"),                      NULL,           _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
2234                 layout_actions_setup_mark(lw, i, "IntMark%d",   _("_Intersection with mark %d"),        NULL,           _("Intersection with mark %d"), G_CALLBACK(layout_menu_sel_mark_and_cb));
2235                 layout_actions_setup_mark(lw, i, "UnselMark%d", _("_Unselect mark %d"),                 NULL,           _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
2236                 layout_actions_setup_mark(lw, i, "FilterMark%d",        _("_Filter mark %d"),                   NULL,           _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
2237
2238                 g_string_append_printf(desc,
2239                                 "      <menu action='Mark%d'>"
2240                                 "        <menuitem action='ToggleMark%d'/>"
2241                                 "        <menuitem action='SetMark%d'/>"
2242                                 "        <menuitem action='ResetMark%d'/>"
2243                                 "        <separator/>"
2244                                 "        <menuitem action='SelectMark%d'/>"
2245                                 "        <menuitem action='AddMark%d'/>"
2246                                 "        <menuitem action='IntMark%d'/>"
2247                                 "        <menuitem action='UnselMark%d'/>"
2248                                 "        <separator/>"
2249                                 "        <menuitem action='FilterMark%d'/>"
2250                                 "      </menu>",
2251                                 i, i, i, i, i, i, i, i, i);
2252                 }
2253
2254         g_string_append(desc,
2255                                 "    </menu>"
2256                                 "  </menubar>");
2257         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
2258                 {
2259                 gint i = (mark < 10 ? mark : 0);
2260
2261                 g_string_append_printf(desc,
2262                                 "<accelerator action='ToggleMark%dAlt1'/>"
2263                                 "<accelerator action='SelectMark%dAlt1'/>",
2264                                 i, i);
2265                 }
2266         g_string_append(desc,   "</ui>" );
2267
2268         error = NULL;
2269         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
2270                 {
2271                 g_message("building menus failed: %s", error->message);
2272                 g_error_free(error);
2273                 exit(EXIT_FAILURE);
2274                 }
2275         g_string_free(desc, TRUE);
2276 }
2277
2278 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
2279 {
2280         gchar **split = g_strsplit(editor->menu_path, "/", 0);
2281         gint i = 0;
2282         GList *ret = NULL;
2283
2284         if (split[0] == NULL)
2285                 {
2286                 g_strfreev(split);
2287                 return NULL;
2288                 }
2289
2290         while (split[i])
2291                 {
2292                 ret = g_list_prepend(ret, g_strdup(split[i]));
2293                 i++;
2294                 }
2295
2296         g_strfreev(split);
2297
2298         ret = g_list_prepend(ret, g_strdup(editor->key));
2299
2300         return g_list_reverse(ret);
2301 }
2302
2303 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
2304 {
2305         gint to_open, to_close, i;
2306         while (path && old_path && strcmp((gchar *)path->data, (gchar *)old_path->data) == 0)
2307                 {
2308                 path = path->next;
2309                 old_path = old_path->next;
2310                 }
2311         to_open = g_list_length(path) - 1;
2312         to_close = g_list_length(old_path) - 1;
2313
2314         if (to_close > 0)
2315                 {
2316                 old_path = g_list_last(old_path);
2317                 old_path = old_path->prev;
2318                 }
2319
2320         for (i =  0; i < to_close; i++)
2321                 {
2322                 gchar *name = old_path->data;
2323                 if (g_str_has_suffix(name, "Section"))
2324                         {
2325                         g_string_append(desc,   "      </placeholder>");
2326                         }
2327                 else if (g_str_has_suffix(name, "Menu"))
2328                         {
2329                         g_string_append(desc,   "    </menu>");
2330                         }
2331                 else
2332                         {
2333                         g_warning("invalid menu path item %s", name);
2334                         }
2335                 old_path = old_path->prev;
2336                 }
2337
2338         for (i =  0; i < to_open; i++)
2339                 {
2340                 gchar *name = path->data;
2341                 if (g_str_has_suffix(name, "Section"))
2342                         {
2343                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
2344                         }
2345                 else if (g_str_has_suffix(name, "Menu"))
2346                         {
2347                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
2348                         }
2349                 else
2350                         {
2351                         g_warning("invalid menu path item %s", name);
2352                         }
2353                 path = path->next;
2354                 }
2355
2356         if (path)
2357                 g_string_append_printf(desc, "      <menuitem action='%s'/>", (gchar *)path->data);
2358 }
2359
2360 static void layout_actions_setup_editors(LayoutWindow *lw)
2361 {
2362         GError *error;
2363         GList *editors_list;
2364         GList *work;
2365         GList *old_path;
2366         GString *desc;
2367
2368         if (lw->ui_editors_id)
2369                 {
2370                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
2371                 }
2372
2373         if (lw->action_group_editors)
2374                 {
2375                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
2376                 g_object_unref(lw->action_group_editors);
2377                 }
2378         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
2379         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
2380
2381         /* lw->action_group_editors contains translated entries, no translate func is required */
2382         desc = g_string_new(
2383                                 "<ui>"
2384                                 "  <menubar name='MainMenu'>");
2385
2386         editors_list = editor_list_get();
2387
2388         old_path = NULL;
2389         work = editors_list;
2390         while (work)
2391                 {
2392                 GList *path;
2393                 EditorDescription *editor = work->data;
2394                 GtkActionEntry entry = { editor->key,
2395                                          NULL,
2396                                          editor->name,
2397                                          editor->hotkey,
2398                                          editor->comment ? editor->comment : editor->name,
2399                                          G_CALLBACK(layout_menu_edit_cb) };
2400
2401                 if (editor->icon)
2402                         {
2403                         entry.stock_id = editor->key;
2404                         }
2405                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
2406
2407                 path = layout_actions_editor_menu_path(editor);
2408                 layout_actions_editor_add(desc, path, old_path);
2409
2410                 string_list_free(old_path);
2411                 old_path = path;
2412                 work = work->next;
2413                 }
2414
2415         layout_actions_editor_add(desc, NULL, old_path);
2416         string_list_free(old_path);
2417
2418         g_string_append(desc,   "  </menubar>"
2419                                 "</ui>" );
2420
2421         error = NULL;
2422
2423         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
2424         if (!lw->ui_editors_id)
2425                 {
2426                 g_message("building menus failed: %s", error->message);
2427                 g_error_free(error);
2428                 exit(EXIT_FAILURE);
2429                 }
2430         g_string_free(desc, TRUE);
2431         g_list_free(editors_list);
2432 }
2433
2434 void layout_actions_setup(LayoutWindow *lw)
2435 {
2436         GError *error;
2437
2438         DEBUG_1("%s layout_actions_setup: start", get_exec_time());
2439         if (lw->ui_manager) return;
2440
2441         lw->action_group = gtk_action_group_new("MenuActions");
2442         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
2443
2444         gtk_action_group_add_actions(lw->action_group,
2445                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
2446         gtk_action_group_add_toggle_actions(lw->action_group,
2447                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
2448         gtk_action_group_add_radio_actions(lw->action_group,
2449                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
2450                                            0, G_CALLBACK(layout_menu_list_cb), lw);
2451         gtk_action_group_add_radio_actions(lw->action_group,
2452                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
2453                                            0, G_CALLBACK(layout_menu_split_cb), lw);
2454         gtk_action_group_add_toggle_actions(lw->action_group,
2455                                            menu_view_dir_toggle_entries, G_N_ELEMENTS(menu_view_dir_toggle_entries),
2456                                             lw);
2457         gtk_action_group_add_radio_actions(lw->action_group,
2458                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
2459                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
2460         gtk_action_group_add_radio_actions(lw->action_group,
2461                                            menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
2462                                            0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
2463         gtk_action_group_add_radio_actions(lw->action_group,
2464                                            menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
2465                                            0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
2466         gtk_action_group_add_radio_actions(lw->action_group,
2467                                            menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
2468                                            0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
2469
2470
2471         lw->ui_manager = gtk_ui_manager_new();
2472         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
2473         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
2474
2475         DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
2476         error = NULL;
2477         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
2478                 {
2479                 g_message("building menus failed: %s", error->message);
2480                 g_error_free(error);
2481                 exit(EXIT_FAILURE);
2482                 }
2483
2484         layout_toolbar_clear(lw, TOOLBAR_MAIN);
2485         layout_toolbar_add_default(lw, TOOLBAR_MAIN);
2486
2487         DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
2488         layout_actions_setup_marks(lw);
2489
2490         DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
2491         layout_actions_setup_editors(lw);
2492
2493         DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
2494         layout_util_status_update_write(lw);
2495
2496         DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
2497         layout_actions_add_window(lw, lw->window);
2498         DEBUG_1("%s layout_actions_setup: end", get_exec_time());
2499 }
2500
2501 static gint layout_editors_reload_idle_id = -1;
2502 static GList *layout_editors_desktop_files = NULL;
2503
2504 static gboolean layout_editors_reload_idle_cb(gpointer data)
2505 {
2506         if (!layout_editors_desktop_files)
2507                 {
2508                 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
2509                 layout_editors_desktop_files = editor_get_desktop_files();
2510                 return TRUE;
2511                 }
2512
2513         editor_read_desktop_file(layout_editors_desktop_files->data);
2514         g_free(layout_editors_desktop_files->data);
2515         layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
2516
2517
2518         if (!layout_editors_desktop_files)
2519                 {
2520                 GList *work;
2521                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
2522                 editor_table_finish();
2523
2524                 work = layout_window_list;
2525                 while (work)
2526                         {
2527                         LayoutWindow *lw = work->data;
2528                         work = work->next;
2529                         layout_actions_setup_editors(lw);
2530                         if (lw->bar_sort_enabled)
2531                                 {
2532                                 layout_bar_sort_toggle(lw);
2533                                 }
2534                         }
2535
2536                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
2537
2538                 layout_editors_reload_idle_id = -1;
2539                 return FALSE;
2540                 }
2541         return TRUE;
2542 }
2543
2544 void layout_editors_reload_start(void)
2545 {
2546         DEBUG_1("%s layout_editors_reload_start", get_exec_time());
2547
2548         if (layout_editors_reload_idle_id != -1)
2549                 {
2550                 g_source_remove(layout_editors_reload_idle_id);
2551                 string_list_free(layout_editors_desktop_files);
2552                 }
2553
2554         editor_table_clear();
2555         layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL);
2556 }
2557
2558 void layout_editors_reload_finish(void)
2559 {
2560         if (layout_editors_reload_idle_id != -1)
2561                 {
2562                 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
2563                 g_source_remove(layout_editors_reload_idle_id);
2564                 while (layout_editors_reload_idle_id != -1)
2565                         {
2566                         layout_editors_reload_idle_cb(NULL);
2567                         }
2568                 }
2569 }
2570
2571 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
2572 {
2573         GtkAccelGroup *group;
2574
2575         if (!lw->ui_manager) return;
2576
2577         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
2578         gtk_window_add_accel_group(GTK_WINDOW(window), group);
2579 }
2580
2581 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
2582 {
2583         if (lw->menu_bar) return lw->menu_bar;
2584         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
2585         g_object_ref(lw->menu_bar);
2586         return lw->menu_bar;
2587 }
2588
2589 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
2590 {
2591         if (lw->toolbar[type]) return lw->toolbar[type];
2592         switch (type)
2593                 {
2594                 case TOOLBAR_MAIN:
2595                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar");
2596                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_SMALL_TOOLBAR);
2597                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2598                         break;
2599                 case TOOLBAR_STATUS:
2600                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/StatusBar");
2601                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_MENU);
2602                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2603                         gtk_toolbar_set_show_arrow(GTK_TOOLBAR(lw->toolbar[type]), FALSE);
2604                         break;
2605                 default:
2606                         break;
2607                 }
2608         g_object_ref(lw->toolbar[type]);
2609         return lw->toolbar[type];
2610 }
2611
2612 void layout_toolbar_clear(LayoutWindow *lw, ToolbarType type)
2613 {
2614         if (lw->toolbar_merge_id[type])
2615                 {
2616                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id[type]);
2617                 gtk_ui_manager_ensure_update(lw->ui_manager);
2618                 }
2619         string_list_free(lw->toolbar_actions[type]);
2620         lw->toolbar_actions[type] = NULL;
2621
2622         lw->toolbar_merge_id[type] = gtk_ui_manager_new_merge_id(lw->ui_manager);
2623 }
2624
2625 void layout_toolbar_add(LayoutWindow *lw, ToolbarType type, const gchar *action)
2626 {
2627         const gchar *path = NULL;
2628
2629         if (!action || !lw->ui_manager) return;
2630
2631         if (g_list_find_custom(lw->toolbar_actions[type], action, (GCompareFunc)strcmp)) return;
2632
2633         switch (type)
2634                 {
2635                 case TOOLBAR_MAIN:
2636                         path = "/ToolBar";
2637                         break;
2638                 default:
2639                         break;
2640                 }
2641
2642
2643         if (g_str_has_suffix(action, ".desktop"))
2644                 {
2645                 /* this may be called before the external editors are read
2646                    create a dummy action for now */
2647                 if (!lw->action_group_editors)
2648                         {
2649                         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
2650                         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
2651                         }
2652                 if (!gtk_action_group_get_action(lw->action_group_editors, action))
2653                         {
2654                         GtkActionEntry entry = { action,
2655                                                  GTK_STOCK_MISSING_IMAGE,
2656                                                  action,
2657                                                  NULL,
2658                                                  NULL,
2659                                                  NULL };
2660                         DEBUG_1("Creating temporary action %s", action);
2661                         gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
2662                         }
2663                 }
2664         gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action, action, GTK_UI_MANAGER_TOOLITEM, FALSE);
2665         lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action));
2666 }
2667
2668
2669 void layout_toolbar_add_default(LayoutWindow *lw, ToolbarType type)
2670 {
2671         LayoutWindow *lw_first;
2672         GList *work_action;
2673
2674         switch (type)
2675                 {
2676                 case TOOLBAR_MAIN:
2677                         if (layout_window_list)
2678                                 {
2679                                 lw_first = layout_window_list->data;
2680                                 if (lw_first->toolbar_actions[TOOLBAR_MAIN])
2681                                         {
2682                                         work_action = lw_first->toolbar_actions[type];
2683                                         while (work_action)
2684                                                 {
2685                                                 gchar *action = work_action->data;
2686                                                 work_action = work_action->next;
2687                                                 layout_toolbar_add(lw, type, action);
2688                                                 }
2689                                         }
2690                                 else
2691                                         {
2692                                         layout_toolbar_add(lw, type, "Thumbnails");
2693                                         layout_toolbar_add(lw, type, "Back");
2694                                         layout_toolbar_add(lw, type, "Forward");
2695                                         layout_toolbar_add(lw, type, "Up");
2696                                         layout_toolbar_add(lw, type, "Home");
2697                                         layout_toolbar_add(lw, type, "Refresh");
2698                                         layout_toolbar_add(lw, type, "ZoomIn");
2699                                         layout_toolbar_add(lw, type, "ZoomOut");
2700                                         layout_toolbar_add(lw, type, "ZoomFit");
2701                                         layout_toolbar_add(lw, type, "Zoom100");
2702                                         layout_toolbar_add(lw, type, "Preferences");
2703                                         layout_toolbar_add(lw, type, "FloatTools");
2704                                         }
2705                                 }
2706                         else
2707                                 {
2708                                 layout_toolbar_add(lw, type, "Thumbnails");
2709                                 layout_toolbar_add(lw, type, "Back");
2710                                 layout_toolbar_add(lw, type, "Forward");
2711                                 layout_toolbar_add(lw, type, "Up");
2712                                 layout_toolbar_add(lw, type, "Home");
2713                                 layout_toolbar_add(lw, type, "Refresh");
2714                                 layout_toolbar_add(lw, type, "ZoomIn");
2715                                 layout_toolbar_add(lw, type, "ZoomOut");
2716                                 layout_toolbar_add(lw, type, "ZoomFit");
2717                                 layout_toolbar_add(lw, type, "Zoom100");
2718                                 layout_toolbar_add(lw, type, "Preferences");
2719                                 layout_toolbar_add(lw, type, "FloatTools");
2720                                 }
2721                         break;
2722                 default:
2723                         break;
2724                 }
2725 }
2726
2727
2728
2729 void layout_toolbar_write_config(LayoutWindow *lw, ToolbarType type, GString *outstr, gint indent)
2730 {
2731         const gchar *name = NULL;
2732         GList *work = lw->toolbar_actions[type];
2733
2734         switch (type)
2735                 {
2736                 case TOOLBAR_MAIN:
2737                         name = "toolbar";
2738                         break;
2739                 default:
2740                         break;
2741                 }
2742
2743         WRITE_NL(); WRITE_STRING("<%s>", name);
2744         indent++;
2745         WRITE_NL(); WRITE_STRING("<clear/>");
2746         while (work)
2747                 {
2748                 gchar *action = work->data;
2749                 work = work->next;
2750                 WRITE_NL(); WRITE_STRING("<toolitem ");
2751                 write_char_option(outstr, indent + 1, "action", action);
2752                 WRITE_STRING("/>");
2753                 }
2754         indent--;
2755         WRITE_NL(); WRITE_STRING("</%s>", name);
2756 }
2757
2758 void layout_toolbar_add_from_config(LayoutWindow *lw, ToolbarType type, const char **attribute_names, const gchar **attribute_values)
2759 {
2760         gchar *action = NULL;
2761
2762         while (*attribute_names)
2763                 {
2764                 const gchar *option = *attribute_names++;
2765                 const gchar *value = *attribute_values++;
2766
2767                 if (READ_CHAR_FULL("action", action)) continue;
2768
2769                 log_printf("unknown attribute %s = %s\n", option, value);
2770                 }
2771
2772         layout_toolbar_add(lw, type, action);
2773         g_free(action);
2774 }
2775
2776 /*
2777  *-----------------------------------------------------------------------------
2778  * misc
2779  *-----------------------------------------------------------------------------
2780  */
2781
2782 void layout_util_status_update_write(LayoutWindow *lw)
2783 {
2784         GtkAction *action;
2785         gint n = metadata_queue_length();
2786         action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
2787         gtk_action_set_sensitive(action, n > 0);
2788         if (n > 0)
2789                 {
2790                 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
2791                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2792                 g_free(buf);
2793                 }
2794         else
2795                 {
2796                 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
2797                 }
2798 }
2799
2800 void layout_util_status_update_write_all(void)
2801 {
2802         GList *work;
2803
2804         work = layout_window_list;
2805         while (work)
2806                 {
2807                 LayoutWindow *lw = work->data;
2808                 work = work->next;
2809
2810                 layout_util_status_update_write(lw);
2811                 }
2812 }
2813
2814 static gchar *layout_color_name_parse(const gchar *name)
2815 {
2816         if (!name || !*name) return g_strdup(_("Empty"));
2817         return g_strdelimit(g_strdup(name), "_", '-');
2818 }
2819
2820 void layout_util_sync_color(LayoutWindow *lw)
2821 {
2822         GtkAction *action;
2823         gint input = 0;
2824         gboolean use_color;
2825         gboolean use_image = FALSE;
2826         gint i;
2827         gchar action_name[15];
2828         gchar *image_profile;
2829         gchar *screen_profile;
2830
2831
2832         if (!lw->action_group) return;
2833         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
2834
2835         use_color = layout_image_color_profile_get_use(lw);
2836
2837         action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
2838 #ifdef HAVE_LCMS
2839         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
2840         if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
2841                 {
2842                 gchar *buf;
2843                 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
2844                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2845                 g_free(image_profile);
2846                 g_free(screen_profile);
2847                 g_free(buf);
2848                 }
2849         else
2850                 {
2851                 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
2852                 }
2853 #else
2854         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
2855         gtk_action_set_sensitive(action, FALSE);
2856         g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
2857 #endif
2858
2859         action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
2860         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
2861         gtk_action_set_sensitive(action, use_color);
2862
2863         for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
2864                 {
2865                 sprintf(action_name, "ColorProfile%d", i);
2866                 action = gtk_action_group_get_action(lw->action_group, action_name);
2867
2868                 if (i >= COLOR_PROFILE_FILE)
2869                         {
2870                         const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
2871                         const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
2872                         gchar *end;
2873                         gchar *buf;
2874
2875                         if (!name || !name[0]) name = filename_from_path(file);
2876
2877                         end = layout_color_name_parse(name);
2878                         buf = g_strdup_printf(_("Input _%d: %s"), i, end);
2879                         g_free(end);
2880
2881                         g_object_set(G_OBJECT(action), "label", buf, NULL);
2882                         g_free(buf);
2883
2884                         gtk_action_set_visible(action, file && file[0]);
2885                         }
2886
2887                 gtk_action_set_sensitive(action, !use_image);
2888                 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
2889                 }
2890
2891         action = gtk_action_group_get_action(lw->action_group, "Grayscale");
2892         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
2893 }
2894
2895 void layout_util_sync_marks(LayoutWindow *lw)
2896 {
2897         GtkAction *action;
2898
2899         if (!lw->action_group) return;
2900
2901         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
2902         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
2903 }
2904
2905 static void layout_util_sync_views(LayoutWindow *lw)
2906 {
2907         GtkAction *action;
2908         OsdShowFlags osd_flags = image_osd_get(lw->image);
2909
2910         if (!lw->action_group) return;
2911
2912         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
2913         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.dir_view_type);
2914
2915         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
2916         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
2917
2918         action = gtk_action_group_get_action(lw->action_group, "SplitNextPane");
2919         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
2920         action = gtk_action_group_get_action(lw->action_group, "SplitPreviousPane");
2921         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
2922         action = gtk_action_group_get_action(lw->action_group, "SplitUpPane");
2923         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
2924         action = gtk_action_group_get_action(lw->action_group, "SplitDownPane");
2925         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
2926
2927         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
2928         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
2929
2930         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
2931         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
2932
2933         action = gtk_action_group_get_action(lw->action_group, "SBar");
2934         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
2935
2936         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
2937         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
2938
2939         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
2940         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
2941
2942         action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
2943         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
2944
2945         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
2946         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
2947
2948         action = gtk_action_group_get_action(lw->action_group, "Animate");
2949         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
2950
2951         action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
2952         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
2953
2954         action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
2955         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
2956
2957         action = gtk_action_group_get_action(lw->action_group, "ExifRotate");
2958         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->image.exif_rotate_enable);
2959
2960         action = gtk_action_group_get_action(lw->action_group, "RectangularSelection");
2961         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->collections.rectangular_selection);
2962
2963         if (osd_flags & OSD_SHOW_HISTOGRAM)
2964                 {
2965                 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
2966                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
2967
2968                 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
2969                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
2970                 }
2971
2972         action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
2973         gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
2974
2975         action = gtk_action_group_get_action(lw->action_group, "WriteRotation");
2976         gtk_action_set_sensitive(action, !(runcmd("which exiftran >/dev/null 2>&1") ||
2977                                                         runcmd("which mogrify >/dev/null 2>&1") || options->metadata.write_orientation));
2978         action = gtk_action_group_get_action(lw->action_group, "WriteRotationKeepDate");
2979         gtk_action_set_sensitive(action, !(runcmd("which exiftran >/dev/null 2>&1") ||
2980                                                         runcmd("which mogrify >/dev/null 2>&1") || options->metadata.write_orientation));
2981
2982         action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
2983         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
2984
2985         layout_util_sync_marks(lw);
2986         layout_util_sync_color(lw);
2987 }
2988
2989 void layout_util_sync_thumb(LayoutWindow *lw)
2990 {
2991         GtkAction *action;
2992
2993         if (!lw->action_group) return;
2994
2995         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
2996         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
2997         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
2998 }
2999
3000 void layout_util_sync(LayoutWindow *lw)
3001 {
3002         layout_util_sync_views(lw);
3003         layout_util_sync_thumb(lw);
3004         layout_menu_recent_update(lw);
3005 //      layout_menu_edit_update(lw);
3006 }
3007
3008 /**
3009  * @brief Checks if event key is mapped to Help
3010  * @param event 
3011  * @returns 
3012  * 
3013  * Used to check if the user has re-mapped the Help key
3014  * in Preferences/Keyboard
3015  * 
3016  * Note: help_key.accel_mods and event->state
3017  * differ in the higher bits
3018  */
3019 gboolean is_help_key(GdkEventKey *event)
3020 {
3021         GtkAccelKey help_key;
3022         gboolean ret = FALSE;
3023         guint mask = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK;
3024
3025         if (gtk_accel_map_lookup_entry("<Actions>/MenuActions/HelpContents", &help_key))
3026                 {
3027                 if (help_key.accel_key == event->keyval &&
3028                                         (help_key.accel_mods & mask) == (event->state & mask))
3029                         {
3030                         ret = TRUE;
3031                         }
3032                 }
3033
3034         return ret;
3035 }
3036
3037 /*
3038  *-----------------------------------------------------------------------------
3039  * sidebars
3040  *-----------------------------------------------------------------------------
3041  */
3042
3043 static gboolean layout_bar_enabled(LayoutWindow *lw)
3044 {
3045         return lw->bar && gtk_widget_get_visible(lw->bar);
3046 }
3047
3048 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
3049 {
3050         LayoutWindow *lw = data;
3051
3052         lw->bar = NULL;
3053 /*
3054     do not call layout_util_sync_views(lw) here
3055     this is called either when whole layout is destroyed - no need for update
3056     or when the bar is replaced - sync is called by upper function at the end of whole operation
3057
3058 */
3059 }
3060
3061 static void layout_bar_set_default(LayoutWindow *lw)
3062 {
3063         GtkWidget *bar;
3064
3065         if (!lw->utility_box) return;
3066
3067         bar = bar_new(lw);
3068
3069         layout_bar_set(lw, bar);
3070
3071         bar_populate_default(bar);
3072 }
3073
3074 static void layout_bar_close(LayoutWindow *lw)
3075 {
3076         if (lw->bar)
3077                 {
3078                 bar_close(lw->bar);
3079                 lw->bar = NULL;
3080                 }
3081 }
3082
3083
3084 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
3085 {
3086         if (!lw->utility_box) return;
3087
3088         layout_bar_close(lw); /* if any */
3089
3090         if (!bar) return;
3091         lw->bar = bar;
3092
3093         g_signal_connect(G_OBJECT(lw->bar), "destroy",
3094                          G_CALLBACK(layout_bar_destroyed), lw);
3095
3096
3097 //      gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
3098         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
3099
3100         bar_set_fd(lw->bar, layout_image_get_fd(lw));
3101 }
3102
3103
3104 void layout_bar_toggle(LayoutWindow *lw)
3105 {
3106         if (layout_bar_enabled(lw))
3107                 {
3108                 gtk_widget_hide(lw->bar);
3109                 }
3110         else
3111                 {
3112                 if (!lw->bar)
3113                         {
3114                         layout_bar_set_default(lw);
3115                         }
3116                 gtk_widget_show(lw->bar);
3117                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
3118                 }
3119         layout_util_sync_views(lw);
3120 }
3121
3122 static void layout_bar_new_image(LayoutWindow *lw)
3123 {
3124         if (!layout_bar_enabled(lw)) return;
3125
3126         bar_set_fd(lw->bar, layout_image_get_fd(lw));
3127 }
3128
3129 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
3130 {
3131         if (!layout_bar_enabled(lw)) return;
3132
3133         bar_notify_selection(lw->bar, count);
3134 }
3135
3136 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
3137 {
3138         return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
3139 }
3140
3141
3142 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
3143 {
3144         LayoutWindow *lw = data;
3145
3146         lw->bar_sort = NULL;
3147
3148 /*
3149     do not call layout_util_sync_views(lw) here
3150     this is called either when whole layout is destroyed - no need for update
3151     or when the bar is replaced - sync is called by upper function at the end of whole operation
3152
3153 */
3154 }
3155
3156 static void layout_bar_sort_set_default(LayoutWindow *lw)
3157 {
3158         GtkWidget *bar;
3159
3160         if (!lw->utility_box) return;
3161
3162         bar = bar_sort_new_default(lw);
3163
3164         layout_bar_sort_set(lw, bar);
3165 }
3166
3167 static void layout_bar_sort_close(LayoutWindow *lw)
3168 {
3169         if (lw->bar_sort)
3170                 {
3171                 bar_sort_close(lw->bar_sort);
3172                 lw->bar_sort = NULL;
3173                 }
3174 }
3175
3176 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
3177 {
3178         if (!lw->utility_box) return;
3179
3180         layout_bar_sort_close(lw); /* if any */
3181
3182         if (!bar) return;
3183         lw->bar_sort = bar;
3184
3185         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
3186                          G_CALLBACK(layout_bar_sort_destroyed), lw);
3187
3188         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
3189 }
3190
3191 void layout_bar_sort_toggle(LayoutWindow *lw)
3192 {
3193         if (layout_bar_sort_enabled(lw))
3194                 {
3195                 gtk_widget_hide(lw->bar_sort);
3196                 }
3197         else
3198                 {
3199                 if (!lw->bar_sort)
3200                         {
3201                         layout_bar_sort_set_default(lw);
3202                         }
3203                 gtk_widget_show(lw->bar_sort);
3204                 }
3205         layout_util_sync_views(lw);
3206 }
3207
3208 static void layout_bars_hide_toggle(LayoutWindow *lw)
3209 {
3210         if (lw->options.bars_state.hidden)
3211                 {
3212                 lw->options.bars_state.hidden = FALSE;
3213                 if (lw->options.bars_state.sort)
3214                         {
3215                         gtk_widget_show(lw->bar_sort);
3216                         }
3217                 if (lw->options.bars_state.info)
3218                         {
3219                         gtk_widget_show(lw->bar);
3220                         }
3221                 layout_tools_float_set(lw, lw->options.tools_float,
3222                                                                         lw->options.bars_state.tools_hidden);
3223                 }
3224         else
3225                 {
3226                 lw->options.bars_state.hidden = TRUE;
3227                 lw->options.bars_state.sort = layout_bar_sort_enabled(lw);
3228                 lw->options.bars_state.info = layout_bar_enabled(lw);
3229                 lw->options.bars_state.tools_float = lw->options.tools_float;
3230                 lw->options.bars_state.tools_hidden = lw->options.tools_hidden;
3231
3232                 gtk_widget_hide(lw->bar);
3233                 if (lw->bar_sort)
3234                         gtk_widget_hide(lw->bar_sort);
3235                 layout_tools_float_set(lw, lw->options.tools_float, TRUE);
3236                 }
3237
3238         layout_util_sync_views(lw);
3239 }
3240
3241 void layout_bars_new_image(LayoutWindow *lw)
3242 {
3243         layout_bar_new_image(lw);
3244
3245         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
3246
3247         /* this should be called here to handle the metadata edited in bars */
3248         if (options->metadata.confirm_on_image_change)
3249                 metadata_write_queue_confirm(FALSE, NULL, NULL);
3250 }
3251
3252 void layout_bars_new_selection(LayoutWindow *lw, gint count)
3253 {
3254         layout_bar_new_selection(lw, count);
3255 }
3256
3257 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
3258 {
3259         if (lw->utility_box) return lw->utility_box;
3260         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
3261         lw->utility_paned = gtk_hpaned_new();
3262         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
3263
3264         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
3265         gtk_widget_show(lw->utility_paned);
3266
3267         gtk_widget_show(image);
3268
3269         g_object_ref(lw->utility_box);
3270         return lw->utility_box;
3271 }
3272
3273 void layout_bars_close(LayoutWindow *lw)
3274 {
3275         layout_bar_sort_close(lw);
3276         layout_bar_close(lw);
3277 }
3278
3279 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
3280 {
3281         LayoutWindow *lw = data;
3282         lw->exif_window = NULL;
3283 }
3284
3285 void layout_exif_window_new(LayoutWindow *lw)
3286 {
3287         if (lw->exif_window) return;
3288
3289         lw->exif_window = advanced_exif_new();
3290         if (!lw->exif_window) return;
3291         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
3292                          G_CALLBACK(layout_exif_window_destroy), lw);
3293         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
3294 }
3295
3296 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */