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