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