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