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