Fix #447: Preferences Enable Delete key
[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 "search.h"
48 #include "ui_fileops.h"
49 #include "ui_menu.h"
50 #include "ui_misc.h"
51 #include "ui_tabcomp.h"
52 #include "utilops.h"
53 #include "view_dir.h"
54 #include "window.h"
55 #include "metadata.h"
56 #include "desktop_file.h"
57
58 #include <gdk/gdkkeysyms.h> /* for keyboard values */
59 #include "keymap_template.c"
60
61 #define MENU_EDIT_ACTION_OFFSET 16
62
63 static gboolean layout_bar_enabled(LayoutWindow *lw);
64 static gboolean layout_bar_sort_enabled(LayoutWindow *lw);
65 static void layout_util_sync_views(LayoutWindow *lw);
66
67 /*
68  *-----------------------------------------------------------------------------
69  * keyboard handler
70  *-----------------------------------------------------------------------------
71  */
72
73 static guint tree_key_overrides[] = {
74         GDK_KEY_Page_Up,        GDK_KEY_KP_Page_Up,
75         GDK_KEY_Page_Down,      GDK_KEY_KP_Page_Down,
76         GDK_KEY_Home,   GDK_KEY_KP_Home,
77         GDK_KEY_End,    GDK_KEY_KP_End
78 };
79
80 static gboolean layout_key_match(guint keyval)
81 {
82         guint i;
83
84         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
85                 {
86                 if (keyval == tree_key_overrides[i]) return TRUE;
87                 }
88
89         return FALSE;
90 }
91
92 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
93 {
94         LayoutWindow *lw = data;
95         GtkWidget *focused;
96         gboolean stop_signal = FALSE;
97         gint x = 0;
98         gint y = 0;
99
100         if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
101                 {
102                 if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
103                         {
104                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
105                         }
106
107                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
108                  * so when the some widgets have focus, give them priority (HACK)
109                  */
110                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
111                         {
112                         return TRUE;
113                         }
114                 }
115         if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
116             !layout_key_match(event->keyval) &&
117             gtk_widget_event(lw->vd->view, (GdkEvent *)event))
118                 {
119                 return TRUE;
120                 }
121         if (lw->bar &&
122             bar_event(lw->bar, (GdkEvent *)event))
123                 {
124                 return TRUE;
125                 }
126
127         focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
128         if (lw->image &&
129             ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
130                 {
131                 stop_signal = TRUE;
132                 switch (event->keyval)
133                         {
134                         case GDK_KEY_Left: case GDK_KEY_KP_Left:
135                                 x -= 1;
136                                 break;
137                         case GDK_KEY_Right: case GDK_KEY_KP_Right:
138                                 x += 1;
139                                 break;
140                         case GDK_KEY_Up: case GDK_KEY_KP_Up:
141                                 y -= 1;
142                                 break;
143                         case GDK_KEY_Down: case GDK_KEY_KP_Down:
144                                 y += 1;
145                                 break;
146                         default:
147                                 stop_signal = FALSE;
148                                 break;
149                         }
150
151                 if (!stop_signal &&
152                     !(event->state & GDK_CONTROL_MASK))
153                         {
154                         stop_signal = TRUE;
155                         switch (event->keyval)
156                                 {
157                                 case GDK_KEY_Menu:
158                                         layout_image_menu_popup(lw);
159                                         break;
160                                 default:
161                                         stop_signal = FALSE;
162                                         break;
163                                 }
164                         }
165                 }
166
167         if (x != 0 || y!= 0)
168                 {
169                 keyboard_scroll_calc(&x, &y, event);
170                 layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK));
171                 }
172
173         return stop_signal;
174 }
175
176 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
177 {
178         g_signal_connect(G_OBJECT(window), "key_press_event",
179                          G_CALLBACK(layout_key_press_cb), lw);
180 }
181
182 /*
183  *-----------------------------------------------------------------------------
184  * menu callbacks
185  *-----------------------------------------------------------------------------
186  */
187
188
189 static GtkWidget *layout_window(LayoutWindow *lw)
190 {
191         return lw->full_screen ? lw->full_screen->window : lw->window;
192 }
193
194 static void layout_exit_fullscreen(LayoutWindow *lw)
195 {
196         if (!lw->full_screen) return;
197         layout_image_full_screen_stop(lw);
198 }
199
200 static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
201 {
202         LayoutWindow *lw = data;
203         LayoutWindow *nw;
204         LayoutOptions lop;
205         gboolean tmp = options->save_window_positions;
206
207         if (!options->use_saved_window_positions_for_new_windows)
208                 options->save_window_positions = FALSE; /* let the windowmanager decide for the first time */
209
210         layout_exit_fullscreen(lw);
211
212         layout_sync_options_with_current_state(lw);
213         lop = lw->options; /* we can copy it directly, no strings are modified */
214
215         lop.id = NULL; /* get a new id */
216         nw = layout_new(NULL, &lop);
217         layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
218         layout_set_fd(nw, lw->dir_fd);
219         options->save_window_positions = tmp;
220 }
221
222 static void layout_menu_new_cb(GtkAction *action, gpointer data)
223 {
224         LayoutWindow *lw = data;
225
226         layout_exit_fullscreen(lw);
227         collection_window_new(NULL);
228 }
229
230 static void layout_menu_open_cb(GtkAction *action, gpointer data)
231 {
232         LayoutWindow *lw = data;
233
234         layout_exit_fullscreen(lw);
235         collection_dialog_load(NULL);
236 }
237
238 static void layout_menu_search_cb(GtkAction *action, gpointer data)
239 {
240         LayoutWindow *lw = data;
241
242         layout_exit_fullscreen(lw);
243         search_new(lw->dir_fd, layout_image_get_fd(lw));
244 }
245
246 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
247 {
248         LayoutWindow *lw = data;
249
250         layout_exit_fullscreen(lw);
251         dupe_window_new(DUPE_MATCH_NAME);
252 }
253
254 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
255 {
256         LayoutWindow *lw = data;
257
258         layout_exit_fullscreen(lw);
259         pan_window_new(lw->dir_fd);
260 }
261
262 static void layout_menu_print_cb(GtkAction *action, gpointer data)
263 {
264         LayoutWindow *lw = data;
265
266         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
267 }
268
269 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
270 {
271         LayoutWindow *lw = data;
272
273         if (lw->vd) vd_new_folder(lw->vd, lw->dir_fd);
274 }
275
276 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
277 {
278         LayoutWindow *lw = data;
279
280         file_util_copy(NULL, layout_selection_list(lw), NULL, layout_window(lw));
281 }
282
283 static void layout_menu_copy_path_cb(GtkAction *action, gpointer data)
284 {
285         LayoutWindow *lw = data;
286
287         file_util_copy_path_list_to_clipboard(layout_selection_list(lw));
288 }
289
290 static void layout_menu_move_cb(GtkAction *action, gpointer data)
291 {
292         LayoutWindow *lw = data;
293
294         file_util_move(NULL, layout_selection_list(lw), NULL, layout_window(lw));
295 }
296
297 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
298 {
299         LayoutWindow *lw = data;
300
301         file_util_rename(NULL, layout_selection_list(lw), layout_window(lw));
302 }
303
304 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
305 {
306         LayoutWindow *lw = data;
307
308         file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
309 }
310
311 static void layout_menu_delete_key_cb(GtkAction *action, gpointer data)
312 {
313         LayoutWindow *lw = data;
314
315         if (options->file_ops.enable_delete_key)
316                 {
317                 file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
318                 }
319 }
320
321 static void layout_menu_disable_grouping_cb(GtkAction *action, gpointer data)
322 {
323         LayoutWindow *lw = data;
324
325         file_data_disable_grouping_list(layout_selection_list(lw), TRUE);
326 }
327
328 static void layout_menu_enable_grouping_cb(GtkAction *action, gpointer data)
329 {
330         LayoutWindow *lw = data;
331
332         file_data_disable_grouping_list(layout_selection_list(lw), FALSE);
333 }
334
335 static void layout_menu_close_cb(GtkAction *action, gpointer data)
336 {
337         LayoutWindow *lw = data;
338
339         layout_exit_fullscreen(lw);
340         layout_close(lw);
341 }
342
343 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
344 {
345         exit_program();
346 }
347
348 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
349 {
350         LayoutWindow *lw = data;
351
352         layout_image_alter_orientation(lw, ALTER_ROTATE_90);
353 }
354
355 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
356 {
357         LayoutWindow *lw = data;
358
359         layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
360 }
361
362 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
363 {
364         LayoutWindow *lw = data;
365
366         layout_image_alter_orientation(lw, ALTER_ROTATE_180);
367 }
368
369 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
370 {
371         LayoutWindow *lw = data;
372
373         layout_image_alter_orientation(lw, ALTER_MIRROR);
374 }
375
376 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
377 {
378         LayoutWindow *lw = data;
379
380         layout_image_alter_orientation(lw, ALTER_FLIP);
381 }
382
383 static void layout_menu_alter_desaturate_cb(GtkToggleAction *action, gpointer data)
384 {
385         LayoutWindow *lw = data;
386
387         layout_image_set_desaturate(lw, gtk_toggle_action_get_active(action));
388 }
389
390 static void layout_menu_alter_none_cb(GtkAction *action, gpointer data)
391 {
392         LayoutWindow *lw = data;
393
394         layout_image_alter_orientation(lw, ALTER_NONE);
395 }
396
397 static void layout_menu_config_cb(GtkAction *action, gpointer data)
398 {
399         LayoutWindow *lw = data;
400
401         layout_exit_fullscreen(lw);
402         show_config_window();
403 }
404
405 static void layout_menu_editors_cb(GtkAction *action, gpointer data)
406 {
407         LayoutWindow *lw = data;
408
409         layout_exit_fullscreen(lw);
410         show_editor_list_window();
411 }
412
413 static void layout_menu_layout_config_cb(GtkAction *action, gpointer data)
414 {
415         LayoutWindow *lw = data;
416
417         layout_exit_fullscreen(lw);
418         layout_show_config_window(lw);
419 }
420
421 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
422 {
423         LayoutWindow *lw = data;
424
425         layout_exit_fullscreen(lw);
426         cache_manager_show();
427 }
428
429 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
430 {
431         LayoutWindow *lw = data;
432
433         layout_image_to_root(lw);
434 }
435
436 /* single window zoom */
437 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
438 {
439         LayoutWindow *lw = data;
440
441         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
442 }
443
444 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
445 {
446         LayoutWindow *lw = data;
447
448         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
449 }
450
451 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
452 {
453         LayoutWindow *lw = data;
454
455         layout_image_zoom_set(lw, 1.0, FALSE);
456 }
457
458 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
459 {
460         LayoutWindow *lw = data;
461
462         layout_image_zoom_set(lw, 0.0, FALSE);
463 }
464
465 static void layout_menu_zoom_fit_hor_cb(GtkAction *action, gpointer data)
466 {
467         LayoutWindow *lw = data;
468
469         layout_image_zoom_set_fill_geometry(lw, FALSE, FALSE);
470 }
471
472 static void layout_menu_zoom_fit_vert_cb(GtkAction *action, gpointer data)
473 {
474         LayoutWindow *lw = data;
475
476         layout_image_zoom_set_fill_geometry(lw, TRUE, FALSE);
477 }
478
479 static void layout_menu_zoom_2_1_cb(GtkAction *action, gpointer data)
480 {
481         LayoutWindow *lw = data;
482
483         layout_image_zoom_set(lw, 2.0, FALSE);
484 }
485
486 static void layout_menu_zoom_3_1_cb(GtkAction *action, gpointer data)
487 {
488         LayoutWindow *lw = data;
489
490         layout_image_zoom_set(lw, 3.0, FALSE);
491 }
492 static void layout_menu_zoom_4_1_cb(GtkAction *action, gpointer data)
493 {
494         LayoutWindow *lw = data;
495
496         layout_image_zoom_set(lw, 4.0, FALSE);
497 }
498
499 static void layout_menu_zoom_1_2_cb(GtkAction *action, gpointer data)
500 {
501         LayoutWindow *lw = data;
502
503         layout_image_zoom_set(lw, -2.0, FALSE);
504 }
505
506 static void layout_menu_zoom_1_3_cb(GtkAction *action, gpointer data)
507 {
508         LayoutWindow *lw = data;
509
510         layout_image_zoom_set(lw, -3.0, FALSE);
511 }
512
513 static void layout_menu_zoom_1_4_cb(GtkAction *action, gpointer data)
514 {
515         LayoutWindow *lw = data;
516
517         layout_image_zoom_set(lw, -4.0, FALSE);
518 }
519
520 /* connected zoom */
521 static void layout_menu_connect_zoom_in_cb(GtkAction *action, gpointer data)
522 {
523         LayoutWindow *lw = data;
524
525         layout_image_zoom_adjust(lw, get_zoom_increment(), TRUE);
526 }
527
528 static void layout_menu_connect_zoom_out_cb(GtkAction *action, gpointer data)
529 {
530         LayoutWindow *lw = data;
531
532         layout_image_zoom_adjust(lw, -get_zoom_increment(), TRUE);
533 }
534
535 static void layout_menu_connect_zoom_1_1_cb(GtkAction *action, gpointer data)
536 {
537         LayoutWindow *lw = data;
538
539         layout_image_zoom_set(lw, 1.0, TRUE);
540 }
541
542 static void layout_menu_connect_zoom_fit_cb(GtkAction *action, gpointer data)
543 {
544         LayoutWindow *lw = data;
545
546         layout_image_zoom_set(lw, 0.0, TRUE);
547 }
548
549 static void layout_menu_connect_zoom_fit_hor_cb(GtkAction *action, gpointer data)
550 {
551         LayoutWindow *lw = data;
552
553         layout_image_zoom_set_fill_geometry(lw, FALSE, TRUE);
554 }
555
556 static void layout_menu_connect_zoom_fit_vert_cb(GtkAction *action, gpointer data)
557 {
558         LayoutWindow *lw = data;
559
560         layout_image_zoom_set_fill_geometry(lw, TRUE, TRUE);
561 }
562
563 static void layout_menu_connect_zoom_2_1_cb(GtkAction *action, gpointer data)
564 {
565         LayoutWindow *lw = data;
566
567         layout_image_zoom_set(lw, 2.0, TRUE);
568 }
569
570 static void layout_menu_connect_zoom_3_1_cb(GtkAction *action, gpointer data)
571 {
572         LayoutWindow *lw = data;
573
574         layout_image_zoom_set(lw, 3.0, TRUE);
575 }
576 static void layout_menu_connect_zoom_4_1_cb(GtkAction *action, gpointer data)
577 {
578         LayoutWindow *lw = data;
579
580         layout_image_zoom_set(lw, 4.0, TRUE);
581 }
582
583 static void layout_menu_connect_zoom_1_2_cb(GtkAction *action, gpointer data)
584 {
585         LayoutWindow *lw = data;
586
587         layout_image_zoom_set(lw, -2.0, TRUE);
588 }
589
590 static void layout_menu_connect_zoom_1_3_cb(GtkAction *action, gpointer data)
591 {
592         LayoutWindow *lw = data;
593
594         layout_image_zoom_set(lw, -3.0, TRUE);
595 }
596
597 static void layout_menu_connect_zoom_1_4_cb(GtkAction *action, gpointer data)
598 {
599         LayoutWindow *lw = data;
600
601         layout_image_zoom_set(lw, -4.0, TRUE);
602 }
603
604
605 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
606 {
607         LayoutWindow *lw = data;
608         ImageSplitMode mode;
609
610         layout_exit_fullscreen(lw);
611         mode = gtk_radio_action_get_current_value(action);
612         layout_split_change(lw, mode);
613 }
614
615
616 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
617 {
618         LayoutWindow *lw = data;
619
620         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
621 }
622
623
624 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
625 {
626         LayoutWindow *lw = data;
627
628         layout_exit_fullscreen(lw);
629         layout_views_set(lw, lw->options.dir_view_type, (FileViewType) gtk_radio_action_get_current_value(action));
630 }
631
632 static void layout_menu_view_dir_as_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
633 {
634         LayoutWindow *lw = data;
635
636         layout_exit_fullscreen(lw);
637         layout_views_set(lw, (DirViewType) gtk_radio_action_get_current_value(action), lw->options.file_view_type);
638 }
639
640 static void layout_menu_view_in_new_window_cb(GtkAction *action, gpointer data)
641 {
642         LayoutWindow *lw = data;
643
644         layout_exit_fullscreen(lw);
645         view_window_new(layout_image_get_fd(lw));
646 }
647
648 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
649 {
650         LayoutWindow *lw = data;
651
652         layout_image_full_screen_toggle(lw);
653 }
654
655 static void layout_menu_escape_cb(GtkAction *action, gpointer data)
656 {
657         LayoutWindow *lw = data;
658
659         layout_exit_fullscreen(lw);
660 }
661
662 static void layout_menu_overlay_toggle_cb(GtkAction *action, gpointer data)
663 {
664         LayoutWindow *lw = data;
665
666         image_osd_toggle(lw->image);
667         layout_util_sync_views(lw);
668 }
669
670
671 static void layout_menu_overlay_cb(GtkToggleAction *action, gpointer data)
672 {
673         LayoutWindow *lw = data;
674
675         if (gtk_toggle_action_get_active(action))
676                 {
677                 OsdShowFlags flags = image_osd_get(lw->image);
678
679                 if ((flags | OSD_SHOW_INFO | OSD_SHOW_STATUS) != flags)
680                         image_osd_set(lw->image, flags | OSD_SHOW_INFO | OSD_SHOW_STATUS);
681                 }
682         else
683                 {
684                 GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
685
686                 image_osd_set(lw->image, OSD_SHOW_NOTHING);
687                 gtk_toggle_action_set_active(histogram_action, FALSE); /* this calls layout_menu_histogram_cb */
688                 }
689 }
690
691 static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
692 {
693         LayoutWindow *lw = data;
694
695         if (gtk_toggle_action_get_active(action))
696                 {
697                 image_osd_set(lw->image, OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_HISTOGRAM);
698                 layout_util_sync_views(lw); /* show the overlay state, default channel and mode in the menu */
699                 }
700         else
701                 {
702                 OsdShowFlags flags = image_osd_get(lw->image);
703                 if (flags & OSD_SHOW_HISTOGRAM)
704                         image_osd_set(lw->image, flags & ~OSD_SHOW_HISTOGRAM);
705                 }
706 }
707
708 static void layout_menu_histogram_toggle_channel_cb(GtkAction *action, gpointer data)
709 {
710         LayoutWindow *lw = data;
711
712         image_osd_histogram_toggle_channel(lw->image);
713         layout_util_sync_views(lw);
714 }
715
716 static void layout_menu_histogram_toggle_mode_cb(GtkAction *action, gpointer data)
717 {
718         LayoutWindow *lw = data;
719
720         image_osd_histogram_toggle_mode(lw->image);
721         layout_util_sync_views(lw);
722 }
723
724 static void layout_menu_histogram_channel_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
725 {
726         LayoutWindow *lw = data;
727         gint channel = gtk_radio_action_get_current_value(action);
728         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
729
730         if (channel < 0 || channel >= HCHAN_COUNT) return;
731
732         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
733         image_osd_histogram_set_channel(lw->image, channel);
734 }
735
736 static void layout_menu_histogram_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
737 {
738         LayoutWindow *lw = data;
739         gint mode = gtk_radio_action_get_current_value(action);
740         GtkToggleAction *histogram_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(lw->action_group, "ImageHistogram"));
741
742         if (mode < 0 || mode > 1) return;
743
744         gtk_toggle_action_set_active(histogram_action, TRUE); /* this calls layout_menu_histogram_cb */
745         image_osd_histogram_set_mode(lw->image, mode);
746 }
747
748 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
749 {
750         LayoutWindow *lw = data;
751
752         layout_refresh(lw);
753 }
754
755 static void layout_menu_bar_exif_cb(GtkAction *action, gpointer data)
756 {
757         LayoutWindow *lw = data;
758
759         layout_exit_fullscreen(lw);
760         layout_exif_window_new(lw);
761 }
762
763 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
764 {
765         LayoutWindow *lw = data;
766
767         if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return;
768
769         layout_exit_fullscreen(lw);
770         layout_tools_float_toggle(lw);
771 }
772
773 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
774 {
775         LayoutWindow *lw = data;
776
777         layout_exit_fullscreen(lw);
778         layout_tools_hide_toggle(lw);
779 }
780
781 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
782 {
783         LayoutWindow *lw = data;
784
785         if (lw->options.toolbar_hidden == gtk_toggle_action_get_active(action)) return;
786
787         layout_exit_fullscreen(lw);
788         layout_toolbar_toggle(lw);
789 }
790
791 static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
792 {
793         LayoutWindow *lw = data;
794
795         if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
796
797         layout_exit_fullscreen(lw);
798         layout_info_pixel_set(lw, !lw->options.show_info_pixel);
799 }
800
801 /* NOTE: these callbacks are called also from layout_util_sync_views */
802 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
803 {
804         LayoutWindow *lw = data;
805
806         if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
807
808         layout_exit_fullscreen(lw);
809         layout_bar_toggle(lw);
810 }
811
812 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
813 {
814         LayoutWindow *lw = data;
815
816         if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return;
817
818         layout_exit_fullscreen(lw);
819         layout_bar_sort_toggle(lw);
820 }
821
822 static void layout_menu_slideshow_cb(GtkToggleAction *action, gpointer data)
823 {
824         LayoutWindow *lw = data;
825
826         if (layout_image_slideshow_active(lw) == gtk_toggle_action_get_active(action)) return;
827         layout_image_slideshow_toggle(lw);
828 }
829
830 static void layout_menu_slideshow_pause_cb(GtkAction *action, gpointer data)
831 {
832         LayoutWindow *lw = data;
833
834         layout_image_slideshow_pause_toggle(lw);
835 }
836
837
838 static void layout_menu_stereo_mode_next_cb(GtkAction *action, gpointer data)
839 {
840         LayoutWindow *lw = data;
841         gint mode = layout_image_stereo_pixbuf_get(lw);
842
843         /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
844         mode = mode % 3 + 1;
845
846         GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
847         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
848
849         /*
850         this is called via fallback in layout_menu_stereo_mode_cb
851         layout_image_stereo_pixbuf_set(lw, mode);
852         */
853
854 }
855
856 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
857 {
858         LayoutWindow *lw = data;
859         gint mode = gtk_radio_action_get_current_value(action);
860         layout_image_stereo_pixbuf_set(lw, mode);
861 }
862
863 static void layout_menu_help_cb(GtkAction *action, gpointer data)
864 {
865         LayoutWindow *lw = data;
866
867         layout_exit_fullscreen(lw);
868         help_window_show("index.html");
869 }
870
871 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
872 {
873         LayoutWindow *lw = data;
874
875         layout_exit_fullscreen(lw);
876         help_window_show("GuideReferenceKeyboardShortcuts.html");
877 }
878
879 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
880 {
881         LayoutWindow *lw = data;
882
883         layout_exit_fullscreen(lw);
884         help_window_show("release_notes");
885 }
886
887 static char *keyboard_map_hardcoded[][2] = {
888         {"Scroll","Left"},
889         {"FastScroll", "&lt;Shift&gt;Left"},
890         {"Left Border", "&lt;Primary&gt;Left"},
891         {"Left Border", "&lt;Primary&gt;&lt;Shift&gt;Left"},
892         {"Scroll", "Right"},
893         {"FastScroll", "&lt;Shift&gt;Right"},
894         {"Right Border", "&lt;Primary&gt;Right"},
895         {"Right Border", "&lt;Primary&gt;&lt;Shift&gt;Right"},
896         {"Scroll", "Up"},
897         {"FastScroll", "&lt;Shift&gt;Up"},
898         {"Uper Border", "&lt;Primary&gt;Up"},
899         {"Uper Border", "&lt;Primary&gt;&lt;Shift&gt;Up"},
900         {"Scroll", "Down"},
901         {"FastScroll", "&lt;Shift&gt;Down"},
902         {"Lower Border", "&lt;Primary&gt;Down"},
903         {"Lower Border", "&lt;Primary&gt;&lt;Shift&gt;Down"},
904         {"Next/Drag", "M1"},
905         {"FastDrag", "&lt;Shift&gt;M1"},
906         {"DnD Start", "M2"},
907         {"Menu", "M3"},
908         {"PrevImage", "MW4"},
909         {"NextImage", "MW5"},
910         {"ScrollUp", "&lt;Shift&gt;MW4"},
911         {"ScrollDown", "&lt;Shift&gt;MW5"},
912         {"ZoomIn", "&lt;Primary&gt;MW4"},
913         {"ZoomOut", "&lt;Primary&gt;MW5"},
914         {NULL, NULL}
915 };
916
917 static void layout_menu_foreach_func(
918                                         gpointer data,
919                                         const gchar *accel_path,
920                                         guint accel_key,
921                                         GdkModifierType accel_mods,
922                                         gboolean changed)
923 {
924         gchar *path, *name;
925         gchar *key_name, *menu_name;
926         gchar **subset_lt_arr, **subset_gt_arr;
927         gchar *subset_lt, *converted_name;
928         GPtrArray *array = data;
929
930         path = g_strescape(accel_path, NULL);
931         name = gtk_accelerator_name(accel_key, accel_mods);
932
933         menu_name = g_strdup(g_strrstr(path, "/")+1);
934
935         if (g_strrstr(name, ">"))
936                 {
937                 subset_lt_arr = g_strsplit_set(name,"<", 4);
938                 subset_lt = g_strjoinv("&lt;", subset_lt_arr);
939                 subset_gt_arr = g_strsplit_set(subset_lt,">", 4);
940                 converted_name = g_strjoinv("&gt;", subset_gt_arr);
941                 key_name = g_strdup(converted_name);
942
943                 g_free(converted_name);
944                 g_free(subset_lt);
945                 g_strfreev(subset_lt_arr);
946                 g_strfreev(subset_gt_arr);
947                 }
948         else
949                 key_name = g_strdup(name);
950
951         g_ptr_array_add(array, (gpointer)menu_name);
952         g_ptr_array_add(array, (gpointer)key_name);
953
954         g_free(name);
955         g_free(path);
956 }
957
958 static void layout_menu_kbd_map_cb(GtkAction *action, gpointer data)
959 {
960         LayoutWindow *lw = data;
961         gint fd = -1;
962         GPtrArray *array;
963         char * tmp_file;
964         GError *error = NULL;
965         GIOChannel *channel;
966         char **pre_key, **post_key;
967         char *key_name, *converted_line;
968         int keymap_index, index;
969
970         fd = g_file_open_tmp("geeqie_keymap_XXXXXX.svg", &tmp_file, &error);
971         if (error)
972                 {
973                 DEBUG_0("Keyboard Map - cannot create file:%s\n",error->message);
974                 g_error_free(error);
975                 }
976         else
977                 {
978                 array = g_ptr_array_new();
979
980                 gtk_accel_map_foreach(array, layout_menu_foreach_func);
981
982                 channel = g_io_channel_unix_new(fd);
983
984                 keymap_index = 0;
985                 while (keymap_template[keymap_index])
986                         {
987                         if (g_strrstr(keymap_template[keymap_index], ">key:"))
988                                 {
989                                 pre_key = g_strsplit(keymap_template[keymap_index],">key:",2);
990                                 post_key = g_strsplit(pre_key[1],"<",2);
991
992                                 index=0;
993                                 key_name = " ";
994                                 for (index=0; index < array->len-2; index=index+2)
995                                         {
996                                         if (!(g_ascii_strcasecmp(g_ptr_array_index(array,index+1), post_key[0])))
997                                                 {
998                                                 key_name = g_ptr_array_index(array,index+0);
999                                                 break;
1000                                                 }
1001                                         }
1002
1003                                 index=0;
1004                                 while (keyboard_map_hardcoded[index][0])
1005                                         {
1006                                         if (!(g_strcmp0(keyboard_map_hardcoded[index][1], post_key[0])))
1007                                                 {
1008                                                 key_name = keyboard_map_hardcoded[index][0];
1009                                                 break;
1010                                                 }
1011                                         index++;
1012                                         }
1013
1014                                 converted_line = g_strconcat(pre_key[0], ">", key_name, "<", post_key[1], "\n", NULL);
1015                                 g_io_channel_write_chars(channel, converted_line, -1, NULL, &error);
1016                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1017
1018                                 g_free(converted_line);
1019                                 g_strfreev(pre_key);
1020                                 g_strfreev(post_key);
1021                                 }
1022                         else
1023                                 {
1024                                 g_io_channel_write_chars(channel, keymap_template[keymap_index], -1, NULL, &error);
1025                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1026                                 g_io_channel_write_chars(channel, "\n", -1, NULL, &error);
1027                                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1028                                 }
1029                         keymap_index++;
1030                         }
1031
1032                 g_io_channel_flush(channel, &error);
1033                 if (error) {DEBUG_0("Keyboard Map:%s\n",error->message); g_error_free(error);}
1034                 g_io_channel_unref(channel);
1035
1036                 index=0;
1037                 for (index=0; index < array->len-2; index=index+2)
1038                         {
1039                         g_free(g_ptr_array_index(array,index));
1040                         g_free(g_ptr_array_index(array,index+1));
1041                         }
1042                 g_ptr_array_unref(array);
1043
1044                 view_window_new(file_data_new_simple(tmp_file));
1045                 g_free(tmp_file);
1046                 }
1047 }
1048
1049 static void layout_menu_about_cb(GtkAction *action, gpointer data)
1050 {
1051         LayoutWindow *lw = data;
1052
1053         layout_exit_fullscreen(lw);
1054         show_about_window();
1055 }
1056
1057 static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
1058 {
1059         LayoutWindow *lw = data;
1060
1061         layout_exit_fullscreen(lw);
1062         log_window_new();
1063 }
1064
1065
1066 /*
1067  *-----------------------------------------------------------------------------
1068  * select menu
1069  *-----------------------------------------------------------------------------
1070  */
1071
1072 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
1073 {
1074         LayoutWindow *lw = data;
1075
1076         layout_select_all(lw);
1077 }
1078
1079 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
1080 {
1081         LayoutWindow *lw = data;
1082
1083         layout_select_none(lw);
1084 }
1085
1086 static void layout_menu_invert_selection_cb(GtkAction *action, gpointer data)
1087 {
1088         LayoutWindow *lw = data;
1089
1090         layout_select_invert(lw);
1091 }
1092
1093 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
1094 {
1095         LayoutWindow *lw = data;
1096
1097         layout_marks_set(lw, gtk_toggle_action_get_active(action));
1098 }
1099
1100
1101 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
1102 {
1103         LayoutWindow *lw = data;
1104         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1105         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1106
1107         layout_selection_to_mark(lw, mark, STM_MODE_SET);
1108 }
1109
1110 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
1111 {
1112         LayoutWindow *lw = data;
1113         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1114         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1115
1116         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
1117 }
1118
1119 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
1120 {
1121         LayoutWindow *lw = data;
1122         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1123         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1124
1125         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
1126 }
1127
1128 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
1129 {
1130         LayoutWindow *lw = data;
1131         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1132         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1133
1134         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
1135 }
1136
1137 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
1138 {
1139         LayoutWindow *lw = data;
1140         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1141         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1142
1143         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
1144 }
1145
1146 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
1147 {
1148         LayoutWindow *lw = data;
1149         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1150         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1151
1152         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
1153 }
1154
1155 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
1156 {
1157         LayoutWindow *lw = data;
1158         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1159         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1160
1161         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
1162 }
1163
1164 static void layout_menu_mark_filter_toggle_cb(GtkAction *action, gpointer data)
1165 {
1166         LayoutWindow *lw = data;
1167         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
1168         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
1169
1170         layout_marks_set(lw, TRUE);
1171         layout_mark_filter_toggle(lw, mark);
1172 }
1173
1174
1175 /*
1176  *-----------------------------------------------------------------------------
1177  * go menu
1178  *-----------------------------------------------------------------------------
1179  */
1180
1181 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
1182 {
1183         LayoutWindow *lw = data;
1184         layout_image_first(lw);
1185 }
1186
1187 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
1188 {
1189         LayoutWindow *lw = data;
1190         layout_image_prev(lw);
1191 }
1192
1193 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
1194 {
1195         LayoutWindow *lw = data;
1196         layout_image_next(lw);
1197 }
1198
1199 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
1200 {
1201         LayoutWindow *lw = data;
1202         layout_image_last(lw);
1203 }
1204
1205 static void layout_menu_back_cb(GtkAction *action, gpointer data)
1206 {
1207         LayoutWindow *lw = data;
1208         FileData *dir_fd;
1209         gchar *path = NULL;
1210         GList *list = history_list_get_by_key("path_list");
1211         gint n = 0;
1212
1213         while (list)
1214                 {
1215                 if (n == 1) {
1216                         /* Previous path from history */
1217                         path = (gchar *)list->data;
1218                         break;
1219                 }
1220                 list = list->next;
1221                 n++;
1222                 }
1223
1224         if (!path) return;
1225
1226         /* Open previous path */
1227         dir_fd = file_data_new_dir(path);
1228         layout_set_fd(lw, dir_fd);
1229         file_data_unref(dir_fd);
1230 }
1231
1232 static void layout_menu_home_cb(GtkAction *action, gpointer data)
1233 {
1234         LayoutWindow *lw = data;
1235         const gchar *path;
1236
1237         if (lw->options.home_path && *lw->options.home_path)
1238                 path = lw->options.home_path;
1239         else
1240                 path = homedir();
1241
1242         if (path)
1243                 {
1244                 FileData *dir_fd = file_data_new_dir(path);
1245                 layout_set_fd(lw, dir_fd);
1246                 file_data_unref(dir_fd);
1247                 }
1248 }
1249
1250 static void layout_menu_up_cb(GtkAction *action, gpointer data)
1251 {
1252         LayoutWindow *lw = data;
1253         ViewDir *vd = lw->vd;
1254         gchar *path;
1255
1256         if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
1257         path = remove_level_from_path(vd->dir_fd->path);
1258
1259         if (vd->select_func)
1260                 {
1261                 FileData *fd = file_data_new_dir(path);
1262                 vd->select_func(vd, fd, vd->select_data);
1263                 file_data_unref(fd);
1264                 }
1265
1266         g_free(path);
1267 }
1268
1269
1270 /*
1271  *-----------------------------------------------------------------------------
1272  * edit menu
1273  *-----------------------------------------------------------------------------
1274  */
1275
1276 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
1277 {
1278         LayoutWindow *lw = data;
1279         const gchar *key = gtk_action_get_name(action);
1280
1281         if (!editor_window_flag_set(key))
1282                 layout_exit_fullscreen(lw);
1283
1284         file_util_start_editor_from_filelist(key, layout_selection_list(lw), layout_get_path(lw), lw->window);
1285 }
1286
1287
1288 static void layout_menu_metadata_write_cb(GtkAction *action, gpointer data)
1289 {
1290         metadata_write_queue_confirm(TRUE, NULL, NULL);
1291 }
1292
1293
1294 /*
1295  *-----------------------------------------------------------------------------
1296  * color profile button (and menu)
1297  *-----------------------------------------------------------------------------
1298  */
1299
1300 static void layout_color_menu_enable_cb(GtkToggleAction *action, gpointer data)
1301 {
1302 #ifdef HAVE_LCMS
1303         LayoutWindow *lw = data;
1304
1305         if (layout_image_color_profile_get_use(lw) == gtk_toggle_action_get_active(action)) return;
1306
1307         layout_image_color_profile_set_use(lw, gtk_toggle_action_get_active(action));
1308         layout_util_sync_color(lw);
1309         layout_image_refresh(lw);
1310 #endif
1311 }
1312
1313 static void layout_color_menu_use_image_cb(GtkToggleAction *action, gpointer data)
1314 {
1315 #ifdef HAVE_LCMS
1316         LayoutWindow *lw = data;
1317         gint input;
1318         gboolean use_image;
1319
1320         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1321         if (use_image == gtk_toggle_action_get_active(action)) return;
1322         layout_image_color_profile_set(lw, input, gtk_toggle_action_get_active(action));
1323         layout_util_sync_color(lw);
1324         layout_image_refresh(lw);
1325 #endif
1326 }
1327
1328 static void layout_color_menu_input_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
1329 {
1330 #ifdef HAVE_LCMS
1331         LayoutWindow *lw = data;
1332         gint type;
1333         gint input;
1334         gboolean use_image;
1335
1336         type = gtk_radio_action_get_current_value(action);
1337         if (type < 0 || type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS) return;
1338
1339         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
1340         if (type == input) return;
1341
1342         layout_image_color_profile_set(lw, type, use_image);
1343         layout_image_refresh(lw);
1344 #endif
1345 }
1346
1347
1348 /*
1349  *-----------------------------------------------------------------------------
1350  * recent menu
1351  *-----------------------------------------------------------------------------
1352  */
1353
1354 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
1355 {
1356         gint n;
1357         gchar *path;
1358
1359         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
1360
1361         path = g_list_nth_data(history_list_get_by_key("recent"), n);
1362
1363         if (!path) return;
1364
1365         /* make a copy of it */
1366         path = g_strdup(path);
1367         collection_window_new(path);
1368         g_free(path);
1369 }
1370
1371 static void layout_menu_recent_update(LayoutWindow *lw)
1372 {
1373         GtkWidget *menu;
1374         GtkWidget *recent;
1375         GtkWidget *item;
1376         GList *list;
1377         gint n;
1378
1379         if (!lw->ui_manager) return;
1380
1381         list = history_list_get_by_key("recent");
1382         n = 0;
1383
1384         menu = gtk_menu_new();
1385
1386         while (list)
1387                 {
1388                 const gchar *filename = filename_from_path((gchar *)list->data);
1389                 gchar *name;
1390                 gboolean free_name = FALSE;
1391
1392                 if (file_extension_match(filename, GQ_COLLECTION_EXT))
1393                         {
1394                         name = remove_extension_from_path(filename);
1395                         free_name = TRUE;
1396                         }
1397                 else
1398                         {
1399                         name = (gchar *) filename;
1400                         }
1401
1402                 item = menu_item_add_simple(menu, name, G_CALLBACK(layout_menu_recent_cb), lw);
1403                 if (free_name) g_free(name);
1404                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
1405                 list = list->next;
1406                 n++;
1407                 }
1408
1409         if (n == 0)
1410                 {
1411                 menu_item_add(menu, _("Empty"), NULL, NULL);
1412                 }
1413
1414         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
1415         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
1416         gtk_widget_set_sensitive(recent, (n != 0));
1417 }
1418
1419 void layout_recent_update_all(void)
1420 {
1421         GList *work;
1422
1423         work = layout_window_list;
1424         while (work)
1425                 {
1426                 LayoutWindow *lw = work->data;
1427                 work = work->next;
1428
1429                 layout_menu_recent_update(lw);
1430                 }
1431 }
1432
1433 void layout_recent_add_path(const gchar *path)
1434 {
1435         if (!path) return;
1436
1437         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
1438
1439         layout_recent_update_all();
1440 }
1441
1442 /*
1443  *-----------------------------------------------------------------------------
1444  * menu
1445  *-----------------------------------------------------------------------------
1446  */
1447
1448 #define CB G_CALLBACK
1449
1450 static GtkActionEntry menu_entries[] = {
1451   { "FileMenu",         NULL,                   N_("_File"),                            NULL,                   NULL,                                   NULL },
1452   { "GoMenu",           NULL,                   N_("_Go"),                              NULL,                   NULL,                                   NULL },
1453   { "EditMenu",         NULL,                   N_("_Edit"),                            NULL,                   NULL,                                   NULL },
1454   { "SelectMenu",       NULL,                   N_("_Select"),                          NULL,                   NULL,                                   NULL },
1455   { "OrientationMenu",  NULL,                   N_("_Orientation"),                     NULL,                   NULL,                                   NULL },
1456   { "ExternalMenu",     NULL,                   N_("E_xternal Editors"),                NULL,                   NULL,                                   NULL },
1457   { "PreferencesMenu",  NULL,                   N_("P_references"),                     NULL,                   NULL,                                   NULL },
1458   { "ViewMenu",         NULL,                   N_("_View"),                            NULL,                   NULL,                                   NULL },
1459   { "FileDirMenu",      NULL,                   N_("_Files and Folders"),               NULL,                   NULL,                                   NULL },
1460   { "ZoomMenu",         NULL,                   N_("_Zoom"),                            NULL,                   NULL,                                   NULL },
1461   { "ColorMenu",        NULL,                   N_("_Color Management"),                NULL,                   NULL,                                   NULL },
1462   { "ConnectZoomMenu",  NULL,                   N_("_Connected Zoom"),                  NULL,                   NULL,                                   NULL },
1463   { "SplitMenu",        NULL,                   N_("Spli_t"),                           NULL,                   NULL,                                   NULL },
1464   { "StereoMenu",       NULL,                   N_("Stere_o"),                          NULL,                   NULL,                                   NULL },
1465   { "OverlayMenu",      NULL,                   N_("Image _Overlay"),                   NULL,                   NULL,                                   NULL },
1466   { "HelpMenu",         NULL,                   N_("_Help"),                            NULL,                   NULL,                                   NULL },
1467
1468   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),                     "Home",                 N_("First Image"),                      CB(layout_menu_image_first_cb) },
1469   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "BackSpace",            N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1470   { "PrevImageAlt1",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "Page_Up",              N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1471   { "PrevImageAlt2",    GTK_STOCK_GO_UP,        N_("_Previous Image"),                  "KP_Page_Up",           N_("Previous Image"),                   CB(layout_menu_image_prev_cb) },
1472   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "space",                N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1473   { "NextImageAlt1",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "Page_Down",            N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1474   { "NextImageAlt2",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),                      "KP_Page_Down",         N_("Next Image"),                       CB(layout_menu_image_next_cb) },
1475   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),                      "End",                  N_("Last Image"),                       CB(layout_menu_image_last_cb) },
1476   { "Back",             GTK_STOCK_GO_BACK,      N_("_Back"),                            NULL,                   N_("Back"),                             CB(layout_menu_back_cb) },
1477   { "Home",             GTK_STOCK_HOME,         N_("_Home"),                            NULL,                   N_("Home"),                             CB(layout_menu_home_cb) },
1478   { "Up",               GTK_STOCK_GO_UP,        N_("_Up"),                              NULL,                   N_("Up"),                               CB(layout_menu_up_cb) },
1479
1480   { "NewWindow",        GTK_STOCK_NEW,          N_("New _window"),                      "<control>N",           N_("New window"),                       CB(layout_menu_new_window_cb) },
1481   { "NewCollection",    GTK_STOCK_INDEX,        N_("_New collection"),                  "C",                    N_("New collection"),                   CB(layout_menu_new_cb) },
1482   { "OpenCollection",   GTK_STOCK_OPEN,         N_("_Open collection..."),              "O",                    N_("Open collection..."),               CB(layout_menu_open_cb) },
1483   { "OpenRecent",       NULL,                   N_("Open recen_t"),                     NULL,                   N_("Open recent"),                      NULL },
1484   { "Search",           GTK_STOCK_FIND,         N_("_Search..."),                       "F3",                   N_("Search..."),                        CB(layout_menu_search_cb) },
1485   { "FindDupes",        GTK_STOCK_FIND,         N_("_Find duplicates..."),              "D",                    N_("Find duplicates..."),               CB(layout_menu_dupes_cb) },
1486   { "PanView",          NULL,                   N_("Pa_n view"),                        "<control>J",           N_("Pan view"),                         CB(layout_menu_pan_cb) },
1487   { "Print",            GTK_STOCK_PRINT,        N_("_Print..."),                        "<shift>P",             N_("Print..."),                         CB(layout_menu_print_cb) },
1488   { "NewFolder",        GTK_STOCK_DIRECTORY,    N_("N_ew folder..."),                   "<control>F",           N_("New folder..."),                    CB(layout_menu_dir_cb) },
1489   { "Copy",             GTK_STOCK_COPY,         N_("_Copy..."),                         "<control>C",           N_("Copy..."),                          CB(layout_menu_copy_cb) },
1490   { "Move",             NULL,                   N_("_Move..."),                         "<control>M",           N_("Move..."),                          CB(layout_menu_move_cb) },
1491   { "Rename",           NULL,                   N_("_Rename..."),                       "<control>R",           N_("Rename..."),                        CB(layout_menu_rename_cb) },
1492   { "Delete",           GTK_STOCK_DELETE,       N_("_Delete..."),                       "<control>D",           N_("Delete..."),                        CB(layout_menu_delete_cb) },
1493   { "DeleteAlt1",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "Delete",               N_("Delete..."),                        CB(layout_menu_delete_key_cb) },
1494   { "DeleteAlt2",       GTK_STOCK_DELETE,       N_("_Delete..."),                       "KP_Delete",            N_("Delete..."),                        CB(layout_menu_delete_key_cb) },
1495   { "EnableGrouping",   NULL,                   N_("Enable file _grouping"),            NULL,                   N_("Enable file grouping"),             CB(layout_menu_enable_grouping_cb) },
1496   { "DisableGrouping",  NULL,                   N_("Disable file groupi_ng"),           NULL,                   N_("Disable file grouping"),            CB(layout_menu_disable_grouping_cb) },
1497   { "CopyPath",         NULL,                   N_("_Copy path to clipboard"),          NULL,                   N_("Copy path to clipboard"),           CB(layout_menu_copy_path_cb) },
1498   { "CloseWindow",      GTK_STOCK_CLOSE,        N_("C_lose window"),                    "<control>W",           N_("Close window"),                     CB(layout_menu_close_cb) },
1499   { "Quit",             GTK_STOCK_QUIT,         N_("_Quit"),                            "<control>Q",           N_("Quit"),                             CB(layout_menu_exit_cb) },
1500   { "RotateCW",         NULL,                   N_("_Rotate clockwise"),                "bracketright",         N_("Rotate clockwise"),                 CB(layout_menu_alter_90_cb) },
1501   { "RotateCCW",        NULL,                   N_("Rotate _counterclockwise"),         "bracketleft",          N_("Rotate counterclockwise"),          CB(layout_menu_alter_90cc_cb) },
1502   { "Rotate180",        NULL,                   N_("Rotate 1_80"),                      "<shift>R",             N_("Rotate 180"),                       CB(layout_menu_alter_180_cb) },
1503   { "Mirror",           NULL,                   N_("_Mirror"),                          "<shift>M",             N_("Mirror"),                           CB(layout_menu_alter_mirror_cb) },
1504   { "Flip",             NULL,                   N_("_Flip"),                            "<shift>F",             N_("Flip"),                             CB(layout_menu_alter_flip_cb) },
1505   { "AlterNone",        NULL,                   N_("_Original state"),                  "<shift>O",             N_("Original state"),                   CB(layout_menu_alter_none_cb) },
1506   { "SelectAll",        NULL,                   N_("Select _all"),                      "<control>A",           N_("Select all"),                       CB(layout_menu_select_all_cb) },
1507   { "SelectNone",       NULL,                   N_("Select _none"),                     "<control><shift>A",    N_("Select none"),                      CB(layout_menu_unselect_all_cb) },
1508   { "SelectInvert",     NULL,                   N_("_Invert Selection"),                "<control><shift>I",    N_("Invert Selection"),                 CB(layout_menu_invert_selection_cb) },
1509   { "Preferences",      GTK_STOCK_PREFERENCES,  N_("P_references..."),                  "<control>O",           N_("Preferences..."),                   CB(layout_menu_config_cb) },
1510   { "Editors",          GTK_STOCK_PREFERENCES,  N_("Configure _Editors..."),            NULL,                   N_("Configure Editors..."),             CB(layout_menu_editors_cb) },
1511   { "LayoutConfig",     GTK_STOCK_PREFERENCES,  N_("_Configure this window..."),        NULL,                   N_("Configure this window..."),         CB(layout_menu_layout_config_cb) },
1512   { "Maintenance",      NULL,                   N_("_Thumbnail maintenance..."),        NULL,                   N_("Thumbnail maintenance..."),         CB(layout_menu_remove_thumb_cb) },
1513   { "Wallpaper",        NULL,                   N_("Set as _wallpaper"),                NULL,                   N_("Set as wallpaper"),                 CB(layout_menu_wallpaper_cb) },
1514   { "SaveMetadata",     GTK_STOCK_SAVE,         N_("_Save metadata"),                   "<control>S",           N_("Save metadata"),                    CB(layout_menu_metadata_write_cb) },
1515   { "ZoomIn",           GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "equal",                N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1516   { "ZoomInAlt1",       GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "KP_Add",               N_("Zoom in"),                          CB(layout_menu_zoom_in_cb) },
1517   { "ZoomOut",          GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "minus",                N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1518   { "ZoomOutAlt1",      GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "KP_Subtract",          N_("Zoom out"),                         CB(layout_menu_zoom_out_cb) },
1519   { "Zoom100",          GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "Z",                    N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1520   { "Zoom100Alt1",      GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "KP_Divide",            N_("Zoom 1:1"),                         CB(layout_menu_zoom_1_1_cb) },
1521   { "ZoomFit",          GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "X",                    N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1522   { "ZoomFitAlt1",      GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "KP_Multiply",          N_("Zoom to fit"),                      CB(layout_menu_zoom_fit_cb) },
1523   { "ZoomFillHor",      NULL,                   N_("Fit _Horizontally"),                "H",                    N_("Fit Horizontally"),                 CB(layout_menu_zoom_fit_hor_cb) },
1524   { "ZoomFillVert",     NULL,                   N_("Fit _Vertically"),                  "W",                    N_("Fit Vertically"),                   CB(layout_menu_zoom_fit_vert_cb) },
1525   { "Zoom200",          NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Zoom 2:1"),                         CB(layout_menu_zoom_2_1_cb) },
1526   { "Zoom300",          NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Zoom 3:1"),                         CB(layout_menu_zoom_3_1_cb) },
1527   { "Zoom400",          NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Zoom 4:1"),                         CB(layout_menu_zoom_4_1_cb) },
1528   { "Zoom50",           NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Zoom 1:2"),                         CB(layout_menu_zoom_1_2_cb) },
1529   { "Zoom33",           NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Zoom 1:3"),                         CB(layout_menu_zoom_1_3_cb) },
1530   { "Zoom25",           NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Zoom 1:4"),                         CB(layout_menu_zoom_1_4_cb) },
1531   { "ConnectZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "plus",                 N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1532   { "ConnectZoomInAlt1",GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),                         "<shift>KP_Add",        N_("Connected Zoom in"),                CB(layout_menu_connect_zoom_in_cb) },
1533   { "ConnectZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),                        "underscore",           N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1534   { "ConnectZoomOutAlt1",GTK_STOCK_ZOOM_OUT,    N_("Zoom _out"),                        "<shift>KP_Subtract",   N_("Connected Zoom out"),               CB(layout_menu_connect_zoom_out_cb) },
1535   { "ConnectZoom100",   GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),                        "<shift>Z",             N_("Connected Zoom 1:1"),               CB(layout_menu_connect_zoom_1_1_cb) },
1536   { "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) },
1537   { "ConnectZoomFit",   GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),                     "<shift>X",             N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1538   { "ConnectZoomFitAlt1",GTK_STOCK_ZOOM_FIT,    N_("_Zoom to fit"),                     "<shift>KP_Multiply",   N_("Connected Zoom to fit"),            CB(layout_menu_connect_zoom_fit_cb) },
1539   { "ConnectZoomFillHor",NULL,                  N_("Fit _Horizontally"),                "<shift>H",             N_("Connected Fit Horizontally"),       CB(layout_menu_connect_zoom_fit_hor_cb) },
1540   { "ConnectZoomFillVert",NULL,                 N_("Fit _Vertically"),                  "<shift>W",             N_("Connected Fit Vertically"),         CB(layout_menu_connect_zoom_fit_vert_cb) },
1541   { "ConnectZoom200",   NULL,                   N_("Zoom _2:1"),                        NULL,                   N_("Connected Zoom 2:1"),               CB(layout_menu_connect_zoom_2_1_cb) },
1542   { "ConnectZoom300",   NULL,                   N_("Zoom _3:1"),                        NULL,                   N_("Connected Zoom 3:1"),               CB(layout_menu_connect_zoom_3_1_cb) },
1543   { "ConnectZoom400",   NULL,                   N_("Zoom _4:1"),                        NULL,                   N_("Connected Zoom 4:1"),               CB(layout_menu_connect_zoom_4_1_cb) },
1544   { "ConnectZoom50",    NULL,                   N_("Zoom 1:2"),                         NULL,                   N_("Connected Zoom 1:2"),               CB(layout_menu_connect_zoom_1_2_cb) },
1545   { "ConnectZoom33",    NULL,                   N_("Zoom 1:3"),                         NULL,                   N_("Connected Zoom 1:3"),               CB(layout_menu_connect_zoom_1_3_cb) },
1546   { "ConnectZoom25",    NULL,                   N_("Zoom 1:4"),                         NULL,                   N_("Connected Zoom 1:4"),               CB(layout_menu_connect_zoom_1_4_cb) },
1547   { "ViewInNewWindow",  NULL,                   N_("_View in new window"),              "<control>V",           N_("View in new window"),               CB(layout_menu_view_in_new_window_cb) },
1548   { "FullScreen",       GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1549   { "FullScreenAlt1",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "V",                    N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1550   { "FullScreenAlt2",   GTK_STOCK_FULLSCREEN,   N_("F_ull screen"),                     "F11",                  N_("Full screen"),                      CB(layout_menu_fullscreen_cb) },
1551   { "Escape",           GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Escape",               N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1552   { "EscapeAlt1",       GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),            "Q",                    N_("Leave full screen"),                CB(layout_menu_escape_cb) },
1553   { "ImageOverlayCycle",NULL,                   N_("_Cycle through overlay modes"),     "I",                    N_("Cycle through Overlay modes"),      CB(layout_menu_overlay_toggle_cb) },
1554   { "HistogramChanCycle",NULL,                  N_("Cycle through histogram ch_annels"),"K",                    N_("Cycle through histogram channels"), CB(layout_menu_histogram_toggle_channel_cb) },
1555   { "HistogramModeCycle",NULL,                  N_("Cycle through histogram mo_des"),   "J",                    N_("Cycle through histogram modes"),    CB(layout_menu_histogram_toggle_mode_cb) },
1556   { "HideTools",        NULL,                   N_("_Hide file list"),                  "<control>H",           N_("Hide file list"),                   CB(layout_menu_hide_cb) },
1557   { "SlideShowPause",   GTK_STOCK_MEDIA_PAUSE,  N_("_Pause slideshow"),                 "P",                    N_("Pause slideshow"),                  CB(layout_menu_slideshow_pause_cb) },
1558   { "Refresh",          GTK_STOCK_REFRESH,      N_("_Refresh"),                         "R",                    N_("Refresh"),                          CB(layout_menu_refresh_cb) },
1559   { "HelpContents",     GTK_STOCK_HELP,         N_("_Contents"),                        "F1",                   N_("Contents"),                         CB(layout_menu_help_cb) },
1560   { "HelpShortcuts",    NULL,                   N_("_Keyboard shortcuts"),              NULL,                   N_("Keyboard shortcuts"),               CB(layout_menu_help_keys_cb) },
1561   { "HelpKbd",          NULL,                   N_("_Keyboard map"),                    NULL,                   N_("Keyboard map"),                     CB(layout_menu_kbd_map_cb) },
1562   { "HelpNotes",        NULL,                   N_("_Release notes"),                   NULL,                   N_("Release notes"),                    CB(layout_menu_notes_cb) },
1563   { "About",            GTK_STOCK_ABOUT,        N_("_About"),                           NULL,                   N_("About"),                            CB(layout_menu_about_cb) },
1564   { "LogWindow",        NULL,                   N_("_Log Window"),                      NULL,                   N_("Log Window"),                       CB(layout_menu_log_window_cb) },
1565   { "ExifWin",          NULL,                   N_("_Exif window"),                     "<control>E",           N_("Exif window"),                      CB(layout_menu_bar_exif_cb) },
1566   { "StereoCycle",      NULL,                   N_("_Cycle through stereo modes"),      NULL,                   N_("Cycle through stereo modes"),       CB(layout_menu_stereo_mode_next_cb) },
1567
1568 };
1569
1570 static GtkToggleActionEntry menu_toggle_entries[] = {
1571   { "Thumbnails",       PIXBUF_INLINE_ICON_THUMB,N_("Show _Thumbnails"),                "T",                    N_("Show Thumbnails"),                  CB(layout_menu_thumb_cb),        FALSE },
1572   { "ShowMarks",        NULL,                   N_("Show _Marks"),                      "M",                    N_("Show Marks"),                       CB(layout_menu_marks_cb),        FALSE  },
1573   { "ShowInfoPixel",    GTK_STOCK_COLOR_PICKER, N_("Pi_xel Info"),                      NULL,                   N_("Show Pixel Info"),                  CB(layout_menu_info_pixel_cb),   FALSE  },
1574   { "FloatTools",       PIXBUF_INLINE_ICON_FLOAT,N_("_Float file list"),                "L",                    N_("Float file list"),                  CB(layout_menu_float_cb),        FALSE  },
1575   { "HideToolbar",      NULL,                   N_("Hide tool_bar"),                    NULL,                   N_("Hide toolbar"),                     CB(layout_menu_toolbar_cb),      FALSE  },
1576   { "SBar",             NULL,                   N_("_Info sidebar"),                    "<control>K",           N_("Info sidebar"),                     CB(layout_menu_bar_cb),          FALSE  },
1577   { "SBarSort",         NULL,                   N_("Sort _manager"),                    "<shift>S",             N_("Sort manager"),                     CB(layout_menu_bar_sort_cb),     FALSE  },
1578   { "SlideShow",        GTK_STOCK_MEDIA_PLAY,   N_("Toggle _slideshow"),                "S",                    N_("Toggle slideshow"),                 CB(layout_menu_slideshow_cb),    FALSE  },
1579   { "UseColorProfiles", GTK_STOCK_SELECT_COLOR, N_("Use _color profiles"),              NULL,                   N_("Use color profiles"),               CB(layout_color_menu_enable_cb), FALSE},
1580   { "UseImageProfile",  NULL,                   N_("Use profile from _image"),          NULL,                   N_("Use profile from image"),           CB(layout_color_menu_use_image_cb), FALSE},
1581   { "Grayscale",        NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
1582   { "ImageOverlay",     NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
1583   { "ImageHistogram",   NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
1584 };
1585
1586 static GtkRadioActionEntry menu_radio_entries[] = {
1587   { "ViewList",         NULL,                   N_("Image _List"),                      "<control>L",           N_("View Images as List"),              FILEVIEW_LIST },
1588   { "ViewIcons",        NULL,                   N_("I_cons"),                           "<control>I",           N_("View Images as Icons"),             FILEVIEW_ICON }
1589 };
1590
1591 static GtkRadioActionEntry menu_view_dir_radio_entries[] = {
1592   { "FolderList",       NULL,                   N_("Folder Li_st"),                     "<meta>L",              N_("View Folders as List"),             DIRVIEW_LIST },
1593   { "FolderTree",       NULL,                   N_("Folder T_ree"),                     "<control>T",           N_("View Folders as Tree"),             DIRVIEW_TREE },
1594 };
1595
1596 static GtkRadioActionEntry menu_split_radio_entries[] = {
1597   { "SplitHorizontal",  NULL,                   N_("_Horizontal"),                      "E",                    N_("Split Horizontal"),                 SPLIT_HOR },
1598   { "SplitVertical",    NULL,                   N_("_Vertical"),                        "U",                    N_("Split Vertical"),                           SPLIT_VERT },
1599   { "SplitQuad",        NULL,                   N_("_Quad"),                            NULL,                   N_("Split Quad"),                               SPLIT_QUAD },
1600   { "SplitSingle",      NULL,                   N_("_Single"),                          "Y",                    N_("Split Single"),                             SPLIT_NONE }
1601 };
1602
1603 static GtkRadioActionEntry menu_color_radio_entries[] = {
1604   { "ColorProfile0",    NULL,                   N_("Input _0: sRGB"),                   NULL,                   N_("Input 0: sRGB"),                    COLOR_PROFILE_SRGB },
1605   { "ColorProfile1",    NULL,                   N_("Input _1: AdobeRGB compatible"),    NULL,                   N_("Input 1: AdobeRGB compatible"),     COLOR_PROFILE_ADOBERGB },
1606   { "ColorProfile2",    NULL,                   N_("Input _2"),                         NULL,                   N_("Input 2"),                          COLOR_PROFILE_FILE },
1607   { "ColorProfile3",    NULL,                   N_("Input _3"),                         NULL,                   N_("Input 3"),                          COLOR_PROFILE_FILE + 1 },
1608   { "ColorProfile4",    NULL,                   N_("Input _4"),                         NULL,                   N_("Input 4"),                          COLOR_PROFILE_FILE + 2 },
1609   { "ColorProfile5",    NULL,                   N_("Input _5"),                         NULL,                   N_("Input 5"),                          COLOR_PROFILE_FILE + 3 }
1610 };
1611
1612 static GtkRadioActionEntry menu_histogram_channel[] = {
1613   { "HistogramChanR",   NULL,                   N_("Histogram on _Red"),                NULL,                   N_("Histogram on Red"),         HCHAN_R },
1614   { "HistogramChanG",   NULL,                   N_("Histogram on _Green"),              NULL,                   N_("Histogram on Green"),       HCHAN_G },
1615   { "HistogramChanB",   NULL,                   N_("Histogram on _Blue"),               NULL,                   N_("Histogram on Blue"),        HCHAN_B },
1616   { "HistogramChanRGB", NULL,                   N_("_Histogram on RGB"),                        NULL,                   N_("Histogram on RGB"),         HCHAN_RGB },
1617   { "HistogramChanV",   NULL,                   N_("Histogram on _Value"),              NULL,                   N_("Histogram on Value"),       HCHAN_MAX }
1618 };
1619
1620 static GtkRadioActionEntry menu_histogram_mode[] = {
1621   { "HistogramModeLin", NULL,                   N_("Li_near Histogram"),                NULL,                   N_("Linear Histogram"),         0 },
1622   { "HistogramModeLog", NULL,                   N_("_Log Histogram"),                   NULL,                   N_("Log Histogram"),            1 },
1623 };
1624
1625 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
1626   { "StereoAuto",       NULL,                   N_("_Auto"),                            NULL,                   N_("Stereo Auto"),              STEREO_PIXBUF_DEFAULT },
1627   { "StereoSBS",        NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      STEREO_PIXBUF_SBS },
1628   { "StereoCross",      NULL,                   N_("_Cross"),                           NULL,                   N_("Stereo Cross"),             STEREO_PIXBUF_CROSS },
1629   { "StereoOff",        NULL,                   N_("_Off"),                             NULL,                   N_("Stereo Off"),               STEREO_PIXBUF_NONE }
1630 };
1631
1632
1633 #undef CB
1634
1635 static const gchar *menu_ui_description =
1636 "<ui>"
1637 "  <menubar name='MainMenu'>"
1638 "    <menu action='FileMenu'>"
1639 "      <menuitem action='NewWindow'/>"
1640 "      <menuitem action='NewCollection'/>"
1641 "      <menuitem action='OpenCollection'/>"
1642 "      <menuitem action='OpenRecent'/>"
1643 "      <placeholder name='OpenSection'/>"
1644 "      <separator/>"
1645 "      <menuitem action='Search'/>"
1646 "      <menuitem action='FindDupes'/>"
1647 "      <placeholder name='SearchSection'/>"
1648 "      <separator/>"
1649 "      <menuitem action='Print'/>"
1650 "      <placeholder name='PrintSection'/>"
1651 "      <separator/>"
1652 "      <menuitem action='NewFolder'/>"
1653 "      <menuitem action='Copy'/>"
1654 "      <menuitem action='Move'/>"
1655 "      <menuitem action='Rename'/>"
1656 "      <menuitem action='Delete'/>"
1657 "      <placeholder name='FileOpsSection'/>"
1658 "      <separator/>"
1659 "      <placeholder name='QuitSection'/>"
1660 "      <menuitem action='CloseWindow'/>"
1661 "      <menuitem action='Quit'/>"
1662 "      <separator/>"
1663 "    </menu>"
1664 "    <menu action='GoMenu'>"
1665 "      <menuitem action='FirstImage'/>"
1666 "      <menuitem action='PrevImage'/>"
1667 "      <menuitem action='NextImage'/>"
1668 "      <menuitem action='LastImage'/>"
1669 "      <separator/>"
1670 "      <menuitem action='Back'/>"
1671 "      <menuitem action='Up'/>"
1672 "      <menuitem action='Home'/>"
1673 "      <separator/>"
1674 "    </menu>"
1675 "    <menu action='SelectMenu'>"
1676 "      <menuitem action='SelectAll'/>"
1677 "      <menuitem action='SelectNone'/>"
1678 "      <menuitem action='SelectInvert'/>"
1679 "      <placeholder name='SelectSection'/>"
1680 "      <separator/>"
1681 "      <menuitem action='CopyPath'/>"
1682 "      <placeholder name='ClipboardSection'/>"
1683 "      <separator/>"
1684 "      <menuitem action='ShowMarks'/>"
1685 "      <placeholder name='MarksSection'/>"
1686 "      <separator/>"
1687 "    </menu>"
1688 "    <menu action='EditMenu'>"
1689 "      <menu action='ExternalMenu'>"
1690 "      </menu>"
1691 "      <placeholder name='EditSection'/>"
1692 "      <separator/>"
1693 "      <menu action='OrientationMenu'>"
1694 "        <menuitem action='RotateCW'/>"
1695 "        <menuitem action='RotateCCW'/>"
1696 "        <menuitem action='Rotate180'/>"
1697 "        <menuitem action='Mirror'/>"
1698 "        <menuitem action='Flip'/>"
1699 "        <menuitem action='AlterNone'/>"
1700 "      </menu>"
1701 "      <menuitem action='SaveMetadata'/>"
1702 "      <placeholder name='PropertiesSection'/>"
1703 "      <separator/>"
1704 "        <menu action='PreferencesMenu'>"
1705 "        <menuitem action='Preferences'/>"
1706 "        <menuitem action='Editors'/>"
1707 "        <menuitem action='LayoutConfig'/>"
1708 "        <menuitem action='Maintenance'/>"
1709 "      </menu>"
1710 "      <placeholder name='PreferencesSection'/>"
1711 "      <separator/>"
1712 "      <menuitem action='Wallpaper'/>"
1713 "      <separator/>"
1714 "    </menu>"
1715 "    <menu action='ViewMenu'>"
1716 "      <menuitem action='ViewInNewWindow'/>"
1717 "      <menuitem action='PanView'/>"
1718 "      <menuitem action='ExifWin'/>"
1719 "      <placeholder name='WindowSection'/>"
1720 "      <separator/>"
1721 "      <menu action='FileDirMenu'>"
1722 "        <menuitem action='FolderList'/>"
1723 "        <menuitem action='FolderTree'/>"
1724 "        <placeholder name='FolderSection'/>"
1725 "        <separator/>"
1726 "        <menuitem action='ViewList'/>"
1727 "        <menuitem action='ViewIcons'/>"
1728 "        <menuitem action='Thumbnails'/>"
1729 "        <placeholder name='ListSection'/>"
1730 "        <separator/>"
1731 "        <menuitem action='FloatTools'/>"
1732 "        <menuitem action='HideTools'/>"
1733 "        <menuitem action='HideToolbar'/>"
1734 "      </menu>"
1735 "      <placeholder name='DirSection'/>"
1736 "      <separator/>"
1737 "      <menu action='ZoomMenu'>"
1738 "        <menu action='ConnectZoomMenu'>"
1739 "          <menuitem action='ConnectZoomIn'/>"
1740 "          <menuitem action='ConnectZoomOut'/>"
1741 "          <menuitem action='ConnectZoomFit'/>"
1742 "          <menuitem action='ConnectZoomFillHor'/>"
1743 "          <menuitem action='ConnectZoomFillVert'/>"
1744 "          <menuitem action='ConnectZoom100'/>"
1745 "          <menuitem action='ConnectZoom200'/>"
1746 "          <menuitem action='ConnectZoom300'/>"
1747 "          <menuitem action='ConnectZoom400'/>"
1748 "          <menuitem action='ConnectZoom50'/>"
1749 "          <menuitem action='ConnectZoom33'/>"
1750 "          <menuitem action='ConnectZoom25'/>"
1751 "        </menu>"
1752 "        <menuitem action='ZoomIn'/>"
1753 "        <menuitem action='ZoomOut'/>"
1754 "        <menuitem action='ZoomFit'/>"
1755 "        <menuitem action='ZoomFillHor'/>"
1756 "        <menuitem action='ZoomFillVert'/>"
1757 "        <menuitem action='Zoom100'/>"
1758 "        <menuitem action='Zoom200'/>"
1759 "        <menuitem action='Zoom300'/>"
1760 "        <menuitem action='Zoom400'/>"
1761 "        <menuitem action='Zoom50'/>"
1762 "        <menuitem action='Zoom33'/>"
1763 "        <menuitem action='Zoom25'/>"
1764 "      </menu>"
1765 "      <menu action='SplitMenu'>"
1766 "        <menuitem action='SplitHorizontal'/>"
1767 "        <menuitem action='SplitVertical'/>"
1768 "        <menuitem action='SplitQuad'/>"
1769 "        <menuitem action='SplitSingle'/>"
1770 "      </menu>"
1771 "      <menu action='StereoMenu'>"
1772 "        <menuitem action='StereoAuto'/>"
1773 "        <menuitem action='StereoSBS'/>"
1774 "        <menuitem action='StereoCross'/>"
1775 "        <menuitem action='StereoOff'/>"
1776 "        <separator/>"
1777 "        <menuitem action='StereoCycle'/>"
1778 "      </menu>"
1779 "      <menu action='ColorMenu'>"
1780 "        <menuitem action='UseColorProfiles'/>"
1781 "        <menuitem action='UseImageProfile'/>"
1782 "        <menuitem action='ColorProfile0'/>"
1783 "        <menuitem action='ColorProfile1'/>"
1784 "        <menuitem action='ColorProfile2'/>"
1785 "        <menuitem action='ColorProfile3'/>"
1786 "        <menuitem action='ColorProfile4'/>"
1787 "        <menuitem action='ColorProfile5'/>"
1788 "        <separator/>"
1789 "        <menuitem action='Grayscale'/>"
1790 "      </menu>"
1791 "      <menu action='OverlayMenu'>"
1792 "        <menuitem action='ImageOverlay'/>"
1793 "        <menuitem action='ImageHistogram'/>"
1794 "        <menuitem action='ImageOverlayCycle'/>"
1795 "        <separator/>"
1796 "        <menuitem action='HistogramChanR'/>"
1797 "        <menuitem action='HistogramChanG'/>"
1798 "        <menuitem action='HistogramChanB'/>"
1799 "        <menuitem action='HistogramChanRGB'/>"
1800 "        <menuitem action='HistogramChanV'/>"
1801 "        <menuitem action='HistogramChanCycle'/>"
1802 "        <separator/>"
1803 "        <menuitem action='HistogramModeLin'/>"
1804 "        <menuitem action='HistogramModeLog'/>"
1805 "        <menuitem action='HistogramModeCycle'/>"
1806 "      </menu>"
1807 "      <menuitem action='FullScreen'/>"
1808 "      <placeholder name='ViewSection'/>"
1809 "      <separator/>"
1810 "      <menuitem action='SBar'/>"
1811 "      <menuitem action='SBarSort'/>"
1812 "      <menuitem action='ShowInfoPixel'/>"
1813 "      <placeholder name='ToolsSection'/>"
1814 "      <separator/>"
1815 "      <menuitem action='SlideShow'/>"
1816 "      <menuitem action='SlideShowPause'/>"
1817 "      <menuitem action='Refresh'/>"
1818 "      <placeholder name='SlideShowSection'/>"
1819 "      <separator/>"
1820 "    </menu>"
1821 "    <menu action='HelpMenu'>"
1822 "      <separator/>"
1823 "      <menuitem action='HelpContents'/>"
1824 "      <menuitem action='HelpShortcuts'/>"
1825 "      <menuitem action='HelpKbd'/>"
1826 "      <menuitem action='HelpNotes'/>"
1827 "      <placeholder name='HelpSection'/>"
1828 "      <separator/>"
1829 "      <menuitem action='About'/>"
1830 "      <separator/>"
1831 "      <menuitem action='LogWindow'/>"
1832 "      <separator/>"
1833 "    </menu>"
1834 "  </menubar>"
1835 "  <toolbar name='ToolBar'>"
1836 "    <toolitem action='Thumbnails'/>"
1837 "    <toolitem action='Back'/>"
1838 "    <toolitem action='Up'/>"
1839 "    <toolitem action='Home'/>"
1840 "    <toolitem action='Refresh'/>"
1841 "    <toolitem action='ZoomIn'/>"
1842 "    <toolitem action='ZoomOut'/>"
1843 "    <toolitem action='ZoomFit'/>"
1844 "    <toolitem action='Zoom100'/>"
1845 "    <toolitem action='Preferences'/>"
1846 "    <toolitem action='FloatTools'/>"
1847 "  </toolbar>"
1848 "  <toolbar name='StatusBar'>"
1849 "    <toolitem action='ShowInfoPixel'/>"
1850 "    <toolitem action='UseColorProfiles'/>"
1851 "    <toolitem action='SaveMetadata'/>"
1852 "  </toolbar>"
1853 "<accelerator action='PrevImageAlt1'/>"
1854 "<accelerator action='PrevImageAlt2'/>"
1855 "<accelerator action='NextImageAlt1'/>"
1856 "<accelerator action='NextImageAlt2'/>"
1857 "<accelerator action='DeleteAlt1'/>"
1858 "<accelerator action='DeleteAlt2'/>"
1859 "<accelerator action='FullScreenAlt1'/>"
1860 "<accelerator action='FullScreenAlt2'/>"
1861 "<accelerator action='Escape'/>"
1862 "<accelerator action='EscapeAlt1'/>"
1863
1864 "<accelerator action='ZoomInAlt1'/>"
1865 "<accelerator action='ZoomOutAlt1'/>"
1866 "<accelerator action='Zoom100Alt1'/>"
1867 "<accelerator action='ZoomFitAlt1'/>"
1868
1869 "<accelerator action='ConnectZoomInAlt1'/>"
1870 "<accelerator action='ConnectZoomOutAlt1'/>"
1871 "<accelerator action='ConnectZoom100Alt1'/>"
1872 "<accelerator action='ConnectZoomFitAlt1'/>"
1873 "</ui>";
1874
1875 static gchar *menu_translate(const gchar *path, gpointer data)
1876 {
1877         return (gchar *)(_(path));
1878 }
1879
1880 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl,
1881                                       gchar *label_tmpl, gchar *accel_tmpl, gchar *tooltip_tmpl, GCallback cb)
1882 {
1883         gchar name[50];
1884         gchar label[100];
1885         gchar accel[50];
1886         gchar tooltip[100];
1887         GtkActionEntry entry = { name, NULL, label, accel, tooltip, cb };
1888         GtkAction *action;
1889
1890         g_snprintf(name, sizeof(name), name_tmpl, mark);
1891         g_snprintf(label, sizeof(label), label_tmpl, mark);
1892
1893         if (accel_tmpl)
1894                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
1895         else
1896                 entry.accelerator = NULL;
1897
1898         if (tooltip_tmpl)
1899                 g_snprintf(tooltip, sizeof(tooltip), tooltip_tmpl, mark);
1900         else
1901                 entry.tooltip = NULL;
1902
1903         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
1904         action = gtk_action_group_get_action(lw->action_group, name);
1905         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark));
1906 }
1907
1908 static void layout_actions_setup_marks(LayoutWindow *lw)
1909 {
1910         gint mark;
1911         GError *error;
1912         GString *desc = g_string_new(
1913                                 "<ui>"
1914                                 "  <menubar name='MainMenu'>"
1915                                 "    <menu action='SelectMenu'>");
1916
1917         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1918                 {
1919                 layout_actions_setup_mark(lw, mark, "Mark%d",           _("Mark _%d"), NULL, NULL, NULL);
1920                 layout_actions_setup_mark(lw, mark, "SetMark%d",        _("_Set mark %d"),                      NULL,           _("Set mark %d"), G_CALLBACK(layout_menu_set_mark_sel_cb));
1921                 layout_actions_setup_mark(lw, mark, "ResetMark%d",      _("_Reset mark %d"),                    NULL,           _("Reset mark %d"), G_CALLBACK(layout_menu_res_mark_sel_cb));
1922                 layout_actions_setup_mark(lw, mark, "ToggleMark%d",     _("_Toggle mark %d"),                   "%d",           _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1923                 layout_actions_setup_mark(lw, mark, "ToggleMark%dAlt1", _("_Toggle mark %d"),                   "KP_%d",        _("Toggle mark %d"), G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1924                 layout_actions_setup_mark(lw, mark, "SelectMark%d",     _("Se_lect mark %d"),                   "<control>%d",  _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1925                 layout_actions_setup_mark(lw, mark, "SelectMark%dAlt1", _("_Select mark %d"),                   "<control>KP_%d", _("Select mark %d"), G_CALLBACK(layout_menu_sel_mark_cb));
1926                 layout_actions_setup_mark(lw, mark, "AddMark%d",        _("_Add mark %d"),                      NULL,           _("Add mark %d"), G_CALLBACK(layout_menu_sel_mark_or_cb));
1927                 layout_actions_setup_mark(lw, mark, "IntMark%d",        _("_Intersection with mark %d"),        NULL,           _("Intersection with mark %d"), G_CALLBACK(layout_menu_sel_mark_and_cb));
1928                 layout_actions_setup_mark(lw, mark, "UnselMark%d",      _("_Unselect mark %d"),                 NULL,           _("Unselect mark %d"), G_CALLBACK(layout_menu_sel_mark_minus_cb));
1929                 layout_actions_setup_mark(lw, mark, "FilterMark%d",     _("_Filter mark %d"),                   NULL,           _("Filter mark %d"), G_CALLBACK(layout_menu_mark_filter_toggle_cb));
1930
1931                 g_string_append_printf(desc,
1932                                 "      <menu action='Mark%d'>"
1933                                 "        <menuitem action='ToggleMark%d'/>"
1934                                 "        <menuitem action='SetMark%d'/>"
1935                                 "        <menuitem action='ResetMark%d'/>"
1936                                 "        <separator/>"
1937                                 "        <menuitem action='SelectMark%d'/>"
1938                                 "        <menuitem action='AddMark%d'/>"
1939                                 "        <menuitem action='IntMark%d'/>"
1940                                 "        <menuitem action='UnselMark%d'/>"
1941                                 "        <separator/>"
1942                                 "        <menuitem action='FilterMark%d'/>"
1943                                 "      </menu>",
1944                                 mark, mark, mark, mark, mark, mark, mark, mark, mark);
1945                 }
1946
1947         g_string_append(desc,
1948                                 "    </menu>"
1949                                 "  </menubar>");
1950         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1951                 {
1952                 g_string_append_printf(desc,
1953                                 "<accelerator action='ToggleMark%dAlt1'/>"
1954                                 "<accelerator action='SelectMark%dAlt1'/>",
1955                                 mark, mark);
1956                 }
1957         g_string_append(desc,   "</ui>" );
1958
1959         error = NULL;
1960         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
1961                 {
1962                 g_message("building menus failed: %s", error->message);
1963                 g_error_free(error);
1964                 exit(EXIT_FAILURE);
1965                 }
1966         g_string_free(desc, TRUE);
1967 }
1968
1969 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
1970 {
1971         gchar **split = g_strsplit(editor->menu_path, "/", 0);
1972         gint i = 0;
1973         GList *ret = NULL;
1974
1975         if (split[0] == NULL)
1976                 {
1977                 g_strfreev(split);
1978                 return NULL;
1979                 }
1980
1981         while (split[i])
1982                 {
1983                 ret = g_list_prepend(ret, g_strdup(split[i]));
1984                 i++;
1985                 }
1986
1987         g_strfreev(split);
1988
1989         ret = g_list_prepend(ret, g_strdup(editor->key));
1990
1991         return g_list_reverse(ret);
1992 }
1993
1994 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
1995 {
1996         gint to_open, to_close, i;
1997         while (path && old_path && strcmp((gchar *)path->data, (gchar *)old_path->data) == 0)
1998                 {
1999                 path = path->next;
2000                 old_path = old_path->next;
2001                 }
2002         to_open = g_list_length(path) - 1;
2003         to_close = g_list_length(old_path) - 1;
2004
2005         if (to_close > 0)
2006                 {
2007                 old_path = g_list_last(old_path);
2008                 old_path = old_path->prev;
2009                 }
2010
2011         for (i =  0; i < to_close; i++)
2012                 {
2013                 gchar *name = old_path->data;
2014                 if (g_str_has_suffix(name, "Section"))
2015                         {
2016                         g_string_append(desc,   "      </placeholder>");
2017                         }
2018                 else if (g_str_has_suffix(name, "Menu"))
2019                         {
2020                         g_string_append(desc,   "    </menu>");
2021                         }
2022                 else
2023                         {
2024                         g_warning("invalid menu path item %s", name);
2025                         }
2026                 old_path = old_path->prev;
2027                 }
2028
2029         for (i =  0; i < to_open; i++)
2030                 {
2031                 gchar *name = path->data;
2032                 if (g_str_has_suffix(name, "Section"))
2033                         {
2034                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
2035                         }
2036                 else if (g_str_has_suffix(name, "Menu"))
2037                         {
2038                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
2039                         }
2040                 else
2041                         {
2042                         g_warning("invalid menu path item %s", name);
2043                         }
2044                 path = path->next;
2045                 }
2046
2047         if (path)
2048                 g_string_append_printf(desc, "      <menuitem action='%s'/>", (gchar *)path->data);
2049 }
2050
2051 static void layout_actions_setup_editors(LayoutWindow *lw)
2052 {
2053         GError *error;
2054         GList *editors_list;
2055         GList *work;
2056         GList *old_path;
2057         GString *desc;
2058
2059         if (lw->ui_editors_id)
2060                 {
2061                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
2062                 }
2063
2064         if (lw->action_group_editors)
2065                 {
2066                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
2067                 g_object_unref(lw->action_group_editors);
2068                 }
2069         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
2070         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
2071
2072         /* lw->action_group_editors contains translated entries, no translate func is required */
2073         desc = g_string_new(
2074                                 "<ui>"
2075                                 "  <menubar name='MainMenu'>");
2076
2077         editors_list = editor_list_get();
2078
2079         old_path = NULL;
2080         work = editors_list;
2081         while (work)
2082                 {
2083                 GList *path;
2084                 EditorDescription *editor = work->data;
2085                 GtkActionEntry entry = { editor->key,
2086                                          NULL,
2087                                          editor->name,
2088                                          editor->hotkey,
2089                                          editor->comment ? editor->comment : editor->name,
2090                                          G_CALLBACK(layout_menu_edit_cb) };
2091
2092                 if (editor->icon)
2093                         {
2094                         entry.stock_id = editor->key;
2095                         }
2096                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
2097
2098                 path = layout_actions_editor_menu_path(editor);
2099                 layout_actions_editor_add(desc, path, old_path);
2100
2101                 string_list_free(old_path);
2102                 old_path = path;
2103                 work = work->next;
2104                 }
2105
2106         layout_actions_editor_add(desc, NULL, old_path);
2107         string_list_free(old_path);
2108
2109         g_string_append(desc,   "  </menubar>"
2110                                 "</ui>" );
2111
2112         error = NULL;
2113
2114         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
2115         if (!lw->ui_editors_id)
2116                 {
2117                 g_message("building menus failed: %s", error->message);
2118                 g_error_free(error);
2119                 exit(EXIT_FAILURE);
2120                 }
2121         g_string_free(desc, TRUE);
2122         g_list_free(editors_list);
2123 }
2124
2125 void layout_actions_setup(LayoutWindow *lw)
2126 {
2127         GError *error;
2128         gint i;
2129
2130         DEBUG_1("%s layout_actions_setup: start", get_exec_time());
2131         if (lw->ui_manager) return;
2132
2133         lw->action_group = gtk_action_group_new("MenuActions");
2134         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
2135
2136         gtk_action_group_add_actions(lw->action_group,
2137                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
2138         gtk_action_group_add_toggle_actions(lw->action_group,
2139                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
2140         gtk_action_group_add_radio_actions(lw->action_group,
2141                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
2142                                            0, G_CALLBACK(layout_menu_list_cb), lw);
2143         gtk_action_group_add_radio_actions(lw->action_group,
2144                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
2145                                            0, G_CALLBACK(layout_menu_split_cb), lw);
2146         gtk_action_group_add_radio_actions(lw->action_group,
2147                                            menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
2148                                            0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);
2149         gtk_action_group_add_radio_actions(lw->action_group,
2150                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
2151                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
2152         gtk_action_group_add_radio_actions(lw->action_group,
2153                                            menu_histogram_channel, G_N_ELEMENTS(menu_histogram_channel),
2154                                            0, G_CALLBACK(layout_menu_histogram_channel_cb), lw);
2155         gtk_action_group_add_radio_actions(lw->action_group,
2156                                            menu_histogram_mode, G_N_ELEMENTS(menu_histogram_mode),
2157                                            0, G_CALLBACK(layout_menu_histogram_mode_cb), lw);
2158         gtk_action_group_add_radio_actions(lw->action_group,
2159                                            menu_stereo_mode_entries, G_N_ELEMENTS(menu_stereo_mode_entries),
2160                                            0, G_CALLBACK(layout_menu_stereo_mode_cb), lw);
2161
2162
2163         lw->ui_manager = gtk_ui_manager_new();
2164         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
2165         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
2166
2167         DEBUG_1("%s layout_actions_setup: add menu", get_exec_time());
2168         error = NULL;
2169         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
2170                 {
2171                 g_message("building menus failed: %s", error->message);
2172                 g_error_free(error);
2173                 exit(EXIT_FAILURE);
2174                 }
2175
2176         DEBUG_1("%s layout_actions_setup: marks", get_exec_time());
2177         layout_actions_setup_marks(lw);
2178
2179         DEBUG_1("%s layout_actions_setup: editors", get_exec_time());
2180         layout_actions_setup_editors(lw);
2181
2182         DEBUG_1("%s layout_actions_setup: status_update_write", get_exec_time());
2183         layout_util_status_update_write(lw);
2184
2185         DEBUG_1("%s layout_actions_setup: actions_add_window", get_exec_time());
2186         layout_actions_add_window(lw, lw->window);
2187         DEBUG_1("%s layout_actions_setup: end", get_exec_time());
2188 }
2189
2190 static gint layout_editors_reload_idle_id = -1;
2191 static GList *layout_editors_desktop_files = NULL;
2192
2193 static gboolean layout_editors_reload_idle_cb(gpointer data)
2194 {
2195         if (!layout_editors_desktop_files)
2196                 {
2197                 DEBUG_1("%s layout_editors_reload_idle_cb: get_desktop_files", get_exec_time());
2198                 layout_editors_desktop_files = editor_get_desktop_files();
2199                 return TRUE;
2200                 }
2201
2202         editor_read_desktop_file(layout_editors_desktop_files->data);
2203         g_free(layout_editors_desktop_files->data);
2204         layout_editors_desktop_files = g_list_delete_link(layout_editors_desktop_files, layout_editors_desktop_files);
2205
2206
2207         if (!layout_editors_desktop_files)
2208                 {
2209                 GList *work;
2210                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors", get_exec_time());
2211                 editor_table_finish();
2212
2213                 work = layout_window_list;
2214                 while (work)
2215                         {
2216                         LayoutWindow *lw = work->data;
2217                         work = work->next;
2218                         layout_actions_setup_editors(lw);
2219                         }
2220
2221                 DEBUG_1("%s layout_editors_reload_idle_cb: setup_editors done", get_exec_time());
2222
2223                 layout_editors_reload_idle_id = -1;
2224                 return FALSE;
2225                 }
2226         return TRUE;
2227 }
2228
2229 void layout_editors_reload_start(void)
2230 {
2231         DEBUG_1("%s layout_editors_reload_start", get_exec_time());
2232
2233         if (layout_editors_reload_idle_id != -1)
2234                 {
2235                 g_source_remove(layout_editors_reload_idle_id);
2236                 string_list_free(layout_editors_desktop_files);
2237                 }
2238
2239         editor_table_clear();
2240         layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL);
2241 }
2242
2243 void layout_editors_reload_finish(void)
2244 {
2245         if (layout_editors_reload_idle_id != -1)
2246                 {
2247                 DEBUG_1("%s layout_editors_reload_finish", get_exec_time());
2248                 g_source_remove(layout_editors_reload_idle_id);
2249                 while (layout_editors_reload_idle_id != -1)
2250                         {
2251                         layout_editors_reload_idle_cb(NULL);
2252                         }
2253                 }
2254 }
2255
2256 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
2257 {
2258         GtkAccelGroup *group;
2259
2260         if (!lw->ui_manager) return;
2261
2262         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
2263         gtk_window_add_accel_group(GTK_WINDOW(window), group);
2264 }
2265
2266 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
2267 {
2268         if (lw->menu_bar) return lw->menu_bar;
2269         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
2270         g_object_ref(lw->menu_bar);
2271         return lw->menu_bar;
2272 }
2273
2274 GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
2275 {
2276         if (lw->toolbar[type]) return lw->toolbar[type];
2277         switch (type)
2278                 {
2279                 case TOOLBAR_MAIN:
2280                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar");
2281                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_SMALL_TOOLBAR);
2282                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2283                         break;
2284                 case TOOLBAR_STATUS:
2285                         lw->toolbar[type] = gtk_ui_manager_get_widget(lw->ui_manager, "/StatusBar");
2286                         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar[type]), GTK_ICON_SIZE_MENU);
2287                         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar[type]), GTK_TOOLBAR_ICONS);
2288                         gtk_toolbar_set_show_arrow(GTK_TOOLBAR(lw->toolbar[type]), FALSE);
2289                         break;
2290                 default:
2291                         break;
2292                 }
2293         g_object_ref(lw->toolbar[type]);
2294         return lw->toolbar[type];
2295 }
2296
2297 /*
2298  *-----------------------------------------------------------------------------
2299  * misc
2300  *-----------------------------------------------------------------------------
2301  */
2302
2303 void layout_util_status_update_write(LayoutWindow *lw)
2304 {
2305         GtkAction *action;
2306         gint n = metadata_queue_length();
2307         action = gtk_action_group_get_action(lw->action_group, "SaveMetadata");
2308         gtk_action_set_sensitive(action, n > 0);
2309         if (n > 0)
2310                 {
2311                 gchar *buf = g_strdup_printf(_("Number of files with unsaved metadata: %d"), n);
2312                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2313                 g_free(buf);
2314                 }
2315         else
2316                 {
2317                 g_object_set(G_OBJECT(action), "tooltip", _("No unsaved metadata"), NULL);
2318                 }
2319 }
2320
2321 void layout_util_status_update_write_all(void)
2322 {
2323         GList *work;
2324
2325         work = layout_window_list;
2326         while (work)
2327                 {
2328                 LayoutWindow *lw = work->data;
2329                 work = work->next;
2330
2331                 layout_util_status_update_write(lw);
2332                 }
2333 }
2334
2335 static gchar *layout_color_name_parse(const gchar *name)
2336 {
2337         if (!name || !*name) return g_strdup(_("Empty"));
2338         return g_strdelimit(g_strdup(name), "_", '-');
2339 }
2340
2341 void layout_util_sync_color(LayoutWindow *lw)
2342 {
2343         GtkAction *action;
2344         gint input = 0;
2345         gboolean use_color;
2346         gboolean use_image = FALSE;
2347         gint i;
2348         gchar action_name[15];
2349         gchar *image_profile;
2350         gchar *screen_profile;
2351
2352
2353         if (!lw->action_group) return;
2354         if (!layout_image_color_profile_get(lw, &input, &use_image)) return;
2355
2356         use_color = layout_image_color_profile_get_use(lw);
2357
2358         action = gtk_action_group_get_action(lw->action_group, "UseColorProfiles");
2359 #ifdef HAVE_LCMS
2360         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_color);
2361         if (layout_image_color_profile_get_status(lw, &image_profile, &screen_profile))
2362                 {
2363                 gchar *buf;
2364                 buf = g_strdup_printf(_("Image profile: %s\nScreen profile: %s"), image_profile, screen_profile);
2365                 g_object_set(G_OBJECT(action), "tooltip", buf, NULL);
2366                 g_free(image_profile);
2367                 g_free(screen_profile);
2368                 g_free(buf);
2369                 }
2370         else
2371                 {
2372                 g_object_set(G_OBJECT(action), "tooltip", _("Click to enable color management"), NULL);
2373                 }
2374 #else
2375         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), FALSE);
2376         gtk_action_set_sensitive(action, FALSE);
2377         g_object_set(G_OBJECT(action), "tooltip", _("Color profiles not supported"), NULL);
2378 #endif
2379
2380         action = gtk_action_group_get_action(lw->action_group, "UseImageProfile");
2381         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), use_image);
2382         gtk_action_set_sensitive(action, use_color);
2383
2384         for (i = 0; i < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS; i++)
2385                 {
2386                 sprintf(action_name, "ColorProfile%d", i);
2387                 action = gtk_action_group_get_action(lw->action_group, action_name);
2388
2389                 if (i >= COLOR_PROFILE_FILE)
2390                         {
2391                         const gchar *name = options->color_profile.input_name[i - COLOR_PROFILE_FILE];
2392                         const gchar *file = options->color_profile.input_file[i - COLOR_PROFILE_FILE];
2393                         gchar *end;
2394                         gchar *buf;
2395
2396                         if (!name || !name[0]) name = filename_from_path(file);
2397
2398                         end = layout_color_name_parse(name);
2399                         buf = g_strdup_printf(_("Input _%d: %s"), i, end);
2400                         g_free(end);
2401
2402                         g_object_set(G_OBJECT(action), "label", buf, NULL);
2403                         g_free(buf);
2404
2405                         gtk_action_set_visible(action, file && file[0]);
2406                         }
2407
2408                 gtk_action_set_sensitive(action, !use_image);
2409                 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i == input));
2410                 }
2411
2412         action = gtk_action_group_get_action(lw->action_group, "Grayscale");
2413         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_get_desaturate(lw));
2414 }
2415
2416 static void layout_util_sync_views(LayoutWindow *lw)
2417 {
2418         GtkAction *action;
2419         OsdShowFlags osd_flags = image_osd_get(lw->image);
2420
2421         if (!lw->action_group) return;
2422
2423         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
2424         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
2425
2426         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
2427         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
2428
2429         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
2430         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
2431
2432         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
2433         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
2434
2435         action = gtk_action_group_get_action(lw->action_group, "SBar");
2436         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
2437
2438         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
2439         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
2440
2441         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
2442         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
2443
2444         action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
2445         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
2446
2447         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
2448         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
2449
2450         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
2451         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
2452
2453         action = gtk_action_group_get_action(lw->action_group, "ImageOverlay");
2454         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags != OSD_SHOW_NOTHING);
2455
2456         action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
2457         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
2458
2459         if (osd_flags & OSD_SHOW_HISTOGRAM)
2460                 {
2461                 action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
2462                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
2463
2464                 action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
2465                 gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
2466                 }
2467
2468         action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
2469         gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
2470
2471         action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
2472         gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
2473
2474         layout_util_sync_color(lw);
2475 }
2476
2477 void layout_util_sync_thumb(LayoutWindow *lw)
2478 {
2479         GtkAction *action;
2480
2481         if (!lw->action_group) return;
2482
2483         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
2484         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
2485         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
2486 }
2487
2488 void layout_util_sync(LayoutWindow *lw)
2489 {
2490         layout_util_sync_views(lw);
2491         layout_util_sync_thumb(lw);
2492         layout_menu_recent_update(lw);
2493 //      layout_menu_edit_update(lw);
2494 }
2495
2496
2497 /*
2498  *-----------------------------------------------------------------------------
2499  * sidebars
2500  *-----------------------------------------------------------------------------
2501  */
2502
2503 static gboolean layout_bar_enabled(LayoutWindow *lw)
2504 {
2505         return lw->bar && gtk_widget_get_visible(lw->bar);
2506 }
2507
2508 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
2509 {
2510         LayoutWindow *lw = data;
2511
2512         lw->bar = NULL;
2513 /*
2514     do not call layout_util_sync_views(lw) here
2515     this is called either when whole layout is destroyed - no need for update
2516     or when the bar is replaced - sync is called by upper function at the end of whole operation
2517
2518 */
2519 }
2520
2521 static void layout_bar_set_default(LayoutWindow *lw)
2522 {
2523         GtkWidget *bar;
2524
2525         if (!lw->utility_box) return;
2526
2527         bar = bar_new(lw);
2528
2529         layout_bar_set(lw, bar);
2530
2531         bar_populate_default(bar);
2532 }
2533
2534 static void layout_bar_close(LayoutWindow *lw)
2535 {
2536         if (lw->bar)
2537                 {
2538                 bar_close(lw->bar);
2539                 lw->bar = NULL;
2540                 }
2541 }
2542
2543
2544 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
2545 {
2546         if (!lw->utility_box) return;
2547
2548         layout_bar_close(lw); /* if any */
2549
2550         if (!bar) return;
2551         lw->bar = bar;
2552
2553         g_signal_connect(G_OBJECT(lw->bar), "destroy",
2554                          G_CALLBACK(layout_bar_destroyed), lw);
2555
2556
2557 //      gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
2558         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
2559
2560         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2561 }
2562
2563
2564 void layout_bar_toggle(LayoutWindow *lw)
2565 {
2566         if (layout_bar_enabled(lw))
2567                 {
2568                 gtk_widget_hide(lw->bar);
2569                 }
2570         else
2571                 {
2572                 if (!lw->bar)
2573                         {
2574                         layout_bar_set_default(lw);
2575                         }
2576                 gtk_widget_show(lw->bar);
2577                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
2578                 }
2579         layout_util_sync_views(lw);
2580 }
2581
2582 static void layout_bar_new_image(LayoutWindow *lw)
2583 {
2584         if (!layout_bar_enabled(lw)) return;
2585
2586         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2587 }
2588
2589 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
2590 {
2591         if (!layout_bar_enabled(lw)) return;
2592
2593         bar_notify_selection(lw->bar, count);
2594 }
2595
2596 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
2597 {
2598         return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
2599 }
2600
2601
2602 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
2603 {
2604         LayoutWindow *lw = data;
2605
2606         lw->bar_sort = NULL;
2607
2608 /*
2609     do not call layout_util_sync_views(lw) here
2610     this is called either when whole layout is destroyed - no need for update
2611     or when the bar is replaced - sync is called by upper function at the end of whole operation
2612
2613 */
2614 }
2615
2616 static void layout_bar_sort_set_default(LayoutWindow *lw)
2617 {
2618         GtkWidget *bar;
2619
2620         if (!lw->utility_box) return;
2621
2622         bar = bar_sort_new_default(lw);
2623
2624         layout_bar_sort_set(lw, bar);
2625 }
2626
2627 static void layout_bar_sort_close(LayoutWindow *lw)
2628 {
2629         if (lw->bar_sort)
2630                 {
2631                 bar_sort_close(lw->bar_sort);
2632                 lw->bar_sort = NULL;
2633                 }
2634 }
2635
2636 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
2637 {
2638         if (!lw->utility_box) return;
2639
2640         layout_bar_sort_close(lw); /* if any */
2641
2642         if (!bar) return;
2643         lw->bar_sort = bar;
2644
2645         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
2646                          G_CALLBACK(layout_bar_sort_destroyed), lw);
2647
2648         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
2649 }
2650
2651 void layout_bar_sort_toggle(LayoutWindow *lw)
2652 {
2653         if (layout_bar_sort_enabled(lw))
2654                 {
2655                 gtk_widget_hide(lw->bar_sort);
2656                 }
2657         else
2658                 {
2659                 if (!lw->bar_sort)
2660                         {
2661                         layout_bar_sort_set_default(lw);
2662                         }
2663                 gtk_widget_show(lw->bar_sort);
2664                 }
2665         layout_util_sync_views(lw);
2666 }
2667
2668 void layout_bars_new_image(LayoutWindow *lw)
2669 {
2670         layout_bar_new_image(lw);
2671
2672         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2673
2674         /* this should be called here to handle the metadata edited in bars */
2675         if (options->metadata.confirm_on_image_change)
2676                 metadata_write_queue_confirm(FALSE, NULL, NULL);
2677 }
2678
2679 void layout_bars_new_selection(LayoutWindow *lw, gint count)
2680 {
2681         layout_bar_new_selection(lw, count);
2682 }
2683
2684 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
2685 {
2686         if (lw->utility_box) return lw->utility_box;
2687         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
2688         lw->utility_paned = gtk_hpaned_new();
2689         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
2690
2691         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
2692         gtk_widget_show(lw->utility_paned);
2693
2694         gtk_widget_show(image);
2695
2696         g_object_ref(lw->utility_box);
2697         return lw->utility_box;
2698 }
2699
2700 void layout_bars_close(LayoutWindow *lw)
2701 {
2702         layout_bar_sort_close(lw);
2703         layout_bar_close(lw);
2704 }
2705
2706 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
2707 {
2708         LayoutWindow *lw = data;
2709         lw->exif_window = NULL;
2710 }
2711
2712 void layout_exif_window_new(LayoutWindow *lw)
2713 {
2714         if (lw->exif_window) return;
2715
2716         lw->exif_window = advanced_exif_new();
2717         if (!lw->exif_window) return;
2718         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
2719                          G_CALLBACK(layout_exif_window_destroy), lw);
2720         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2721 }
2722
2723 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */