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