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