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