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