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