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