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