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