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