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