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