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