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