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