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