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