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