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