d3b2f684b7b9e9f44d0ba1991eb7e45bc68401f9
[geeqie.git] / src / layout-util.cc
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 "layout-util.h"
23
24 #include <dirent.h>
25 #include <unistd.h>
26
27 #include <cstdio>
28 #include <cstdlib>
29 #include <cstring>
30
31 #include <gio/gio.h>
32 #include <glib-object.h>
33
34 #include <config.h>
35
36 #include "advanced-exif.h"
37 #include "archives.h"
38 #include "bar-keywords.h"
39 #include "bar-sort.h"
40 #include "bar.h"
41 #include "cache-maint.h"
42 #include "collect-io.h"
43 #include "collect.h"
44 #include "color-man.h"
45 #include "compat.h"
46 #include "debug.h"
47 #include "desktop-file.h"
48 #include "dupe.h"
49 #include "editors.h"
50 #include "filedata.h"
51 #include "fullscreen.h"
52 #include "histogram.h"
53 #include "history-list.h"
54 #include "image-overlay.h"
55 #include "image.h"
56 #include "img-view.h"
57 #include "intl.h"
58 #include "keymap-template.h"
59 #include "layout-image.h"
60 #include "layout.h"
61 #include "logwindow.h"
62 #include "main-defines.h"
63 #include "main.h"
64 #include "metadata.h"
65 #include "misc.h"
66 #include "options.h"
67 #include "pan-view.h"
68 #include "pixbuf-util.h"
69 #include "preferences.h"
70 #include "print.h"
71 #include "rcfile.h"
72 #include "search-and-run.h"
73 #include "search.h"
74 #include "slideshow.h"
75 #include "ui-fileops.h"
76 #include "ui-menu.h"
77 #include "ui-misc.h"
78 #include "ui-utildlg.h"
79 #include "utilops.h"
80 #include "view-dir.h"
81 #include "view-file.h"
82 #include "window.h"
83
84 enum {
85         MENU_EDIT_ACTION_OFFSET = 16,
86         FILE_COLUMN_POINTER = 0
87 };
88
89 static gboolean layout_bar_enabled(LayoutWindow *lw);
90 static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
91 static void layout_bars_hide_toggle(LayoutWindow *lw);
92 static void layout_util_sync_views(LayoutWindow *lw);
93 static void layout_search_and_run_window_new(LayoutWindow *lw);
94
95 /*
96  *-----------------------------------------------------------------------------
97  * keyboard handler
98  *-----------------------------------------------------------------------------
99  */
100
101 static guint tree_key_overrides[] = {
102         GDK_KEY_Page_Up,        GDK_KEY_KP_Page_Up,
103         GDK_KEY_Page_Down,      GDK_KEY_KP_Page_Down,
104         GDK_KEY_Home,   GDK_KEY_KP_Home,
105         GDK_KEY_End,    GDK_KEY_KP_End
106 };
107
108 static gboolean layout_key_match(guint keyval)
109 {
110         guint i;
111
112         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
113                 {
114                 if (keyval == tree_key_overrides[i]) return TRUE;
115                 }
116
117         return FALSE;
118 }
119
120 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
121 {
122         auto lw = static_cast<LayoutWindow *>(data);
123         GtkWidget *focused;
124         gboolean stop_signal = FALSE;
125         gint x = 0;
126         gint y = 0;
127
128         if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
129                 {
130                 if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
131                         {
132                         gq_gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
133                         }
134
135                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
136                  * so when the some widgets have focus, give them priority (HACK)
137                  */
138                 if (gtk_widget_event(lw->path_entry, reinterpret_cast<GdkEvent *>(event)))
139                         {
140                         return TRUE;
141                         }
142                 }
143
144         if (lw->vf->file_filter.combo && gtk_widget_has_focus(gtk_bin_get_child(GTK_BIN(lw->vf->file_filter.combo))))
145                 {
146                 if (gtk_widget_event(gtk_bin_get_child(GTK_BIN(lw->vf->file_filter.combo)), reinterpret_cast<GdkEvent *>(event)))
147                         {
148                         return TRUE;
149                         }
150                 }
151
152         if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
153             !layout_key_match(event->keyval) &&
154             gtk_widget_event(lw->vd->view, reinterpret_cast<GdkEvent *>(event)))
155                 {
156                 return TRUE;
157                 }
158         if (lw->bar &&
159             bar_event(lw->bar, reinterpret_cast<GdkEvent *>(event)))
160                 {
161                 return TRUE;
162                 }
163
164         focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
165         if (lw->image &&
166             ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
167                 {
168                 stop_signal = TRUE;
169                 switch (event->keyval)
170                         {
171                         case GDK_KEY_Left: case GDK_KEY_KP_Left:
172                                 x -= 1;
173                                 break;
174                         case GDK_KEY_Right: case GDK_KEY_KP_Right:
175                                 x += 1;
176                                 break;
177                         case GDK_KEY_Up: case GDK_KEY_KP_Up:
178                                 y -= 1;
179                                 break;
180                         case GDK_KEY_Down: case GDK_KEY_KP_Down:
181                                 y += 1;
182                                 break;
183                         default:
184                                 stop_signal = FALSE;
185                                 break;
186                         }
187
188                 if (!stop_signal &&
189                     !(event->state & GDK_CONTROL_MASK))
190                         {
191                         stop_signal = TRUE;
192                         switch (event->keyval)
193                                 {
194                                 case GDK_KEY_Menu:
195                                         layout_image_menu_popup(lw);
196                                         break;
197                                 default:
198                                         stop_signal = FALSE;
199                                         break;
200                                 }
201                         }
202                 }
203
204         if (x != 0 || y!= 0)
205                 {
206                 if (event->state & GDK_SHIFT_MASK)
207                         {
208                         x *= 3;
209                         y *= 3;
210                         }
211                 keyboard_scroll_calc(&x, &y, event);
212                 layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK));
213                 }
214
215         return stop_signal;
216 }
217
218 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
219 {
220         g_signal_connect(G_OBJECT(window), "key_press_event",
221                          G_CALLBACK(layout_key_press_cb), lw);
222 }
223
224 /*
225  *-----------------------------------------------------------------------------
226  * menu callbacks
227  *-----------------------------------------------------------------------------
228  */
229
230
231 static GtkWidget *layout_window(LayoutWindow *lw)
232 {
233         return lw->full_screen ? lw->full_screen->window : lw->window;
234 }
235
236 static void layout_exit_fullscreen(LayoutWindow *lw)
237 {
238         if (!lw->full_screen) return;
239         layout_image_full_screen_stop(lw);
240 }
241
242 static void clear_marks_cancel_cb(GenericDialog *gd, gpointer)
243 {
244         generic_dialog_close(gd);
245 }
246
247 static void clear_marks_help_cb(GenericDialog *, gpointer)
248 {
249         help_window_show("GuideMainWindowMenus.html");
250 }
251
252 void layout_menu_clear_marks_ok_cb(GenericDialog *gd, gpointer)
253 {
254         marks_clear_all();
255         generic_dialog_close(gd);
256 }
257
258 static void layout_menu_clear_marks_cb(GtkAction *, gpointer)
259 {
260         GenericDialog *gd;
261
262         gd = generic_dialog_new(_("Clear Marks"),
263                                 "marks_clear", nullptr, FALSE, clear_marks_cancel_cb, nullptr);
264         generic_dialog_add_message(gd, GQ_ICON_DIALOG_QUESTION, _("Clear all marks?"), _("This will clear all marks for all images,\nincluding those linked to keywords"), TRUE);
265         generic_dialog_add_button(gd, GQ_ICON_OK, "OK", layout_menu_clear_marks_ok_cb, TRUE);
266         generic_dialog_add_button(gd, GQ_ICON_HELP, _("Help"),
267                                 clear_marks_help_cb, FALSE);
268
269         gtk_widget_show(gd->dialog);
270 }
271
272 static void layout_menu_new_cb(GtkAction *, gpointer data)
273 {
274         auto lw = static_cast<LayoutWindow *>(data);
275
276         layout_exit_fullscreen(lw);
277         collection_window_new(nullptr);
278 }
279
280 static void layout_menu_open_cb(GtkAction *widget, gpointer data)
281 {
282         auto lw = static_cast<LayoutWindow *>(data);
283         gchar *path;
284         gint n;
285         GList *collection_list = nullptr;
286
287         layout_exit_fullscreen(lw);
288
289         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
290         collect_manager_list(nullptr, nullptr, &collection_list);
291
292         path = static_cast<gchar *>(g_list_nth_data(collection_list, n));
293
294         if (path)
295                 {
296                 /* make a copy of it */
297                 path = g_strdup(path);
298                 collection_window_new(path);
299                 g_free(path);
300                 }
301
302         string_list_free(collection_list);
303 }
304
305 static void layout_menu_search_cb(GtkAction *, gpointer data)
306 {
307         auto lw = static_cast<LayoutWindow *>(data);
308
309         layout_exit_fullscreen(lw);
310         search_new(lw->dir_fd, layout_image_get_fd(lw));
311 }
312
313 static void layout_menu_dupes_cb(GtkAction *, gpointer data)
314 {
315         auto lw = static_cast<LayoutWindow *>(data);
316
317         layout_exit_fullscreen(lw);
318         dupe_window_new();
319 }
320
321 static void layout_menu_pan_cb(GtkAction *, gpointer data)
322 {
323         auto lw = static_cast<LayoutWindow *>(data);
324
325         layout_exit_fullscreen(lw);
326         pan_window_new(lw->dir_fd);
327 }
328
329 static void layout_menu_print_cb(GtkAction *, gpointer data)
330 {
331         auto lw = static_cast<LayoutWindow *>(data);
332
333         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
334 }
335
336 static void layout_menu_dir_cb(GtkAction *, gpointer data)
337 {
338         auto lw = static_cast<LayoutWindow *>(data);
339
340         if (lw->vd) vd_new_folder(lw->vd, lw->dir_fd);
341 }
342
343 static void layout_menu_copy_cb(GtkAction *, gpointer data)
344 {
345         auto lw = static_cast<LayoutWindow *>(data);
346
347         file_util_copy(nullptr, layout_selection_list(lw), nullptr, layout_window(lw));
348 }
349
350 static void layout_menu_copy_path_cb(GtkAction *, gpointer data)
351 {
352         auto lw = static_cast<LayoutWindow *>(data);
353
354         file_util_copy_path_list_to_clipboard(layout_selection_list(lw), TRUE);
355 }
356
357 static void layout_menu_copy_path_unquoted_cb(GtkAction *, gpointer data)
358 {
359         auto lw = static_cast<LayoutWindow *>(data);
360
361         file_util_copy_path_list_to_clipboard(layout_selection_list(lw), FALSE);
362 }
363
364 static void layout_menu_move_cb(GtkAction *, gpointer data)
365 {
366         auto lw = static_cast<LayoutWindow *>(data);
367
368         file_util_move(nullptr, layout_selection_list(lw), nullptr, layout_window(lw));
369 }
370
371 static void layout_menu_rename_cb(GtkAction *, gpointer data)
372 {
373         auto lw = static_cast<LayoutWindow *>(data);
374
375         file_util_rename(nullptr, layout_selection_list(lw), layout_window(lw));
376 }
377
378 static void layout_menu_delete_cb(GtkAction *, gpointer data)
379 {
380         auto lw = static_cast<LayoutWindow *>(data);
381
382         options->file_ops.safe_delete_enable = FALSE;
383         file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
384 }
385
386 static void layout_menu_move_to_trash_cb(GtkAction *, gpointer data)
387 {
388         auto lw = static_cast<LayoutWindow *>(data);
389
390         options->file_ops.safe_delete_enable = TRUE;
391         file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
392 }
393
394 static void layout_menu_move_to_trash_key_cb(GtkAction *, gpointer data)
395 {
396         auto lw = static_cast<LayoutWindow *>(data);
397
398         if (options->file_ops.enable_delete_key)
399                 {
400                 options->file_ops.safe_delete_enable = TRUE;
401                 file_util_delete(nullptr, layout_selection_list(lw), layout_window(lw));
402                 }
403 }
404
405 static void layout_menu_disable_grouping_cb(GtkAction *, gpointer data)
406 {
407         auto lw = static_cast<LayoutWindow *>(data);
408
409         file_data_disable_grouping_list(layout_selection_list(lw), TRUE);
410 }
411
412 static void layout_menu_enable_grouping_cb(GtkAction *, gpointer data)
413 {
414         auto lw = static_cast<LayoutWindow *>(data);
415
416         file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
417 }
418
419 void layout_menu_close_cb(GtkAction *, gpointer data)
420 {
421         auto lw = static_cast<LayoutWindow *>(data);
422
423         layout_exit_fullscreen(lw);
424         layout_close(lw);
425 }
426
427 static void layout_menu_exit_cb(GtkAction *, gpointer)
428 {
429         exit_program();
430 }
431
432 static void layout_menu_alter_90_cb(GtkAction *, gpointer data)
433 {
434         auto lw = static_cast<LayoutWindow *>(data);
435
436         layout_image_alter_orientation(lw, ALTER_ROTATE_90);
437 }
438
439 static void layout_menu_rating_0_cb(GtkAction *, gpointer data)
440 {
441         auto lw = static_cast<LayoutWindow *>(data);
442
443         layout_image_rating(lw, "0");
444 }
445
446 static void layout_menu_rating_1_cb(GtkAction *, gpointer data)
447 {
448         auto lw = static_cast<LayoutWindow *>(data);
449
450         layout_image_rating(lw, "1");
451 }
452
453 static void layout_menu_rating_2_cb(GtkAction *, gpointer data)
454 {
455         auto lw = static_cast<LayoutWindow *>(data);
456
457         layout_image_rating(lw, "2");
458 }
459
460 static void layout_menu_rating_3_cb(GtkAction *, gpointer data)
461 {
462         auto lw = static_cast<LayoutWindow *>(data);
463
464         layout_image_rating(lw, "3");
465 }
466
467 static void layout_menu_rating_4_cb(GtkAction *, gpointer data)
468 {
469         auto lw = static_cast<LayoutWindow *>(data);
470
471         layout_image_rating(lw, "4");
472 }
473
474 static void layout_menu_rating_5_cb(GtkAction *, gpointer data)
475 {
476         auto lw = static_cast<LayoutWindow *>(data);
477
478         layout_image_rating(lw, "5");
479 }
480
481 static void layout_menu_rating_m1_cb(GtkAction *, gpointer data)
482 {
483         auto lw = static_cast<LayoutWindow *>(data);
484
485         layout_image_rating(lw, "-1");
486 }
487
488 static void layout_menu_alter_90cc_cb(GtkAction *, gpointer data)
489 {
490         auto lw = static_cast<LayoutWindow *>(data);
491
492         layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
493 }
494
495 static void layout_menu_alter_180_cb(GtkAction *, gpointer data)
496 {
497         auto lw = static_cast<LayoutWindow *>(data);
498
499         layout_image_alter_orientation(lw, ALTER_ROTATE_180);
500 }
501
502 static void layout_menu_alter_mirror_cb(GtkAction *, gpointer data)
503 {
504         auto lw = static_cast<LayoutWindow *>(data);
505
506         layout_image_alter_orientation(lw, ALTER_MIRROR);
507 }
508
509 static void layout_menu_alter_flip_cb(GtkAction *, gpointer data)
510 {
511         auto lw = static_cast<LayoutWindow *>(data);
512
513         layout_image_alter_orientation(lw, ALTER_FLIP);
514 }
515
516 static void layout_menu_alter_desaturate_cb(GtkToggleAction *action, gpointer data)
517 {
518         auto lw = static_cast<LayoutWindow *>(data);
519
520         layout_image_set_desaturate(lw, gtk_toggle_action_get_active(action));
521 }
522
523 static void layout_menu_alter_ignore_alpha_cb(GtkToggleAction *action, gpointer data)
524 {
525    auto lw = static_cast<LayoutWindow *>(data);
526
527         if (lw->options.ignore_alpha == gtk_toggle_action_get_active(action)) return;
528
529    layout_image_set_ignore_alpha(lw, gtk_toggle_action_get_active(action));
530 }
531
532 static void layout_menu_alter_none_cb(GtkAction *, gpointer data)
533 {
534         auto lw = static_cast<LayoutWindow *>(data);
535
536         layout_image_alter_orientation(lw, ALTER_NONE);
537 }
538
539 static void layout_menu_exif_rotate_cb(GtkToggleAction *action, gpointer data)
540 {
541         auto lw = static_cast<LayoutWindow *>(data);
542
543         options->image.exif_rotate_enable = gtk_toggle_action_get_active(action);
544         layout_image_reset_orientation(lw);
545 }
546
547 static void layout_menu_select_rectangle_cb(GtkToggleAction *action, gpointer)
548 {
549         options->draw_rectangle = gtk_toggle_action_get_active(action);
550 }
551
552 static void layout_menu_split_pane_sync_cb(GtkToggleAction *action, gpointer data)
553 {
554         auto lw = static_cast<LayoutWindow *>(data);
555
556         lw->options.split_pane_sync = gtk_toggle_action_get_active(action);
557 }
558
559 static void layout_menu_select_overunderexposed_cb(GtkToggleAction *action, gpointer data)
560 {
561         auto lw = static_cast<LayoutWindow *>(data);
562
563         layout_image_set_overunderexposed(lw, gtk_toggle_action_get_active(action));
564 }
565
566 static void layout_menu_write_rotate(GtkToggleAction *, gpointer data, gboolean keep_date)
567 {
568         auto lw = static_cast<LayoutWindow *>(data);
569         GtkTreeModel *store;
570         GList *work;
571         GtkTreeSelection *selection;
572         GtkTreePath *tpath;
573         FileData *fd_n;
574         GtkTreeIter iter;
575         gchar *rotation;
576         gchar *command;
577         gint run_result;
578         GenericDialog *gd;
579         GString *message;
580         int cmdstatus;
581
582         if (!layout_valid(&lw)) return;
583
584         if (!lw || !lw->vf) return;
585
586         if (lw->vf->type == FILEVIEW_ICON)
587                 {
588                 if (!VFICON(lw->vf)->selection) return;
589                 work = VFICON(lw->vf)->selection;
590                 }
591         else
592                 {
593                 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
594                 work = gtk_tree_selection_get_selected_rows(selection, &store);
595                 }
596
597         while (work)
598                 {
599                 if (lw->vf->type == FILEVIEW_ICON)
600                         {
601                         fd_n = static_cast<FileData *>(work->data);
602                         work = work->next;
603                         }
604                 else
605                         {
606                         tpath = static_cast<GtkTreePath *>(work->data);
607                         gtk_tree_model_get_iter(store, &iter, tpath);
608                         gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
609                         work = work->next;
610                         }
611
612                 rotation = g_strdup_printf("%d", fd_n->user_orientation);
613                 command = g_strconcat(gq_bindir, "/geeqie-rotate -r ", rotation,
614                                                                 keep_date ? " -t \"" : " \"", fd_n->path, "\"", NULL);
615                 cmdstatus = runcmd(command);
616                 run_result = WEXITSTATUS(cmdstatus);
617                 if (!run_result)
618                         {
619                         fd_n->user_orientation = 0;
620                         }
621                 else
622                         {
623                         message = g_string_new(_("Operation failed:\n"));
624
625                         if (run_result == 1)
626                                 message = g_string_append(message, _("No file extension\n"));
627                         else if (run_result == 3)
628                                 message = g_string_append(message, _("Cannot create tmp file\n"));
629                         else if (run_result == 4)
630                                 message = g_string_append(message, _("Operation not supported for filetype\n"));
631                         else if (run_result == 5)
632                                 message = g_string_append(message, _("File is not writable\n"));
633                         else if (run_result == 6)
634                                 message = g_string_append(message, _("Exiftran error\n"));
635                         else if (run_result == 7)
636                                 message = g_string_append(message, _("Mogrify error\n"));
637
638                         message = g_string_append(message, fd_n->name);
639
640                         gd = generic_dialog_new(_("Image orientation"), "image_orientation", nullptr, TRUE, nullptr, nullptr);
641                         generic_dialog_add_message(gd, GQ_ICON_DIALOG_ERROR, _("Image orientation"), message->str, TRUE);
642                         generic_dialog_add_button(gd, GQ_ICON_OK, "OK", nullptr, TRUE);
643
644                         gtk_widget_show(gd->dialog);
645
646                         g_string_free(message, TRUE);
647                         }
648
649                 g_free(rotation);
650                 g_free(command);
651                 }
652 }
653
654 static void layout_menu_write_rotate_keep_date_cb(GtkToggleAction *action, gpointer data)
655 {
656         layout_menu_write_rotate(action, data, TRUE);
657 }
658
659 static void layout_menu_write_rotate_cb(GtkToggleAction *action, gpointer data)
660 {
661         layout_menu_write_rotate(action, data, FALSE);
662 }
663
664 static void layout_menu_config_cb(GtkAction *, gpointer data)
665 {
666         auto lw = static_cast<LayoutWindow *>(data);
667
668         layout_exit_fullscreen(lw);
669         show_config_window(lw);
670 }
671
672 static void layout_menu_editors_cb(GtkAction *, gpointer data)
673 {
674         auto lw = static_cast<LayoutWindow *>(data);
675
676         layout_exit_fullscreen(lw);
677         show_editor_list_window();
678 }
679
680 static void layout_menu_layout_config_cb(GtkAction *, gpointer data)
681 {
682         auto lw = static_cast<LayoutWindow *>(data);
683
684         layout_exit_fullscreen(lw);
685         layout_show_config_window(lw);
686 }
687
688 static void layout_menu_remove_thumb_cb(GtkAction *, gpointer data)
689 {
690         auto lw = static_cast<LayoutWindow *>(data);
691
692         layout_exit_fullscreen(lw);
693         cache_manager_show();
694 }
695
696 static void layout_menu_wallpaper_cb(GtkAction *, gpointer data)
697 {
698         auto lw = static_cast<LayoutWindow *>(data);
699
700         layout_image_to_root(lw);
701 }
702
703 /* single window zoom */
704 static void layout_menu_zoom_in_cb(GtkAction *, gpointer data)
705 {
706         auto lw = static_cast<LayoutWindow *>(data);
707
708         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
709 }
710
711 static void layout_menu_zoom_out_cb(GtkAction *, gpointer data)
712 {
713         auto lw = static_cast<LayoutWindow *>(data);
714
715         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
716 }
717
718 static void layout_menu_zoom_1_1_cb(GtkAction *, gpointer data)
719 {
720         auto lw = static_cast<LayoutWindow *>(data);
721
722         layout_image_zoom_set(lw, 1.0, FALSE);
723 }
724
725 static void layout_menu_zoom_fit_cb(GtkAction *, gpointer data)
726 {
727         auto lw = static_cast<LayoutWindow *>(data);
728
729         layout_image_zoom_set(lw, 0.0, FALSE);
730 }
731
732 static void layout_menu_zoom_fit_hor_cb(GtkAction *, gpointer data)
733 {
734         auto lw = static_cast<LayoutWindow *>(data);
735
736         layout_image_zoom_set_fill_geometry(lw, FALSE, FALSE);
737 }
738
739 static void layout_menu_zoom_fit_vert_cb(GtkAction *, gpointer data)
740 {
741         auto lw = static_cast<LayoutWindow *>(data);
742
743         layout_image_zoom_set_fill_geometry(lw, TRUE, FALSE);
744 }
745
746 static void layout_menu_zoom_2_1_cb(GtkAction *, gpointer data)
747 {
748         auto lw = static_cast<LayoutWindow *>(data);
749
750         layout_image_zoom_set(lw, 2.0, FALSE);
751 }
752
753 static void layout_menu_zoom_3_1_cb(GtkAction *, gpointer data)
754 {
755         auto lw = static_cast<LayoutWindow *>(data);
756
757         layout_image_zoom_set(lw, 3.0, FALSE);
758 }
759 static void layout_menu_zoom_4_1_cb(GtkAction *, gpointer data)
760 {
761         auto lw = static_cast<LayoutWindow *>(data);
762
763         layout_image_zoom_set(lw, 4.0, FALSE);
764 }
765
766 static void layout_menu_zoom_1_2_cb(GtkAction *, gpointer data)
767 {
768         auto lw = static_cast<LayoutWindow *>(data);
769
770         layout_image_zoom_set(lw, -2.0, FALSE);
771 }
772
773 static void layout_menu_zoom_1_3_cb(GtkAction *, gpointer data)
774 {
775         auto lw = static_cast<LayoutWindow *>(data);
776
777         layout_image_zoom_set(lw, -3.0, FALSE);
778 }
779
780 static void layout_menu_zoom_1_4_cb(GtkAction *, gpointer data)
781 {
782         auto lw = static_cast<LayoutWindow *>(data);
783
784         layout_image_zoom_set(lw, -4.0, FALSE);
785 }
786
787 /* connected zoom */
788 static void layout_menu_connect_zoom_in_cb(GtkAction *, gpointer data)
789 {
790         auto lw = static_cast<LayoutWindow *>(data);
791
792         layout_image_zoom_adjust(lw, get_zoom_increment(), TRUE);
793 }
794
795 static void layout_menu_connect_zoom_out_cb(GtkAction *, gpointer data)
796 {
797         auto lw = static_cast<LayoutWindow *>(data);
798
799         layout_image_zoom_adjust(lw, -get_zoom_increment(), TRUE);
800 }
801
802 static void layout_menu_connect_zoom_1_1_cb(GtkAction *, gpointer data)
803 {
804         auto lw = static_cast<LayoutWindow *>(data);
805
806         layout_image_zoom_set(lw, 1.0, TRUE);
807 }
808
809 static void layout_menu_connect_zoom_fit_cb(GtkAction *, gpointer data)
810 {
811         auto lw = static_cast<LayoutWindow *>(data);
812
813         layout_image_zoom_set(lw, 0.0, TRUE);
814 }
815
816 static void layout_menu_connect_zoom_fit_hor_cb(GtkAction *, gpointer data)
817 {
818         auto lw = static_cast<LayoutWindow *>(data);
819
820         layout_image_zoom_set_fill_geometry(lw, FALSE, TRUE);
821 }
822
823 static void layout_menu_connect_zoom_fit_vert_cb(GtkAction *, gpointer data)
824 {
825         auto lw = static_cast<LayoutWindow *>(data);
826
827         layout_image_zoom_set_fill_geometry(lw, TRUE, TRUE);
828 }
829
830 static void layout_menu_connect_zoom_2_1_cb(GtkAction *, gpointer data)
831 {
832         auto lw = static_cast<LayoutWindow *>(data);
833
834         layout_image_zoom_set(lw, 2.0, TRUE);
835 }
836
837 static void layout_menu_connect_zoom_3_1_cb(GtkAction *, gpointer data)
838 {
839         auto lw = static_cast<LayoutWindow *>(data);
840
841         layout_image_zoom_set(lw, 3.0, TRUE);
842 }
843 static void layout_menu_connect_zoom_4_1_cb(GtkAction *, gpointer data)
844 {
845         auto lw = static_cast<LayoutWindow *>(data);
846
847         layout_image_zoom_set(lw, 4.0, TRUE);
848 }
849
850 static void layout_menu_connect_zoom_1_2_cb(GtkAction *, gpointer data)
851 {
852         auto lw = static_cast<LayoutWindow *>(data);
853
854         layout_image_zoom_set(lw, -2.0, TRUE);
855 }
856
857 static void layout_menu_connect_zoom_1_3_cb(GtkAction *, gpointer data)
858 {
859         auto lw = static_cast<LayoutWindow *>(data);
860
861         layout_image_zoom_set(lw, -3.0, TRUE);
862 }
863
864 static void layout_menu_connect_zoom_1_4_cb(GtkAction *, gpointer data)
865 {
866         auto lw = static_cast<LayoutWindow *>(data);
867
868         layout_image_zoom_set(lw, -4.0, TRUE);
869 }
870
871
872 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
873 {
874         auto lw = static_cast<LayoutWindow *>(data);
875         ImageSplitMode mode;
876
877         layout_exit_fullscreen(lw);
878         mode = static_cast<ImageSplitMode>(gtk_radio_action_get_current_value(action));
879         layout_split_change(lw, mode);
880 }
881
882
883 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
884 {
885         auto lw = static_cast<LayoutWindow *>(data);
886
887         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
888 }
889
890
891 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
892 {
893         auto lw = static_cast<LayoutWindow *>(data);
894
895         layout_exit_fullscreen(lw);
896         layout_views_set(lw, lw->options.dir_view_type, static_cast<FileViewType>(gtk_radio_action_get_current_value(action)));
897 }
898
899 static void layout_menu_view_dir_as_cb(GtkToggleAction *action,  gpointer data)
900 {
901         auto lw = static_cast<LayoutWindow *>(data);
902
903         layout_exit_fullscreen(lw);
904
905         if (gtk_toggle_action_get_active(action))
906                 {
907                 layout_views_set(lw, DIRVIEW_TREE, lw->options.file_view_type);
908                 }
909         else
910                 {
911                 layout_views_set(lw, DIRVIEW_LIST, lw->options.file_view_type);
912                 }
913 }
914
915 static void layout_menu_view_in_new_window_cb(GtkAction *, gpointer data)
916 {
917         auto lw = static_cast<LayoutWindow *>(data);
918
919         layout_exit_fullscreen(lw);
920         view_window_new(layout_image_get_fd(lw));
921 }
922
923 struct OpenWithData
924 {
925         GAppInfo *application;
926         GList *g_file_list;
927         GtkWidget *app_chooser_dialog;
928 };
929
930 void open_with_response_cb(GtkDialog *, gint response_id, gpointer data)
931 {
932         GError *error = nullptr;
933         auto open_with_data = static_cast<OpenWithData *>(data);
934
935         if (response_id == GTK_RESPONSE_OK)
936                 {
937                 g_app_info_launch(open_with_data->application, open_with_data->g_file_list, nullptr, &error);
938
939                 if (error)
940                         {
941                         log_printf("Error launching app: %s\n", error->message);
942                         g_error_free(error);
943                         }
944                 }
945
946         g_object_unref(open_with_data->application);
947         g_object_unref(g_list_first(open_with_data->g_file_list)->data);
948         g_list_free(open_with_data->g_file_list);
949         gtk_widget_destroy(GTK_WIDGET(open_with_data->app_chooser_dialog));
950         g_free(open_with_data);
951 }
952
953 static void open_with_application_selected_cb(GtkAppChooserWidget *, GAppInfo *application, gpointer data)
954 {
955         auto open_with_data = static_cast<OpenWithData *>(data);
956
957         g_object_unref(open_with_data->application);
958
959         open_with_data->application = g_app_info_dup(application);
960 }
961
962 static void open_with_application_activated_cb(GtkAppChooserWidget *, GAppInfo *application, gpointer data)
963 {
964         GError *error = nullptr;
965         auto open_with_data = static_cast<OpenWithData *>(data);
966
967         g_app_info_launch(application, open_with_data->g_file_list, nullptr, &error);
968
969         if (error)
970                 {
971                 log_printf("Error launching app.: %s\n", error->message);
972                 g_error_free(error);
973                 }
974
975         g_object_unref(open_with_data->application);
976         g_object_unref(g_list_first(open_with_data->g_file_list)->data);
977         g_list_free(open_with_data->g_file_list);
978         gtk_widget_destroy(GTK_WIDGET(open_with_data->app_chooser_dialog));
979         g_free(open_with_data);
980 }
981
982 static void layout_menu_open_with_cb(GtkAction *, gpointer data)
983 {
984         auto lw = static_cast<LayoutWindow *>(data);
985         FileData *fd;
986         GtkWidget *widget;
987         OpenWithData *open_with_data;
988
989         if (layout_selection_list(lw))
990                 {
991                 open_with_data = g_new(OpenWithData, 1);
992
993                 fd = static_cast<FileData *>(g_list_first(layout_selection_list(lw))->data);
994
995                 open_with_data->g_file_list = g_list_append(nullptr, g_file_new_for_path(fd->path));
996
997                 open_with_data->app_chooser_dialog = gtk_app_chooser_dialog_new(nullptr, GTK_DIALOG_DESTROY_WITH_PARENT, G_FILE(g_list_first(open_with_data->g_file_list)->data));
998
999                 widget = gtk_app_chooser_dialog_get_widget(GTK_APP_CHOOSER_DIALOG(open_with_data->app_chooser_dialog));
1000
1001                 open_with_data->application = gtk_app_chooser_get_app_info(GTK_APP_CHOOSER(open_with_data->app_chooser_dialog));
1002
1003                 g_signal_connect(G_OBJECT(widget), "application-selected", G_CALLBACK(open_with_application_selected_cb), open_with_data);
1004                 g_signal_connect(G_OBJECT(widget), "application-activated", G_CALLBACK(open_with_application_activated_cb), open_with_data);
1005                 g_signal_connect(G_OBJECT(open_with_data->app_chooser_dialog), "response", G_CALLBACK(open_with_response_cb), open_with_data);
1006                 g_signal_connect(G_OBJECT(open_with_data->app_chooser_dialog), "close", G_CALLBACK(open_with_response_cb), open_with_data);
1007
1008                 gtk_widget_show(open_with_data->app_chooser_dialog);
1009                 }
1010 }
1011
1012 static void layout_menu_open_archive_cb(GtkAction *, gpointer data)
1013 {
1014         auto lw = static_cast<LayoutWindow *>(data);
1015         LayoutWindow *lw_new;
1016         gchar *dest_dir;
1017         FileData *fd;
1018
1019         layout_exit_fullscreen(lw);
1020         fd = layout_image_get_fd(lw);
1021
1022         if (fd->format_class == FORMAT_CLASS_ARCHIVE)
1023                 {
1024                 dest_dir = open_archive(layout_image_get_fd(lw));
1025                 if (dest_dir)
1026                         {
1027                         lw_new = layout_new_from_default();
1028                         layout_set_path(lw_new, dest_dir);
1029                         g_free(dest_dir);
1030                         }
1031                 else
1032                         {
1033                         warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1034                         }
1035                 }
1036 }
1037
1038 static void layout_menu_fullscreen_cb(GtkAction *, gpointer data)
1039 {
1040         auto lw = static_cast<LayoutWindow *>(data);
1041
1042         layout_image_full_screen_toggle(lw);
1043 }
1044
1045 static void layout_menu_escape_cb(GtkAction *, gpointer data)
1046 {
1047         auto lw = static_cast<LayoutWindow *>(data);
1048
1049         layout_exit_fullscreen(lw);
1050 }
1051
1052 static void layout_menu_overlay_toggle_cb(GtkAction *, gpointer data)
1053 {
1054         auto lw = static_cast<LayoutWindow *>(data);
1055
1056         image_osd_toggle(lw->image);
1057         layout_util_sync_views(lw);
1058 }
1059
1060
1061 static void layout_menu_overlay_cb(GtkToggleAction *action, gpointer data)
1062 {
1063         auto lw = static_cast<LayoutWindow *>(data);
1064
1065         if (gtk_toggle_action_get_active(action))
1066                 {
1067                 OsdShowFlags flags = image_osd_get(lw->image);
1068
1069                 if ((flags | OSD_SHOW_INFO | OSD_SHOW_STATUS) != flags)
1070                         image_osd_set(lw->image, static_cast<OsdShowFlags>(flags | OSD_SHOW_INFO | OSD_SHOW_STATUS));
1071                 }
1072         else
1073                 {
1074                 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1075
1076                 image_osd_set(lw->image, OSD_SHOW_NOTHING);
1077                 gtk_toggle_action_set_active(histogram_action, FALSE); /* this calls layout_menu_histogram_cb */
1078                 }
1079 }
1080
1081 static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
1082 {
1083         auto lw = static_cast<LayoutWindow *>(data);
1084
1085         if (gtk_toggle_action_get_active(action))
1086                 {
1087                 image_osd_set(lw->image, static_cast<OsdShowFlags>(OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_HISTOGRAM));
1088                 layout_util_sync_views(lw); /* show the overlay state, default channel and mode in the menu */
1089                 }
1090         else
1091                 {
1092                 OsdShowFlags flags = image_osd_get(lw->image);
1093                 if (flags & OSD_SHOW_HISTOGRAM)
1094                         image_osd_set(lw->image, static_cast<OsdShowFlags>(flags & ~OSD_SHOW_HISTOGRAM));
1095                 }
1096 }
1097
1098 static void layout_menu_animate_cb(GtkToggleAction *action, gpointer data)
1099 {
1100         auto lw = static_cast<LayoutWindow *>(data);
1101
1102         if (lw->options.animate == gtk_toggle_action_get_active(action)) return;
1103         layout_image_animate_toggle(lw);
1104 }
1105
1106 static void layout_menu_rectangular_selection_cb(GtkToggleAction *action, gpointer)
1107 {
1108         options->collections.rectangular_selection = gtk_toggle_action_get_active(action);
1109 }
1110
1111 static void layout_menu_histogram_toggle_channel_cb(GtkAction *, gpointer data)
1112 {
1113         auto lw = static_cast<LayoutWindow *>(data);
1114
1115         image_osd_histogram_toggle_channel(lw->image);
1116         layout_util_sync_views(lw);
1117 }
1118
1119 static void layout_menu_histogram_toggle_mode_cb(GtkAction *, gpointer data)
1120 {
1121         auto lw = static_cast<LayoutWindow *>(data);
1122
1123         image_osd_histogram_toggle_mode(lw->image);
1124         layout_util_sync_views(lw);
1125 }
1126
1127 static void layout_menu_histogram_channel_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1128 {
1129         auto lw = static_cast<LayoutWindow *>(data);
1130         gint channel = gtk_radio_action_get_current_value(action);
1131         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1132
1133         if (channel < 0 || channel >= HCHAN_COUNT) return;
1134
1135         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
1136         image_osd_histogram_set_channel(lw->image, channel);
1137 }
1138
1139 static void layout_menu_histogram_mode_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1140 {
1141         auto lw = static_cast<LayoutWindow *>(data);
1142         gint mode = gtk_radio_action_get_current_value(action);
1143         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
1144
1145         if (mode < 0 || mode > 1) return;
1146
1147         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
1148         image_osd_histogram_set_mode(lw->image, mode);
1149 }
1150
1151 static void layout_menu_refresh_cb(GtkAction *, gpointer data)
1152 {
1153         auto lw = static_cast<LayoutWindow *>(data);
1154
1155         layout_refresh(lw);
1156 }
1157
1158 static void layout_menu_bar_exif_cb(GtkAction *, gpointer data)
1159 {
1160         auto lw = static_cast<LayoutWindow *>(data);
1161
1162         layout_exit_fullscreen(lw);
1163         layout_exif_window_new(lw);
1164 }
1165
1166 static void layout_menu_search_and_run_cb(GtkAction *, gpointer data)
1167 {
1168         auto lw = static_cast<LayoutWindow *>(data);
1169
1170         layout_exit_fullscreen(lw);
1171         layout_search_and_run_window_new(lw);
1172 }
1173
1174
1175 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
1176 {
1177         auto lw = static_cast<LayoutWindow *>(data);
1178
1179         if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return;
1180
1181         layout_exit_fullscreen(lw);
1182         layout_tools_float_toggle(lw);
1183 }
1184
1185 static void layout_menu_hide_cb(GtkAction *, gpointer data)
1186 {
1187         auto lw = static_cast<LayoutWindow *>(data);
1188
1189         layout_exit_fullscreen(lw);
1190         layout_tools_hide_toggle(lw);
1191 }
1192
1193 static void layout_menu_selectable_toolbars_cb(GtkToggleAction *action, gpointer data)
1194 {
1195         auto lw = static_cast<LayoutWindow *>(data);
1196
1197         if (lw->options.selectable_toolbars_hidden == gtk_toggle_action_get_active(action)) return;
1198
1199         layout_exit_fullscreen(lw);
1200         layout_selectable_toolbars_toggle(lw);
1201 }
1202
1203 static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
1204 {
1205         auto lw = static_cast<LayoutWindow *>(data);
1206
1207         if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
1208
1209         layout_exit_fullscreen(lw);
1210         layout_info_pixel_set(lw, !lw->options.show_info_pixel);
1211 }
1212
1213 /* NOTE: these callbacks are called also from layout_util_sync_views */
1214 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
1215 {
1216         auto lw = static_cast<LayoutWindow *>(data);
1217
1218         if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
1219
1220         layout_exit_fullscreen(lw);
1221         layout_bar_toggle(lw);
1222 }
1223
1224 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
1225 {
1226         auto lw = static_cast<LayoutWindow *>(data);
1227
1228         if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
1229
1230         layout_exit_fullscreen(lw);
1231         layout_bar_sort_toggle(lw);
1232 }
1233
1234 static void layout_menu_hide_bars_cb(GtkToggleAction *action, gpointer data)
1235 {
1236         auto lw = static_cast<LayoutWindow *>(data);
1237
1238         if (lw->options.bars_state.hidden == gtk_toggle_action_get_active(action))
1239                 {
1240                 return;
1241                 }
1242         layout_bars_hide_toggle(lw);
1243 }
1244
1245 static void layout_menu_slideshow_cb(GtkToggleAction *action, gpointer data)
1246 {
1247         auto lw = static_cast<LayoutWindow *>(data);
1248
1249         if (layout_image_slideshow_active(lw) == gtk_toggle_action_get_active(action)) return;
1250         layout_image_slideshow_toggle(lw);
1251 }
1252
1253 static void layout_menu_slideshow_pause_cb(GtkAction *, gpointer data)
1254 {
1255         auto lw = static_cast<LayoutWindow *>(data);
1256
1257         layout_image_slideshow_pause_toggle(lw);
1258 }
1259
1260 static void layout_menu_slideshow_slower_cb(GtkAction *, gpointer)
1261 {
1262         options->slideshow.delay = options->slideshow.delay + 5;
1263         if (options->slideshow.delay > SLIDESHOW_MAX_SECONDS)
1264                 options->slideshow.delay = SLIDESHOW_MAX_SECONDS;
1265 }
1266
1267 static void layout_menu_slideshow_faster_cb(GtkAction *, gpointer)
1268 {
1269         options->slideshow.delay = options->slideshow.delay - 5;
1270         if (options->slideshow.delay < SLIDESHOW_MIN_SECONDS * 10)
1271                 options->slideshow.delay = SLIDESHOW_MIN_SECONDS * 10;
1272 }
1273
1274
1275 static void layout_menu_stereo_mode_next_cb(GtkAction *, gpointer data)
1276 {
1277         auto lw = static_cast<LayoutWindow *>(data);
1278         gint mode = layout_image_stereo_pixbuf_get(lw);
1279
1280         /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
1281         mode = mode % 3 + 1;
1282
1283         GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
1284         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
1285
1286         /*
1287         this is called via fallback in layout_menu_stereo_mode_cb
1288         layout_image_stereo_pixbuf_set(lw, mode);
1289         */
1290
1291 }
1292
1293 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1294 {
1295         auto lw = static_cast<LayoutWindow *>(data);
1296         gint mode = gtk_radio_action_get_current_value(action);
1297         layout_image_stereo_pixbuf_set(lw, mode);
1298 }
1299
1300 static void layout_menu_help_cb(GtkAction *, gpointer data)
1301 {
1302         auto lw = static_cast<LayoutWindow *>(data);
1303
1304         layout_exit_fullscreen(lw);
1305         help_window_show("index.html");
1306 }
1307
1308 static void layout_menu_help_search_cb(GtkAction *, gpointer data)
1309 {
1310         auto lw = static_cast<LayoutWindow *>(data);
1311
1312         layout_exit_fullscreen(lw);
1313         help_search_window_show();
1314 }
1315
1316 static void layout_menu_help_keys_cb(GtkAction *, gpointer data)
1317 {
1318         auto lw = static_cast<LayoutWindow *>(data);
1319
1320         layout_exit_fullscreen(lw);
1321         help_window_show("GuideReferenceKeyboardShortcuts.html");
1322 }
1323
1324 static void layout_menu_notes_cb(GtkAction *, gpointer data)
1325 {
1326         auto lw = static_cast<LayoutWindow *>(data);
1327
1328         layout_exit_fullscreen(lw);
1329         help_window_show("release_notes");
1330 }
1331
1332 static void layout_menu_changelog_cb(GtkAction *, gpointer data)
1333 {
1334         auto lw = static_cast<LayoutWindow *>(data);
1335
1336         layout_exit_fullscreen(lw);
1337         help_window_show("changelog");
1338 }
1339
1340 static constexpr const char *keyboard_map_hardcoded[][2] = {
1341         {"Scroll","Left"},
1342         {"FastScroll", "&lt;Shift&gt;Left"},
1343         {"Left Border", "&lt;Primary&gt;Left"},
1344         {"Left Border", "&lt;Primary&gt;&lt;Shift&gt;Left"},
1345         {"Scroll", "Right"},
1346         {"FastScroll", "&lt;Shift&gt;Right"},
1347         {"Right Border", "&lt;Primary&gt;Right"},
1348         {"Right Border", "&lt;Primary&gt;&lt;Shift&gt;Right"},
1349         {"Scroll", "Up"},
1350         {"FastScroll", "&lt;Shift&gt;Up"},
1351         {"Upper Border", "&lt;Primary&gt;Up"},
1352         {"Upper Border", "&lt;Primary&gt;&lt;Shift&gt;Up"},
1353         {"Scroll", "Down"},
1354         {"FastScroll", "&lt;Shift&gt;Down"},
1355         {"Lower Border", "&lt;Primary&gt;Down"},
1356         {"Lower Border", "&lt;Primary&gt;&lt;Shift&gt;Down"},
1357         {"Next/Drag", "M1"},
1358         {"FastDrag", "&lt;Shift&gt;M1"},
1359         {"DnD Start", "M2"},
1360         {"Menu", "M3"},
1361         {"PrevImage", "MW4"},
1362         {"NextImage", "MW5"},
1363         {"ScrollUp", "&lt;Shift&gt;MW4"},
1364         {"ScrollDown", "&lt;Shift&gt;MW5"},
1365         {"ZoomIn", "&lt;Primary&gt;MW4"},
1366         {"ZoomOut", "&lt;Primary&gt;MW5"},
1367 };
1368
1369 static void layout_menu_foreach_func(
1370                                         gpointer data,
1371                                         const gchar *accel_path,
1372                                         guint accel_key,
1373                                         GdkModifierType accel_mods,
1374                                         gboolean)
1375 {
1376         gchar *path;
1377         gchar *name;
1378         gchar *key_name;
1379         gchar *menu_name;
1380         gchar **subset_lt_arr;
1381         gchar **subset_gt_arr;
1382         gchar *subset_lt;
1383         gchar *converted_name;
1384         auto array = static_cast<GPtrArray *>(data);
1385
1386         path = g_strescape(accel_path, nullptr);
1387         name = gtk_accelerator_name(accel_key, accel_mods);
1388
1389         menu_name = g_strdup(g_strrstr(path, "/")+1);
1390
1391         if (g_strrstr(name, ">"))
1392                 {
1393                 subset_lt_arr = g_strsplit_set(name,"<", 4);
1394                 subset_lt = g_strjoinv("&lt;", subset_lt_arr);
1395                 subset_gt_arr = g_strsplit_set(subset_lt,">", 4);
1396                 converted_name = g_strjoinv("&gt;", subset_gt_arr);
1397                 key_name = g_strdup(converted_name);
1398
1399                 g_free(converted_name);
1400                 g_free(subset_lt);
1401                 g_strfreev(subset_lt_arr);
1402                 g_strfreev(subset_gt_arr);
1403                 }
1404         else
1405                 key_name = g_strdup(name);
1406
1407         g_ptr_array_add(array, menu_name);
1408         g_ptr_array_add(array, key_name);
1409
1410         g_free(name);
1411         g_free(path);
1412 }
1413
1414 static void layout_menu_kbd_map_cb(GtkAction *, gpointer)
1415 {
1416         gint fd = -1;
1417         GPtrArray *array;
1418         char * tmp_file;
1419         GError *error = nullptr;
1420         GIOChannel *channel;
1421         char **pre_key;
1422         char **post_key;
1423         const char *key_name;
1424         char *converted_line;
1425         int keymap_index;
1426         guint index;
1427
1428         fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
1429         if (error)
1430                 {
1431                 log_printf("Error: Keyboard Map - cannot create file:%s\n",error->message);
1432                 g_error_free(error);
1433                 }
1434         else
1435                 {
1436                 array = g_ptr_array_new();
1437
1438                 gtk_accel_map_foreach(array, layout_menu_foreach_func);
1439
1440                 channel = g_io_channel_unix_new(fd);
1441
1442                 keymap_index = 0;
1443                 while (keymap_template[keymap_index])
1444                         {
1445                         if (g_strrstr(keymap_template[keymap_index], ">key:"))
1446                                 {
1447                                 pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
1448                                 post_key = g_strsplit(pre_key[1],"<",2);
1449
1450                                 index=0;
1451                                 key_name = " ";
1452                                 for (index=0; index < array->len-2; index=index+2)
1453                                         {
1454                                         if (!(g_ascii_strcasecmp(static_cast<const gchar *>(g_ptr_array_index(array,index+1)), post_key[0])))
1455                                                 {
1456                                                 key_name = static_cast<const gchar *>(g_ptr_array_index(array,index+0));
1457                                                 break;
1458                                                 }
1459                                         }
1460
1461                                 for (const auto& m : keyboard_map_hardcoded)
1462                                         {
1463                                         if (!(g_strcmp0(m[1], post_key[0])))
1464                                                 {
1465                                                 key_name = m[0];
1466                                                 break;
1467                                                 }
1468                                         }
1469
1470                                 converted_line = g_strconcat(pre_key[0], ">", key_name, "<", post_key[1], "\n", NULL);
1471                                 g_io_channel_write_chars(channel, converted_line, -1, nullptr, &error);
1472                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1473
1474                                 g_free(converted_line);
1475                                 g_strfreev(pre_key);
1476                                 g_strfreev(post_key);
1477                                 }
1478                         else
1479                                 {
1480                                 g_io_channel_write_chars(channel, keymap_template[keymap_index], -1, nullptr, &error);
1481                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1482                                 g_io_channel_write_chars(channel, "\n", -1, nullptr, &error);
1483                                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1484                                 }
1485                         keymap_index++;
1486                         }
1487
1488                 g_io_channel_flush(channel, &error);
1489                 if (error) {log_printf("Warning: Keyboard Map:%s\n",error->message); g_error_free(error);}
1490                 g_io_channel_unref(channel);
1491
1492                 index=0;
1493                 for (index=0; index < array->len-2; index=index+2)
1494                         {
1495                         g_free(g_ptr_array_index(array,index));
1496                         g_free(g_ptr_array_index(array,index+1));
1497                         }
1498                 g_ptr_array_unref(array);
1499
1500                 view_window_new(file_data_new_simple(tmp_file));
1501                 g_free(tmp_file);
1502                 }
1503 }
1504
1505 static void layout_menu_about_cb(GtkAction *, gpointer data)
1506 {
1507         auto lw = static_cast<LayoutWindow *>(data);
1508
1509         layout_exit_fullscreen(lw);
1510         show_about_window(lw);
1511 }
1512
1513 static void layout_menu_log_window_cb(GtkAction *, gpointer data)
1514 {
1515         auto lw = static_cast<LayoutWindow *>(data);
1516
1517         layout_exit_fullscreen(lw);
1518         log_window_new(lw);
1519 }
1520
1521
1522 /*
1523  *-----------------------------------------------------------------------------
1524  * select menu
1525  *-----------------------------------------------------------------------------
1526  */
1527
1528 static void layout_menu_select_all_cb(GtkAction *, gpointer data)
1529 {
1530         auto lw = static_cast<LayoutWindow *>(data);
1531
1532         layout_select_all(lw);
1533 }
1534
1535 static void layout_menu_unselect_all_cb(GtkAction *, gpointer data)
1536 {
1537         auto lw = static_cast<LayoutWindow *>(data);
1538
1539         layout_select_none(lw);
1540 }
1541
1542 static void layout_menu_invert_selection_cb(GtkAction *, gpointer data)
1543 {
1544         auto lw = static_cast<LayoutWindow *>(data);
1545
1546         layout_select_invert(lw);
1547 }
1548
1549 static void layout_menu_file_filter_cb(GtkToggleAction *action, gpointer data)
1550 {
1551         auto lw = static_cast<LayoutWindow *>(data);
1552
1553         layout_file_filter_set(lw, gtk_toggle_action_get_active(action));
1554 }
1555
1556 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
1557 {
1558         auto lw = static_cast<LayoutWindow *>(data);
1559
1560         layout_marks_set(lw, gtk_toggle_action_get_active(action));
1561 }
1562
1563
1564 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
1565 {
1566         auto lw = static_cast<LayoutWindow *>(data);
1567         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1568         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1569
1570         layout_selection_to_mark(lw, mark, STM_MODE_SET);
1571 }
1572
1573 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
1574 {
1575         auto lw = static_cast<LayoutWindow *>(data);
1576         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1577         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1578
1579         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
1580 }
1581
1582 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
1583 {
1584         auto lw = static_cast<LayoutWindow *>(data);
1585         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1586         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1587
1588         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
1589 }
1590
1591 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
1592 {
1593         auto lw = static_cast<LayoutWindow *>(data);
1594         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1595         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1596
1597         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
1598 }
1599
1600 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
1601 {
1602         auto lw = static_cast<LayoutWindow *>(data);
1603         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1604         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1605
1606         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
1607 }
1608
1609 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
1610 {
1611         auto lw = static_cast<LayoutWindow *>(data);
1612         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1613         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1614
1615         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
1616 }
1617
1618 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
1619 {
1620         auto lw = static_cast<LayoutWindow *>(data);
1621         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1622         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1623
1624         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
1625 }
1626
1627 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
1628 {
1629         auto lw = static_cast<LayoutWindow *>(data);
1630         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1631         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1632
1633         layout_marks_set(lw, TRUE);
1634         layout_mark_filter_toggle(lw, mark);
1635 }
1636
1637
1638 /*
1639  *-----------------------------------------------------------------------------
1640  * go menu
1641  *-----------------------------------------------------------------------------
1642  */
1643
1644 static void layout_menu_image_first_cb(GtkAction *, gpointer data)
1645 {
1646         auto lw = static_cast<LayoutWindow *>(data);
1647         layout_image_first(lw);
1648 }
1649
1650 static void layout_menu_image_prev_cb(GtkAction *, gpointer data)
1651 {
1652         auto lw = static_cast<LayoutWindow *>(data);
1653         gint i;
1654
1655         if (lw->options.split_pane_sync)
1656                 {
1657                 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1658                         {
1659                         if (lw->split_images[i])
1660                                 {
1661                                 if (i != -1)
1662                                         {
1663                                         DEBUG_1("image activate scroll %d", i);
1664                                         layout_image_activate(lw, i, FALSE);
1665                                         layout_image_prev(lw);
1666                                         }
1667                                 }
1668                         }
1669                 }
1670         else
1671                 {
1672                 layout_image_prev(lw);
1673                 }
1674 }
1675
1676 static void layout_menu_image_next_cb(GtkAction *, gpointer data)
1677 {
1678         auto lw = static_cast<LayoutWindow *>(data);
1679         gint i;
1680
1681         if (lw->options.split_pane_sync)
1682                 {
1683                 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1684                         {
1685                         if (lw->split_images[i])
1686                                 {
1687                                 if (i != -1)
1688                                         {
1689                                         DEBUG_1("image activate scroll %d", i);
1690                                         layout_image_activate(lw, i, FALSE);
1691                                         layout_image_next(lw);
1692                                         }
1693                                 }
1694                         }
1695                 }
1696         else
1697                 {
1698                 layout_image_next(lw);
1699                 }
1700 }
1701
1702 static void layout_menu_page_first_cb(GtkAction *, gpointer data)
1703 {
1704         auto lw = static_cast<LayoutWindow *>(data);
1705         FileData *fd = layout_image_get_fd(lw);
1706
1707         if (fd->page_total > 0)
1708                 {
1709                 file_data_set_page_num(fd, 1);
1710                 }
1711 }
1712
1713 static void layout_menu_page_last_cb(GtkAction *, gpointer data)
1714 {
1715         auto lw = static_cast<LayoutWindow *>(data);
1716         FileData *fd = layout_image_get_fd(lw);
1717
1718         if (fd->page_total > 0)
1719                 {
1720                 file_data_set_page_num(fd, -1);
1721                 }
1722 }
1723
1724 static void layout_menu_page_next_cb(GtkAction *, gpointer data)
1725 {
1726         auto lw = static_cast<LayoutWindow *>(data);
1727         FileData *fd = layout_image_get_fd(lw);
1728
1729         if (fd->page_total > 0)
1730                 {
1731                 file_data_inc_page_num(fd);
1732                 }
1733 }
1734
1735 static void layout_menu_page_previous_cb(GtkAction *, gpointer data)
1736 {
1737         auto lw = static_cast<LayoutWindow *>(data);
1738         FileData *fd = layout_image_get_fd(lw);
1739
1740         if (fd->page_total > 0)
1741                 {
1742                 file_data_dec_page_num(fd);
1743                 }
1744 }
1745
1746 static void layout_menu_image_forward_cb(GtkAction *, gpointer data)
1747 {
1748         auto lw = static_cast<LayoutWindow *>(data);
1749
1750         /* Obtain next image */
1751         layout_set_path(lw, image_chain_forward());
1752 }
1753
1754 static void layout_menu_image_back_cb(GtkAction *, gpointer data)
1755 {
1756         auto lw = static_cast<LayoutWindow *>(data);
1757
1758         /* Obtain previous image */
1759         layout_set_path(lw, image_chain_back());
1760 }
1761
1762 static void layout_menu_split_pane_next_cb(GtkAction *, gpointer data)
1763 {
1764         auto lw = static_cast<LayoutWindow *>(data);
1765         gint active_frame;
1766
1767         active_frame = lw->active_split_image;
1768
1769         if (active_frame < MAX_SPLIT_IMAGES-1 && lw->split_images[active_frame+1] )
1770                 {
1771                 active_frame++;
1772                 }
1773         else
1774                 {
1775                 active_frame = 0;
1776                 }
1777         layout_image_activate(lw, active_frame, FALSE);
1778 }
1779
1780 static void layout_menu_split_pane_prev_cb(GtkAction *, gpointer data)
1781 {
1782         auto lw = static_cast<LayoutWindow *>(data);
1783         gint active_frame;
1784
1785         active_frame = lw->active_split_image;
1786
1787         if (active_frame >=1 && lw->split_images[active_frame-1] )
1788                 {
1789                 active_frame--;
1790                 }
1791         else
1792                 {
1793                 active_frame = MAX_SPLIT_IMAGES-1;
1794                 while (!lw->split_images[active_frame])
1795                         {
1796                         active_frame--;
1797                         }
1798                 }
1799         layout_image_activate(lw, active_frame, FALSE);
1800 }
1801
1802 static void layout_menu_split_pane_updown_cb(GtkAction *, gpointer data)
1803 {
1804         auto lw = static_cast<LayoutWindow *>(data);
1805         gint active_frame;
1806
1807         active_frame = lw->active_split_image;
1808
1809         if (lw->split_images[MAX_SPLIT_IMAGES-1] )
1810                 {
1811                 active_frame = active_frame ^ 2;
1812                 }
1813         else
1814                 {
1815                 active_frame = active_frame ^ 1;
1816                 }
1817         layout_image_activate(lw, active_frame, FALSE);
1818 }
1819
1820 static void layout_menu_image_last_cb(GtkAction *, gpointer data)
1821 {
1822         auto lw = static_cast<LayoutWindow *>(data);
1823         layout_image_last(lw);
1824 }
1825
1826 static void layout_menu_back_cb(GtkAction *, gpointer data)
1827 {
1828         auto lw = static_cast<LayoutWindow *>(data);
1829         FileData *dir_fd;
1830
1831         /* Obtain previous path */
1832         dir_fd = file_data_new_dir(history_chain_back());
1833         layout_set_fd(lw, dir_fd);
1834         file_data_unref(dir_fd);
1835 }
1836
1837 static void layout_menu_forward_cb(GtkAction *, gpointer data)
1838 {
1839         auto lw = static_cast<LayoutWindow *>(data);
1840         FileData *dir_fd;
1841
1842         /* Obtain next path */
1843         dir_fd = file_data_new_dir(history_chain_forward());
1844         layout_set_fd(lw, dir_fd);
1845         file_data_unref(dir_fd);
1846 }
1847
1848 static void layout_menu_home_cb(GtkAction *, gpointer data)
1849 {
1850         auto lw = static_cast<LayoutWindow *>(data);
1851         const gchar *path;
1852
1853         if (lw->options.home_path && *lw->options.home_path)
1854                 path = lw->options.home_path;
1855         else
1856                 path = homedir();
1857
1858         if (path)
1859                 {
1860                 FileData *dir_fd = file_data_new_dir(path);
1861                 layout_set_fd(lw, dir_fd);
1862                 file_data_unref(dir_fd);
1863                 }
1864 }
1865
1866 static void layout_menu_up_cb(GtkAction *, gpointer data)
1867 {
1868         auto lw = static_cast<LayoutWindow *>(data);
1869         ViewDir *vd = lw->vd;
1870         gchar *path;
1871
1872         if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1873         path = remove_level_from_path(vd->dir_fd->path);
1874
1875         if (vd->select_func)
1876                 {
1877                 FileData *fd = file_data_new_dir(path);
1878                 vd->select_func(vd, fd, vd->select_data);
1879                 file_data_unref(fd);
1880                 }
1881
1882         g_free(path);
1883 }
1884
1885
1886 /*
1887  *-----------------------------------------------------------------------------
1888  * edit menu
1889  *-----------------------------------------------------------------------------
1890  */
1891
1892 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1893 {
1894         auto lw = static_cast<LayoutWindow *>(data);
1895         const gchar *key = gtk_action_get_name(action);
1896
1897         if (!editor_window_flag_set(key))
1898                 layout_exit_fullscreen(lw);
1899
1900         file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1901 }
1902
1903
1904 static void layout_menu_metadata_write_cb(GtkAction *, gpointer)
1905 {
1906         metadata_write_queue_confirm(TRUE, nullptr, nullptr);
1907 }
1908
1909 static GtkWidget *last_focussed = nullptr;
1910 static void layout_menu_keyword_autocomplete_cb(GtkAction *, gpointer data)
1911 {
1912         auto lw = static_cast<LayoutWindow *>(data);
1913         GtkWidget *tmp;
1914         gboolean auto_has_focus;
1915
1916         tmp = gtk_window_get_focus(GTK_WINDOW(lw->window));
1917         auto_has_focus = bar_keywords_autocomplete_focus(lw);
1918
1919         if (auto_has_focus)
1920                 {
1921                 gtk_widget_grab_focus(last_focussed);
1922                 }
1923         else
1924                 {
1925                 last_focussed = tmp;
1926                 }
1927 }
1928
1929 /*
1930  *-----------------------------------------------------------------------------
1931  * color profile button (and menu)
1932  *-----------------------------------------------------------------------------
1933  */
1934 #if HAVE_LCMS
1935 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1936 {
1937         auto lw = static_cast<LayoutWindow *>(data);
1938
1939         if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1940
1941         layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1942         layout_util_sync_color(lw);
1943         layout_image_refresh(lw);
1944 }
1945
1946 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1947 {
1948         auto lw = static_cast<LayoutWindow *>(data);
1949         gint input;
1950         gboolean use_image;
1951
1952         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1953         if (use_image == gtk_toggle_action_get_active(action)) return;
1954         layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1955         layout_util_sync_color(lw);
1956         layout_image_refresh(lw);
1957 }
1958
1959 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *, gpointer data)
1960 {
1961         auto lw = static_cast<LayoutWindow *>(data);
1962         gint type;
1963         gint input;
1964         gboolean use_image;
1965
1966         type = gtk_radio_action_get_current_value(action);
1967         if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
1968
1969         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1970         if (type == input) return;
1971
1972         layout_image_color_profile_set(lw, type, use_image);
1973         layout_image_refresh(lw);
1974 }
1975 #else
1976 static void layout_color_menu_enable_cb()
1977 {
1978 }
1979
1980 static void layout_color_menu_use_image_cb()
1981 {
1982 }
1983
1984 static void layout_color_menu_input_cb()
1985 {
1986 }
1987 #endif
1988
1989
1990 /*
1991  *-----------------------------------------------------------------------------
1992  * recent menu
1993  *-----------------------------------------------------------------------------
1994  */
1995
1996 static void layout_menu_recent_cb(GtkWidget *widget, gpointer)
1997 {
1998         gint n;
1999         gchar *path;
2000
2001         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
2002
2003         path = static_cast<gchar *>(g_list_nth_data(history_list_get_by_key("recent"), n));
2004
2005         if (!path) return;
2006
2007         /* make a copy of it */
2008         path = g_strdup(path);
2009         collection_window_new(path);
2010         g_free(path);
2011 }
2012
2013 static void layout_menu_collection_recent_update(LayoutWindow *lw)
2014 {
2015         GtkWidget *menu;
2016         GtkWidget *recent;
2017         GtkWidget *item;
2018         GList *list;
2019         gint n;
2020
2021         if (!lw->ui_manager) return;
2022
2023         list = history_list_get_by_key("recent");
2024         n = 0;
2025
2026         menu = gtk_menu_new();
2027
2028         while (list)
2029                 {
2030                 const gchar *filename = filename_from_path(static_cast<gchar *>(list->data));
2031                 gchar *name;
2032                 gboolean free_name = FALSE;
2033
2034                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
2035                         {
2036                         name = remove_extension_from_path(filename);
2037                         free_name = TRUE;
2038                         }
2039                 else
2040                         {
2041                         name = const_cast<gchar *>(filename);
2042                         }
2043
2044                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
2045                 if (free_name) g_free(name);
2046                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
2047                 list = list->next;
2048                 n++;
2049                 }
2050
2051         if (n == 0)
2052                 {
2053                 menu_item_add(menu, _("Empty"), nullptr, nullptr);
2054                 }
2055
2056         recent = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/FileMenu/OpenRecent" : "/MainMenu/FileMenu/OpenRecent");
2057         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
2058         gtk_widget_set_sensitive(recent, (n != 0));
2059 }
2060
2061 static void layout_menu_collection_open_update(LayoutWindow *lw)
2062 {
2063         gboolean free_name = FALSE;
2064         gchar *name;
2065         gint n;
2066         GList *collection_list = nullptr;
2067         GList *work;
2068         GtkWidget *item;
2069         GtkWidget *menu;
2070         GtkWidget *recent;
2071
2072         if (!lw->ui_manager) return;
2073
2074         collect_manager_list(&collection_list, nullptr, nullptr);
2075
2076         n = 0;
2077
2078         menu = gtk_menu_new();
2079
2080         work = collection_list;
2081         while (work)
2082                 {
2083                 const gchar *filename = static_cast<gchar *>(work->data);
2084
2085                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
2086                         {
2087                         name = remove_extension_from_path(filename);
2088                         free_name = TRUE;
2089                         }
2090                 else
2091                         {
2092                         name = const_cast<gchar *>(filename);
2093                         }
2094
2095                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_open_cb), lw);
2096                 if (free_name)
2097                         {
2098                         g_free(name);
2099                         }
2100                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
2101                 work = work->next;
2102                 n++;
2103                 }
2104
2105         string_list_free(collection_list);
2106
2107         if (n == 0)
2108                 {
2109                 menu_item_add(menu, _("Empty"), nullptr, nullptr);
2110                 }
2111
2112         recent = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/FileMenu/OpenCollection" : "/MainMenu/FileMenu/OpenCollection");
2113         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
2114         gtk_widget_set_sensitive(recent, (n != 0));
2115 }
2116
2117 void layout_recent_update_all()
2118 {
2119         GList *work;
2120
2121         work = layout_window_list;
2122         while (work)
2123                 {
2124                 auto lw = static_cast<LayoutWindow *>(work->data);
2125                 work = work->next;
2126
2127                 layout_menu_collection_recent_update(lw);
2128                 layout_menu_collection_open_update(lw);
2129                 }
2130 }
2131
2132 void layout_recent_add_path(const gchar *path)
2133 {
2134         if (!path) return;
2135
2136         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
2137
2138         layout_recent_update_all();
2139 }
2140
2141 /*
2142  *-----------------------------------------------------------------------------
2143  * window layout menu
2144  *-----------------------------------------------------------------------------
2145  */
2146 struct WindowNames
2147 {
2148         gboolean displayed;
2149         gchar *name;
2150         gchar *path;
2151 };
2152
2153 struct RenameWindow
2154 {
2155         GenericDialog *gd;
2156         LayoutWindow *lw;
2157
2158         GtkWidget *button_ok;
2159         GtkWidget *window_name_entry;
2160 };
2161
2162 struct DeleteWindow
2163 {
2164         GenericDialog *gd;
2165         LayoutWindow *lw;
2166
2167         GtkWidget *button_ok;
2168         GtkWidget *group;
2169 };
2170
2171 static gint layout_window_menu_list_sort_cb(gconstpointer a, gconstpointer b)
2172 {
2173         auto wna = static_cast<const WindowNames *>(a);
2174         auto wnb = static_cast<const WindowNames *>(b);
2175
2176         return g_strcmp0(wna->name, wnb->name);
2177 }
2178
2179 static GList *layout_window_menu_list(GList *listin)
2180 {
2181         GList *list;
2182         WindowNames *wn;
2183         gboolean dupe;
2184         DIR *dp;
2185         struct dirent *dir;
2186         gchar *pathl;
2187
2188         pathl = path_from_utf8(get_window_layouts_dir());
2189         dp = opendir(pathl);
2190         if (!dp)
2191                 {
2192                 /* dir not found */
2193                 g_free(pathl);
2194                 return listin;
2195                 }
2196
2197         while ((dir = readdir(dp)) != nullptr)
2198                 {
2199                 gchar *name_file = dir->d_name;
2200
2201                 if (g_str_has_suffix(name_file, ".xml"))
2202                         {
2203                         LayoutWindow *lw_tmp ;
2204                         gchar *name_utf8 = path_to_utf8(name_file);
2205                         gchar *name_base = g_strndup(name_utf8, strlen(name_utf8) - 4);
2206                         list = layout_window_list;
2207                         dupe = FALSE;
2208                         while (list)
2209                                 {
2210                                 lw_tmp = static_cast<LayoutWindow *>(list->data);
2211                                 if (g_strcmp0(lw_tmp->options.id, name_base) == 0)
2212                                         {
2213                                         dupe = TRUE;
2214                                         }
2215                                 list = list->next;
2216                                 }
2217                         gchar *dpath = g_build_filename(pathl, name_utf8, NULL);
2218                         wn  = g_new0(WindowNames, 1);
2219                         wn->displayed = dupe;
2220                         wn->name = g_strdup(name_base);
2221                         wn->path = g_strdup(dpath);
2222                         listin = g_list_append(listin, wn);
2223
2224                         g_free(dpath);
2225                         g_free(name_utf8);
2226                         g_free(name_base);
2227                         }
2228                 }
2229         closedir(dp);
2230
2231         g_free(pathl);
2232
2233         return g_list_sort(listin, layout_window_menu_list_sort_cb);
2234 }
2235
2236 static void layout_menu_new_window_cb(GtkWidget *, gpointer data)
2237 {
2238         gint n;
2239
2240         n = GPOINTER_TO_INT(data);
2241         GList *menulist = nullptr;
2242
2243         menulist = layout_window_menu_list(menulist);
2244         auto wn = static_cast<WindowNames *>(g_list_nth(menulist, n )->data);
2245
2246         if (wn->path)
2247                 {
2248                 load_config_from_file(wn->path, FALSE);
2249                 }
2250         else
2251                 {
2252                 log_printf(_("Error: window layout name: %s does not exist\n"), wn->path);
2253                 }
2254 }
2255
2256 static void layout_menu_new_window_update(LayoutWindow *lw)
2257 {
2258         GtkWidget *menu;
2259         GtkWidget *sub_menu;
2260         GtkWidget *item;
2261         GList *children;
2262         GList *iter;
2263         gint n;
2264         GList *list = nullptr;
2265         gint i = 0;
2266         WindowNames *wn;
2267
2268         if (!lw->ui_manager) return;
2269
2270         list = layout_window_menu_list(list);
2271
2272         menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/WindowsMenu/NewWindow" : "/MainMenu/WindowsMenu/NewWindow");
2273         sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2274
2275         children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2276         for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2277                 {
2278                 if (i >= 4) // separator, default, from current, separator
2279                         {
2280                         gq_gtk_widget_destroy(GTK_WIDGET(iter->data));
2281                         }
2282                 }
2283         g_list_free(children);
2284
2285         menu_item_add_divider(sub_menu);
2286
2287         n = 0;
2288         while (list)
2289                 {
2290                 wn = static_cast<WindowNames *>(list->data);
2291                 item = menu_item_add_simple(sub_menu, wn->name, G_CALLBACK(layout_menu_new_window_cb), GINT_TO_POINTER(n));
2292                 if (wn->displayed)
2293                         {
2294                         gtk_widget_set_sensitive(item, FALSE);
2295                         }
2296                 list = list->next;
2297                 n++;
2298                 }
2299 }
2300
2301 static void window_rename_cancel_cb(GenericDialog *, gpointer data)
2302 {
2303         auto rw = static_cast<RenameWindow *>(data);
2304
2305         generic_dialog_close(rw->gd);
2306         g_free(rw);
2307 }
2308
2309 static void window_rename_ok(GenericDialog *, gpointer data)
2310 {
2311         auto rw = static_cast<RenameWindow *>(data);
2312         gchar *path;
2313         gboolean window_layout_name_exists = FALSE;
2314         GList *list = nullptr;
2315         gchar *xml_name;
2316         gchar *new_id;
2317
2318         new_id = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(rw->window_name_entry)));
2319
2320         list = layout_window_menu_list(list);
2321         while (list)
2322                 {
2323                 auto ln = static_cast<WindowNames *>(list->data);
2324                 if (g_strcmp0(ln->name, new_id) == 0)
2325                         {
2326                         gchar *buf;
2327                         buf = g_strdup_printf(_("Window layout name \"%s\" already exists."), new_id);
2328                         warning_dialog(_("Rename window"), buf, GQ_ICON_DIALOG_WARNING, rw->gd->dialog);
2329                         g_free(buf);
2330                         window_layout_name_exists = TRUE;
2331                         break;
2332                         }
2333                 list = list->next;
2334                 }
2335
2336         if (!window_layout_name_exists)
2337                 {
2338                 xml_name = g_strdup_printf("%s.xml", rw->lw->options.id);
2339                 path = g_build_filename(get_window_layouts_dir(), xml_name, NULL);
2340
2341                 if (isfile(path))
2342                         {
2343                         unlink_file(path);
2344                         }
2345                 g_free(xml_name);
2346                 g_free(path);
2347
2348                 g_free(rw->lw->options.id);
2349                 rw->lw->options.id = g_strdup(new_id);
2350                 layout_menu_new_window_update(rw->lw);
2351                 layout_refresh(rw->lw);
2352                 image_update_title(rw->lw->image);
2353                 }
2354
2355         save_layout(rw->lw);
2356
2357         g_free(new_id);
2358         generic_dialog_close(rw->gd);
2359         g_free(rw);
2360 }
2361
2362 static void window_rename_ok_cb(GenericDialog *gd, gpointer data)
2363 {
2364         auto rw = static_cast<RenameWindow *>(data);
2365
2366         window_rename_ok(gd, rw);
2367 }
2368
2369 static void window_rename_entry_activate_cb(GenericDialog *gd, gpointer data)
2370 {
2371         auto rw = static_cast<RenameWindow *>(data);
2372
2373         window_rename_ok(gd, rw);
2374 }
2375
2376 static void window_delete_cancel_cb(GenericDialog *, gpointer data)
2377 {
2378         auto dw = static_cast<DeleteWindow *>(data);
2379
2380         g_free(dw);
2381 }
2382
2383 static void window_delete_ok_cb(GenericDialog *, gpointer data)
2384 {
2385         auto dw = static_cast<DeleteWindow *>(data);
2386         gchar *path;
2387         gchar *xml_name;
2388
2389         xml_name = g_strdup_printf("%s.xml", dw->lw->options.id);
2390         path = g_build_filename(get_window_layouts_dir(), xml_name, NULL);
2391
2392         layout_close(dw->lw);
2393         g_free(dw);
2394
2395         if (isfile(path))
2396                 {
2397                 unlink_file(path);
2398                 }
2399         g_free(xml_name);
2400         g_free(path);
2401 }
2402
2403 static void layout_menu_window_default_cb(GtkWidget *, gpointer)
2404 {
2405         layout_new_from_default();
2406 }
2407
2408 static void layout_menu_windows_menu_cb(GtkWidget *, gpointer data)
2409 {
2410         auto lw = static_cast<LayoutWindow *>(data);
2411         GtkWidget *menu;
2412         GtkWidget *sub_menu;
2413         gchar *menu_label;
2414         GList *children;
2415         GList *iter;
2416         gint i;
2417
2418         menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/WindowsMenu/" : "/MainMenu/WindowsMenu/");
2419
2420         sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2421
2422         /* disable Delete for temporary windows */
2423         if (g_str_has_prefix(lw->options.id, "lw"))
2424                 {
2425                 i = 0;
2426                 children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2427                 for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2428                         {
2429                         menu_label = g_strdup(gtk_menu_item_get_label(GTK_MENU_ITEM(iter->data)));
2430                         if (g_strcmp0(menu_label, _("Delete window")) == 0)
2431                                 {
2432                                 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), FALSE);
2433                                 }
2434                         g_free(menu_label);
2435                         }
2436                 g_list_free(children);
2437                 }
2438 }
2439
2440 static void layout_menu_view_menu_cb(GtkWidget *, gpointer data)
2441 {
2442         auto lw = static_cast<LayoutWindow *>(data);
2443         GtkWidget *menu;
2444         GtkWidget *sub_menu;
2445         gchar *menu_label;
2446         GList *children;
2447         GList *iter;
2448         gint i;
2449         FileData *fd;
2450
2451         menu = gtk_ui_manager_get_widget(lw->ui_manager, options->hamburger_menu ? "/MainMenu/OpenMenu/ViewMenu/" : "/MainMenu/ViewMenu/");
2452         sub_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu));
2453
2454         fd = layout_image_get_fd(lw);
2455
2456         i = 0;
2457         children = gtk_container_get_children(GTK_CONTAINER(sub_menu));
2458         for (iter = children; iter != nullptr; iter = g_list_next(iter), i++)
2459                 {
2460                 menu_label = g_strdup(gtk_menu_item_get_label(GTK_MENU_ITEM(iter->data)));
2461                 if (g_strcmp0(menu_label, _("Open archive")) == 0)
2462                         {
2463                         if (fd && fd->format_class == FORMAT_CLASS_ARCHIVE)
2464                                 {
2465                                 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), TRUE);
2466                                 }
2467                         else
2468                                 {
2469                                 gtk_widget_set_sensitive(GTK_WIDGET(iter->data), FALSE);
2470                                 }
2471                         }
2472                 g_free(menu_label);
2473                 }
2474         g_list_free(children);
2475 }
2476
2477 static void change_window_id(const gchar *infile, const gchar *outfile)
2478 {
2479         GFile *in_file;
2480         GFile *out_file;
2481         GFileInputStream *in_file_stream;
2482         GFileOutputStream *out_file_stream;
2483         GDataInputStream *in_data_stream;
2484         GDataOutputStream *out_data_stream;
2485         gchar *line;
2486         gchar *id_name;
2487
2488         id_name = layout_get_unique_id();
2489
2490         in_file = g_file_new_for_path(infile);
2491         in_file_stream = g_file_read(in_file, nullptr, nullptr);
2492         in_data_stream = g_data_input_stream_new(G_INPUT_STREAM(in_file_stream));
2493
2494         out_file = g_file_new_for_path(outfile);
2495         out_file_stream = g_file_append_to(out_file, G_FILE_CREATE_PRIVATE, nullptr, nullptr);
2496         out_data_stream = g_data_output_stream_new(G_OUTPUT_STREAM(out_file_stream));
2497
2498         while ((line = g_data_input_stream_read_line(in_data_stream, nullptr, nullptr, nullptr)))
2499                 {
2500                 if (g_str_has_suffix(line, "<layout"))
2501                         {
2502                         g_data_output_stream_put_string(out_data_stream, line, nullptr, nullptr);
2503                         g_data_output_stream_put_string(out_data_stream, "\n", nullptr, nullptr);
2504                         g_free(line);
2505
2506                         line = g_data_input_stream_read_line(in_data_stream, nullptr, nullptr, nullptr);
2507                         g_data_output_stream_put_string(out_data_stream, "id = \"", nullptr, nullptr);
2508                         g_data_output_stream_put_string(out_data_stream, id_name, nullptr, nullptr);
2509                         g_data_output_stream_put_string(out_data_stream, "\"\n", nullptr, nullptr);
2510                         }
2511                 else
2512                         {
2513                         g_data_output_stream_put_string(out_data_stream, line, nullptr, nullptr);
2514                         g_data_output_stream_put_string(out_data_stream, "\n", nullptr, nullptr);
2515                         }
2516                 g_free(line);
2517                 }
2518
2519         g_free(id_name);
2520         g_object_unref(out_data_stream);
2521         g_object_unref(in_data_stream);
2522         g_object_unref(out_file_stream);
2523         g_object_unref(in_file_stream);
2524         g_object_unref(out_file);
2525         g_object_unref(in_file);
2526 }
2527
2528 static void layout_menu_window_from_current_cb(GtkWidget *, gpointer data)
2529 {
2530         auto lw = static_cast<LayoutWindow *>(data);
2531         gint fd_in = -1;
2532         gint fd_out = -1;
2533         char * tmp_file_in;
2534         char * tmp_file_out;
2535         GError *error = nullptr;
2536
2537         fd_in = g_file_open_tmp("geeqie_layout_name_XXXXXX.xml", &tmp_file_in, &error);
2538         if (error)
2539                 {
2540                 log_printf("Error: Window layout - cannot create file:%s\n",error->message);
2541                 g_error_free(error);
2542                 return;
2543                 }
2544         close(fd_in);
2545         fd_out = g_file_open_tmp("geeqie_layout_name_XXXXXX.xml", &tmp_file_out, &error);
2546         if (error)
2547                 {
2548                 log_printf("Error: Window layout - cannot create file:%s\n",error->message);
2549                 g_error_free(error);
2550                 return;
2551                 }
2552         close(fd_out);
2553
2554         save_config_to_file(tmp_file_in, options, lw);
2555         change_window_id(tmp_file_in, tmp_file_out);
2556         load_config_from_file(tmp_file_out, FALSE);
2557
2558         unlink_file(tmp_file_in);
2559         unlink_file(tmp_file_out);
2560         g_free(tmp_file_in);
2561         g_free(tmp_file_out);
2562 }
2563
2564 static void layout_menu_window_cb(GtkWidget *, gpointer data)
2565 {
2566         auto lw = static_cast<LayoutWindow *>(data);
2567
2568         layout_menu_new_window_update(lw);
2569 }
2570
2571 static void layout_menu_window_rename_cb(GtkWidget *, gpointer data)
2572 {
2573         auto lw = static_cast<LayoutWindow *>(data);
2574         RenameWindow *rw;
2575         GtkWidget *hbox;
2576
2577         rw = g_new0(RenameWindow, 1);
2578         rw->lw = lw;
2579
2580         rw->gd = generic_dialog_new(_("Rename window"), "rename_window", nullptr, FALSE, window_rename_cancel_cb, rw);
2581         rw->button_ok = generic_dialog_add_button(rw->gd, GQ_ICON_OK, _("OK"), window_rename_ok_cb, TRUE);
2582
2583         generic_dialog_add_message(rw->gd, nullptr, _("rename window"), nullptr, FALSE);
2584
2585         hbox = pref_box_new(rw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
2586         pref_spacer(hbox, PREF_PAD_INDENT);
2587
2588         hbox = pref_box_new(rw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2589
2590         rw->window_name_entry = gtk_entry_new();
2591         gtk_widget_set_can_focus(rw->window_name_entry, TRUE);
2592         gtk_editable_set_editable(GTK_EDITABLE(rw->window_name_entry), TRUE);
2593         gq_gtk_entry_set_text(GTK_ENTRY(rw->window_name_entry), lw->options.id);
2594         gq_gtk_box_pack_start(GTK_BOX(hbox), rw->window_name_entry, TRUE, TRUE, 0);
2595         gtk_widget_grab_focus(GTK_WIDGET(rw->window_name_entry));
2596         gtk_widget_show(rw->window_name_entry);
2597         g_signal_connect(rw->window_name_entry, "activate", G_CALLBACK(window_rename_entry_activate_cb), rw);
2598
2599         gtk_widget_show(rw->gd->dialog);
2600 }
2601
2602 static void layout_menu_window_delete_cb(GtkWidget *, gpointer data)
2603 {
2604         auto lw = static_cast<LayoutWindow *>(data);
2605         DeleteWindow *dw;
2606         GtkWidget *hbox;
2607
2608         dw = g_new0(DeleteWindow, 1);
2609         dw->lw = lw;
2610
2611         dw->gd = generic_dialog_new(_("Delete window"), "delete_window", nullptr, TRUE, window_delete_cancel_cb, dw);
2612         dw->button_ok = generic_dialog_add_button(dw->gd, GQ_ICON_OK, _("OK"), window_delete_ok_cb, TRUE);
2613
2614         generic_dialog_add_message(dw->gd, nullptr, _("Delete window layout"), nullptr, FALSE);
2615
2616         hbox = pref_box_new(dw->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
2617         pref_spacer(hbox, PREF_PAD_INDENT);
2618         dw->group = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
2619
2620         hbox = pref_box_new(dw->group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2621         pref_label_new(hbox, (lw->options.id));
2622
2623         gtk_widget_show(dw->gd->dialog);
2624 }
2625
2626 /*
2627  *-----------------------------------------------------------------------------
2628  * menu
2629  *-----------------------------------------------------------------------------
2630  */
2631
2632 #define CB G_CALLBACK
2633 /**
2634  * tooltip is used as the description field in the Help manual shortcuts documentation
2635  *
2636  * struct GtkActionEntry:
2637  *  name, stock_id, label, accelerator, tooltip, callback
2638  */
2639 static GtkActionEntry menu_entries[] = {
2640   { "About",                 GQ_ICON_ABOUT,                     N_("_About"),                                           nullptr,               N_("About"),                                           CB(layout_menu_about_cb) },
2641   { "AlterNone",             PIXBUF_INLINE_ICON_ORIGINAL,       N_("_Original state"),                                  "<shift>O",            N_("Image rotate Original state"),                     CB(layout_menu_alter_none_cb) },
2642   { "Back",                  GQ_ICON_GO_PREV,                   N_("_Back"),                                            nullptr,               N_("Back in folder history"),                          CB(layout_menu_back_cb) },
2643   { "ClearMarks",            nullptr,                           N_("Clear Marks..."),                                   nullptr,               N_("Clear Marks"),                                     CB(layout_menu_clear_marks_cb) },
2644   { "CloseWindow",           GQ_ICON_CLOSE,                     N_("C_lose window"),                                    "<control>W",          N_("Close window"),                                    CB(layout_menu_close_cb) },
2645   { "ColorMenu",             nullptr,                           N_("_Color Management"),                                nullptr,               nullptr,                                               nullptr },
2646   { "ConnectZoom100Alt1",    GQ_ICON_ZOOM_100,                  N_("Zoom _1:1"),                                        "<shift>KP_Divide",    N_("Connected Zoom 1:1"),                              CB(layout_menu_connect_zoom_1_1_cb) },                 
2647   { "ConnectZoom100",        GQ_ICON_ZOOM_100,                  N_("Zoom _1:1"),                                        "<shift>Z",            N_("Connected Zoom 1:1"),                              CB(layout_menu_connect_zoom_1_1_cb) },
2648   { "ConnectZoom200",        nullptr,                           N_("Zoom _2:1"),                                        nullptr,               N_("Connected Zoom 2:1"),                              CB(layout_menu_connect_zoom_2_1_cb) },
2649   { "ConnectZoom25",         nullptr,                           N_("Zoom 1:4"),                                         nullptr,               N_("Connected Zoom 1:4"),                              CB(layout_menu_connect_zoom_1_4_cb) },
2650   { "ConnectZoom300",        nullptr,                           N_("Zoom _3:1"),                                        nullptr,               N_("Connected Zoom 3:1"),                              CB(layout_menu_connect_zoom_3_1_cb) },
2651   { "ConnectZoom33",         nullptr,                           N_("Zoom 1:3"),                                         nullptr,               N_("Connected Zoom 1:3"),                              CB(layout_menu_connect_zoom_1_3_cb) },
2652   { "ConnectZoom400",        nullptr,                           N_("Zoom _4:1"),                                        nullptr,               N_("Connected Zoom 4:1"),                              CB(layout_menu_connect_zoom_4_1_cb) },
2653   { "ConnectZoom50",         nullptr,                           N_("Zoom 1:2"),                                         nullptr,               N_("Connected Zoom 1:2"),                              CB(layout_menu_connect_zoom_1_2_cb) },
2654   { "ConnectZoomFillHor",    nullptr,                           N_("Fit _Horizontally"),                                "<shift>H",            N_("Connected Fit Horizontally"),                      CB(layout_menu_connect_zoom_fit_hor_cb) },             
2655   { "ConnectZoomFillVert",   nullptr,                           N_("Fit _Vertically"),                                  "<shift>W",            N_("Connected Fit Vertically"),                        CB(layout_menu_connect_zoom_fit_vert_cb) },            
2656   { "ConnectZoomFitAlt1",    GQ_ICON_ZOOM_FIT,                  N_("_Zoom to fit"),                                     "<shift>KP_Multiply",  N_("Connected Zoom to fit"),                           CB(layout_menu_connect_zoom_fit_cb) },                 
2657   { "ConnectZoomFit",        GQ_ICON_ZOOM_FIT,                  N_("_Zoom to fit"),                                     "<shift>X",            N_("Connected Zoom to fit"),                           CB(layout_menu_connect_zoom_fit_cb) },
2658   { "ConnectZoomInAlt1",     GQ_ICON_ZOOM_IN,                   N_("Zoom _in"),                                         "<shift>KP_Add",       N_("Connected Zoom in"),                               CB(layout_menu_connect_zoom_in_cb) },                  
2659   { "ConnectZoomIn",         GQ_ICON_ZOOM_IN,                   N_("Zoom _in"),                                         "plus",                N_("Connected Zoom in"),                               CB(layout_menu_connect_zoom_in_cb) },
2660   { "ConnectZoomMenu",       nullptr,                           N_("_Connected Zoom"),                                  nullptr,               nullptr,                                               nullptr },
2661   { "ConnectZoomOutAlt1",    GQ_ICON_ZOOM_OUT,                  N_("Zoom _out"),                                        "<shift>KP_Subtract",  N_("Connected Zoom out"),                              CB(layout_menu_connect_zoom_out_cb) },                 
2662   { "ConnectZoomOut",        GQ_ICON_ZOOM_OUT,                  N_("Zoom _out"),                                        "underscore",          N_("Connected Zoom out"),                              CB(layout_menu_connect_zoom_out_cb) },
2663   { "Copy",                  GQ_ICON_COPY,                      N_("_Copy..."),                                         "<control>C",          N_("Copy..."),                                         CB(layout_menu_copy_cb) },
2664   { "CopyPath",              nullptr,                           N_("_Copy path to clipboard"),                          nullptr,               N_("Copy path to clipboard"),                          CB(layout_menu_copy_path_cb) },
2665   { "CopyPathUnquoted",      nullptr,                           N_("_Copy path unquoted to clipboard"),                 nullptr,               N_("Copy path unquoted to clipboard"),                 CB(layout_menu_copy_path_unquoted_cb) },
2666   { "DeleteAlt1",            GQ_ICON_USER_TRASH,                N_("Move to Trash..."),                                 "Delete",              N_("Move to Trash..."),                                CB(layout_menu_move_to_trash_key_cb) },                
2667   { "DeleteAlt2",            GQ_ICON_USER_TRASH,                N_("Move to Trash..."),                                 "KP_Delete",           N_("Move to Trash..."),                                CB(layout_menu_move_to_trash_key_cb) },                
2668   { "Delete",                GQ_ICON_USER_TRASH,                N_("Move to Trash..."),                                 "<control>D",          N_("Move to Trash..."),                                CB(layout_menu_move_to_trash_cb) },
2669   { "DeleteWindow",          GQ_ICON_DELETE,                    N_("Delete window"),                                    nullptr,               N_("Delete window"),                                   CB(layout_menu_window_delete_cb) },
2670   { "DisableGrouping",       nullptr,                           N_("Disable file groupi_ng"),                           nullptr,               N_("Disable file grouping"),                           CB(layout_menu_disable_grouping_cb) },
2671   { "EditMenu",              nullptr,                           N_("_Edit"),                                            nullptr,               nullptr,                                               nullptr },
2672   { "EnableGrouping",        nullptr,                           N_("Enable file _grouping"),                            nullptr,               N_("Enable file grouping"),                            CB(layout_menu_enable_grouping_cb) },
2673   { "EscapeAlt1",            GQ_ICON_LEAVE_FULLSCREEN,          N_("_Leave full screen"),                               "Q",                   N_("Leave full screen"),                               CB(layout_menu_escape_cb) },                           
2674   { "Escape",                GQ_ICON_LEAVE_FULLSCREEN,          N_("_Leave full screen"),                              "Escape",               N_("Leave full screen"),                               CB(layout_menu_escape_cb) },                           
2675   { "ExifWin",               PIXBUF_INLINE_ICON_EXIF,           N_("_Exif window"),                                     "<control>E",          N_("Exif window"),                                     CB(layout_menu_bar_exif_cb) },
2676   { "FileDirMenu",           nullptr,                           N_("_Files and Folders"),                               nullptr,               nullptr,                                               nullptr },
2677   { "FileMenu",              nullptr,                           N_("_File"),                                            nullptr,               nullptr,                                               nullptr },
2678   { "FindDupes",             GQ_ICON_FIND,                      N_("_Find duplicates..."),                              "D",                   N_("Find duplicates..."),                              CB(layout_menu_dupes_cb) },
2679   { "FirstImage",            GQ_ICON_GO_TOP,                    N_("_First Image"),                                     "Home",                N_("First Image"),                                     CB(layout_menu_image_first_cb) },
2680   { "FirstPage",             GQ_ICON_PREV_PAGE,                 N_("_First Page"),                                      nullptr,               N_( "First Page of multi-page image"),                 CB(layout_menu_page_first_cb) },                       
2681   { "Flip",                  GQ_ICON_FLIP_VERTICAL,             N_("_Flip"),                                            "<shift>F",            N_("Image Flip"),                                      CB(layout_menu_alter_flip_cb) },
2682   { "Forward",               GQ_ICON_GO_NEXT,                   N_("_Forward"),                                         nullptr,               N_("Forward in folder history"),                       CB(layout_menu_forward_cb) },
2683   { "FullScreenAlt1",        GQ_ICON_FULLSCREEN,                N_("F_ull screen"),                                     "V",                   N_("Full screen"),                                     CB(layout_menu_fullscreen_cb) },
2684   { "FullScreenAlt2",        GQ_ICON_FULLSCREEN,                N_("F_ull screen"),                                     "F11",                 N_("Full screen"),                                     CB(layout_menu_fullscreen_cb) },
2685   { "FullScreen",            GQ_ICON_FULLSCREEN,                N_("F_ull screen"),                                     "F",                   N_("Full screen"),                                     CB(layout_menu_fullscreen_cb) },
2686   { "GoMenu",                nullptr,                           N_("_Go"),                                              nullptr,               nullptr,                                               nullptr },
2687   { "HelpChangeLog",         nullptr,                           N_("_ChangeLog"),                                       nullptr,               N_("ChangeLog notes"),                                 CB(layout_menu_changelog_cb) },
2688   { "HelpContents",          GQ_ICON_HELP,                      N_("_Help manual"),                                     "F1",                  N_("Help manual"),                                     CB(layout_menu_help_cb) },
2689   { "HelpKbd",               nullptr,                           N_("_Keyboard map"),                                    nullptr,               N_("Keyboard map"),                                    CB(layout_menu_kbd_map_cb) },
2690   { "HelpMenu",              nullptr,                           N_("_Help"),                                            nullptr,               nullptr,                                               nullptr },
2691   { "HelpNotes",             nullptr,                           N_("_Readme"),                                          nullptr,               N_("Readme"),                                          CB(layout_menu_notes_cb) },
2692   { "HelpSearch",            nullptr,                           N_("On-line help search"),                              nullptr,               N_("On-line help search"),                             CB(layout_menu_help_search_cb) },
2693   { "HelpShortcuts",         nullptr,                           N_("_Keyboard shortcuts"),                              nullptr,               N_("Keyboard shortcuts"),                              CB(layout_menu_help_keys_cb) },
2694   { "HideTools",             PIXBUF_INLINE_ICON_HIDETOOLS,      N_("_Hide file list"),                                  "<control>H",          N_("Hide file list"),                                  CB(layout_menu_hide_cb) },
2695   { "HistogramChanCycle",    nullptr,                           N_("Cycle through histogram ch_annels"),                "K",                   N_("Cycle through histogram channels"),                CB(layout_menu_histogram_toggle_channel_cb) },                                                         
2696   { "HistogramModeCycle",    nullptr,                           N_("Cycle through histogram mo_des"),                   "J",                   N_("Cycle through histogram modes"),                   CB(layout_menu_histogram_toggle_mode_cb) },            
2697   { "Home",                  GQ_ICON_HOME,                      N_("_Home"),                                            nullptr,               N_("Home"),                                            CB(layout_menu_home_cb) },
2698   { "ImageBack",             GQ_ICON_GO_FIRST,                  N_("Image Back"),                                       nullptr,               N_("Back in image history"),                           CB(layout_menu_image_back_cb) },
2699   { "ImageForward",          GQ_ICON_GO_LAST,                   N_("Image Forward"),                                    nullptr,               N_("Forward in image history"),                        CB(layout_menu_image_forward_cb) },
2700   { "ImageOverlayCycle",     nullptr,                           N_("_Cycle through overlay modes"),                     "I",                   N_("Cycle through Overlay modes"),                     CB(layout_menu_overlay_toggle_cb) },                   
2701   { "KeywordAutocomplete",   nullptr,                           N_("Keyword autocomplete"),                             "<alt>K",              N_("Keyword Autocomplete"),                            CB(layout_menu_keyword_autocomplete_cb) },
2702   { "LastImage",             GQ_ICON_GO_BOTTOM,                 N_("_Last Image"),                                      "End",                 N_("Last Image"),                                      CB(layout_menu_image_last_cb) },
2703   { "LastPage",              GQ_ICON_NEXT_PAGE,                 N_("_Last Page"),                                       nullptr,               N_("Last Page of multi-page image"),                   CB(layout_menu_page_last_cb) },
2704   { "LayoutConfig",          GQ_ICON_PREFERENCES,               N_("_Configure this window..."),                        nullptr,               N_("Configure this window..."),                        CB(layout_menu_layout_config_cb) },
2705   { "LogWindow",             nullptr,                           N_("_Log Window"),                                      nullptr,               N_("Log Window"),                                      CB(layout_menu_log_window_cb) },
2706   { "Maintenance",           PIXBUF_INLINE_ICON_MAINTENANCE,    N_("_Cache maintenance..."),                            nullptr,               N_("Cache maintenance..."),                            CB(layout_menu_remove_thumb_cb) },
2707   { "Mirror",                GQ_ICON_FLIP_HORIZONTAL,           N_("_Mirror"),                                          "<shift>M",            N_("Image Mirror"),                                    CB(layout_menu_alter_mirror_cb) },
2708   { "Move",                  PIXBUF_INLINE_ICON_MOVE,           N_("_Move..."),                                         "<control>M",          N_("Move..."),                                         CB(layout_menu_move_cb) },
2709   { "NewCollection",         GQ_ICON_COLLECTION,                N_("_New collection"),                                  "C",                   N_("New collection"),                                  CB(layout_menu_new_cb) },
2710   { "NewFolder",             GQ_ICON_DIRECTORY,                 N_("N_ew folder..."),                                   "<control>F",          N_("New folder..."),                                   CB(layout_menu_dir_cb) },
2711   { "NewWindowDefault",      nullptr,                           N_("default"),                                          "<control>N",          N_("New window (default)"),                            CB(layout_menu_window_default_cb)  },
2712   { "NewWindowFromCurrent",  nullptr,                           N_("from current"),                                     nullptr,               N_("from current"),                                    CB(layout_menu_window_from_current_cb)  },
2713   { "NewWindow",             nullptr,                           N_("New window"),                                       nullptr,               N_("New window"),                                      CB(layout_menu_window_cb) },
2714   { "NextImageAlt1",         GQ_ICON_GO_DOWN,                   N_("_Next Image"),                                      "Page_Down",           N_("Next Image"),                                      CB(layout_menu_image_next_cb) },
2715   { "NextImageAlt2",         GQ_ICON_GO_DOWN,                   N_("_Next Image"),                                      "KP_Page_Down",        N_("Next Image"),                                      CB(layout_menu_image_next_cb) },
2716   { "NextImage",             GQ_ICON_GO_DOWN,                   N_("_Next Image"),                                      "space",               N_("Next Image"),                                      CB(layout_menu_image_next_cb) },
2717   { "NextPage",              GQ_ICON_FORWARD_PAGE,              N_("_Next Page"),                                       nullptr,               N_("Next Page of multi-page image"),                   CB(layout_menu_page_next_cb) },
2718   { "OpenArchive",           GQ_ICON_OPEN,                      N_("Open archive"),                                     nullptr,               N_("Open archive"),                                    CB(layout_menu_open_archive_cb) },
2719   { "OpenCollection",        GQ_ICON_OPEN,                      N_("_Open collection..."),                              "O",                   N_("Open collection..."),                              nullptr },
2720   { "OpenMenu",              nullptr,                           N_("☰"),                                                nullptr,               nullptr,                                               nullptr },
2721   { "OpenRecent",            nullptr,                           N_("Open recen_t"),                                     nullptr,               N_("Open recent collection"),                          nullptr },
2722   { "OpenWith",              GQ_ICON_OPEN_WITH,                 N_("Open With..."),                                     nullptr,               N_("Open With..."),                                    CB(layout_menu_open_with_cb) },
2723   { "OrientationMenu",       nullptr,                           N_("_Orientation"),                                     nullptr,               nullptr,                                               nullptr },
2724   { "OverlayMenu",           nullptr,                           N_("Image _Overlay"),                                   nullptr,               nullptr,                                               nullptr },
2725   { "PanView",               PIXBUF_INLINE_ICON_PANORAMA,       N_("Pa_n view"),                                        "<control>J",          N_("Pan view"),                                        CB(layout_menu_pan_cb) },
2726   { "PermanentDelete",       GQ_ICON_DELETE,                    N_("Delete..."),                                        "<shift>Delete",       N_("Delete..."),                                       CB(layout_menu_delete_cb) },                           
2727   { "Plugins",               GQ_ICON_PREFERENCES,               N_("Configure _Plugins..."),                            nullptr,               N_("Configure Plugins..."),                            CB(layout_menu_editors_cb) },
2728   { "PluginsMenu",           nullptr,                           N_("_Plugins"),                                         nullptr,               nullptr,                                               nullptr },
2729   { "Preferences",           GQ_ICON_PREFERENCES,               N_("P_references..."),                                  "<control>O",          N_("Preferences..."),                                  CB(layout_menu_config_cb) },
2730   { "PreferencesMenu",       nullptr,                           N_("P_references"),                                     nullptr,               nullptr,                                               nullptr },
2731   { "PrevImageAlt1",         GQ_ICON_GO_UP,                     N_("_Previous Image"),                                  "Page_Up",             N_("Previous Image"),                                  CB(layout_menu_image_prev_cb) },
2732   { "PrevImageAlt2",         GQ_ICON_GO_UP,                     N_("_Previous Image"),                                  "KP_Page_Up",          N_("Previous Image"),                                  CB(layout_menu_image_prev_cb) },
2733   { "PrevImage",             GQ_ICON_GO_UP,                     N_("_Previous Image"),                                  "BackSpace",           N_("Previous Image"),                                  CB(layout_menu_image_prev_cb) },
2734   { "PrevPage",              GQ_ICON_BACK_PAGE,                 N_("_Previous Page"),                                   nullptr,               N_("Previous Page of multi-page image"),               CB(layout_menu_page_previous_cb) },
2735   { "Print",                 GQ_ICON_PRINT,                     N_("_Print..."),                                        "<shift>P",            N_("Print..."),                                        CB(layout_menu_print_cb) },
2736   { "Quit",                  GQ_ICON_QUIT,                      N_("_Quit"),                                            "<control>Q",          N_("Quit"),                                            CB(layout_menu_exit_cb) },
2737   { "Rating0",               nullptr,                           N_("_Rating 0"),                                        "<alt>KP_0",           N_("Rating 0"),                                        CB(layout_menu_rating_0_cb) },
2738   { "Rating1",               nullptr,                           N_("_Rating 1"),                                        "<alt>KP_1",           N_("Rating 1"),                                        CB(layout_menu_rating_1_cb) },
2739   { "Rating2",               nullptr,                           N_("_Rating 2"),                                        "<alt>KP_2",           N_("Rating 2"),                                        CB(layout_menu_rating_2_cb) },
2740   { "Rating3",               nullptr,                           N_("_Rating 3"),                                        "<alt>KP_3",           N_("Rating 3"),                                        CB(layout_menu_rating_3_cb) },
2741   { "Rating4",               nullptr,                           N_("_Rating 4"),                                        "<alt>KP_4",           N_("Rating 4"),                                        CB(layout_menu_rating_4_cb) },
2742   { "Rating5",               nullptr,                           N_("_Rating 5"),                                        "<alt>KP_5",           N_("Rating 5"),                                        CB(layout_menu_rating_5_cb) },
2743   { "RatingM1",              nullptr,                           N_("_Rating -1"),                                       "<alt>KP_Subtract",    N_("Rating -1"),                                       CB(layout_menu_rating_m1_cb) },
2744   { "RatingMenu",            nullptr,                           N_("_Rating"),                                          nullptr,               nullptr,                                               nullptr },
2745   { "Refresh",               GQ_ICON_REFRESH,                   N_("_Refresh"),                                         "R",                   N_("Refresh"),                                         CB(layout_menu_refresh_cb) },
2746   { "Rename",                PIXBUF_INLINE_ICON_RENAME,         N_("_Rename..."),                                       "<control>R",          N_("Rename..."),                                       CB(layout_menu_rename_cb) },
2747   { "RenameWindow",          GQ_ICON_EDIT,                      N_("Rename window"),                                    nullptr,               N_("Rename window"),                                   CB(layout_menu_window_rename_cb) },
2748   { "Rotate180",             PIXBUF_INLINE_ICON_180,            N_("Rotate 1_80°"),                                     "<shift>R",            N_("Image Rotate 180°"),                               CB(layout_menu_alter_180_cb) },
2749   { "RotateCCW",             GQ_ICON_ROTATE_LEFT,               N_("Rotate _counterclockwise 90°"),                     "bracketleft",         N_("Rotate counterclockwise 90°"),                     CB(layout_menu_alter_90cc_cb) },
2750   { "RotateCW",              GQ_ICON_ROTATE_RIGHT,              N_("_Rotate clockwise 90°"),                            "bracketright",        N_("Image Rotate clockwise 90°"),                      CB(layout_menu_alter_90_cb) },
2751   { "SaveMetadata",          GQ_ICON_SAVE,                      N_("_Save metadata"),                                   "<control>S",          N_("Save metadata"),                                   CB(layout_menu_metadata_write_cb) },
2752   { "SearchAndRunCommand",   GQ_ICON_FIND,                      N_("Search and Run command"),                           "slash",               N_("Search commands by keyword and run them"),         CB(layout_menu_search_and_run_cb) },
2753   { "Search",                GQ_ICON_FIND,                      N_("_Search..."),                                       "F3",                  N_("Search..."),                                       CB(layout_menu_search_cb) },
2754   { "SelectAll",             PIXBUF_INLINE_ICON_SELECT_ALL,     N_("Select _all"),                                      "<control>A",          N_("Select all"),                                      CB(layout_menu_select_all_cb) },
2755   { "SelectInvert",          PIXBUF_INLINE_ICON_SELECT_INVERT,  N_("_Invert Selection"),                                "<control><shift>I",   N_("Invert Selection"),                                CB(layout_menu_invert_selection_cb) },
2756   { "SelectMenu",            nullptr,                           N_("_Select"),                                          nullptr,               nullptr,                                               nullptr },
2757   { "SelectNone",            PIXBUF_INLINE_ICON_SELECT_NONE,    N_("Select _none"),                                     "<control><shift>A",   N_("Select none"),                                     CB(layout_menu_unselect_all_cb) },
2758   { "SlideShowFaster",       GQ_ICON_GENERIC,                   N_("Faster"),                                           "<control>equal",      N_("Slideshow Faster"),                                CB(layout_menu_slideshow_faster_cb) },
2759   { "SlideShowPause",        GQ_ICON_PAUSE,                     N_("_Pause slideshow"),                                 "P",                   N_("Pause slideshow"),                                 CB(layout_menu_slideshow_pause_cb) },
2760   { "SlideShowSlower",       GQ_ICON_GENERIC,                   N_("Slower"),                                           "<control>minus",      N_("Slideshow Slower"),                                CB(layout_menu_slideshow_slower_cb) },
2761   { "SplitDownPane",         nullptr,                           N_("_Down Pane"),                                       "<alt>Down",           N_("Down Split Pane"),                                 CB(layout_menu_split_pane_updown_cb) },
2762   { "SplitMenu",             nullptr,                           N_("Spli_t"),                                           nullptr,               nullptr,                                               nullptr },
2763   { "SplitNextPane",         nullptr,                           N_("_Next Pane"),                                       "<alt>Right",          N_("Next Split Pane"),                                 CB(layout_menu_split_pane_next_cb) },
2764   { "SplitPreviousPane",     nullptr,                           N_("_Previous Pane"),                                   "<alt>Left",           N_("Previous Split Pane"),                             CB(layout_menu_split_pane_prev_cb) },
2765   { "SplitUpPane",           nullptr,                           N_("_Up Pane"),                                         "<alt>Up",             N_("Up Split Pane"),                                   CB(layout_menu_split_pane_updown_cb) },
2766   { "StereoCycle",           nullptr,                           N_("_Cycle through stereo modes"),                      nullptr,               N_("Cycle through stereo modes"),                      CB(layout_menu_stereo_mode_next_cb) },
2767   { "StereoMenu",            nullptr,                           N_("Stere_o"),                                          nullptr,               nullptr,                                               nullptr },
2768   { "Up",                    GQ_ICON_GO_UP,                     N_("_Up"),                                              nullptr,               N_("Up one folder"),                                   CB(layout_menu_up_cb) },
2769   { "ViewInNewWindow",       nullptr,                           N_("_View in new window"),                              "<control>V",          N_("View in new window"),                              CB(layout_menu_view_in_new_window_cb) },
2770   { "ViewMenu",              nullptr,                           N_("_View"),                                            nullptr,               nullptr,                                               CB(layout_menu_view_menu_cb)  },
2771   { "Wallpaper",             nullptr,                           N_("Set as _wallpaper"),                                nullptr,               N_("Set as wallpaper"),                                CB(layout_menu_wallpaper_cb) },
2772   { "WindowsMenu",           nullptr,                           N_("_Windows"),                                         nullptr,               nullptr,                                               CB(layout_menu_windows_menu_cb)  },
2773   { "WriteRotationKeepDate", nullptr,                           N_("_Write orientation to file (preserve timestamp)"),  nullptr,               N_("Write orientation to file (preserve timestamp)"),  CB(layout_menu_write_rotate_keep_date_cb) },
2774   { "WriteRotation",         nullptr,                           N_("_Write orientation to file"),                       nullptr,               N_("Write orientation to file"),                       CB(layout_menu_write_rotate_cb) },
2775   { "Zoom100Alt1",           GQ_ICON_ZOOM_100,                  N_("Zoom _1:1"),                                        "KP_Divide",           N_("Zoom 1:1"),                                        CB(layout_menu_zoom_1_1_cb) },
2776   { "Zoom100",               GQ_ICON_ZOOM_100,                  N_("Zoom _1:1"),                                        "Z",                   N_("Zoom 1:1"),                                        CB(layout_menu_zoom_1_1_cb) },
2777   { "Zoom200",               GQ_ICON_GENERIC,                   N_("Zoom _2:1"),                                        nullptr,               N_("Zoom 2:1"),                                        CB(layout_menu_zoom_2_1_cb) },
2778   { "Zoom25",                GQ_ICON_GENERIC,                   N_("Zoom 1:4"),                                         nullptr,               N_("Zoom 1:4"),                                        CB(layout_menu_zoom_1_4_cb) },
2779   { "Zoom300",               GQ_ICON_GENERIC,                   N_("Zoom _3:1"),                                        nullptr,               N_("Zoom 3:1"),                                        CB(layout_menu_zoom_3_1_cb) },
2780   { "Zoom33",                GQ_ICON_GENERIC,                   N_("Zoom 1:3"),                                         nullptr,               N_("Zoom 1:3"),                                        CB(layout_menu_zoom_1_3_cb) },
2781   { "Zoom400",               GQ_ICON_GENERIC,                   N_("Zoom _4:1"),                                        nullptr,               N_("Zoom 4:1"),                                        CB(layout_menu_zoom_4_1_cb) },
2782   { "Zoom50",                GQ_ICON_GENERIC,                   N_("Zoom 1:2"),                                         nullptr,               N_("Zoom 1:2"),                                        CB(layout_menu_zoom_1_2_cb) },
2783   { "ZoomFillHor",           PIXBUF_INLINE_ICON_ZOOMFILLHOR,    N_("Fit _Horizontally"),                                "H",                   N_("Fit Horizontally"),                                CB(layout_menu_zoom_fit_hor_cb) },
2784   { "ZoomFillVert",          PIXBUF_INLINE_ICON_ZOOMFILLVERT,   N_("Fit _Vertically"),                                  "W",                   N_("Fit Vertically"),                                  CB(layout_menu_zoom_fit_vert_cb) },
2785   { "ZoomFitAlt1",           GQ_ICON_ZOOM_FIT,                  N_("_Zoom to fit"),                                     "KP_Multiply",         N_("Zoom to fit"),                                     CB(layout_menu_zoom_fit_cb) },
2786   { "ZoomFit",               GQ_ICON_ZOOM_FIT,                  N_("_Zoom to fit"),                                     "X",                   N_("Zoom to fit"),                                     CB(layout_menu_zoom_fit_cb) },
2787   { "ZoomInAlt1",            GQ_ICON_ZOOM_IN,                   N_("Zoom _in"),                                         "KP_Add",              N_("Zoom in"),                                         CB(layout_menu_zoom_in_cb) },
2788   { "ZoomIn",                GQ_ICON_ZOOM_IN,                   N_("Zoom _in"),                                         "equal",               N_("Zoom in"),                                         CB(layout_menu_zoom_in_cb) },
2789   { "ZoomMenu",              nullptr,                           N_("_Zoom"),                                            nullptr,               nullptr,                                               nullptr },
2790   { "ZoomOutAlt1",           GQ_ICON_ZOOM_OUT,                  N_("Zoom _out"),                                        "KP_Subtract",         N_("Zoom out"),                                        CB(layout_menu_zoom_out_cb) },
2791   { "ZoomOut",               GQ_ICON_ZOOM_OUT,                  N_("Zoom _out"),                                        "minus",               N_("Zoom out"),                                        CB(layout_menu_zoom_out_cb) }
2792 };
2793
2794 static GtkToggleActionEntry menu_toggle_entries[] = {
2795   { "Animate",                 nullptr,                              N_("_Animation"),               "A",               N_("Toggle animation"),              CB(layout_menu_animate_cb),                  FALSE  },
2796   { "DrawRectangle",           PIXBUF_INLINE_ICON_DRAW_RECTANGLE,    N_("Draw Rectangle"),           nullptr,           N_("Draw Rectangle"),                CB(layout_menu_select_rectangle_cb),         FALSE  },
2797   { "ExifRotate",              GQ_ICON_ROTATE_LEFT,                  N_("_Exif rotate"),             "<alt>X",          N_("Toggle Exif rotate"),            CB(layout_menu_exif_rotate_cb),              FALSE  },
2798   { "FloatTools",              PIXBUF_INLINE_ICON_FLOAT,             N_("_Float file list"),         "L",               N_("Float file list"),               CB(layout_menu_float_cb),                    FALSE  },
2799   { "Grayscale",               PIXBUF_INLINE_ICON_GRAYSCALE,         N_("Toggle _grayscale"),        "<shift>G",        N_("Toggle grayscale"),              CB(layout_menu_alter_desaturate_cb),         FALSE  },
2800   { "HideBars",                nullptr,                              N_("Hide Bars and Files"),      "grave",           N_("Hide Bars and Files"),           CB(layout_menu_hide_bars_cb),                FALSE  },
2801   { "HideSelectableToolbars",  nullptr,                              N_("Hide Selectable Bars"),     "<control>grave",  N_("Hide Selectable Bars"),          CB(layout_menu_selectable_toolbars_cb),      FALSE  },
2802   { "IgnoreAlpha",             GQ_ICON_STRIKETHROUGH,                N_("Hide _alpha"),              "<shift>A",        N_("Hide alpha channel"),            CB(layout_menu_alter_ignore_alpha_cb),       FALSE  },
2803   { "ImageHistogram",          nullptr,                              N_("_Show Histogram"),          nullptr,           N_("Show Histogram"),                CB(layout_menu_histogram_cb),                FALSE  },
2804   { "ImageOverlay",            nullptr,                              N_("Image _Overlay"),           nullptr,           N_("Image Overlay"),                 CB(layout_menu_overlay_cb),                  FALSE  },
2805   { "OverUnderExposed",        PIXBUF_INLINE_ICON_EXPOSURE,          N_("Over/Under Exposed"),       "<shift>E",        N_("Highlight over/under exposed"),  CB(layout_menu_select_overunderexposed_cb),  FALSE  },
2806   { "RectangularSelection",    PIXBUF_INLINE_ICON_SELECT_RECTANGLE,  N_("Rectangular Selection"),    "<alt>R",          N_("Rectangular Selection"),         CB(layout_menu_rectangular_selection_cb),    FALSE  },
2807   { "SBar",                    PIXBUF_INLINE_ICON_PROPERTIES,        N_("_Info sidebar"),            "<control>K",      N_("Info sidebar"),                  CB(layout_menu_bar_cb),                      FALSE  },
2808   { "SBarSort",                PIXBUF_INLINE_ICON_SORT,              N_("Sort _manager"),            "<shift>S",        N_("Sort manager"),                  CB(layout_menu_bar_sort_cb),                 FALSE  },
2809   { "ShowFileFilter",          GQ_ICON_FILE_FILTER,                  N_("Show File Filter"),         nullptr,           N_("Show File Filter"),              CB(layout_menu_file_filter_cb),              FALSE  },
2810   { "ShowInfoPixel",           GQ_ICON_SELECT_COLOR,                 N_("Pi_xel Info"),              nullptr,           N_("Show Pixel Info"),               CB(layout_menu_info_pixel_cb),               FALSE  },
2811   { "ShowMarks",               PIXBUF_INLINE_ICON_MARKS,             N_("Show _Marks"),              "M",               N_("Show Marks"),                    CB(layout_menu_marks_cb),                    FALSE  },
2812   { "SlideShow",               GQ_ICON_PLAY,                         N_("Toggle _slideshow"),        "S",               N_("Toggle slideshow"),              CB(layout_menu_slideshow_cb),                FALSE  },
2813   { "SplitPaneSync",           PIXBUF_INLINE_SPLIT_PANE_SYNC,        N_("Split Pane Sync"),          nullptr,           N_("Split Pane Sync"),               CB(layout_menu_split_pane_sync_cb),          FALSE  },
2814   { "Thumbnails",              PIXBUF_INLINE_ICON_THUMB,             N_("Show _Thumbnails"),         "T",               N_("Show Thumbnails"),               CB(layout_menu_thumb_cb),                    FALSE  },
2815   { "UseColorProfiles",        GQ_ICON_COLOR_MANAGEMENT,             N_("Use _color profiles"),      nullptr,           N_("Use color profiles"),            CB(layout_color_menu_enable_cb),             FALSE  },
2816   { "UseImageProfile",         nullptr,                              N_("Use profile from _image"),  nullptr,           N_("Use profile from image"),        CB(layout_color_menu_use_image_cb),          FALSE  }
2817 };
2818
2819 static GtkRadioActionEntry menu_radio_entries[] = {
2820   { "ViewIcons",  nullptr,  N_("Images as I_cons"),  "<control>I",  N_("View Images as Icons"),  FILEVIEW_ICON },
2821   { "ViewList",   nullptr,  N_("Images as _List"),   "<control>L",  N_("View Images as List"),   FILEVIEW_LIST }
2822 };
2823
2824 static GtkToggleActionEntry menu_view_dir_toggle_entries[] = {
2825   { "FolderTree",  nullptr,  N_("T_oggle Folder View"),  "<control>T",  N_("Toggle Folders View"),  CB(layout_menu_view_dir_as_cb),FALSE },
2826 };
2827
2828 static GtkRadioActionEntry menu_split_radio_entries[] = {
2829   { "SplitHorizontal",  nullptr,  N_("_Horizontal"),  "E",      N_("Split panes horizontal."),  SPLIT_HOR },
2830   { "SplitQuad",        nullptr,  N_("_Quad"),        nullptr,  N_("Split panes quad"),         SPLIT_QUAD },
2831   { "SplitSingle",      nullptr,  N_("_Single"),      "Y",      N_("Single pane"),              SPLIT_NONE },
2832   { "SplitTriple",      nullptr,  N_("_Triple"),      nullptr,  N_("Split panes triple"),       SPLIT_TRIPLE },
2833   { "SplitVertical",    nullptr,  N_("_Vertical"),    "U",      N_("Split panes vertical"),     SPLIT_VERT }
2834 };
2835
2836 static GtkRadioActionEntry menu_color_radio_entries[] = {
2837   { "ColorProfile0",  nullptr,  N_("Input _0: sRGB"),                 nullptr,  N_("Input 0: sRGB"),                 COLOR_PROFILE_SRGB },
2838   { "ColorProfile1",  nullptr,  N_("Input _1: AdobeRGB compatible"),  nullptr,  N_("Input 1: AdobeRGB compatible"),  COLOR_PROFILE_ADOBERGB },
2839   { "ColorProfile2",  nullptr,  N_("Input _2"),                       nullptr,  N_("Input 2"),                       COLOR_PROFILE_FILE },
2840   { "ColorProfile3",  nullptr,  N_("Input _3"),                       nullptr,  N_("Input 3"),                       COLOR_PROFILE_FILE + 1 },
2841   { "ColorProfile4",  nullptr,  N_("Input _4"),                       nullptr,  N_("Input 4"),                       COLOR_PROFILE_FILE + 2 },
2842   { "ColorProfile5",  nullptr,  N_("Input _5"),                       nullptr,  N_("Input 5"),                       COLOR_PROFILE_FILE + 3 }
2843 };
2844
2845 static GtkRadioActionEntry menu_histogram_channel[] = {
2846   { "HistogramChanB",    nullptr,  N_("Histogram on _Blue"),   nullptr,  N_("Histogram on Blue"),   HCHAN_B },
2847   { "HistogramChanG",    nullptr,  N_("Histogram on _Green"),  nullptr,  N_("Histogram on Green"),  HCHAN_G },
2848   { "HistogramChanRGB",  nullptr,  N_("_Histogram on RGB"),    nullptr,  N_("Histogram on RGB"),    HCHAN_RGB },
2849   { "HistogramChanR",    nullptr,  N_("Histogram on _Red"),    nullptr,  N_("Histogram on Red"),    HCHAN_R },
2850   { "HistogramChanV",    nullptr,  N_("Histogram on _Value"),  nullptr,  N_("Histogram on Value"),  HCHAN_MAX }
2851 };
2852
2853 static GtkRadioActionEntry menu_histogram_mode[] = {
2854   { "HistogramModeLin",  nullptr,  N_("Li_near Histogram"),  nullptr,  N_("Linear Histogram"),  0 },
2855   { "HistogramModeLog",  nullptr,  N_("_Log Histogram"),     nullptr,  N_("Log Histogram"),     1 },
2856 };
2857
2858 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
2859   { "StereoAuto",   nullptr,  N_("_Auto"),          nullptr,  N_("Stereo Auto"),          STEREO_PIXBUF_DEFAULT },
2860   { "StereoCross",  nullptr,  N_("_Cross"),         nullptr,  N_("Stereo Cross"),         STEREO_PIXBUF_CROSS },
2861   { "StereoOff",    nullptr,  N_("_Off"),           nullptr,  N_("Stereo Off"),           STEREO_PIXBUF_NONE },
2862   { "StereoSBS",    nullptr,  N_("_Side by Side"),  nullptr,  N_("Stereo Side by Side"),  STEREO_PIXBUF_SBS }
2863 };
2864 #undef CB
2865
2866 static gchar *menu_translate(const gchar *path, gpointer)
2867 {
2868         return static_cast<gchar *>(_(path));
2869 }
2870
2871 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, const gchar *name_tmpl,
2872                                       const gchar *label_tmpl, const gchar *accel_tmpl, const gchar *tooltip_tmpl, GCallback cb)
2873 {
2874         gchar name[50];
2875         gchar label[100];
2876         gchar accel[50];
2877         gchar tooltip[100];
2878         GtkActionEntry entry = { name, nullptr, label, accel, tooltip, cb };
2879         GtkAction *action;
2880
2881         g_snprintf(name, sizeof(name), name_tmpl, mark);
2882         g_snprintf(label, sizeof(label), label_tmpl, mark);
2883
2884         if (accel_tmpl)
2885                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
2886         else
2887                 entry.accelerator = nullptr;
2888
2889         if (tooltip_tmpl)
2890                 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
2891         else
2892                 entry.tooltip = nullptr;
2893
2894         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
2895         action = gtk_action_group_get_action(lw->action_group, name);
2896         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark > 0 ? mark : 10));
2897 }
2898
2899 static void layout_actions_setup_marks(LayoutWindow *lw)
2900 {
2901         gint mark;
2902         GError *error;
2903         GString *desc = g_string_new(
2904                                 "<ui>"
2905                                 "  <menubar name='MainMenu'>");
2906
2907         if (options->hamburger_menu)
2908                 {
2909                 g_string_append(desc, "    <menu action='OpenMenu'>");
2910                 }
2911         g_string_append(desc, "      <menu action='SelectMenu'>");
2912
2913         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
2914                 {
2915                 gint i = (mark < 10 ? mark : 0);
2916
2917                 layout_actions_setup_mark(lw, i, "Mark%d",              _("Mark _%d"), nullptr, nullptr, nullptr);
2918                 layout_actions_setup_mark(lw, i, "SetMark%d",   _("_Set mark %d"),                      nullptr,                _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
2919                 layout_actions_setup_mark(lw, i, "ResetMark%d", _("_Reset mark %d"),                    nullptr,                _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
2920                 layout_actions_setup_mark(lw, i, "ToggleMark%d",        _("_Toggle mark %d"),                   "%d",           _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2921                 layout_actions_setup_mark(lw, i, "ToggleMark%dAlt1",    _("_Toggle mark %d"),                   "KP_%d",        _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
2922                 layout_actions_setup_mark(lw, i, "SelectMark%d",        _("Se_lect mark %d"),                   "<control>%d",  _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2923                 layout_actions_setup_mark(lw, i, "SelectMark%dAlt1",    _("_Select mark %d"),                   "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
2924                 layout_actions_setup_mark(lw, i, "AddMark%d",   _("_Add mark %d"),                      nullptr,                _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
2925                 layout_actions_setup_mark(lw, i, "IntMark%d",   _("_Intersection with mark %d"),        nullptr,                _("Intersection with mark %d"), G_CALLBACK(layout_menu_sel_mark_and_cb));
2926                 layout_actions_setup_mark(lw, i, "UnselMark%d", _("_Unselect mark %d"),                 nullptr,                _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
2927                 layout_actions_setup_mark(lw, i, "FilterMark%d",        _("_Filter mark %d"),                   nullptr,                _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
2928
2929                 g_string_append_printf(desc,
2930                                 "      <menu action='Mark%d'>"
2931                                 "        <menuitem action='ToggleMark%d'/>"
2932                                 "        <menuitem action='SetMark%d'/>"
2933                                 "        <menuitem action='ResetMark%d'/>"
2934                                 "        <separator/>"
2935                                 "        <menuitem action='SelectMark%d'/>"
2936                                 "        <menuitem action='AddMark%d'/>"
2937                                 "        <menuitem action='IntMark%d'/>"
2938                                 "        <menuitem action='UnselMark%d'/>"
2939                                 "        <separator/>"
2940                                 "        <menuitem action='FilterMark%d'/>"
2941                                 "      </menu>",
2942                                 i, i, i, i, i, i, i, i, i);
2943                 }
2944
2945         g_string_append(desc,
2946                                 "      </menu>");
2947         if (options->hamburger_menu)
2948                 {
2949                 g_string_append(desc, "    </menu>");
2950                 }
2951         g_string_append(desc, "  </menubar>");
2952
2953         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
2954                 {
2955                 gint i = (mark < 10 ? mark : 0);
2956
2957                 g_string_append_printf(desc,
2958                                 "<accelerator action='ToggleMark%dAlt1'/>"
2959                                 "<accelerator action='SelectMark%dAlt1'/>",
2960                                 i, i);
2961                 }
2962         g_string_append(desc,   "</ui>" );
2963
2964         error = nullptr;
2965         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
2966                 {
2967                 g_message("building menus failed: %s", error->message);
2968                 g_error_free(error);
2969                 exit(EXIT_FAILURE);
2970                 }
2971         g_string_free(desc, TRUE);
2972 }
2973
2974 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
2975 {
2976         gchar **split = g_strsplit(editor->menu_path, "/", 0);
2977         gint i = 0;
2978         GList *ret = nullptr;
2979
2980         if (split[0] == nullptr)
2981                 {
2982                 g_strfreev(split);
2983                 return nullptr;
2984                 }
2985
2986         while (split[i])
2987                 {
2988                 ret = g_list_prepend(ret, g_strdup(split[i]));
2989                 i++;
2990                 }
2991
2992         g_strfreev(split);
2993
2994         ret = g_list_prepend(ret, g_strdup(editor->key));
2995
2996         return g_list_reverse(ret);
2997 }
2998
2999 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
3000 {
3001         gint to_open;
3002         gint to_close;
3003         gint i;
3004         while (path && old_path && strcmp(static_cast<gchar *>(path->data), static_cast<gchar *>(old_path->data)) == 0)
3005                 {
3006                 path = path->next;
3007                 old_path = old_path->next;
3008                 }
3009         to_open = g_list_length(path) - 1;
3010         to_close = g_list_length(old_path) - 1;
3011
3012         if (to_close > 0)
3013                 {
3014                 old_path = g_list_last(old_path);
3015                 old_path = old_path->prev;
3016                 }
3017
3018         for (i =  0; i < to_close; i++)
3019                 {
3020                 auto name = static_cast<gchar *>(old_path->data);
3021                 if (g_str_has_suffix(name, "Section"))
3022                         {
3023                         g_string_append(desc,   "      </placeholder>");
3024                         }
3025                 else if (g_str_has_suffix(name, "Menu"))
3026                         {
3027                         g_string_append(desc,   "    </menu>");
3028                         }
3029                 else
3030                         {
3031                         g_warning("invalid menu path item %s", name);
3032                         }
3033                 old_path = old_path->prev;
3034                 }
3035
3036         for (i =  0; i < to_open; i++)
3037                 {
3038                 auto name = static_cast<gchar *>(path->data);
3039                 if (g_str_has_suffix(name, "Section"))
3040                         {
3041                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
3042                         }
3043                 else if (g_str_has_suffix(name, "Menu"))
3044                         {
3045                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
3046                         }
3047                 else
3048                         {
3049                         g_warning("invalid menu path item %s", name);
3050                         }
3051                 path = path->next;
3052                 }
3053
3054         if (path)
3055                 g_string_append_printf(desc, "      <menuitem action='%s'/>", static_cast<gchar *>(path->data));
3056 }
3057
3058 static void layout_actions_setup_editors(LayoutWindow *lw)
3059 {
3060         GError *error;
3061         GList *editors_list;
3062         GList *work;
3063         GList *old_path;
3064         GString *desc;
3065
3066         if (lw->ui_editors_id)
3067                 {
3068                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
3069                 }
3070
3071         if (lw->action_group_editors)
3072                 {
3073                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
3074                 g_object_unref(lw->action_group_editors);
3075                 }
3076         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
3077         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
3078
3079         /* lw->action_group_editors contains translated entries, no translate func is required */
3080         desc = g_string_new(
3081                                 "<ui>"
3082                                 "  <menubar name='MainMenu'>");
3083
3084         if (options->hamburger_menu)
3085                 {
3086                 g_string_append(desc, "    <menu action='OpenMenu'>");
3087                 }
3088
3089         editors_list = editor_list_get();
3090
3091         old_path = nullptr;
3092         work = editors_list;
3093         while (work)
3094                 {
3095                 GList *path;
3096                 auto editor = static_cast<EditorDescription *>(work->data);
3097                 GtkActionEntry entry = { editor->key,
3098                                          nullptr,
3099                                          editor->name,
3100                                          editor->hotkey,
3101                                          editor->comment ? editor->comment : editor->name,
3102                                          G_CALLBACK(layout_menu_edit_cb) };
3103
3104                 if (editor->icon)
3105                         {
3106                         entry.stock_id = editor->key;
3107                         }
3108                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
3109
3110                 path = layout_actions_editor_menu_path(editor);
3111                 layout_actions_editor_add(desc, path, old_path);
3112
3113                 g_list_free_full(old_path, g_free);
3114                 old_path = path;
3115                 work = work->next;
3116                 }
3117
3118         layout_actions_editor_add(desc, nullptr, old_path);
3119         g_list_free_full(old_path, g_free);
3120
3121         if (options->hamburger_menu)
3122                 {
3123                 g_string_append(desc, "</menu>");
3124                 }
3125
3126         g_string_append(desc,"  </menubar>"
3127                                 "</ui>" );
3128
3129         error = nullptr;
3130
3131         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
3132         if (!lw->ui_editors_id)
3133                 {
3134                 g_message("building menus failed: %s", error->message);
3135                 g_error_free(error);
3136                 exit(EXIT_FAILURE);
3137                 }
3138         g_string_free(desc, TRUE);
3139         g_list_free(editors_list);
3140 }
3141
3142 void create_toolbars(LayoutWindow *lw)
3143 {
3144         gint i;
3145
3146         for (i = 0; i < TOOLBAR_COUNT; i++)
3147                 {
3148                 layout_actions_toolbar(lw, static_cast<ToolbarType>(i));
3149                 layout_toolbar_clear(lw, static_cast<ToolbarType>(i));
3150                 layout_toolbar_add_default(lw, static_cast<ToolbarType>(i));
3151                 }
3152 }
3153
3154 void layout_actions_setup(LayoutWindow *lw)
3155 {
3156         GError *error;
3157
3158         DEBUG_1("%s layout_actions_setup: start", get_exec_time());
3159         if (lw->ui_manager) return;
3160
3161         lw->action_group = gtk_action_group_new("MenuActions");
3162         gtk_action_group_set_translate_func(lw->action_group, menu_translate, nullptr, nullptr);
3163
3164         gtk_action_group_add_actions(lw->action_group,
3165                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
3166         gtk_action_group_add_toggle_actions(lw->action_group,
3167                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
3168         gtk_action_group_add_radio_actions(lw->action_group,
3169                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
3170                                            0, G_CALLBACK(layout_menu_list_cb), lw);
3171         gtk_action_group_add_radio_actions(lw->action_group,
3172                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
3173                                            0, G_CALLBACK(layout_menu_split_cb), lw);
3174         gtk_action_group_add_toggle_actions(lw->action_group,
3175                                            menu_view_dir_toggle_entries, G_N_ELEMENTS(menu_view_dir_toggle_entries),
3176                                             lw);
3177         gtk_action_group_add_radio_actions(lw->action_group,
3178                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
3179                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
3180         gtk_action_group_add_radio_actions(lw->action_group,
3181                                            menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
3182                                            0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
3183         gtk_action_group_add_radio_actions(lw->action_group,
3184                                            menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
3185                                            0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
3186         gtk_action_group_add_radio_actions(lw->action_group,
3187                                            menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
3188                                            0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
3189
3190
3191         lw->ui_manager = gtk_ui_manager_new();
3192         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
3193         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
3194
3195         DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
3196         error = nullptr;
3197
3198         if (!gtk_ui_manager_add_ui_from_resource(lw->ui_manager, options->hamburger_menu ? GQ_RESOURCE_PATH_UI "/menu-hamburger.ui" : GQ_RESOURCE_PATH_UI "/menu-classic.ui" , &error))
3199                 {
3200                 g_message("building menus failed: %s", error->message);
3201                 g_error_free(error);
3202                 exit(EXIT_FAILURE);
3203                 }
3204
3205         DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
3206         layout_actions_setup_marks(lw);
3207
3208         DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
3209         layout_actions_setup_editors(lw);
3210
3211         DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
3212         layout_util_status_update_write(lw);
3213
3214         DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
3215         layout_actions_add_window(lw, lw->window);
3216         DEBUG_1("%s layout_actions_setup: end", get_exec_time());
3217 }
3218
3219 static gint layout_editors_reload_idle_id = -1;
3220 static GList *layout_editors_desktop_files = nullptr;
3221
3222 static gboolean layout_editors_reload_idle_cb(gpointer)
3223 {
3224         if (!layout_editors_desktop_files)
3225                 {
3226                 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
3227                 layout_editors_desktop_files = editor_get_desktop_files();
3228                 return G_SOURCE_CONTINUE;
3229                 }
3230
3231         editor_read_desktop_file(static_cast<const gchar *>(layout_editors_desktop_files->data));
3232         g_free(layout_editors_desktop_files->data);
3233         layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
3234
3235
3236         if (!layout_editors_desktop_files)
3237                 {
3238                 GList *work;
3239                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
3240                 editor_table_finish();
3241
3242                 work = layout_window_list;
3243                 while (work)
3244                         {
3245                         auto lw = static_cast<LayoutWindow *>(work->data);
3246                         work = work->next;
3247                         layout_actions_setup_editors(lw);
3248                         if (lw->bar_sort_enabled)
3249                                 {
3250                                 layout_bar_sort_toggle(lw);
3251                                 }
3252                         }
3253
3254                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
3255
3256                 layout_editors_reload_idle_id = -1;
3257                 return G_SOURCE_REMOVE;
3258                 }
3259         return G_SOURCE_CONTINUE;
3260 }
3261
3262 void layout_editors_reload_start()
3263 {
3264         DEBUG_1("%s layout_editors_reload_start", get_exec_time());
3265
3266         if (layout_editors_reload_idle_id != -1)
3267                 {
3268                 g_source_remove(layout_editors_reload_idle_id);
3269                 g_list_free_full(layout_editors_desktop_files, g_free);
3270                 }
3271
3272         editor_table_clear();
3273         layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, nullptr);
3274 }
3275
3276 void layout_editors_reload_finish()
3277 {
3278         if (layout_editors_reload_idle_id != -1)
3279                 {
3280                 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
3281                 g_source_remove(layout_editors_reload_idle_id);
3282                 while (layout_editors_reload_idle_id != -1)
3283                         {
3284                         layout_editors_reload_idle_cb(nullptr);
3285                         }
3286                 }
3287 }
3288
3289 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
3290 {
3291         GtkAccelGroup *group;
3292
3293         if (!lw->ui_manager) return;
3294
3295         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
3296         gtk_window_add_accel_group(GTK_WINDOW(window), group);
3297 }
3298
3299 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
3300 {
3301         if (lw->menu_bar) return lw->menu_bar;
3302         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
3303         g_object_ref(lw->menu_bar);
3304         return lw->menu_bar;
3305 }
3306
3307 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
3308 {
3309         if (lw->toolbar[type]) return lw->toolbar[type];
3310
3311         lw->toolbar[type] = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3312
3313         gtk_widget_show(lw->toolbar[type]);
3314         g_object_ref(lw->toolbar[type]);
3315         return lw->toolbar[type];
3316 }
3317
3318 GtkWidget *layout_actions_menu_tool_bar(LayoutWindow *lw)
3319 {
3320         GtkWidget *menu_bar;
3321         GtkWidget *toolbar;
3322
3323         if (lw->menu_tool_bar) return lw->menu_tool_bar;
3324
3325         toolbar = layout_actions_toolbar(lw, TOOLBAR_MAIN);
3326         DEBUG_NAME(toolbar);
3327         lw->menu_tool_bar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
3328
3329         if (!options->hamburger_menu)
3330                 {
3331                 menu_bar = layout_actions_menu_bar(lw);
3332                 DEBUG_NAME(menu_bar);
3333                 gq_gtk_box_pack_start(GTK_BOX(lw->menu_tool_bar), menu_bar, FALSE, FALSE, 0);
3334                 }
3335
3336         gq_gtk_box_pack_start(GTK_BOX(lw->menu_tool_bar), toolbar, FALSE, FALSE, 0);
3337
3338         g_object_ref(lw->menu_tool_bar);
3339         return lw->menu_tool_bar;
3340 }
3341
3342 void toolbar_clear_cb(GtkWidget *widget, gpointer)
3343 {
3344         GtkAction *action;
3345
3346         if (GTK_IS_BUTTON(widget))
3347                 {
3348                 action = static_cast<GtkAction *>(g_object_get_data(G_OBJECT(widget), "action"));
3349                 if (g_object_get_data(G_OBJECT(widget), "id") )
3350                         {
3351                         g_signal_handler_disconnect(action, GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), "id")));
3352                         }
3353                 }
3354         gtk_widget_destroy(widget);
3355 }
3356
3357 void layout_toolbar_clear(LayoutWindow *lw, ToolbarType type)
3358 {
3359         if (lw->toolbar_merge_id[type])
3360                 {
3361                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id[type]);
3362                 gtk_ui_manager_ensure_update(lw->ui_manager);
3363                 }
3364         g_list_free_full(lw->toolbar_actions[type], g_free);
3365         lw->toolbar_actions[type] = nullptr;
3366
3367         lw->toolbar_merge_id[type] = gtk_ui_manager_new_merge_id(lw->ui_manager);
3368
3369         if (lw->toolbar[type])
3370                 {
3371                 gtk_container_foreach(GTK_CONTAINER(lw->toolbar[type]), (GtkCallback)G_CALLBACK(toolbar_clear_cb), nullptr);
3372                 }
3373 }
3374
3375 void action_radio_changed_cb(GtkAction *action, GtkAction *current, gpointer data)
3376 {
3377         auto button = static_cast<GtkToggleButton *>(data);
3378
3379         if (action == current )
3380                 {
3381                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
3382                 }
3383         else
3384                 {
3385                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
3386                 }
3387 }
3388
3389 void action_toggle_activate_cb(GtkAction* self, gpointer data)
3390 {
3391         auto button = static_cast<GtkToggleButton *>(data);
3392
3393         if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(self)) != gtk_toggle_button_get_active(button))
3394                 {
3395                 gtk_toggle_button_set_active(button, gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(self)));
3396                 }
3397 }
3398
3399 gboolean toolbar_button_press_event_cb(GtkWidget *, GdkEvent *, gpointer data)
3400 {
3401         gtk_action_activate(GTK_ACTION(data));
3402
3403         return TRUE;
3404 }
3405
3406 void layout_toolbar_add(LayoutWindow *lw, ToolbarType type, const gchar *action_name)
3407 {
3408         const gchar *path = nullptr;
3409         const gchar *tooltip_text = nullptr;
3410         GtkAction *action;
3411         GtkWidget *action_icon = nullptr;
3412         GtkWidget *button;
3413         gulong id;
3414
3415         if (!action_name || !lw->ui_manager) return;
3416
3417         if (!lw->toolbar[type])
3418                 {
3419                 return;
3420                 }
3421
3422         switch (type)
3423                 {
3424                 case TOOLBAR_MAIN:
3425                         path = "/ToolBar";
3426                         break;
3427                 case TOOLBAR_STATUS:
3428                         path = "/StatusBar";
3429                         break;
3430                 default:
3431                         break;
3432                 }
3433
3434         if (g_str_has_suffix(action_name, ".desktop"))
3435                 {
3436                 /* this may be called before the external editors are read
3437                    create a dummy action for now */
3438                 if (!lw->action_group_editors)
3439                         {
3440                         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
3441                         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
3442                         }
3443                 if (!gtk_action_group_get_action(lw->action_group_editors, action_name))
3444                         {
3445                         GtkActionEntry entry = { action_name,
3446                                                  GQ_ICON_MISSING_IMAGE,
3447                                                  action_name,
3448                                                  nullptr,
3449                                                  nullptr,
3450                                                  nullptr
3451                                                };
3452                         DEBUG_1("Creating temporary action %s", action_name);
3453                         gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
3454                         }
3455                 }
3456
3457         if (g_strcmp0(action_name, "Separator") == 0)
3458                 {
3459                 button = gtk_separator_new(GTK_ORIENTATION_VERTICAL);
3460                 }
3461         else
3462                 {
3463                 action = gtk_action_group_get_action(lw->action_group, action_name);
3464
3465                 action_icon = gtk_action_create_icon(action, GTK_ICON_SIZE_SMALL_TOOLBAR);
3466                 tooltip_text = gtk_action_get_tooltip(action);
3467
3468                 gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action_name, action_name, GTK_UI_MANAGER_TOOLITEM, FALSE);
3469
3470                 if (GTK_IS_RADIO_ACTION(action) || GTK_IS_TOGGLE_ACTION(action))
3471                         {
3472                         button = gtk_toggle_button_new();
3473                         }
3474                 else
3475                         {
3476                         button = gtk_button_new();
3477                         }
3478
3479                 if (GTK_IS_TOGGLE_ACTION(action) || GTK_IS_RADIO_ACTION(action))
3480                         {
3481                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)));
3482                         }
3483
3484                 if (action_icon)
3485                         {
3486                         gtk_button_set_image(GTK_BUTTON(button), action_icon);
3487                         }
3488                 else
3489                         {
3490                         gtk_button_set_label(GTK_BUTTON(button), action_name);
3491                         }
3492
3493                 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
3494                 gtk_widget_set_tooltip_text(button, tooltip_text);
3495
3496                 if (GTK_IS_RADIO_ACTION(action))
3497                         {
3498                         id = g_signal_connect(G_OBJECT(action), "changed", G_CALLBACK(action_radio_changed_cb), button);
3499                         g_object_set_data(G_OBJECT(button), "id", GUINT_TO_POINTER(id));
3500                         }
3501                 else if (GTK_IS_TOGGLE_ACTION(action))
3502                         {
3503                         id = g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(action_toggle_activate_cb), button);
3504                         g_object_set_data(G_OBJECT(button), "id", GUINT_TO_POINTER(id));
3505                         }
3506
3507                 g_signal_connect(G_OBJECT(button), "button_press_event", G_CALLBACK(toolbar_button_press_event_cb), action);
3508                 g_object_set_data(G_OBJECT(button), "action", action);
3509                 }
3510
3511         gq_gtk_container_add(GTK_WIDGET(lw->toolbar[type]), GTK_WIDGET(button));
3512         gtk_widget_show(GTK_WIDGET(button));
3513
3514         lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action_name));
3515 }
3516
3517 void layout_toolbar_add_default(LayoutWindow *lw, ToolbarType type)
3518 {
3519         LayoutWindow *lw_first;
3520         GList *work_action;
3521
3522         switch (type)
3523                 {
3524                 case TOOLBAR_MAIN:
3525                         if (layout_window_list)
3526                                 {
3527                                 lw_first = static_cast<LayoutWindow *>(layout_window_list->data);
3528                                 if (lw_first->toolbar_actions[TOOLBAR_MAIN])
3529                                         {
3530                                         work_action = lw_first->toolbar_actions[type];
3531                                         while (work_action)
3532                                                 {
3533                                                 auto action = static_cast<gchar *>(work_action->data);
3534                                                 work_action = work_action->next;
3535                                                 layout_toolbar_add(lw, type, action);
3536                                                 }
3537                                         }
3538                                 else
3539                                         {
3540                                         layout_toolbar_add(lw, type, "Thumbnails");
3541                                         layout_toolbar_add(lw, type, "Back");
3542                                         layout_toolbar_add(lw, type, "Forward");
3543                                         layout_toolbar_add(lw, type, "Up");
3544                                         layout_toolbar_add(lw, type, "Home");
3545                                         layout_toolbar_add(lw, type, "Refresh");
3546                                         layout_toolbar_add(lw, type, "ZoomIn");
3547                                         layout_toolbar_add(lw, type, "ZoomOut");
3548                                         layout_toolbar_add(lw, type, "ZoomFit");
3549                                         layout_toolbar_add(lw, type, "Zoom100");
3550                                         layout_toolbar_add(lw, type, "Preferences");
3551                                         layout_toolbar_add(lw, type, "FloatTools");
3552                                         }
3553                                 }
3554                         else
3555                                 {
3556                                 layout_toolbar_add(lw, type, "Thumbnails");
3557                                 layout_toolbar_add(lw, type, "Back");
3558                                 layout_toolbar_add(lw, type, "Forward");
3559                                 layout_toolbar_add(lw, type, "Up");
3560                                 layout_toolbar_add(lw, type, "Home");
3561                                 layout_toolbar_add(lw, type, "Refresh");
3562                                 layout_toolbar_add(lw, type, "ZoomIn");
3563                                 layout_toolbar_add(lw, type, "ZoomOut");
3564                                 layout_toolbar_add(lw, type, "ZoomFit");
3565                                 layout_toolbar_add(lw, type, "Zoom100");
3566                                 layout_toolbar_add(lw, type, "Preferences");
3567                                 layout_toolbar_add(lw, type, "FloatTools");
3568                                 }
3569                         break;
3570                 case TOOLBAR_STATUS:
3571                         if (layout_window_list)
3572                                 {
3573                                 lw_first = static_cast<LayoutWindow *>(layout_window_list->data);
3574                                 if (lw_first->toolbar_actions[TOOLBAR_MAIN])
3575                                         {
3576                                         work_action = lw_first->toolbar_actions[type];
3577                                         while (work_action)
3578                                                 {
3579                                                 auto action = static_cast<gchar *>(work_action->data);
3580                                                 work_action = work_action->next;
3581                                                 layout_toolbar_add(lw, type, action);
3582                                                 }
3583                                         }
3584                                 else
3585                                         {
3586                                         layout_toolbar_add(lw, type, "ExifRotate");
3587                                         layout_toolbar_add(lw, type, "ShowInfoPixel");
3588                                         layout_toolbar_add(lw, type, "UseColorProfiles");
3589                                         layout_toolbar_add(lw, type, "SaveMetadata");
3590                                         }
3591                                 }
3592                         else
3593                                 {
3594                                 layout_toolbar_add(lw, type, "ExifRotate");
3595                                 layout_toolbar_add(lw, type, "ShowInfoPixel");
3596                                 layout_toolbar_add(lw, type, "UseColorProfiles");
3597                                 layout_toolbar_add(lw, type, "SaveMetadata");
3598                                 }
3599                         break;
3600                 default:
3601                         break;
3602                 }
3603 }
3604
3605
3606
3607 void layout_toolbar_write_config(LayoutWindow *lw, ToolbarType type, GString *outstr, gint indent)
3608 {
3609         const gchar *name = nullptr;
3610         GList *work = lw->toolbar_actions[type];
3611
3612         switch (type)
3613                 {
3614                 case TOOLBAR_MAIN:
3615                         name = "toolbar";
3616                         break;
3617                 case TOOLBAR_STATUS:
3618                         name = "statusbar";
3619                         break;
3620                 default:
3621                         break;
3622                 }
3623
3624         WRITE_NL(); WRITE_STRING("<%s>", name);
3625         indent++;
3626         WRITE_NL(); WRITE_STRING("<clear/>");
3627         while (work)
3628                 {
3629                 auto action = static_cast<gchar *>(work->data);
3630                 work = work->next;
3631                 WRITE_NL(); WRITE_STRING("<toolitem ");
3632                 write_char_option(outstr, indent + 1, "action", action);
3633                 WRITE_STRING("/>");
3634                 }
3635         indent--;
3636         WRITE_NL(); WRITE_STRING("</%s>", name);
3637 }
3638
3639 void layout_toolbar_add_from_config(LayoutWindow *lw, ToolbarType type, const char **attribute_names, const gchar **attribute_values)
3640 {
3641         gchar *action = nullptr;
3642
3643         while (*attribute_names)
3644                 {
3645                 const gchar *option = *attribute_names++;
3646                 const gchar *value = *attribute_values++;
3647
3648                 if (READ_CHAR_FULL("action", action)) continue;
3649
3650                 log_printf("unknown attribute %s = %s\n", option, value);
3651                 }
3652
3653         layout_toolbar_add(lw, type, action);
3654         g_free(action);
3655 }
3656
3657 /*
3658  *-----------------------------------------------------------------------------
3659  * misc
3660  *-----------------------------------------------------------------------------
3661  */
3662
3663 void layout_util_status_update_write(LayoutWindow *lw)
3664 {
3665         GtkAction *action;
3666         gint n = metadata_queue_length();
3667         action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
3668         gtk_action_set_sensitive(action, n > 0);
3669         if (n > 0)
3670                 {
3671                 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
3672                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
3673                 g_free(buf);
3674                 }
3675         else
3676                 {
3677                 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
3678                 }
3679 }
3680
3681 void layout_util_status_update_write_all()
3682 {
3683         GList *work;
3684
3685         work = layout_window_list;
3686         while (work)
3687                 {
3688                 auto lw = static_cast<LayoutWindow *>(work->data);
3689                 work = work->next;
3690
3691                 layout_util_status_update_write(lw);
3692                 }
3693 }
3694
3695 static gchar *layout_color_name_parse(const gchar *name)
3696 {
3697         if (!name || !*name) return g_strdup(_("Empty"));
3698         return g_strdelimit(g_strdup(name), "_", '-');
3699 }
3700
3701 void layout_util_sync_color(LayoutWindow *lw)
3702 {
3703         GtkAction *action;
3704         gint input = 0;
3705         gboolean use_color;
3706         gboolean use_image = FALSE;
3707         gint i;
3708         gchar action_name[15];
3709 #if HAVE_LCMS
3710         gchar *image_profile;
3711         gchar *screen_profile;
3712 #endif
3713
3714         if (!lw->action_group) return;
3715         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
3716
3717         use_color = layout_image_color_profile_get_use(lw);
3718
3719         action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
3720 #if HAVE_LCMS
3721         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
3722         if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
3723                 {
3724                 gchar *buf;
3725                 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
3726                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
3727                 g_free(image_profile);
3728                 g_free(screen_profile);
3729                 g_free(buf);
3730                 }
3731         else
3732                 {
3733                 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
3734                 }
3735 #else
3736         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
3737         gtk_action_set_sensitive(action, FALSE);
3738         g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
3739 #endif
3740
3741         action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
3742         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
3743         gtk_action_set_sensitive(action, use_color);
3744
3745         for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
3746                 {
3747                 sprintf(action_name, "ColorProfile%d", i);
3748                 action = gtk_action_group_get_action(lw->action_group, action_name);
3749
3750                 if (i >= COLOR_PROFILE_FILE)
3751                         {
3752                         const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
3753                         const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
3754                         gchar *end;
3755                         gchar *buf;
3756
3757                         if (!name || !name[0]) name = filename_from_path(file);
3758
3759                         end = layout_color_name_parse(name);
3760                         buf = g_strdup_printf(_("Input _%d: %s"), i, end);
3761                         g_free(end);
3762
3763                         g_object_set(G_OBJECT(action), "label", buf, NULL);
3764                         g_free(buf);
3765
3766                         gtk_action_set_visible(action, file && file[0]);
3767                         }
3768
3769                 gtk_action_set_sensitive(action, !use_image);
3770                 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
3771                 }
3772
3773         action = gtk_action_group_get_action(lw->action_group, "Grayscale");
3774         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
3775 }
3776
3777 void layout_util_sync_file_filter(LayoutWindow *lw)
3778 {
3779         GtkAction *action;
3780
3781         if (!lw->action_group) return;
3782
3783         action = gtk_action_group_get_action(lw->action_group, "ShowFileFilter");
3784         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_file_filter);
3785 }
3786
3787 void layout_util_sync_marks(LayoutWindow *lw)
3788 {
3789         GtkAction *action;
3790
3791         if (!lw->action_group) return;
3792
3793         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
3794         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
3795 }
3796
3797 static void layout_util_sync_views(LayoutWindow *lw)
3798 {
3799         GtkAction *action;
3800         OsdShowFlags osd_flags = image_osd_get(lw->image);
3801
3802         if (!lw->action_group) return;
3803
3804         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
3805         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.dir_view_type);
3806
3807         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
3808         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
3809
3810         action = gtk_action_group_get_action(lw->action_group, "SplitNextPane");
3811         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3812         action = gtk_action_group_get_action(lw->action_group, "SplitPreviousPane");
3813         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3814         action = gtk_action_group_get_action(lw->action_group, "SplitUpPane");
3815         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3816         action = gtk_action_group_get_action(lw->action_group, "SplitDownPane");
3817         gtk_action_set_sensitive(action, !(lw->split_mode == SPLIT_NONE));
3818
3819         action = gtk_action_group_get_action(lw->action_group, "SplitPaneSync");
3820         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.split_pane_sync);
3821
3822         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
3823         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
3824
3825         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
3826         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
3827
3828         action = gtk_action_group_get_action(lw->action_group, "SBar");
3829         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
3830
3831         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
3832         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
3833
3834         action = gtk_action_group_get_action(lw->action_group, "HideSelectableToolbars");
3835         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.selectable_toolbars_hidden);
3836
3837         action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
3838         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
3839
3840         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
3841         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
3842
3843         action = gtk_action_group_get_action(lw->action_group, "IgnoreAlpha");
3844         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.ignore_alpha);
3845
3846         action = gtk_action_group_get_action(lw->action_group, "Animate");
3847         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
3848
3849         action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
3850         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
3851
3852         action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
3853         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
3854
3855         action = gtk_action_group_get_action(lw->action_group, "ExifRotate");
3856         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->image.exif_rotate_enable);
3857
3858         action = gtk_action_group_get_action(lw->action_group, "OverUnderExposed");
3859         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->overunderexposed);
3860
3861         action = gtk_action_group_get_action(lw->action_group, "DrawRectangle");
3862         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->draw_rectangle);
3863
3864         action = gtk_action_group_get_action(lw->action_group, "RectangularSelection");
3865         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->collections.rectangular_selection);
3866
3867         action = gtk_action_group_get_action(lw->action_group, "ShowFileFilter");
3868         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_file_filter);
3869
3870         action = gtk_action_group_get_action(lw->action_group, "HideBars");
3871         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (lw->options.bars_state.hidden));
3872
3873         if (osd_flags & OSD_SHOW_HISTOGRAM)
3874                 {
3875                 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
3876                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
3877
3878                 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
3879                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
3880                 }
3881
3882         action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
3883         gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
3884
3885         action = gtk_action_group_get_action(lw->action_group, "WriteRotation");
3886         gtk_action_set_sensitive(action, !(runcmd("which exiftran >/dev/null 2>&1") ||
3887                                                         runcmd("which mogrify >/dev/null 2>&1") || options->metadata.write_orientation));
3888         action = gtk_action_group_get_action(lw->action_group, "WriteRotationKeepDate");
3889         gtk_action_set_sensitive(action, !(runcmd("which exiftran >/dev/null 2>&1") ||
3890                                                         runcmd("which mogrify >/dev/null 2>&1") || options->metadata.write_orientation));
3891
3892         action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
3893         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
3894
3895         layout_util_sync_marks(lw);
3896         layout_util_sync_color(lw);
3897         layout_image_set_ignore_alpha(lw, lw->options.ignore_alpha);
3898 }
3899
3900 void layout_util_sync_thumb(LayoutWindow *lw)
3901 {
3902         GtkAction *action;
3903
3904         if (!lw->action_group) return;
3905
3906         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
3907         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
3908         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
3909 }
3910
3911 void layout_util_sync(LayoutWindow *lw)
3912 {
3913         layout_util_sync_views(lw);
3914         layout_util_sync_thumb(lw);
3915         layout_menu_collection_recent_update(lw);
3916         layout_menu_collection_open_update(lw);
3917 }
3918
3919 /**
3920  * @brief Checks if event key is mapped to Help
3921  * @param event
3922  * @returns
3923  *
3924  * Used to check if the user has re-mapped the Help key
3925  * in Preferences/Keyboard
3926  *
3927  * Note: help_key.accel_mods and event->state
3928  * differ in the higher bits
3929  */
3930 gboolean is_help_key(GdkEventKey *event)
3931 {
3932         GtkAccelKey help_key;
3933         gboolean ret = FALSE;
3934         guint mask = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK;
3935
3936         if (gtk_accel_map_lookup_entry("<Actions>/MenuActions/HelpContents", &help_key))
3937                 {
3938                 if (help_key.accel_key == event->keyval &&
3939                                         (help_key.accel_mods & mask) == (event->state & mask))
3940                         {
3941                         ret = TRUE;
3942                         }
3943                 }
3944
3945         return ret;
3946 }
3947
3948 /*
3949  *-----------------------------------------------------------------------------
3950  * sidebars
3951  *-----------------------------------------------------------------------------
3952  */
3953
3954 static gboolean layout_bar_enabled(LayoutWindow *lw)
3955 {
3956         return lw->bar && gtk_widget_get_visible(lw->bar);
3957 }
3958
3959 static void layout_bar_destroyed(GtkWidget *, gpointer data)
3960 {
3961         auto lw = static_cast<LayoutWindow *>(data);
3962
3963         lw->bar = nullptr;
3964 /*
3965     do not call layout_util_sync_views(lw) here
3966     this is called either when whole layout is destroyed - no need for update
3967     or when the bar is replaced - sync is called by upper function at the end of whole operation
3968
3969 */
3970 }
3971
3972 static void layout_bar_set_default(LayoutWindow *lw)
3973 {
3974         GtkWidget *bar;
3975
3976         if (!lw->utility_box) return;
3977
3978         bar = bar_new(lw);
3979         DEBUG_NAME(bar);
3980
3981         layout_bar_set(lw, bar);
3982
3983         bar_populate_default(bar);
3984 }
3985
3986 static void layout_bar_close(LayoutWindow *lw)
3987 {
3988         if (lw->bar)
3989                 {
3990                 bar_close(lw->bar);
3991                 lw->bar = nullptr;
3992                 }
3993 }
3994
3995
3996 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
3997 {
3998         if (!lw->utility_box) return;
3999
4000         layout_bar_close(lw); /* if any */
4001
4002         if (!bar) return;
4003         lw->bar = bar;
4004
4005         g_signal_connect(G_OBJECT(lw->bar), "destroy",
4006                          G_CALLBACK(layout_bar_destroyed), lw);
4007
4008         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
4009
4010         bar_set_fd(lw->bar, layout_image_get_fd(lw));
4011 }
4012
4013
4014 void layout_bar_toggle(LayoutWindow *lw)
4015 {
4016         if (layout_bar_enabled(lw))
4017                 {
4018                 gtk_widget_hide(lw->bar);
4019                 }
4020         else
4021                 {
4022                 if (!lw->bar)
4023                         {
4024                         layout_bar_set_default(lw);
4025                         }
4026                 gtk_widget_show(lw->bar);
4027                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
4028                 }
4029         layout_util_sync_views(lw);
4030 }
4031
4032 static void layout_bar_new_image(LayoutWindow *lw)
4033 {
4034         if (!layout_bar_enabled(lw)) return;
4035
4036         bar_set_fd(lw->bar, layout_image_get_fd(lw));
4037 }
4038
4039 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
4040 {
4041         if (!layout_bar_enabled(lw)) return;
4042
4043         bar_notify_selection(lw->bar, count);
4044 }
4045
4046 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
4047 {
4048         return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
4049 }
4050
4051
4052 static void layout_bar_sort_destroyed(GtkWidget *, gpointer data)
4053 {
4054         auto lw = static_cast<LayoutWindow *>(data);
4055
4056         lw->bar_sort = nullptr;
4057
4058 /*
4059     do not call layout_util_sync_views(lw) here
4060     this is called either when whole layout is destroyed - no need for update
4061     or when the bar is replaced - sync is called by upper function at the end of whole operation
4062
4063 */
4064 }
4065
4066 static void layout_bar_sort_set_default(LayoutWindow *lw)
4067 {
4068         GtkWidget *bar;
4069
4070         if (!lw->utility_box) return;
4071
4072         bar = bar_sort_new_default(lw);
4073
4074         layout_bar_sort_set(lw, bar);
4075 }
4076
4077 static void layout_bar_sort_close(LayoutWindow *lw)
4078 {
4079         if (lw->bar_sort)
4080                 {
4081                 bar_sort_close(lw->bar_sort);
4082                 lw->bar_sort = nullptr;
4083                 }
4084 }
4085
4086 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
4087 {
4088         if (!lw->utility_box) return;
4089
4090         layout_bar_sort_close(lw); /* if any */
4091
4092         if (!bar) return;
4093         lw->bar_sort = bar;
4094
4095         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
4096                          G_CALLBACK(layout_bar_sort_destroyed), lw);
4097
4098         gq_gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
4099 }
4100
4101 void layout_bar_sort_toggle(LayoutWindow *lw)
4102 {
4103         if (layout_bar_sort_enabled(lw))
4104                 {
4105                 gtk_widget_hide(lw->bar_sort);
4106                 }
4107         else
4108                 {
4109                 if (!lw->bar_sort)
4110                         {
4111                         layout_bar_sort_set_default(lw);
4112                         }
4113                 gtk_widget_show(lw->bar_sort);
4114                 }
4115         layout_util_sync_views(lw);
4116 }
4117
4118 static void layout_bars_hide_toggle(LayoutWindow *lw)
4119 {
4120         if (lw->options.bars_state.hidden)
4121                 {
4122                 lw->options.bars_state.hidden = FALSE;
4123                 if (lw->options.bars_state.sort)
4124                         {
4125                         if (lw->bar_sort)
4126                                 {
4127                                 gtk_widget_show(lw->bar_sort);
4128                                 }
4129                         else
4130                                 {
4131                                 layout_bar_sort_set_default(lw);
4132                                 }
4133                         }
4134                 if (lw->options.bars_state.info)
4135                         {
4136                         gtk_widget_show(lw->bar);
4137                         }
4138                 layout_tools_float_set(lw, lw->options.tools_float,
4139                                                                         lw->options.bars_state.tools_hidden);
4140                 }
4141         else
4142                 {
4143                 lw->options.bars_state.hidden = TRUE;
4144                 lw->options.bars_state.sort = layout_bar_sort_enabled(lw);
4145                 lw->options.bars_state.info = layout_bar_enabled(lw);
4146                 lw->options.bars_state.tools_float = lw->options.tools_float;
4147                 lw->options.bars_state.tools_hidden = lw->options.tools_hidden;
4148
4149                 if (lw->bar)
4150                         {
4151                         gtk_widget_hide(lw->bar);
4152                         }
4153
4154                 if (lw->bar_sort)
4155                         gtk_widget_hide(lw->bar_sort);
4156                 layout_tools_float_set(lw, lw->options.tools_float, TRUE);
4157                 }
4158
4159         layout_util_sync_views(lw);
4160 }
4161
4162 void layout_bars_new_image(LayoutWindow *lw)
4163 {
4164         layout_bar_new_image(lw);
4165
4166         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
4167
4168         /* this should be called here to handle the metadata edited in bars */
4169         if (options->metadata.confirm_on_image_change)
4170                 metadata_write_queue_confirm(FALSE, nullptr, nullptr);
4171 }
4172
4173 void layout_bars_new_selection(LayoutWindow *lw, gint count)
4174 {
4175         layout_bar_new_selection(lw, count);
4176 }
4177
4178 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
4179 {
4180         if (lw->utility_box) return lw->utility_box;
4181         lw->utility_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
4182         lw->utility_paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
4183         DEBUG_NAME(lw->utility_paned);
4184         gq_gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
4185
4186         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
4187         gtk_widget_show(lw->utility_paned);
4188
4189         gtk_widget_show(image);
4190
4191         g_object_ref(lw->utility_box);
4192         return lw->utility_box;
4193 }
4194
4195 void layout_bars_close(LayoutWindow *lw)
4196 {
4197         layout_bar_sort_close(lw);
4198         layout_bar_close(lw);
4199 }
4200
4201 static gboolean layout_exif_window_destroy(GtkWidget *, gpointer data)
4202 {
4203         auto lw = static_cast<LayoutWindow *>(data);
4204         lw->exif_window = nullptr;
4205
4206         return TRUE;
4207 }
4208
4209 void layout_exif_window_new(LayoutWindow *lw)
4210 {
4211         if (lw->exif_window) return;
4212
4213         lw->exif_window = advanced_exif_new(lw);
4214         if (!lw->exif_window) return;
4215         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
4216                          G_CALLBACK(layout_exif_window_destroy), lw);
4217         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
4218 }
4219
4220 static void layout_search_and_run_window_new(LayoutWindow *lw)
4221 {
4222         if (lw->sar_window)
4223                 {
4224                 gtk_window_present(GTK_WINDOW(lw->sar_window));
4225                 return;
4226                 }
4227
4228         lw->sar_window = search_and_run_new(lw);
4229 }
4230
4231 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */