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