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