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