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