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