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