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