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