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