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