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