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