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