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