moved color profiles from statusbar to View menu
[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(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(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(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(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(lw, ALTER_FLIP);
351 }
352
353 static void layout_menu_alter_desaturate_cb(GtkAction *action, gpointer data)
354 {
355         LayoutWindow *lw = data;
356
357         layout_image_alter(lw, ALTER_DESATURATE);
358 }
359
360 static void layout_menu_alter_none_cb(GtkAction *action, gpointer data)
361 {
362         LayoutWindow *lw = data;
363
364         layout_image_alter(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, screen;
1063         gboolean use_image;
1064
1065         if (!layout_image_color_profile_get(lw, &input, &screen, &use_image)) return;
1066         layout_image_color_profile_set(lw, input, screen, 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, screen;
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, &screen, &use_image)) return;
1084         if (type == input) return;
1085
1086         layout_image_color_profile_set(lw, type, screen, 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   { "AdjustMenu",       NULL,           N_("_Adjust"),                  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   { "Grayscale",        NULL,           N_("Toggle _grayscale"),"<shift>G",     NULL,   CB(layout_menu_alter_desaturate_cb) },
1351   { "AlterNone",        NULL,           N_("_Original state"),  "<shift>O",     NULL,   CB(layout_menu_alter_none_cb) },
1352
1353   { "SelectAll",        NULL,           N_("Select _all"),      "<control>A",   NULL,   CB(layout_menu_select_all_cb) },
1354   { "SelectNone",       NULL,           N_("Select _none"), "<control><shift>A",NULL,   CB(layout_menu_unselect_all_cb) },
1355   { "SelectInvert",     NULL,           N_("_Invert Selection"), "<control><shift>I",   NULL,   CB(layout_menu_invert_selection_cb) },
1356
1357   { "Preferences",GTK_STOCK_PREFERENCES,N_("P_references..."),  "<control>O",   NULL,   CB(layout_menu_config_cb) },
1358   { "Editors",GTK_STOCK_PREFERENCES,N_("Configure _Editors..."),        NULL,   NULL,   CB(layout_menu_editors_cb) },
1359   { "LayoutConfig",GTK_STOCK_PREFERENCES,N_("_Configure this window..."),       NULL,   NULL,   CB(layout_menu_layout_config_cb) },
1360   { "Maintenance",      NULL,           N_("_Thumbnail maintenance..."),NULL,   NULL,   CB(layout_menu_remove_thumb_cb) },
1361   { "Wallpaper",        NULL,           N_("Set as _wallpaper"),NULL,           NULL,   CB(layout_menu_wallpaper_cb) },
1362
1363   { "ZoomIn",   GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "equal",        N_("Zoom in"),  CB(layout_menu_zoom_in_cb) },
1364   { "ZoomInAlt1",GTK_STOCK_ZOOM_IN,     N_("Zoom _in"),         "KP_Add",       N_("Zoom in"),  CB(layout_menu_zoom_in_cb) },
1365   { "ZoomOut",  GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "minus",        N_("Zoom out"), CB(layout_menu_zoom_out_cb) },
1366   { "ZoomOutAlt1",GTK_STOCK_ZOOM_OUT,   N_("Zoom _out"),        "KP_Subtract",  N_("Zoom out"), CB(layout_menu_zoom_out_cb) },
1367   { "Zoom100",  GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "Z",            N_("Zoom 1:1"), CB(layout_menu_zoom_1_1_cb) },
1368   { "Zoom100Alt1",GTK_STOCK_ZOOM_100,   N_("Zoom _1:1"),        "KP_Divide",    N_("Zoom 1:1"), CB(layout_menu_zoom_1_1_cb) },
1369   { "ZoomFit",  GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "X",            N_("Zoom to fit"),      CB(layout_menu_zoom_fit_cb) },
1370   { "ZoomFitAlt1",GTK_STOCK_ZOOM_FIT,   N_("_Zoom to fit"),     "KP_Multiply",  N_("Zoom to fit"),      CB(layout_menu_zoom_fit_cb) },
1371   { "ZoomFillHor",      NULL,           N_("Fit _Horizontally"),"H",            NULL,   CB(layout_menu_zoom_fit_hor_cb) },
1372   { "ZoomFillVert",     NULL,           N_("Fit _Vertically"),  "W",            NULL,   CB(layout_menu_zoom_fit_vert_cb) },
1373   { "Zoom200",          NULL,           N_("Zoom _2:1"),        NULL,           NULL,   CB(layout_menu_zoom_2_1_cb) },
1374   { "Zoom300",          NULL,           N_("Zoom _3:1"),        NULL,           NULL,   CB(layout_menu_zoom_3_1_cb) },
1375   { "Zoom400",          NULL,           N_("Zoom _4:1"),        NULL,           NULL,   CB(layout_menu_zoom_4_1_cb) },
1376   { "Zoom50",           NULL,           N_("Zoom 1:2"),         NULL,           NULL,   CB(layout_menu_zoom_1_2_cb) },
1377   { "Zoom33",           NULL,           N_("Zoom 1:3"),         NULL,           NULL,   CB(layout_menu_zoom_1_3_cb) },
1378   { "Zoom25",           NULL,           N_("Zoom 1:4"),         NULL,           NULL,   CB(layout_menu_zoom_1_4_cb) },
1379
1380   { "ConnectZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "plus",                 NULL,   CB(layout_menu_connect_zoom_in_cb) },
1381   { "ConnectZoomInAlt1",GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "<shift>KP_Add",        NULL,   CB(layout_menu_connect_zoom_in_cb) },
1382   { "ConnectZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "underscore",           NULL,   CB(layout_menu_connect_zoom_out_cb) },
1383   { "ConnectZoomOutAlt1",GTK_STOCK_ZOOM_OUT,    N_("Zoom _out"),        "<shift>KP_Subtract",   NULL,   CB(layout_menu_connect_zoom_out_cb) },
1384   { "ConnectZoom100",   GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "<shift>Z",             NULL,   CB(layout_menu_connect_zoom_1_1_cb) },
1385   { "ConnectZoom100Alt1",GTK_STOCK_ZOOM_100,    N_("Zoom _1:1"),        "<shift>KP_Divide",     NULL,   CB(layout_menu_connect_zoom_1_1_cb) },
1386   { "ConnectZoomFit",   GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "<shift>X",             NULL,   CB(layout_menu_connect_zoom_fit_cb) },
1387   { "ConnectZoomFitAlt1",GTK_STOCK_ZOOM_FIT,    N_("_Zoom to fit"),     "<shift>KP_Multiply",   NULL,   CB(layout_menu_connect_zoom_fit_cb) },
1388   { "ConnectZoomFillHor",       NULL,           N_("Fit _Horizontally"),"<shift>H",             NULL,   CB(layout_menu_connect_zoom_fit_hor_cb) },
1389   { "ConnectZoomFillVert",      NULL,           N_("Fit _Vertically"),  "<shift>W",             NULL,   CB(layout_menu_connect_zoom_fit_vert_cb) },
1390   { "ConnectZoom200",           NULL,           N_("Zoom _2:1"),        NULL,                   NULL,   CB(layout_menu_connect_zoom_2_1_cb) },
1391   { "ConnectZoom300",           NULL,           N_("Zoom _3:1"),        NULL,                   NULL,   CB(layout_menu_connect_zoom_3_1_cb) },
1392   { "ConnectZoom400",           NULL,           N_("Zoom _4:1"),        NULL,                   NULL,   CB(layout_menu_connect_zoom_4_1_cb) },
1393   { "ConnectZoom50",            NULL,           N_("Zoom 1:2"),         NULL,                   NULL,   CB(layout_menu_connect_zoom_1_2_cb) },
1394   { "ConnectZoom33",            NULL,           N_("Zoom 1:3"),         NULL,                   NULL,   CB(layout_menu_connect_zoom_1_3_cb) },
1395   { "ConnectZoom25",            NULL,           N_("Zoom 1:4"),         NULL,                   NULL,   CB(layout_menu_connect_zoom_1_4_cb) },
1396
1397
1398   { "ViewInNewWindow",  NULL,           N_("_View in new window"),      "<control>V",           NULL,   CB(layout_menu_view_in_new_window_cb) },
1399
1400   { "FullScreen",       NULL,           N_("F_ull screen"),     "F",            NULL,   CB(layout_menu_fullscreen_cb) },
1401   { "FullScreenAlt1",   NULL,           N_("F_ull screen"),     "V",            NULL,   CB(layout_menu_fullscreen_cb) },
1402   { "FullScreenAlt2",   NULL,           N_("F_ull screen"),     "F11",          NULL,   CB(layout_menu_fullscreen_cb) },
1403   { "Escape",           NULL,           N_("Escape"),           "Escape",       NULL,   CB(layout_menu_escape_cb) },
1404   { "EscapeAlt1",       NULL,           N_("Escape"),           "Q",            NULL,   CB(layout_menu_escape_cb) },
1405   { "ImageOverlay",     NULL,           N_("_Image Overlay"),   "I",            NULL,   CB(layout_menu_overlay_cb) },
1406   { "HistogramChan",    NULL,   N_("Histogram _channels"),      "K",            NULL,   CB(layout_menu_histogram_chan_cb) },
1407   { "HistogramLog",     NULL,   N_("Histogram _log mode"),      "J",            NULL,   CB(layout_menu_histogram_log_cb) },
1408   { "HideTools",        NULL,           N_("_Hide file list"),  "<control>H",   NULL,   CB(layout_menu_hide_cb) },
1409   { "SlideShowPause",   NULL,           N_("_Pause slideshow"), "P",            NULL,   CB(layout_menu_slideshow_pause_cb) },
1410   { "Refresh",  GTK_STOCK_REFRESH,      N_("_Refresh"),         "R",            NULL,   CB(layout_menu_refresh_cb) },
1411
1412   { "HelpContents",     GTK_STOCK_HELP, N_("_Contents"),        "F1",           NULL,   CB(layout_menu_help_cb) },
1413   { "HelpShortcuts",    NULL,           N_("_Keyboard shortcuts"),NULL,         NULL,   CB(layout_menu_help_keys_cb) },
1414   { "HelpNotes",        NULL,           N_("_Release notes"),   NULL,           NULL,   CB(layout_menu_notes_cb) },
1415   { "About",            NULL,           N_("_About"),           NULL,           NULL,   CB(layout_menu_about_cb) },
1416   { "LogWindow",        NULL,           N_("_Log Window"),      NULL,           NULL,   CB(layout_menu_log_window_cb) },
1417   
1418   { "ExifWin",          NULL,           N_("E_xif window"),     "<control>E",   NULL,   CB(layout_menu_bar_exif_cb) },
1419
1420 };
1421
1422 static GtkToggleActionEntry menu_toggle_entries[] = {
1423   { "Thumbnails",       PIXBUF_INLINE_ICON_THUMB,               N_("Show _Thumbnails"), "T",            N_("Show Thumbnails"),  CB(layout_menu_thumb_cb),        FALSE },
1424   { "ShowMarks",        NULL,           N_("Show _Marks"),      "M",            NULL,   CB(layout_menu_marks_cb),        FALSE  },
1425   { "FloatTools",       PIXBUF_INLINE_ICON_FLOAT,               N_("_Float file list"), "L",            NULL,   CB(layout_menu_float_cb),        FALSE  },
1426   { "HideToolbar",      NULL,           N_("Hide tool_bar"),    NULL,           NULL,   CB(layout_menu_toolbar_cb),      FALSE  },
1427   { "HideInfoPixel",    NULL,           N_("Hide Pi_xel Info"), NULL,           NULL,   CB(layout_menu_info_pixel_cb),   FALSE  },
1428   { "SBar",             NULL,           N_("_Info"),            "<control>K",   NULL,   CB(layout_menu_bar_cb),          FALSE  },
1429   { "SBarSort",         NULL,           N_("Sort _manager"),    "<control>S",   NULL,   CB(layout_menu_bar_sort_cb),     FALSE  },
1430   { "SlideShow",        NULL,           N_("Toggle _slideshow"),"S",            NULL,   CB(layout_menu_slideshow_cb),    FALSE  },
1431   { "UseColorProfiles", NULL,           N_("Use _color profiles"), NULL,        NULL,   CB(layout_color_menu_enable_cb), FALSE},
1432   { "UseImageProfile",  NULL,           N_("Use profile from _image"), NULL,    NULL,   CB(layout_color_menu_use_image_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='AdjustMenu'>"
1516 "        <menuitem action='RotateCW'/>"
1517 "        <menuitem action='RotateCCW'/>"
1518 "        <menuitem action='Rotate180'/>"
1519 "        <menuitem action='Mirror'/>"
1520 "        <menuitem action='Flip'/>"
1521 "        <menuitem action='Grayscale'/>"
1522 "        <menuitem action='AlterNone'/>"
1523 "      </menu>"
1524 "      <placeholder name='PropertiesSection'/>"
1525 "      <separator/>"
1526 "      <menuitem action='Preferences'/>"
1527 "      <menuitem action='Editors'/>"
1528 "      <menuitem action='LayoutConfig'/>"
1529 "      <menuitem action='Maintenance'/>"
1530 "      <placeholder name='PreferencesSection'/>"
1531 "      <separator/>"
1532 "      <menuitem action='Wallpaper'/>"
1533 "      <separator/>"
1534 "    </menu>"
1535 "    <menu action='ViewMenu'>"
1536 "      <menuitem action='ViewInNewWindow'/>"
1537 "      <menuitem action='PanView'/>"
1538 "      <placeholder name='WindowSection'/>"
1539 "      <separator/>"
1540 "      <menu action='ColorMenu'>"
1541 "        <menuitem action='UseColorProfiles'/>"
1542 "        <menuitem action='UseImageProfile'/>"
1543 "        <menuitem action='ColorProfile0'/>"
1544 "        <menuitem action='ColorProfile1'/>"
1545 "        <menuitem action='ColorProfile2'/>"
1546 "        <menuitem action='ColorProfile3'/>"
1547 "        <menuitem action='ColorProfile4'/>"
1548 "        <menuitem action='ColorProfile5'/>"
1549 "      </menu>"
1550 "      <menu action='ZoomMenu'>"
1551 "        <menuitem action='ZoomIn'/>"
1552 "        <menuitem action='ZoomOut'/>"
1553 "        <menuitem action='ZoomFit'/>"
1554 "        <menuitem action='ZoomFillHor'/>"
1555 "        <menuitem action='ZoomFillVert'/>"
1556 "        <menuitem action='Zoom100'/>"
1557 "        <menuitem action='Zoom200'/>"
1558 "        <menuitem action='Zoom300'/>"
1559 "        <menuitem action='Zoom400'/>"
1560 "        <menuitem action='Zoom50'/>"
1561 "        <menuitem action='Zoom33'/>"
1562 "        <menuitem action='Zoom25'/>"
1563 "      </menu>"
1564 "      <menu action='ConnectZoomMenu'>"
1565 "        <menuitem action='ConnectZoomIn'/>"
1566 "        <menuitem action='ConnectZoomOut'/>"
1567 "        <menuitem action='ConnectZoomFit'/>"
1568 "        <menuitem action='ConnectZoomFillHor'/>"
1569 "        <menuitem action='ConnectZoomFillVert'/>"
1570 "        <menuitem action='ConnectZoom100'/>"
1571 "        <menuitem action='ConnectZoom200'/>"
1572 "        <menuitem action='ConnectZoom300'/>"
1573 "        <menuitem action='ConnectZoom400'/>"
1574 "        <menuitem action='ConnectZoom50'/>"
1575 "        <menuitem action='ConnectZoom33'/>"
1576 "        <menuitem action='ConnectZoom25'/>"
1577 "      </menu>"
1578 "      <placeholder name='ZoomSection'/>"
1579 "      <separator/>"
1580 "      <menu action='SplitMenu'>"
1581 "        <menuitem action='SplitHorizontal'/>"
1582 "        <menuitem action='SplitVertical'/>"
1583 "        <menuitem action='SplitQuad'/>"
1584 "        <menuitem action='SplitSingle'/>"
1585 "      </menu>"
1586 "      <separator/>"
1587 "      <menuitem action='ViewList'/>"
1588 "      <menuitem action='ViewIcons'/>"
1589 "      <menuitem action='Thumbnails'/>"
1590 "      <placeholder name='ListSection'/>"
1591 "      <separator/>"
1592 "      <menu action='DirMenu'>"
1593 "        <menuitem action='FolderList'/>"
1594 "        <menuitem action='FolderTree'/>"
1595 "      </menu>"
1596 "      <placeholder name='DirSection'/>"
1597 "      <separator/>"
1598 "      <menuitem action='ImageOverlay'/>"
1599 "      <menuitem action='HistogramChan'/>"
1600 "      <menuitem action='HistogramLog'/>"
1601 "      <menuitem action='FullScreen'/>"
1602 "      <placeholder name='OverlaySection'/>"
1603 "      <separator/>"
1604 "      <menuitem action='FloatTools'/>"
1605 "      <menuitem action='HideTools'/>"
1606 "      <menuitem action='HideToolbar'/>"
1607 "      <menuitem action='HideInfoPixel'/>"
1608 "      <placeholder name='ToolsSection'/>"
1609 "      <separator/>"
1610 "      <menuitem action='SBar'/>"
1611 "      <menuitem action='ExifWin'/>"
1612 "      <menuitem action='SBarSort'/>"
1613 "      <placeholder name='SideBarSection'/>"
1614 "      <separator/>"
1615 "      <menuitem action='SlideShow'/>"
1616 "      <menuitem action='SlideShowPause'/>"
1617 "      <menuitem action='Refresh'/>"
1618 "      <placeholder name='SlideShowSection'/>"
1619 "      <separator/>"
1620 "    </menu>"
1621 "    <menu action='HelpMenu'>"
1622 "      <separator/>"
1623 "      <menuitem action='HelpContents'/>"
1624 "      <menuitem action='HelpShortcuts'/>"
1625 "      <menuitem action='HelpNotes'/>"
1626 "      <placeholder name='HelpSection'/>"
1627 "      <separator/>"
1628 "      <menuitem action='About'/>"
1629 "      <separator/>"
1630 "      <menuitem action='LogWindow'/>"
1631 "      <separator/>"
1632 "    </menu>"
1633 "  </menubar>"
1634 "  <toolbar name='ToolBar'>"
1635 "  </toolbar>"
1636 "<accelerator action='PrevImageAlt1'/>"
1637 "<accelerator action='PrevImageAlt2'/>"
1638 "<accelerator action='NextImageAlt1'/>"
1639 "<accelerator action='NextImageAlt2'/>"
1640 "<accelerator action='DeleteAlt1'/>"
1641 "<accelerator action='DeleteAlt2'/>"
1642 "<accelerator action='FullScreenAlt1'/>"
1643 "<accelerator action='FullScreenAlt2'/>"
1644 "<accelerator action='Escape'/>"
1645 "<accelerator action='EscapeAlt1'/>"
1646
1647 "<accelerator action='ZoomInAlt1'/>"
1648 "<accelerator action='ZoomOutAlt1'/>"
1649 "<accelerator action='Zoom100Alt1'/>"
1650 "<accelerator action='ZoomFitAlt1'/>"
1651
1652 "<accelerator action='ConnectZoomInAlt1'/>"
1653 "<accelerator action='ConnectZoomOutAlt1'/>"
1654 "<accelerator action='ConnectZoom100Alt1'/>"
1655 "<accelerator action='ConnectZoomFitAlt1'/>"
1656 "</ui>";
1657
1658 static gchar *menu_translate(const gchar *path, gpointer data)
1659 {
1660         return (gchar *)(_(path));
1661 }
1662
1663 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl,
1664                                       gchar *label_tmpl, gchar *accel_tmpl, GCallback cb)
1665 {
1666         gchar name[50];
1667         gchar label[100];
1668         gchar accel[50];
1669         GtkActionEntry entry = { name, NULL, label, accel, NULL, cb };
1670         GtkAction *action;
1671
1672         g_snprintf(name, sizeof(name), name_tmpl, mark);
1673         g_snprintf(label, sizeof(label), label_tmpl, mark);
1674         if (accel_tmpl)
1675                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
1676         else
1677                 accel[0] = 0;
1678         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
1679         action = gtk_action_group_get_action(lw->action_group, name);
1680         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark));
1681 }
1682
1683 static void layout_actions_setup_marks(LayoutWindow *lw)
1684 {
1685         gint mark;
1686         GError *error;
1687         GString *desc = g_string_new(
1688                                 "<ui>"
1689                                 "  <menubar name='MainMenu'>"
1690                                 "    <menu action='SelectMenu'>");
1691
1692         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1693                 {
1694                 layout_actions_setup_mark(lw, mark, "Mark%d",           _("Mark _%d"), NULL, NULL);
1695                 layout_actions_setup_mark(lw, mark, "SetMark%d",        _("_Set mark %d"),                      NULL, G_CALLBACK(layout_menu_set_mark_sel_cb));
1696                 layout_actions_setup_mark(lw, mark, "ResetMark%d",      _("_Reset mark %d"),                    NULL, G_CALLBACK(layout_menu_res_mark_sel_cb));
1697                 layout_actions_setup_mark(lw, mark, "ToggleMark%d",     _("_Toggle mark %d"),                   "%d", G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1698                 layout_actions_setup_mark(lw, mark, "ToggleMark%dAlt1", _("_Toggle mark %d"),                   "KP_%d", G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1699                 layout_actions_setup_mark(lw, mark, "SelectMark%d",     _("_Select mark %d"),                   "<control>%d", G_CALLBACK(layout_menu_sel_mark_cb));
1700                 layout_actions_setup_mark(lw, mark, "SelectMark%dAlt1", _("_Select mark %d"),                   "<control>KP_%d", G_CALLBACK(layout_menu_sel_mark_cb));
1701                 layout_actions_setup_mark(lw, mark, "AddMark%d",        _("_Add mark %d"),                      NULL, G_CALLBACK(layout_menu_sel_mark_or_cb));
1702                 layout_actions_setup_mark(lw, mark, "IntMark%d",        _("_Intersection with mark %d"),        NULL, G_CALLBACK(layout_menu_sel_mark_and_cb));
1703                 layout_actions_setup_mark(lw, mark, "UnselMark%d",      _("_Unselect mark %d"),                 NULL, G_CALLBACK(layout_menu_sel_mark_minus_cb));
1704
1705                 g_string_append_printf(desc,
1706                                 "      <menu action='Mark%d'>"
1707                                 "        <menuitem action='ToggleMark%d'/>"
1708                                 "        <menuitem action='SetMark%d'/>"
1709                                 "        <menuitem action='ResetMark%d'/>"
1710                                 "        <separator/>"
1711                                 "        <menuitem action='SelectMark%d'/>"
1712                                 "        <menuitem action='AddMark%d'/>"
1713                                 "        <menuitem action='IntMark%d'/>"
1714                                 "        <menuitem action='UnselMark%d'/>"
1715                                 "      </menu>",
1716                                 mark, mark, mark, mark, mark, mark, mark, mark);
1717                 }
1718
1719         g_string_append(desc,
1720                                 "    </menu>"
1721                                 "  </menubar>");
1722         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1723                 {
1724                 g_string_append_printf(desc,
1725                                 "<accelerator action='ToggleMark%dAlt1'/>"
1726                                 "<accelerator action='SelectMark%dAlt1'/>",
1727                                 mark, mark);
1728                 }
1729         g_string_append(desc,   "</ui>" );
1730
1731         error = NULL;
1732         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
1733                 {
1734                 g_message("building menus failed: %s", error->message);
1735                 g_error_free(error);
1736                 exit(EXIT_FAILURE);
1737                 }
1738         g_string_free(desc, TRUE);
1739 }
1740
1741 static GList *layout_actions_editor_menu_path(EditorDescription *editor)
1742 {
1743         gchar **split = g_strsplit(editor->menu_path, "/", 0);
1744         gint i = 0;
1745         GList *ret = NULL;
1746         
1747         if (split[0] == NULL) 
1748                 {
1749                 g_strfreev(split);
1750                 return NULL;
1751                 }
1752         
1753         while (split[i])
1754                 {
1755                 ret = g_list_prepend(ret, g_strdup(split[i]));
1756                 i++;
1757                 }
1758         
1759         g_strfreev(split);
1760         
1761         ret = g_list_prepend(ret, g_strdup(editor->key));
1762         
1763         return g_list_reverse(ret);
1764 }
1765
1766 static void layout_actions_editor_add(GString *desc, GList *path, GList *old_path)
1767 {
1768         gint to_open, to_close, i;
1769         while (path && old_path && strcmp((gchar *)path->data, (gchar *)old_path->data) == 0)
1770                 {
1771                 path = path->next;
1772                 old_path = old_path->next;
1773                 }
1774         to_open = g_list_length(path) - 1;
1775         to_close = g_list_length(old_path) - 1;
1776         
1777         if (to_close > 0)
1778                 {
1779                 old_path = g_list_last(old_path);
1780                 old_path = old_path->prev;
1781                 }
1782         
1783         for (i =  0; i < to_close; i++)
1784                 {
1785                 gchar *name = old_path->data;
1786                 if (g_str_has_suffix(name, "Section"))
1787                         {
1788                         g_string_append(desc,   "      </placeholder>");
1789                         }
1790                 else if (g_str_has_suffix(name, "Menu"))
1791                         {
1792                         g_string_append(desc,   "    </menu>");
1793                         }
1794                 else
1795                         {
1796                         g_warning("invalid menu path item %s", name);
1797                         }
1798                 old_path = old_path->prev;
1799                 }
1800
1801         for (i =  0; i < to_open; i++)
1802                 {
1803                 gchar *name = path->data;
1804                 if (g_str_has_suffix(name, "Section"))
1805                         {
1806                         g_string_append_printf(desc,    "      <placeholder name='%s'>", name);
1807                         }
1808                 else if (g_str_has_suffix(name, "Menu"))
1809                         {
1810                         g_string_append_printf(desc,    "    <menu action='%s'>", name);
1811                         }
1812                 else
1813                         {
1814                         g_warning("invalid menu path item %s", name);
1815                         }
1816                 path = path->next;
1817                 }
1818         
1819         if (path)
1820                 g_string_append_printf(desc, "      <menuitem action='%s'/>", (gchar *)path->data);
1821 }
1822
1823 static void layout_actions_setup_editors(LayoutWindow *lw)
1824 {
1825         GError *error;
1826         GList *editors_list;
1827         GList *work;
1828         GList *old_path;
1829         GString *desc;
1830         
1831         lw->action_group_editors = gtk_action_group_new("MenuActionsExternal");
1832         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group_editors, 1);
1833
1834         /* lw->action_group_editors contains translated entries, no translate func is required */
1835         desc = g_string_new(
1836                                 "<ui>"
1837                                 "  <menubar name='MainMenu'>");
1838
1839         editors_list = editor_list_get();
1840         
1841         old_path = NULL;
1842         work = editors_list;
1843         while (work)
1844                 {
1845                 GList *path;
1846                 EditorDescription *editor = work->data;
1847                 GtkActionEntry entry = { editor->key, NULL, editor->name, editor->hotkey, editor->comment, G_CALLBACK(layout_menu_edit_cb) };
1848                 
1849                 if (editor->icon && register_theme_icon_as_stock(editor->key, editor->icon))
1850                         {
1851                         entry.stock_id = editor->key;
1852                         }
1853                 gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
1854                 
1855                 path = layout_actions_editor_menu_path(editor);
1856                 layout_actions_editor_add(desc, path, old_path);
1857                 
1858                 string_list_free(old_path);
1859                 old_path = path;
1860                 work = work->next;
1861                 }
1862
1863         layout_actions_editor_add(desc, NULL, old_path);
1864         string_list_free(old_path);
1865
1866         g_string_append(desc,   "  </menubar>"
1867                                 "</ui>" );
1868
1869         error = NULL;
1870         
1871         lw->ui_editors_id = gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error);
1872         if (!lw->ui_editors_id)
1873                 {
1874                 g_message("building menus failed: %s", error->message);
1875                 g_error_free(error);
1876                 exit(EXIT_FAILURE);
1877                 }
1878         g_string_free(desc, TRUE);
1879         g_list_free(editors_list);
1880 }
1881
1882 void layout_actions_setup(LayoutWindow *lw)
1883 {
1884         GError *error;
1885
1886         if (lw->ui_manager) return;
1887
1888         lw->action_group = gtk_action_group_new("MenuActions");
1889         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
1890
1891         gtk_action_group_add_actions(lw->action_group,
1892                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
1893         gtk_action_group_add_toggle_actions(lw->action_group,
1894                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
1895         gtk_action_group_add_radio_actions(lw->action_group,
1896                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
1897                                            0, G_CALLBACK(layout_menu_list_cb), lw);
1898         gtk_action_group_add_radio_actions(lw->action_group,
1899                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
1900                                            0, G_CALLBACK(layout_menu_split_cb), lw);
1901         gtk_action_group_add_radio_actions(lw->action_group,
1902                                            menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
1903                                            0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);
1904         gtk_action_group_add_radio_actions(lw->action_group,
1905                                            menu_color_radio_entries, COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS,
1906                                            0, G_CALLBACK(layout_color_menu_input_cb), lw);
1907
1908
1909         lw->ui_manager = gtk_ui_manager_new();
1910         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
1911         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
1912
1913         error = NULL;
1914         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
1915                 {
1916                 g_message("building menus failed: %s", error->message);
1917                 g_error_free(error);
1918                 exit(EXIT_FAILURE);
1919                 }
1920         
1921         layout_toolbar_clear(lw);
1922         layout_toolbar_add_default(lw);
1923         
1924         layout_actions_setup_marks(lw);
1925         layout_actions_setup_editors(lw);
1926
1927         layout_actions_add_window(lw, lw->window);
1928 }
1929
1930 void layout_editors_reload_all(void)
1931 {
1932         GList *work;
1933
1934         work = layout_window_list;
1935         while (work)
1936                 {
1937                 LayoutWindow *lw = work->data;
1938                 work = work->next;
1939
1940                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->ui_editors_id);
1941                 gtk_ui_manager_remove_action_group(lw->ui_manager, lw->action_group_editors);
1942                 g_object_unref(lw->action_group_editors);
1943                 }
1944         
1945         editor_load_descriptions();
1946         
1947         work = layout_window_list;
1948         while (work)
1949                 {
1950                 LayoutWindow *lw = work->data;
1951                 work = work->next;
1952                 layout_actions_setup_editors(lw);
1953                 }
1954 }
1955
1956 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
1957 {
1958         GtkAccelGroup *group;
1959
1960         if (!lw->ui_manager) return;
1961
1962         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
1963         gtk_window_add_accel_group(GTK_WINDOW(window), group);
1964 }
1965
1966 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
1967 {
1968         if (lw->menu_bar) return lw->menu_bar;
1969         lw->menu_bar = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
1970         g_object_ref(lw->menu_bar);
1971         return lw->menu_bar;
1972 }
1973
1974 GtkWidget *layout_actions_toolbar(LayoutWindow *lw)
1975 {
1976         if (lw->toolbar) return lw->toolbar;
1977         lw->toolbar = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar");
1978         g_object_ref(lw->toolbar);
1979         gtk_toolbar_set_icon_size(GTK_TOOLBAR(lw->toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
1980         gtk_toolbar_set_style(GTK_TOOLBAR(lw->toolbar), GTK_TOOLBAR_ICONS);
1981         return lw->toolbar;
1982 }
1983
1984 void layout_toolbar_clear(LayoutWindow *lw)
1985 {
1986         if (lw->toolbar_merge_id) 
1987                 {
1988                 gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id);
1989                 gtk_ui_manager_ensure_update(lw->ui_manager);
1990                 }
1991         string_list_free(lw->toolbar_actions);
1992         lw->toolbar_actions = NULL;
1993         
1994         lw->toolbar_merge_id = gtk_ui_manager_new_merge_id(lw->ui_manager);
1995 }
1996         
1997
1998 void layout_toolbar_add(LayoutWindow *lw, const gchar *action)
1999 {
2000         if (!action || !lw->ui_manager) return;
2001         
2002         if (g_list_find_custom(lw->toolbar_actions, action, (GCompareFunc)strcmp)) return;
2003         
2004         gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id, "/ToolBar", action, action, GTK_UI_MANAGER_TOOLITEM, FALSE); 
2005         lw->toolbar_actions = g_list_append(lw->toolbar_actions, g_strdup(action));
2006 }
2007
2008
2009 void layout_toolbar_add_default(LayoutWindow *lw)
2010 {
2011         layout_toolbar_add(lw, "Thumbnails");
2012         layout_toolbar_add(lw, "Back");
2013         layout_toolbar_add(lw, "Home");
2014         layout_toolbar_add(lw, "Refresh");
2015         layout_toolbar_add(lw, "ZoomIn");
2016         layout_toolbar_add(lw, "ZoomOut");
2017         layout_toolbar_add(lw, "ZoomFit");
2018         layout_toolbar_add(lw, "Zoom100");
2019         layout_toolbar_add(lw, "Preferences");
2020         layout_toolbar_add(lw, "FloatTools");
2021 }
2022
2023 void layout_toolbar_write_config(LayoutWindow *lw, GString *outstr, gint indent)
2024 {
2025         GList *work = lw->toolbar_actions;
2026         WRITE_NL(); WRITE_STRING("<toolbar>");
2027         indent++;
2028         WRITE_NL(); WRITE_STRING("<clear/>");
2029         while (work)
2030                 {
2031                 gchar *action = work->data;
2032                 work = work->next;
2033                 WRITE_NL(); WRITE_STRING("<toolitem ");
2034                 write_char_option(outstr, indent + 1, "action", action);
2035                 WRITE_STRING("/>");
2036                 }
2037         indent--;
2038         WRITE_NL(); WRITE_STRING("</toolbar>");
2039 }
2040
2041 void layout_toolbar_add_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values)
2042 {
2043         gchar *action = NULL;
2044         
2045         while (*attribute_names)
2046                 {
2047                 const gchar *option = *attribute_names++;
2048                 const gchar *value = *attribute_values++;
2049
2050                 if (READ_CHAR_FULL("action", action)) continue;
2051
2052                 log_printf("unknown attribute %s = %s\n", option, value);
2053                 }
2054
2055         layout_toolbar_add(lw, action);
2056         g_free(action); 
2057 }
2058
2059 /*
2060  *-----------------------------------------------------------------------------
2061  * misc
2062  *-----------------------------------------------------------------------------
2063  */
2064 static gchar *layout_color_name_parse(const gchar *name)
2065 {
2066         if (!name || !*name) return g_strdup(_("Empty"));
2067         return g_strdelimit(g_strdup(name), "_", '-');
2068 }
2069
2070 static void layout_util_sync_color(LayoutWindow *lw)
2071 {
2072         GtkAction *action;
2073         gint input = 0;
2074         gint screen = 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, &screen, &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
2121 static void layout_util_sync_views(LayoutWindow *lw)
2122 {
2123         GtkAction *action;
2124
2125         if (!lw->action_group) return;
2126
2127         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
2128         radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
2129
2130         action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
2131         radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
2132
2133         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
2134         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.file_view_type);
2135
2136         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
2137         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
2138
2139         action = gtk_action_group_get_action(lw->action_group, "SBar");
2140         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
2141
2142         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
2143         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw));
2144
2145         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
2146         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
2147         
2148         action = gtk_action_group_get_action(lw->action_group, "HideInfoPixel");
2149         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.info_pixel_hidden);
2150
2151         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
2152         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
2153
2154         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
2155         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
2156
2157         layout_util_sync_color(lw);
2158 }
2159
2160 void layout_util_sync_thumb(LayoutWindow *lw)
2161 {
2162         GtkAction *action;
2163
2164         if (!lw->action_group) return;
2165
2166         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
2167         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails);
2168         g_object_set(action, "sensitive", (lw->options.file_view_type == FILEVIEW_LIST), NULL);
2169 }
2170
2171 void layout_util_sync(LayoutWindow *lw)
2172 {
2173         layout_util_sync_views(lw);
2174         layout_util_sync_thumb(lw);
2175         layout_menu_recent_update(lw);
2176 //      layout_menu_edit_update(lw);
2177 }
2178
2179 /*
2180  *-----------------------------------------------------------------------------
2181  * icons (since all the toolbar icons are included here, best place as any)
2182  *-----------------------------------------------------------------------------
2183  */
2184
2185 PixmapFolders *folder_icons_new(void)
2186 {
2187         PixmapFolders *pf;
2188
2189         pf = g_new0(PixmapFolders, 1);
2190
2191         pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
2192         pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
2193         pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
2194         pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
2195
2196         return pf;
2197 }
2198
2199 void folder_icons_free(PixmapFolders *pf)
2200 {
2201         if (!pf) return;
2202
2203         g_object_unref(pf->close);
2204         g_object_unref(pf->open);
2205         g_object_unref(pf->deny);
2206         g_object_unref(pf->parent);
2207
2208         g_free(pf);
2209 }
2210
2211 /*
2212  *-----------------------------------------------------------------------------
2213  * sidebars
2214  *-----------------------------------------------------------------------------
2215  */
2216
2217 static gboolean layout_bar_enabled(LayoutWindow *lw)
2218 {
2219         return lw->bar && GTK_WIDGET_VISIBLE(lw->bar);
2220 }
2221
2222 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
2223 {
2224         LayoutWindow *lw = data;
2225
2226         lw->bar = NULL;
2227 /* 
2228     do not call layout_util_sync_views(lw) here
2229     this is called either when whole layout is destroyed - no need for update
2230     or when the bar is replaced - sync is called by upper function at the end of whole operation
2231
2232 */
2233 }
2234
2235 static void layout_bar_set_default(LayoutWindow *lw)
2236 {
2237         GtkWidget *bar;
2238         
2239         if (!lw->utility_box) return;
2240
2241         bar = bar_new(lw);
2242         
2243         layout_bar_set(lw, bar);
2244         
2245         bar_populate_default(bar);
2246 }
2247
2248 static void layout_bar_close(LayoutWindow *lw)
2249 {
2250         if (lw->bar)
2251                 {
2252                 bar_close(lw->bar);
2253                 lw->bar = NULL;
2254                 }
2255 }
2256
2257
2258 void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
2259 {
2260         if (!lw->utility_box) return;
2261
2262         layout_bar_close(lw); /* if any */
2263
2264         if (!bar) return;
2265         lw->bar = bar;
2266
2267         g_signal_connect(G_OBJECT(lw->bar), "destroy",
2268                          G_CALLBACK(layout_bar_destroyed), lw);
2269
2270
2271 //      gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
2272         gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE); 
2273
2274         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2275 }
2276
2277
2278 void layout_bar_toggle(LayoutWindow *lw)
2279 {
2280         if (layout_bar_enabled(lw))
2281                 {
2282                 gtk_widget_hide(lw->bar);
2283                 }
2284         else
2285                 {
2286                 if (!lw->bar)
2287                         {
2288                         layout_bar_set_default(lw);
2289                         }
2290                 gtk_widget_show(lw->bar);
2291                 bar_set_fd(lw->bar, layout_image_get_fd(lw));
2292                 }
2293         layout_util_sync_views(lw);
2294 }
2295
2296 static void layout_bar_new_image(LayoutWindow *lw)
2297 {
2298         if (!layout_bar_enabled(lw)) return;
2299
2300         bar_set_fd(lw->bar, layout_image_get_fd(lw));
2301 }
2302
2303 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
2304 {
2305         if (!layout_bar_enabled(lw)) return;
2306
2307         bar_notify_selection(lw->bar, count);
2308 }
2309
2310 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
2311 {
2312         return lw->bar_sort && GTK_WIDGET_VISIBLE(lw->bar_sort);
2313 }
2314
2315
2316 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
2317 {
2318         LayoutWindow *lw = data;
2319
2320         lw->bar_sort = NULL;
2321
2322 /* 
2323     do not call layout_util_sync_views(lw) here
2324     this is called either when whole layout is destroyed - no need for update
2325     or when the bar is replaced - sync is called by upper function at the end of whole operation
2326
2327 */
2328 }
2329
2330 static void layout_bar_sort_set_default(LayoutWindow *lw)
2331 {
2332         GtkWidget *bar;
2333         
2334         if (!lw->utility_box) return;
2335
2336         bar = bar_sort_new_default(lw);
2337         
2338         layout_bar_sort_set(lw, bar);
2339 }
2340
2341 static void layout_bar_sort_close(LayoutWindow *lw)
2342 {
2343         if (lw->bar_sort)
2344                 {
2345                 bar_sort_close(lw->bar_sort);
2346                 lw->bar_sort = NULL;
2347                 }
2348 }
2349
2350 void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar)
2351 {
2352         if (!lw->utility_box) return;
2353
2354         layout_bar_sort_close(lw); /* if any */
2355
2356         if (!bar) return;
2357         lw->bar_sort = bar;
2358
2359         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
2360                          G_CALLBACK(layout_bar_sort_destroyed), lw);
2361
2362         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
2363 }
2364
2365 void layout_bar_sort_toggle(LayoutWindow *lw)
2366 {
2367         if (layout_bar_sort_enabled(lw))
2368                 {
2369                 gtk_widget_hide(lw->bar_sort);
2370                 }
2371         else
2372                 {
2373                 if (!lw->bar_sort)
2374                         {
2375                         layout_bar_sort_set_default(lw);
2376                         }
2377                 gtk_widget_show(lw->bar_sort);
2378                 }
2379         layout_util_sync_views(lw);
2380 }
2381
2382 void layout_bars_new_image(LayoutWindow *lw)
2383 {
2384         layout_bar_new_image(lw);
2385
2386         if (lw->exif_window) advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2387
2388         /* this should be called here to handle the metadata edited in bars */
2389         if (options->metadata.confirm_on_image_change)
2390                 metadata_write_queue_confirm(NULL, NULL);
2391 }
2392
2393 void layout_bars_new_selection(LayoutWindow *lw, gint count)
2394 {
2395         layout_bar_new_selection(lw, count);
2396 }
2397
2398 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
2399 {
2400         if (lw->utility_box) return lw->utility_box;
2401         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
2402         lw->utility_paned = gtk_hpaned_new();
2403         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
2404
2405         gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE); 
2406         gtk_widget_show(lw->utility_paned);
2407         
2408         gtk_widget_show(image);
2409
2410         g_object_ref(lw->utility_box);
2411         return lw->utility_box;
2412 }
2413
2414 void layout_bars_close(LayoutWindow *lw)
2415 {
2416         layout_bar_sort_close(lw);
2417         layout_bar_close(lw);
2418 }
2419
2420 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
2421 {
2422         LayoutWindow *lw = data;
2423         lw->exif_window = NULL;
2424 }
2425
2426 void layout_exif_window_new(LayoutWindow *lw)
2427 {
2428         if (lw->exif_window) return; 
2429         
2430         lw->exif_window = advanced_exif_new();
2431         if (!lw->exif_window) return;
2432         g_signal_connect(G_OBJECT(lw->exif_window), "destroy",
2433                          G_CALLBACK(layout_exif_window_destroy), lw);
2434         advanced_exif_set_fd(lw->exif_window, layout_image_get_fd(lw));
2435 }
2436
2437 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */