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