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