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