Move miscellaneous functions to their own files (new misc.[ch]).
[geeqie.git] / src / layout_util.c
1 /*
2  * Geeqie
3  * (C) 2004 John Ellis
4  * Copyright (C) 2008 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 "bar_exif.h"
18 #include "bar_info.h"
19 #include "bar_sort.h"
20 #include "cache_maint.h"
21 #include "collect.h"
22 #include "collect-dlg.h"
23 #include "compat.h"
24 #include "dupe.h"
25 #include "editors.h"
26 #include "filedata.h"
27 #include "history_list.h"
28 #include "image-overlay.h"
29 #include "img-view.h"
30 #include "info.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
47 #include <gdk/gdkkeysyms.h> /* for keyboard values */
48
49
50 #define MENU_EDIT_ACTION_OFFSET 16
51
52
53 /*
54  *-----------------------------------------------------------------------------
55  * keyboard handler
56  *-----------------------------------------------------------------------------
57  */
58
59 static guint tree_key_overrides[] = {
60         GDK_Page_Up,    GDK_KP_Page_Up,
61         GDK_Page_Down,  GDK_KP_Page_Down,
62         GDK_Home,       GDK_KP_Home,
63         GDK_End,        GDK_KP_End
64 };
65
66 static gboolean layout_key_match(guint keyval)
67 {
68         guint i;
69
70         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
71                 {
72                 if (keyval == tree_key_overrides[i]) return TRUE;
73                 }
74
75         return FALSE;
76 }
77
78 gint layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
79 {
80         LayoutWindow *lw = data;
81         gint stop_signal = FALSE;
82         gint x = 0;
83         gint y = 0;
84
85         if (lw->path_entry && GTK_WIDGET_HAS_FOCUS(lw->path_entry))
86                 {
87                 if (event->keyval == GDK_Escape && lw->dir_fd)
88                         {
89                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
90                         }
91
92                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
93                  * so when the some widgets have focus, give them priority (HACK)
94                  */
95                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
96                         {
97                         return TRUE;
98                         }
99                 }
100         if (lw->vd && lw->dir_view_type == DIRVIEW_TREE && GTK_WIDGET_HAS_FOCUS(lw->vd->view) &&
101             !layout_key_match(event->keyval) &&
102             gtk_widget_event(lw->vd->view, (GdkEvent *)event))
103                 {
104                 return TRUE;
105                 }
106         if (lw->bar_info &&
107             bar_info_event(lw->bar_info, (GdkEvent *)event))
108                 {
109                 return TRUE;
110                 }
111
112 /*
113         if (event->type == GDK_KEY_PRESS && lw->full_screen &&
114             gtk_accel_groups_activate(G_OBJECT(lw->window), event->keyval, event->state))
115                 return TRUE;
116 */
117
118         if (lw->image &&
119             (GTK_WIDGET_HAS_FOCUS(lw->image->widget) || (lw->tools && widget == lw->window) || lw->full_screen) )
120                 {
121                 stop_signal = TRUE;
122                 switch (event->keyval)
123                         {
124                         case GDK_Left: case GDK_KP_Left:
125                                 x -= 1;
126                                 break;
127                         case GDK_Right: case GDK_KP_Right:
128                                 x += 1;
129                                 break;
130                         case GDK_Up: case GDK_KP_Up:
131                                 y -= 1;
132                                 break;
133                         case GDK_Down: case GDK_KP_Down:
134                                 y += 1;
135                                 break;
136                         default:
137                                 stop_signal = FALSE;
138                                 break;
139                         }
140
141                 if (!stop_signal &&
142                     !(event->state & GDK_CONTROL_MASK))
143                         {
144                         stop_signal = TRUE;
145                         switch (event->keyval)
146                                 {
147                                 case GDK_Menu:
148                                         layout_image_menu_popup(lw);
149                                         break;
150                                 default:
151                                         stop_signal = FALSE;
152                                         break;
153                                 }
154                         }
155                 }
156
157         if (x != 0 || y!= 0)
158                 {
159                 if (event->state & GDK_SHIFT_MASK)
160                         {
161                         x *= 3;
162                         y *= 3;
163                         }
164
165                 keyboard_scroll_calc(&x, &y, event);
166                 layout_image_scroll(lw, x, y);
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
201         layout_exit_fullscreen(lw);
202
203         nw = layout_new(NULL, FALSE, FALSE);
204         layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending);
205         layout_set_fd(nw, lw->dir_fd);
206 }
207
208 static void layout_menu_new_cb(GtkAction *action, gpointer data)
209 {
210         LayoutWindow *lw = data;
211
212         layout_exit_fullscreen(lw);
213         collection_window_new(NULL);
214 }
215
216 static void layout_menu_open_cb(GtkAction *action, gpointer data)
217 {
218         LayoutWindow *lw = data;
219
220         layout_exit_fullscreen(lw);
221         collection_dialog_load(NULL);
222 }
223
224 static void layout_menu_search_cb(GtkAction *action, gpointer data)
225 {
226         LayoutWindow *lw = data;
227
228         layout_exit_fullscreen(lw);
229         search_new(lw->dir_fd, layout_image_get_fd(lw));
230 }
231
232 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
233 {
234         LayoutWindow *lw = data;
235
236         layout_exit_fullscreen(lw);
237         dupe_window_new(DUPE_MATCH_NAME);
238 }
239
240 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
241 {
242         LayoutWindow *lw = data;
243
244         layout_exit_fullscreen(lw);
245         pan_window_new(lw->dir_fd);
246 }
247
248 static void layout_menu_print_cb(GtkAction *action, gpointer data)
249 {
250         LayoutWindow *lw = data;
251
252         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), layout_window(lw));
253 }
254
255 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
256 {
257         LayoutWindow *lw = data;
258
259         file_util_create_dir(lw->dir_fd, layout_window(lw));
260 }
261
262 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
263 {
264         LayoutWindow *lw = data;
265
266         file_util_copy(NULL, layout_selection_list(lw), NULL, layout_window(lw));
267 }
268
269 static void layout_menu_copy_path_cb(GtkAction *action, gpointer data)
270 {
271         LayoutWindow *lw = data;
272
273         file_util_copy_path_list_to_clipboard(layout_selection_list(lw));
274 }
275
276 static void layout_menu_move_cb(GtkAction *action, gpointer data)
277 {
278         LayoutWindow *lw = data;
279
280         file_util_move(NULL, layout_selection_list(lw), NULL, layout_window(lw));
281 }
282
283 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
284 {
285         LayoutWindow *lw = data;
286
287         file_util_rename(NULL, layout_selection_list(lw), layout_window(lw));
288 }
289
290 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
291 {
292         LayoutWindow *lw = data;
293
294         file_util_delete(NULL, layout_selection_list(lw), layout_window(lw));
295 }
296
297 static void layout_menu_close_cb(GtkAction *action, gpointer data)
298 {
299         LayoutWindow *lw = data;
300
301         layout_exit_fullscreen(lw);
302         layout_close(lw);
303 }
304
305 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
306 {
307         exit_program();
308 }
309
310 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
311 {
312         LayoutWindow *lw = data;
313
314         layout_image_alter(lw, ALTER_ROTATE_90);
315 }
316
317 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
318 {
319         LayoutWindow *lw = data;
320
321         layout_image_alter(lw, ALTER_ROTATE_90_CC);
322 }
323
324 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
325 {
326         LayoutWindow *lw = data;
327
328         layout_image_alter(lw, ALTER_ROTATE_180);
329 }
330
331 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
332 {
333         LayoutWindow *lw = data;
334
335         layout_image_alter(lw, ALTER_MIRROR);
336 }
337
338 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
339 {
340         LayoutWindow *lw = data;
341
342         layout_image_alter(lw, ALTER_FLIP);
343 }
344
345 static void layout_menu_alter_desaturate_cb(GtkAction *action, gpointer data)
346 {
347         LayoutWindow *lw = data;
348
349         layout_image_alter(lw, ALTER_DESATURATE);
350 }
351
352 static void layout_menu_alter_none_cb(GtkAction *action, gpointer data)
353 {
354         LayoutWindow *lw = data;
355
356         layout_image_alter(lw, ALTER_NONE);
357 }
358
359 static void layout_menu_info_cb(GtkAction *action, gpointer data)
360 {
361         LayoutWindow *lw = data;
362         GList *list;
363         FileData *fd = NULL;
364
365         list = layout_selection_list(lw);
366         if (!list) fd = layout_image_get_fd(lw);
367
368         info_window_new(fd, list, NULL);
369 }
370
371
372 static void layout_menu_config_cb(GtkAction *action, gpointer data)
373 {
374         LayoutWindow *lw = data;
375
376         layout_exit_fullscreen(lw);
377         show_config_window();
378 }
379
380 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
381 {
382         LayoutWindow *lw = data;
383
384         layout_exit_fullscreen(lw);
385         cache_manager_show();
386 }
387
388 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
389 {
390         LayoutWindow *lw = data;
391
392         layout_image_to_root(lw);
393 }
394
395 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
396 {
397         LayoutWindow *lw = data;
398
399         layout_image_zoom_adjust(lw, get_zoom_increment());
400 }
401
402 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
403 {
404         LayoutWindow *lw = data;
405
406         layout_image_zoom_adjust(lw, -get_zoom_increment());
407 }
408
409 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
410 {
411         LayoutWindow *lw = data;
412
413         layout_image_zoom_set(lw, 1.0);
414 }
415
416 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
417 {
418         LayoutWindow *lw = data;
419
420         layout_image_zoom_set(lw, 0.0);
421 }
422
423 static void layout_menu_zoom_fit_hor_cb(GtkAction *action, gpointer data)
424 {
425         LayoutWindow *lw = data;
426
427         layout_image_zoom_set_fill_geometry(lw, TRUE);
428 }
429
430 static void layout_menu_zoom_fit_vert_cb(GtkAction *action, gpointer data)
431 {
432         LayoutWindow *lw = data;
433
434         layout_image_zoom_set_fill_geometry(lw, FALSE);
435 }
436
437 static void layout_menu_zoom_2_1_cb(GtkAction *action, gpointer data)
438 {
439         LayoutWindow *lw = data;
440
441         layout_image_zoom_set(lw, 2.0);
442 }
443
444 static void layout_menu_zoom_3_1_cb(GtkAction *action, gpointer data)
445 {
446         LayoutWindow *lw = data;
447
448         layout_image_zoom_set(lw, 3.0);
449 }
450 static void layout_menu_zoom_4_1_cb(GtkAction *action, gpointer data)
451 {
452         LayoutWindow *lw = data;
453
454         layout_image_zoom_set(lw, 4.0);
455 }
456
457 static void layout_menu_zoom_1_2_cb(GtkAction *action, gpointer data)
458 {
459         LayoutWindow *lw = data;
460
461         layout_image_zoom_set(lw, -2.0);
462 }
463
464 static void layout_menu_zoom_1_3_cb(GtkAction *action, gpointer data)
465 {
466         LayoutWindow *lw = data;
467
468         layout_image_zoom_set(lw, -3.0);
469 }
470
471 static void layout_menu_zoom_1_4_cb(GtkAction *action, gpointer data)
472 {
473         LayoutWindow *lw = data;
474
475         layout_image_zoom_set(lw, -4.0);
476 }
477
478
479 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
480 {
481         LayoutWindow *lw = data;
482         ImageSplitMode mode;
483
484         layout_exit_fullscreen(lw);
485
486         mode = gtk_radio_action_get_current_value(action);
487         if (mode == lw->split_mode) mode = 0; /* toggle back */
488
489         layout_split_change(lw, mode);
490 }
491
492 static void layout_menu_connect_scroll_cb(GtkToggleAction *action, gpointer data)
493 {
494         LayoutWindow *lw = data;
495         lw->connect_scroll = gtk_toggle_action_get_active(action);
496 }
497
498 static void layout_menu_connect_zoom_cb(GtkToggleAction *action, gpointer data)
499 {
500         LayoutWindow *lw = data;
501         lw->connect_zoom = gtk_toggle_action_get_active(action);
502 }
503
504
505 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
506 {
507         LayoutWindow *lw = data;
508
509         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
510 }
511
512
513 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
514 {
515         LayoutWindow *lw = data;
516         
517         layout_exit_fullscreen(lw);
518         layout_views_set(lw, lw->dir_view_type, (gtk_radio_action_get_current_value(action) == 1) ? FILEVIEW_ICON : FILEVIEW_LIST);
519 }
520
521 static void layout_menu_view_dir_as_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
522 {
523         LayoutWindow *lw = data;
524
525         layout_exit_fullscreen(lw);
526         layout_views_set(lw, (DirViewType) gtk_radio_action_get_current_value(action), lw->file_view_type);
527 }
528
529 static void layout_menu_view_in_new_window_cb(GtkAction *action, gpointer data)
530 {
531         LayoutWindow *lw = data;
532
533         layout_exit_fullscreen(lw);
534         view_window_new(layout_image_get_fd(lw));
535 }
536
537 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
538 {
539         LayoutWindow *lw = data;
540
541         layout_image_full_screen_toggle(lw);
542 }
543
544 static void layout_menu_escape_cb(GtkAction *action, gpointer data)
545 {
546         LayoutWindow *lw = data;
547
548         layout_exit_fullscreen(lw);
549
550         /* FIXME:interrupting thumbs no longer allowed */
551 #if 0
552         interrupt_thumbs();
553 #endif
554 }
555
556 static void layout_menu_overlay_cb(GtkAction *action, gpointer data)
557 {
558         LayoutWindow *lw = data;
559
560         image_osd_toggle(lw->image);
561 }
562
563 static void layout_menu_histogram_chan_cb(GtkAction *action, gpointer data)
564 {
565         LayoutWindow *lw = data;
566
567         image_osd_histogram_chan_toggle(lw->image);
568 }
569
570 static void layout_menu_histogram_log_cb(GtkAction *action, gpointer data)
571 {
572         LayoutWindow *lw = data;
573
574         image_osd_histogram_log_toggle(lw->image);
575 }
576
577 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
578 {
579         LayoutWindow *lw = data;
580
581         layout_refresh(lw);
582 }
583
584 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
585 {
586         LayoutWindow *lw = data;
587         
588         layout_exit_fullscreen(lw);
589
590         if (lw->tools_float == gtk_toggle_action_get_active(action)) return;
591         layout_tools_float_toggle(lw);
592 }
593
594 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
595 {
596         LayoutWindow *lw = data;
597
598         layout_exit_fullscreen(lw);
599         layout_tools_hide_toggle(lw);
600 }
601
602 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
603 {
604         LayoutWindow *lw = data;
605
606         layout_exit_fullscreen(lw);
607
608         if (lw->toolbar_hidden == gtk_toggle_action_get_active(action)) return;
609         layout_toolbar_toggle(lw);
610 }
611
612 static void layout_menu_bar_info_cb(GtkToggleAction *action, gpointer data)
613 {
614         LayoutWindow *lw = data;
615
616         layout_exit_fullscreen(lw);
617
618         if (lw->bar_info_enabled == gtk_toggle_action_get_active(action)) return;
619         layout_bar_info_toggle(lw);
620 }
621
622 static void layout_menu_bar_exif_cb(GtkToggleAction *action, gpointer data)
623 {
624         LayoutWindow *lw = data;
625         
626         layout_exit_fullscreen(lw);
627
628         if (lw->bar_exif_enabled == gtk_toggle_action_get_active(action)) return;
629         layout_bar_exif_toggle(lw);
630 }
631
632 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
633 {
634         LayoutWindow *lw = data;
635
636         layout_exit_fullscreen(lw);
637
638         if (lw->bar_sort_enabled == gtk_toggle_action_get_active(action)) return;
639         layout_bar_sort_toggle(lw);
640 }
641
642 static void layout_menu_slideshow_cb(GtkAction *action, gpointer data)
643 {
644         LayoutWindow *lw = data;
645
646         layout_image_slideshow_toggle(lw);
647 }
648
649 static void layout_menu_slideshow_pause_cb(GtkAction *action, gpointer data)
650 {
651         LayoutWindow *lw = data;
652
653         layout_image_slideshow_pause_toggle(lw);
654 }
655
656 static void layout_menu_help_cb(GtkAction *action, gpointer data)
657 {
658         LayoutWindow *lw = data;
659
660         layout_exit_fullscreen(lw);
661         help_window_show("html_contents");
662 }
663
664 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
665 {
666         LayoutWindow *lw = data;
667
668         layout_exit_fullscreen(lw);
669         help_window_show("documentation");
670 }
671
672 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
673 {
674         LayoutWindow *lw = data;
675         
676         layout_exit_fullscreen(lw);
677         help_window_show("release_notes");
678 }
679
680 static void layout_menu_about_cb(GtkAction *action, gpointer data)
681 {
682         LayoutWindow *lw = data;
683
684         layout_exit_fullscreen(lw);
685         show_about_window();
686 }
687
688 static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
689 {
690         LayoutWindow *lw = data;
691
692         layout_exit_fullscreen(lw);
693         log_window_new();
694 }
695
696
697 /*
698  *-----------------------------------------------------------------------------
699  * select menu
700  *-----------------------------------------------------------------------------
701  */
702
703 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
704 {
705         LayoutWindow *lw = data;
706
707         layout_select_all(lw);
708 }
709
710 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
711 {
712         LayoutWindow *lw = data;
713
714         layout_select_none(lw);
715 }
716
717 static void layout_menu_invert_selection_cb(GtkAction *action, gpointer data)
718 {
719         LayoutWindow *lw = data;
720
721         layout_select_invert(lw);
722 }
723
724 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
725 {
726         LayoutWindow *lw = data;
727
728         layout_marks_set(lw, gtk_toggle_action_get_active(action));
729 }
730
731
732 static void layout_menu_set_mark_sel_cb(GtkAction *action, gpointer data)
733 {
734         LayoutWindow *lw = data;
735         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
736         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
737
738         layout_selection_to_mark(lw, mark, STM_MODE_SET);
739 }
740
741 static void layout_menu_res_mark_sel_cb(GtkAction *action, gpointer data)
742 {
743         LayoutWindow *lw = data;
744         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
745         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
746
747         layout_selection_to_mark(lw, mark, STM_MODE_RESET);
748 }
749
750 static void layout_menu_toggle_mark_sel_cb(GtkAction *action, gpointer data)
751 {
752         LayoutWindow *lw = data;
753         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
754         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
755
756         layout_selection_to_mark(lw, mark, STM_MODE_TOGGLE);
757 }
758
759 static void layout_menu_sel_mark_cb(GtkAction *action, gpointer data)
760 {
761         LayoutWindow *lw = data;
762         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
763         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
764
765         layout_mark_to_selection(lw, mark, MTS_MODE_SET);
766 }
767
768 static void layout_menu_sel_mark_or_cb(GtkAction *action, gpointer data)
769 {
770         LayoutWindow *lw = data;
771         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
772         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
773
774         layout_mark_to_selection(lw, mark, MTS_MODE_OR);
775 }
776
777 static void layout_menu_sel_mark_and_cb(GtkAction *action, gpointer data)
778 {
779         LayoutWindow *lw = data;
780         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
781         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
782
783         layout_mark_to_selection(lw, mark, MTS_MODE_AND);
784 }
785
786 static void layout_menu_sel_mark_minus_cb(GtkAction *action, gpointer data)
787 {
788         LayoutWindow *lw = data;
789         gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "mark_num"));
790         g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
791
792         layout_mark_to_selection(lw, mark, MTS_MODE_MINUS);
793 }
794
795
796 /*
797  *-----------------------------------------------------------------------------
798  * go menu
799  *-----------------------------------------------------------------------------
800  */
801
802 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
803 {
804         LayoutWindow *lw = data;
805         layout_image_first(lw);
806 }
807
808 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
809 {
810         LayoutWindow *lw = data;
811         layout_image_prev(lw);
812 }
813
814 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
815 {
816         LayoutWindow *lw = data;
817         layout_image_next(lw);
818 }
819
820 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
821 {
822         LayoutWindow *lw = data;
823         layout_image_last(lw);
824 }
825
826
827 /*
828  *-----------------------------------------------------------------------------
829  * edit menu
830  *-----------------------------------------------------------------------------
831  */
832
833 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
834 {
835         LayoutWindow *lw = data;
836         GList *list;
837         gint n;
838
839         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "edit_index"));
840
841         if (!editor_window_flag_set(n))
842                 layout_exit_fullscreen(lw);
843
844         list = layout_selection_list(lw);
845         file_util_start_editor_from_filelist(n, list, lw->window);
846         filelist_free(list);
847 }
848
849 static void layout_menu_edit_update(LayoutWindow *lw)
850 {
851         gint i;
852
853         /* main edit menu */
854
855         if (!lw->action_group) return;
856
857         for (i = 0; i < GQ_EDITOR_GENERIC_SLOTS; i++)
858                 {
859                 gchar *key;
860                 GtkAction *action;
861                 const gchar *name;
862         
863                 key = g_strdup_printf("Editor%d", i);
864
865                 action = gtk_action_group_get_action(lw->action_group, key);
866                 g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i));
867
868                 name = editor_get_name(i);
869                 if (name)
870                         {
871                         gchar *text = g_strdup_printf(_("_%d %s..."), i, name);
872
873                         g_object_set(action, "label", text,
874                                              "sensitive", TRUE, NULL);
875                         g_free(text);
876                         }
877                 else
878                         {
879                         gchar *text;
880
881                         text = g_strdup_printf(_("_%d empty"), i);
882                         g_object_set(action, "label", text, "sensitive", FALSE, NULL);
883                         g_free(text);
884                         }
885
886                 g_free(key);
887                 }
888 }
889
890 void layout_edit_update_all(void)
891 {
892         GList *work;
893
894         work = layout_window_list;
895         while (work)
896                 {
897                 LayoutWindow *lw = work->data;
898                 work = work->next;
899
900                 layout_menu_edit_update(lw);
901                 }
902 }
903
904 /*
905  *-----------------------------------------------------------------------------
906  * recent menu
907  *-----------------------------------------------------------------------------
908  */
909
910 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
911 {
912         gint n;
913         gchar *path;
914
915         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
916
917         path = g_list_nth_data(history_list_get_by_key("recent"), n);
918
919         if (!path) return;
920
921         /* make a copy of it */
922         path = g_strdup(path);
923         collection_window_new(path);
924         g_free(path);
925 }
926
927 static void layout_menu_recent_update(LayoutWindow *lw)
928 {
929         GtkWidget *menu;
930         GtkWidget *recent;
931         GtkWidget *item;
932         GList *list;
933         gint n;
934
935         if (!lw->ui_manager) return;
936
937         list = history_list_get_by_key("recent");
938         n = 0;
939
940         menu = gtk_menu_new();
941
942         while (list)
943                 {
944                 item = menu_item_add_simple(menu, filename_from_path((gchar *)list->data),
945                                             G_CALLBACK(layout_menu_recent_cb), lw);
946                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
947                 list = list->next;
948                 n++;
949                 }
950
951         if (n == 0)
952                 {
953                 menu_item_add(menu, _("Empty"), NULL, NULL);
954                 }
955
956         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
957         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
958         gtk_widget_set_sensitive(recent, (n != 0));
959 }
960
961 void layout_recent_update_all(void)
962 {
963         GList *work;
964
965         work = layout_window_list;
966         while (work)
967                 {
968                 LayoutWindow *lw = work->data;
969                 work = work->next;
970
971                 layout_menu_recent_update(lw);
972                 }
973 }
974
975 void layout_recent_add_path(const gchar *path)
976 {
977         if (!path) return;
978
979         history_list_add_to_key("recent", path, options->open_recent_list_maxsize);
980
981         layout_recent_update_all();
982 }
983
984 /*
985  *-----------------------------------------------------------------------------
986  * copy path
987  *-----------------------------------------------------------------------------
988  */
989
990 static void layout_copy_path_update(LayoutWindow *lw)
991 {
992         GtkWidget *item = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/CopyPath");
993
994         if (!item) return;
995         
996         if (options->show_copy_path)
997                 gtk_widget_show(item);
998         else
999                 gtk_widget_hide(item);
1000 }
1001
1002 void layout_copy_path_update_all(void)
1003 {
1004         GList *work;
1005
1006         work = layout_window_list;
1007         while (work)
1008                 {
1009                 LayoutWindow *lw = work->data;
1010                 work = work->next;
1011
1012                 layout_copy_path_update(lw);
1013                 }
1014 }
1015
1016 /*
1017  *-----------------------------------------------------------------------------
1018  * menu
1019  *-----------------------------------------------------------------------------
1020  */
1021
1022 #define CB G_CALLBACK
1023
1024 static GtkActionEntry menu_entries[] = {
1025   { "FileMenu",         NULL,           N_("_File"),                    NULL,           NULL,   NULL },
1026   { "GoMenu",           NULL,           N_("_Go"),                      NULL,           NULL,   NULL },
1027   { "EditMenu",         NULL,           N_("_Edit"),                    NULL,           NULL,   NULL },
1028   { "SelectMenu",       NULL,           N_("_Select"),                  NULL,           NULL,   NULL },
1029   { "AdjustMenu",       NULL,           N_("_Adjust"),                  NULL,           NULL,   NULL },
1030   { "ViewMenu",         NULL,           N_("_View"),                    NULL,           NULL,   NULL },
1031   { "DirMenu",          NULL,           N_("_View Directory as"),       NULL,           NULL,   NULL },
1032   { "ZoomMenu",         NULL,           N_("_Zoom"),                    NULL,           NULL,   NULL },
1033   { "SplitMenu",        NULL,           N_("_Split"),                   NULL,           NULL,   NULL },
1034   { "HelpMenu",         NULL,           N_("_Help"),                    NULL,           NULL,   NULL },
1035
1036   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),     "Home",         NULL,   CB(layout_menu_image_first_cb) },
1037   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),  "BackSpace",    NULL,   CB(layout_menu_image_prev_cb) },
1038   { "PrevImageAlt1",    GTK_STOCK_GO_UP,        N_("_Previous Image"),  "Page_Up",      NULL,   CB(layout_menu_image_prev_cb) },
1039   { "PrevImageAlt2",    GTK_STOCK_GO_UP,        N_("_Previous Image"),  "KP_Page_Up",   NULL,   CB(layout_menu_image_prev_cb) },
1040   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),      "space",        NULL,   CB(layout_menu_image_next_cb) },
1041   { "NextImageAlt1",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),      "Page_Down",    NULL,   CB(layout_menu_image_next_cb) },
1042   { "NextImageAlt2",    GTK_STOCK_GO_DOWN,      N_("_Next Image"),      "KP_Page_Down", NULL,   CB(layout_menu_image_next_cb) },
1043   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),      "End",          NULL,   CB(layout_menu_image_last_cb) },
1044
1045
1046   { "NewWindow",        GTK_STOCK_NEW,  N_("New _window"),      NULL,           NULL,   CB(layout_menu_new_window_cb) },
1047   { "NewCollection",    GTK_STOCK_INDEX,N_("_New collection"),  "C",            NULL,   CB(layout_menu_new_cb) },
1048   { "OpenCollection",   GTK_STOCK_OPEN, N_("_Open collection..."),"O",          NULL,   CB(layout_menu_open_cb) },
1049   { "OpenRecent",       NULL,           N_("Open _recent"),     NULL,           NULL,   NULL },
1050   { "Search",           GTK_STOCK_FIND, N_("_Search..."),       "F3",           NULL,   CB(layout_menu_search_cb) },
1051   { "FindDupes",        GTK_STOCK_FIND, N_("_Find duplicates..."),"D",          NULL,   CB(layout_menu_dupes_cb) },
1052   { "PanView",          NULL,           N_("Pan _view"),        "<control>J",   NULL,   CB(layout_menu_pan_cb) },
1053   { "Print",            GTK_STOCK_PRINT,N_("_Print..."),        "<shift>P",     NULL,   CB(layout_menu_print_cb) },
1054   { "NewFolder",        NULL,           N_("N_ew folder..."),   "<control>F",   NULL,   CB(layout_menu_dir_cb) },
1055   { "Copy",             NULL,           N_("_Copy..."),         "<control>C",   NULL,   CB(layout_menu_copy_cb) },
1056   { "Move",             NULL,           N_("_Move..."),         "<control>M",   NULL,   CB(layout_menu_move_cb) },
1057   { "Rename",           NULL,           N_("_Rename..."),       "<control>R",   NULL,   CB(layout_menu_rename_cb) },
1058   { "Delete",   GTK_STOCK_DELETE,       N_("_Delete..."),       "<control>D",   NULL,   CB(layout_menu_delete_cb) },
1059   { "DeleteAlt1",GTK_STOCK_DELETE,      N_("_Delete..."),       "Delete",       NULL,   CB(layout_menu_delete_cb) },
1060   { "DeleteAlt2",GTK_STOCK_DELETE,      N_("_Delete..."),       "KP_Delete",    NULL,   CB(layout_menu_delete_cb) },
1061   { "CopyPath",         NULL,           N_("_Copy path"),       NULL,           NULL,   CB(layout_menu_copy_path_cb) },
1062   { "CloseWindow",      GTK_STOCK_CLOSE,N_("C_lose window"),    "<control>W",   NULL,   CB(layout_menu_close_cb) },
1063   { "Quit",             GTK_STOCK_QUIT, N_("_Quit"),            "<control>Q",   NULL,   CB(layout_menu_exit_cb) },
1064
1065   { "Editor0",          NULL,           "editor0",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1066   { "Editor1",          NULL,           "editor1",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1067   { "Editor2",          NULL,           "editor2",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1068   { "Editor3",          NULL,           "editor3",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1069   { "Editor4",          NULL,           "editor4",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1070   { "Editor5",          NULL,           "editor5",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1071   { "Editor6",          NULL,           "editor6",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1072   { "Editor7",          NULL,           "editor7",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1073   { "Editor8",          NULL,           "editor8",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1074   { "Editor9",          NULL,           "editor9",              NULL,           NULL,   CB(layout_menu_edit_cb) },
1075
1076   { "RotateCW",         NULL,   N_("_Rotate clockwise"),        "bracketright", NULL,   CB(layout_menu_alter_90_cb) },
1077   { "RotateCCW",        NULL,   N_("Rotate _counterclockwise"), "bracketleft",  NULL,   CB(layout_menu_alter_90cc_cb) },
1078   { "Rotate180",        NULL,           N_("Rotate 1_80"),      "<shift>R",     NULL,   CB(layout_menu_alter_180_cb) },
1079   { "Mirror",           NULL,           N_("_Mirror"),          "<shift>M",     NULL,   CB(layout_menu_alter_mirror_cb) },
1080   { "Flip",             NULL,           N_("_Flip"),            "<shift>F",     NULL,   CB(layout_menu_alter_flip_cb) },
1081   { "Grayscale",        NULL,           N_("Toggle _grayscale"),"<shift>G",     NULL,   CB(layout_menu_alter_desaturate_cb) },
1082   { "AlterNone",        NULL,           N_("_Original state"),  "<shift>O",     NULL,   CB(layout_menu_alter_none_cb) },
1083
1084   { "Properties",GTK_STOCK_PROPERTIES,  N_("_Properties"),      "<control>P",   NULL,   CB(layout_menu_info_cb) },
1085   { "SelectAll",        NULL,           N_("Select _all"),      "<control>A",   NULL,   CB(layout_menu_select_all_cb) },
1086   { "SelectNone",       NULL,           N_("Select _none"), "<control><shift>A",NULL,   CB(layout_menu_unselect_all_cb) },
1087   { "SelectInvert",     NULL,           N_("_Invert Selection"), "<control><shift>I",   NULL,   CB(layout_menu_invert_selection_cb) },
1088
1089   { "Preferences",GTK_STOCK_PREFERENCES,N_("P_references..."),  "<control>O",   NULL,   CB(layout_menu_config_cb) },
1090   { "Maintenance",      NULL,           N_("_Thumbnail maintenance..."),NULL,   NULL,   CB(layout_menu_remove_thumb_cb) },
1091   { "Wallpaper",        NULL,           N_("Set as _wallpaper"),NULL,           NULL,   CB(layout_menu_wallpaper_cb) },
1092
1093   { "ZoomIn",   GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "equal",        NULL,   CB(layout_menu_zoom_in_cb) },
1094   { "ZoomInAlt1",GTK_STOCK_ZOOM_IN,     N_("Zoom _in"),         "plus",         NULL,   CB(layout_menu_zoom_in_cb) },
1095   { "ZoomInAlt2",GTK_STOCK_ZOOM_IN,     N_("Zoom _in"),         "KP_Add",       NULL,   CB(layout_menu_zoom_in_cb) },
1096   { "ZoomOut",  GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "minus",        NULL,   CB(layout_menu_zoom_out_cb) },
1097   { "ZoomOutAlt1",GTK_STOCK_ZOOM_OUT,   N_("Zoom _out"),        "KP_Subtract",  NULL,   CB(layout_menu_zoom_out_cb) },
1098   { "Zoom100",  GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "Z",            NULL,   CB(layout_menu_zoom_1_1_cb) },
1099   { "Zoom100Alt1",GTK_STOCK_ZOOM_100,   N_("Zoom _1:1"),        "KP_Divide",            NULL,   CB(layout_menu_zoom_1_1_cb) },
1100   { "ZoomFit",  GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "X",            NULL,   CB(layout_menu_zoom_fit_cb) },
1101   { "ZoomFitAlt1",GTK_STOCK_ZOOM_FIT,   N_("_Zoom to fit"),     "KP_Multiply",  NULL,   CB(layout_menu_zoom_fit_cb) },
1102   { "ZoomFillHor",      NULL,           N_("Fit _Horizontally"),"H",            NULL,   CB(layout_menu_zoom_fit_hor_cb) },
1103   { "ZoomFillVert",     NULL,           N_("Fit _Vorizontally"),"W",            NULL,   CB(layout_menu_zoom_fit_vert_cb) },
1104   { "Zoom200",          NULL,           N_("Zoom _2:1"),        NULL,           NULL,   CB(layout_menu_zoom_2_1_cb) },
1105   { "Zoom300",          NULL,           N_("Zoom _3:1"),        NULL,           NULL,   CB(layout_menu_zoom_3_1_cb) },
1106   { "Zoom400",          NULL,           N_("Zoom _4:1"),        NULL,           NULL,   CB(layout_menu_zoom_4_1_cb) },
1107   { "Zoom50",           NULL,           N_("Zoom 1:2"),         NULL,           NULL,   CB(layout_menu_zoom_1_2_cb) },
1108   { "Zoom33",           NULL,           N_("Zoom 1:3"),         NULL,           NULL,   CB(layout_menu_zoom_1_3_cb) },
1109   { "Zoom25",           NULL,           N_("Zoom 1:4"),         NULL,           NULL,   CB(layout_menu_zoom_1_4_cb) },
1110
1111
1112   { "ViewInNewWindow",  NULL,           N_("_View in new window"),      "<control>V",           NULL,   CB(layout_menu_view_in_new_window_cb) },
1113
1114   { "FullScreen",       NULL,           N_("F_ull screen"),     "F",            NULL,   CB(layout_menu_fullscreen_cb) },
1115   { "FullScreenAlt1",   NULL,           N_("F_ull screen"),     "V",            NULL,   CB(layout_menu_fullscreen_cb) },
1116   { "FullScreenAlt2",   NULL,           N_("F_ull screen"),     "F11",          NULL,   CB(layout_menu_fullscreen_cb) },
1117   { "Escape",           NULL,           N_("Escape"),           "Escape",       NULL,   CB(layout_menu_escape_cb) },
1118   { "EscapeAlt1",       NULL,           N_("Escape"),           "Q",            NULL,   CB(layout_menu_escape_cb) },
1119   { "ImageOverlay",     NULL,           N_("_Image Overlay"),   "I",            NULL,   CB(layout_menu_overlay_cb) },
1120   { "HistogramChan",    NULL,   N_("Histogram _channels"),      "K",            NULL,   CB(layout_menu_histogram_chan_cb) },
1121   { "HistogramLog",     NULL,   N_("Histogram _log mode"),      "J",            NULL,   CB(layout_menu_histogram_log_cb) },
1122   { "HideTools",        NULL,           N_("_Hide file list"),  "<control>H",   NULL,   CB(layout_menu_hide_cb) },
1123   { "SlideShowPause",   NULL,           N_("_Pause slideshow"), "P",            NULL,   CB(layout_menu_slideshow_pause_cb) },
1124   { "Refresh",  GTK_STOCK_REFRESH,      N_("_Refresh"),         "R",            NULL,   CB(layout_menu_refresh_cb) },
1125
1126   { "HelpContents",     GTK_STOCK_HELP, N_("_Contents"),        "F1",           NULL,   CB(layout_menu_help_cb) },
1127   { "HelpShortcuts",    NULL,           N_("_Keyboard shortcuts"),NULL,         NULL,   CB(layout_menu_help_keys_cb) },
1128   { "HelpNotes",        NULL,           N_("_Release notes"),   NULL,           NULL,   CB(layout_menu_notes_cb) },
1129   { "About",            NULL,           N_("_About"),           NULL,           NULL,   CB(layout_menu_about_cb) },
1130   { "LogWindow",        NULL,           N_("_Log Window"),      NULL,           NULL,   CB(layout_menu_log_window_cb) }
1131 };
1132
1133 static GtkToggleActionEntry menu_toggle_entries[] = {
1134   { "Thumbnails",       NULL,           N_("_Thumbnails"),      "T",            NULL,   CB(layout_menu_thumb_cb),        FALSE },
1135   { "ShowMarks",        NULL,           N_("Show _Marks"),      "M",            NULL,   CB(layout_menu_marks_cb),        FALSE  },
1136   { "FloatTools",       NULL,           N_("_Float file list"), "L",            NULL,   CB(layout_menu_float_cb),        FALSE  },
1137   { "HideToolbar",      NULL,           N_("Hide tool_bar"),    NULL,           NULL,   CB(layout_menu_toolbar_cb),      FALSE  },
1138   { "SBarKeywords",     NULL,           N_("_Keywords"),        "<control>K",   NULL,   CB(layout_menu_bar_info_cb),     FALSE  },
1139   { "SBarExif",         NULL,           N_("E_xif data"),       "<control>E",   NULL,   CB(layout_menu_bar_exif_cb),     FALSE  },
1140   { "SBarSort",         NULL,           N_("Sort _manager"),    "<control>S",   NULL,   CB(layout_menu_bar_sort_cb),     FALSE  },
1141   { "ConnectScroll",    NULL,           N_("Co_nnected scroll"),"<control>U",   NULL,   CB(layout_menu_connect_scroll_cb), FALSE  },
1142   { "ConnectZoom",      NULL,           N_("C_onnected zoom"),  "<control>Y",   NULL,   CB(layout_menu_connect_zoom_cb), FALSE  },
1143   { "SlideShow",        NULL,           N_("Toggle _slideshow"),"S",            NULL,   CB(layout_menu_slideshow_cb),    FALSE  },
1144 };
1145
1146 static GtkRadioActionEntry menu_radio_entries[] = {
1147   { "ViewList",         NULL,           N_("_List"),            "<control>L",   NULL,   0 },
1148   { "ViewIcons",        NULL,           N_("I_cons"),           "<control>I",   NULL,   1 }
1149 };
1150
1151 static GtkRadioActionEntry menu_split_radio_entries[] = {
1152   { "SplitHorizontal",  NULL,           N_("Horizontal"),       "E",            NULL,   SPLIT_HOR },
1153   { "SplitVertical",    NULL,           N_("Vertical"),         "U",            NULL,   SPLIT_VERT },
1154   { "SplitQuad",        NULL,           N_("Quad"),             NULL,           NULL,   SPLIT_QUAD },
1155   { "SplitSingle",      NULL,           N_("Single"),           "Y",            NULL,   SPLIT_NONE }
1156 };
1157
1158
1159 #undef CB
1160
1161 static const gchar *menu_ui_description =
1162 "<ui>"
1163 "  <menubar name='MainMenu'>"
1164 "    <menu action='FileMenu'>"
1165 "      <menuitem action='NewWindow'/>"
1166 "      <menuitem action='NewCollection'/>"
1167 "      <menuitem action='OpenCollection'/>"
1168 "      <menuitem action='OpenRecent'/>"
1169 "      <separator/>"
1170 "      <menuitem action='Search'/>"
1171 "      <menuitem action='FindDupes'/>"
1172 "      <menuitem action='PanView'/>"
1173 "      <separator/>"
1174 "      <menuitem action='Print'/>"
1175 "      <menuitem action='NewFolder'/>"
1176 "      <separator/>"
1177 "      <menuitem action='Copy'/>"
1178 "      <menuitem action='Move'/>"
1179 "      <menuitem action='Rename'/>"
1180 "      <menuitem action='Delete'/>"
1181 "      <menuitem action='CopyPath'/>"
1182 "      <separator/>"
1183 "      <menuitem action='CloseWindow'/>"
1184 "      <menuitem action='Quit'/>"
1185 "    </menu>"
1186 "    <menu action='GoMenu'>"
1187 "      <menuitem action='FirstImage'/>"
1188 "      <menuitem action='PrevImage'/>"
1189 "      <menuitem action='NextImage'/>"
1190 "      <menuitem action='LastImage'/>"
1191 "    </menu>"
1192 "    <menu action='SelectMenu'>"
1193 "      <menuitem action='SelectAll'/>"
1194 "      <menuitem action='SelectNone'/>"
1195 "      <menuitem action='SelectInvert'/>"
1196 "      <separator/>"
1197 "      <menuitem action='ShowMarks'/>"
1198 "      <separator/>"
1199 "    </menu>"
1200 "    <menu action='EditMenu'>"
1201 "      <menuitem action='Editor0'/>"
1202 "      <menuitem action='Editor1'/>"
1203 "      <menuitem action='Editor2'/>"
1204 "      <menuitem action='Editor3'/>"
1205 "      <menuitem action='Editor4'/>"
1206 "      <menuitem action='Editor5'/>"
1207 "      <menuitem action='Editor6'/>"
1208 "      <menuitem action='Editor7'/>"
1209 "      <menuitem action='Editor8'/>"
1210 "      <menuitem action='Editor9'/>"
1211 "      <separator/>"
1212 "      <menu action='AdjustMenu'>"
1213 "        <menuitem action='RotateCW'/>"
1214 "        <menuitem action='RotateCCW'/>"
1215 "        <menuitem action='Rotate180'/>"
1216 "        <menuitem action='Mirror'/>"
1217 "        <menuitem action='Flip'/>"
1218 "        <menuitem action='Grayscale'/>"
1219 "        <menuitem action='AlterNone'/>"
1220 "      </menu>"
1221 "      <menuitem action='Properties'/>"
1222 "      <separator/>"
1223 "      <menuitem action='Preferences'/>"
1224 "      <menuitem action='Maintenance'/>"
1225 "      <separator/>"
1226 "      <menuitem action='Wallpaper'/>"
1227 "    </menu>"
1228 "    <menu action='ViewMenu'>"
1229 "      <menuitem action='ViewInNewWindow'/>"
1230 "      <separator/>"
1231 "      <menu action='ZoomMenu'>"
1232 "        <menuitem action='ZoomIn'/>"
1233 "        <menuitem action='ZoomOut'/>"
1234 "        <menuitem action='ZoomFit'/>"
1235 "        <menuitem action='ZoomFillHor'/>"
1236 "        <menuitem action='ZoomFillVert'/>"
1237 "        <menuitem action='Zoom100'/>"
1238 "        <menuitem action='Zoom200'/>"
1239 "        <menuitem action='Zoom300'/>"
1240 "        <menuitem action='Zoom400'/>"
1241 "        <menuitem action='Zoom50'/>"
1242 "        <menuitem action='Zoom33'/>"
1243 "        <menuitem action='Zoom25'/>"
1244 "      </menu>"
1245 "      <separator/>"
1246 "      <menu action='SplitMenu'>"
1247 "        <menuitem action='SplitHorizontal'/>"
1248 "        <menuitem action='SplitVertical'/>"
1249 "        <menuitem action='SplitQuad'/>"
1250 "        <menuitem action='SplitSingle'/>"
1251 "      </menu>"
1252 "      <menuitem action='ConnectScroll'/>"
1253 "      <menuitem action='ConnectZoom'/>"
1254 "      <separator/>"
1255 "      <menuitem action='Thumbnails'/>"
1256 "      <menuitem action='ViewList'/>"
1257 "      <menuitem action='ViewIcons'/>"
1258 "      <separator/>"
1259 "      <menu action='DirMenu'>"
1260 "        <menuitem action='FolderList'/>"
1261 "        <menuitem action='FolderTree'/>"
1262 "      </menu>"
1263 "      <separator/>"
1264 "      <menuitem action='ImageOverlay'/>"
1265 "      <menuitem action='HistogramChan'/>"
1266 "      <menuitem action='HistogramLog'/>"
1267 "      <menuitem action='FullScreen'/>"
1268 "      <separator/>"
1269 "      <menuitem action='FloatTools'/>"
1270 "      <menuitem action='HideTools'/>"
1271 "      <menuitem action='HideToolbar'/>"
1272 "      <separator/>"
1273 "      <menuitem action='SBarKeywords'/>"
1274 "      <menuitem action='SBarExif'/>"
1275 "      <menuitem action='SBarSort'/>"
1276 "      <separator/>"
1277 "      <menuitem action='SlideShow'/>"
1278 "      <menuitem action='SlideShowPause'/>"
1279 "      <menuitem action='Refresh'/>"
1280 "    </menu>"
1281 "    <menu action='HelpMenu'>"
1282 "      <separator/>"
1283 "      <menuitem action='HelpContents'/>"
1284 "      <menuitem action='HelpShortcuts'/>"
1285 "      <menuitem action='HelpNotes'/>"
1286 "      <separator/>"
1287 "      <menuitem action='About'/>"
1288 "      <separator/>"
1289 "      <menuitem action='LogWindow'/>"
1290 "    </menu>"
1291 "  </menubar>"
1292 "<accelerator action='PrevImageAlt1'/>"
1293 "<accelerator action='PrevImageAlt2'/>"
1294 "<accelerator action='NextImageAlt1'/>"
1295 "<accelerator action='NextImageAlt2'/>"
1296 "<accelerator action='DeleteAlt1'/>"
1297 "<accelerator action='DeleteAlt2'/>"
1298 "<accelerator action='ZoomInAlt1'/>"
1299 "<accelerator action='ZoomInAlt2'/>"
1300 "<accelerator action='ZoomOutAlt1'/>"
1301 "<accelerator action='Zoom100Alt1'/>"
1302 "<accelerator action='ZoomFitAlt1'/>"
1303 "<accelerator action='FullScreenAlt1'/>"
1304 "<accelerator action='FullScreenAlt2'/>"
1305 "<accelerator action='Escape'/>"
1306 "<accelerator action='EscapeAlt1'/>"
1307 "</ui>";
1308
1309
1310 static gchar *menu_translate(const gchar *path, gpointer data)
1311 {
1312         return (gchar *)(_(path));
1313 }
1314
1315 static void layout_actions_setup_mark(LayoutWindow *lw, gint mark, gchar *name_tmpl, gchar *label_tmpl, gchar *accel_tmpl,  GCallback cb)
1316 {
1317         gchar name[50];
1318         gchar label[100];
1319         gchar accel[50];
1320         GtkActionEntry entry = { name, NULL, label, accel, NULL, cb };
1321         GtkAction *action;
1322
1323         g_snprintf(name, sizeof(name), name_tmpl, mark);
1324         g_snprintf(label, sizeof(label), label_tmpl, mark);
1325         if (accel_tmpl)
1326                 g_snprintf(accel, sizeof(accel), accel_tmpl, mark % 10);
1327         else
1328                 accel[0] = 0;
1329         gtk_action_group_add_actions(lw->action_group, &entry, 1, lw);
1330         action = gtk_action_group_get_action(lw->action_group, name);
1331         g_object_set_data(G_OBJECT(action), "mark_num", GINT_TO_POINTER(mark));
1332 }
1333
1334 static void layout_actions_setup_marks(LayoutWindow *lw)
1335 {
1336         gint mark;
1337         GError *error;
1338         GString *desc = g_string_new(
1339                                 "<ui>"
1340                                 "  <menubar name='MainMenu'>"
1341                                 "    <menu action='SelectMenu'>");
1342
1343         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1344                 {
1345                 layout_actions_setup_mark(lw, mark, "Mark%d",           _("Mark _%d"), NULL, NULL);
1346                 layout_actions_setup_mark(lw, mark, "SetMark%d",        _("_Set mark %d"),                      NULL, G_CALLBACK(layout_menu_set_mark_sel_cb));
1347                 layout_actions_setup_mark(lw, mark, "ResetMark%d",      _("_Reset mark %d"),                    NULL, G_CALLBACK(layout_menu_res_mark_sel_cb));
1348                 layout_actions_setup_mark(lw, mark, "ToggleMark%d",     _("_Toggle mark %d"),                   "%d", G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1349                 layout_actions_setup_mark(lw, mark, "ToggleMark%dAlt1", _("_Toggle mark %d"),                   "KP_%d", G_CALLBACK(layout_menu_toggle_mark_sel_cb));
1350                 layout_actions_setup_mark(lw, mark, "SelectMark%d",     _("_Select mark %d"),                   "<control>%d", G_CALLBACK(layout_menu_sel_mark_cb));
1351                 layout_actions_setup_mark(lw, mark, "SelectMark%dAlt1", _("_Select mark %d"),                   "<control>KP_%d", G_CALLBACK(layout_menu_sel_mark_cb));
1352                 layout_actions_setup_mark(lw, mark, "AddMark%d",        _("_Add mark %d"),                      NULL, G_CALLBACK(layout_menu_sel_mark_or_cb));
1353                 layout_actions_setup_mark(lw, mark, "IntMark%d",        _("_Intersection with mark %d"),        NULL, G_CALLBACK(layout_menu_sel_mark_and_cb));
1354                 layout_actions_setup_mark(lw, mark, "UnselMark%d",      _("_Unselect mark %d"),                 NULL, G_CALLBACK(layout_menu_sel_mark_minus_cb));
1355
1356                 g_string_append_printf(desc,
1357                                 "      <menu action='Mark%d'>"
1358                                 "        <menuitem action='ToggleMark%d'/>"
1359                                 "        <menuitem action='SetMark%d'/>"
1360                                 "        <menuitem action='ResetMark%d'/>"
1361                                 "        <separator/>"
1362                                 "        <menuitem action='SelectMark%d'/>"
1363                                 "        <menuitem action='AddMark%d'/>"
1364                                 "        <menuitem action='IntMark%d'/>"
1365                                 "        <menuitem action='UnselMark%d'/>"
1366                                 "      </menu>",
1367                                 mark, mark, mark, mark, mark, mark, mark, mark);
1368                 }
1369
1370         g_string_append(desc,
1371                                 "    </menu>"
1372                                 "  </menubar>");
1373         for (mark = 1; mark <= FILEDATA_MARKS_SIZE; mark++)
1374                 {
1375                 g_string_append_printf(desc,
1376                                 "<accelerator action='ToggleMark%dAlt1'/>"
1377                                 "<accelerator action='SelectMark%dAlt1'/>",
1378                                 mark, mark);
1379                 }
1380         g_string_append(desc,   "</ui>" );
1381
1382         error = NULL;
1383         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, desc->str, -1, &error))
1384                 {
1385                 g_message("building menus failed: %s", error->message);
1386                 g_error_free(error);
1387                 exit(EXIT_FAILURE);
1388                 }
1389         g_string_free(desc, TRUE);
1390 }
1391
1392 void layout_actions_setup(LayoutWindow *lw)
1393 {
1394         GError *error;
1395
1396         if (lw->ui_manager) return;
1397
1398         lw->action_group = gtk_action_group_new("MenuActions");
1399         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
1400
1401         gtk_action_group_add_actions(lw->action_group,
1402                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
1403         gtk_action_group_add_toggle_actions(lw->action_group,
1404                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
1405         gtk_action_group_add_radio_actions(lw->action_group,
1406                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
1407                                            0, G_CALLBACK(layout_menu_list_cb), lw);
1408         gtk_action_group_add_radio_actions(lw->action_group,
1409                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
1410                                            0, G_CALLBACK(layout_menu_split_cb), lw);
1411         gtk_action_group_add_radio_actions(lw->action_group,
1412                                            menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
1413                                            0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);
1414
1415         lw->ui_manager = gtk_ui_manager_new();
1416         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
1417         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
1418
1419         error = NULL;
1420         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
1421                 {
1422                 g_message("building menus failed: %s", error->message);
1423                 g_error_free(error);
1424                 exit(EXIT_FAILURE);
1425                 }
1426         
1427         layout_actions_setup_marks(lw);
1428         layout_copy_path_update(lw);
1429 }
1430
1431 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
1432 {
1433         GtkAccelGroup *group;
1434
1435         if (!lw->ui_manager) return;
1436
1437         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
1438         gtk_window_add_accel_group(GTK_WINDOW(window), group);
1439 }
1440
1441 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
1442 {
1443         return gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
1444 }
1445
1446
1447 /*
1448  *-----------------------------------------------------------------------------
1449  * toolbar
1450  *-----------------------------------------------------------------------------
1451  */
1452
1453 static void layout_button_thumb_cb(GtkWidget *widget, gpointer data)
1454 {
1455         LayoutWindow *lw = data;
1456
1457         layout_thumb_set(lw, gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)));
1458 }
1459
1460 static void layout_button_home_cb(GtkWidget *widget, gpointer data)
1461 {
1462         const gchar *path;
1463         
1464         if (options->layout.home_path && *options->layout.home_path)
1465                 path = options->layout.home_path;
1466         else
1467                 path = homedir();
1468
1469         if (path)
1470                 {
1471                 LayoutWindow *lw = data;
1472                 FileData *dir_fd = file_data_new_simple(path);
1473                 layout_set_fd(lw, dir_fd);
1474                 file_data_unref(dir_fd);
1475                 }
1476 }
1477
1478 static void layout_button_refresh_cb(GtkWidget *widget, gpointer data)
1479 {
1480         LayoutWindow *lw = data;
1481
1482         layout_refresh(lw);
1483 }
1484
1485 static void layout_button_zoom_in_cb(GtkWidget *widget, gpointer data)
1486 {
1487         LayoutWindow *lw = data;
1488
1489         layout_image_zoom_adjust(lw, get_zoom_increment());
1490 }
1491
1492 static void layout_button_zoom_out_cb(GtkWidget *widget, gpointer data)
1493 {
1494         LayoutWindow *lw = data;
1495
1496         layout_image_zoom_adjust(lw, -get_zoom_increment());
1497 }
1498
1499 static void layout_button_zoom_fit_cb(GtkWidget *widget, gpointer data)
1500 {
1501         LayoutWindow *lw = data;
1502
1503         layout_image_zoom_set(lw, 0.0);
1504 }
1505
1506 static void layout_button_zoom_1_1_cb(GtkWidget *widget, gpointer data)
1507 {
1508         LayoutWindow *lw = data;
1509
1510         layout_image_zoom_set(lw, 1.0);
1511 }
1512
1513 static void layout_button_config_cb(GtkWidget *widget, gpointer data)
1514 {
1515         show_config_window();
1516 }
1517
1518 static void layout_button_float_cb(GtkWidget *widget, gpointer data)
1519 {
1520         LayoutWindow *lw = data;
1521
1522         layout_tools_float_toggle(lw);
1523 }
1524
1525 static void layout_button_custom_icon(GtkWidget *button, const gchar *key)
1526 {
1527         GtkWidget *icon;
1528         GdkPixbuf *pixbuf;
1529
1530         pixbuf = pixbuf_inline(key);
1531         if (!pixbuf) return;
1532
1533         icon = gtk_image_new_from_pixbuf(pixbuf);
1534         g_object_unref(pixbuf);
1535
1536         pref_toolbar_button_set_icon(button, icon, NULL);
1537         gtk_widget_show(icon);
1538 }
1539
1540 GtkWidget *layout_button_bar(LayoutWindow *lw)
1541 {
1542         GtkWidget *box;
1543         GtkWidget *button;
1544
1545         box =  pref_toolbar_new(NULL, GTK_TOOLBAR_ICONS);
1546
1547         button = pref_toolbar_button(box, NULL, _("_Thumbnails"), TRUE,
1548                                      _("Show thumbnails"), G_CALLBACK(layout_button_thumb_cb), lw);
1549         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_THUMB);
1550         lw->thumb_button = button;
1551
1552         pref_toolbar_button(box, GTK_STOCK_HOME, NULL, FALSE,
1553                             _("Change to home folder"), G_CALLBACK(layout_button_home_cb), lw);
1554         pref_toolbar_button(box, GTK_STOCK_REFRESH, NULL, FALSE,
1555                             _("Refresh file list"), G_CALLBACK(layout_button_refresh_cb), lw);
1556         pref_toolbar_button(box, GTK_STOCK_ZOOM_IN, NULL, FALSE,
1557                             _("Zoom in"), G_CALLBACK(layout_button_zoom_in_cb), lw);
1558         pref_toolbar_button(box, GTK_STOCK_ZOOM_OUT, NULL, FALSE,
1559                             _("Zoom out"), G_CALLBACK(layout_button_zoom_out_cb), lw);
1560         pref_toolbar_button(box, GTK_STOCK_ZOOM_FIT, NULL, FALSE,
1561                             _("Fit image to window"), G_CALLBACK(layout_button_zoom_fit_cb), lw);
1562         pref_toolbar_button(box, GTK_STOCK_ZOOM_100, NULL, FALSE,
1563                             _("Set zoom 1:1"), G_CALLBACK(layout_button_zoom_1_1_cb), lw);
1564         pref_toolbar_button(box, GTK_STOCK_PREFERENCES, NULL, FALSE,
1565                             _("Preferences"), G_CALLBACK(layout_button_config_cb), lw);
1566         button = pref_toolbar_button(box, NULL, _("_Float"), FALSE,
1567                                      _("Float file list"), G_CALLBACK(layout_button_float_cb), lw);
1568         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_FLOAT);
1569
1570         return box;
1571 }
1572
1573 /*
1574  *-----------------------------------------------------------------------------
1575  * misc
1576  *-----------------------------------------------------------------------------
1577  */
1578
1579 static void layout_util_sync_views(LayoutWindow *lw)
1580 {
1581         GtkAction *action;
1582
1583         if (!lw->action_group) return;
1584
1585         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
1586         radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->dir_view_type);
1587
1588         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
1589         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->file_view_type);
1590
1591         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
1592         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tools_float);
1593
1594         action = gtk_action_group_get_action(lw->action_group, "SBarKeywords");
1595         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_info_enabled);
1596
1597         action = gtk_action_group_get_action(lw->action_group, "SBarExif");
1598         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_exif_enabled);
1599
1600         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
1601         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_sort_enabled);
1602
1603         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
1604         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->toolbar_hidden);
1605
1606         action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
1607         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->marks_enabled);
1608
1609         action = gtk_action_group_get_action(lw->action_group, "SlideShow");
1610         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw));
1611 }
1612
1613 void layout_util_sync_thumb(LayoutWindow *lw)
1614 {
1615         GtkAction *action;
1616
1617         if (!lw->action_group) return;
1618
1619         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
1620         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->thumbs_enabled);
1621         g_object_set(action, "sensitive", (lw->file_view_type == FILEVIEW_LIST), NULL);
1622
1623         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->thumbs_enabled);
1624         gtk_widget_set_sensitive(lw->thumb_button, (lw->file_view_type == FILEVIEW_LIST));
1625 }
1626
1627 void layout_util_sync(LayoutWindow *lw)
1628 {
1629         layout_util_sync_views(lw);
1630         layout_util_sync_thumb(lw);
1631         layout_menu_recent_update(lw);
1632         layout_menu_edit_update(lw);
1633 }
1634
1635 /*
1636  *-----------------------------------------------------------------------------
1637  * icons (since all the toolbar icons are included here, best place as any)
1638  *-----------------------------------------------------------------------------
1639  */
1640
1641 PixmapFolders *folder_icons_new(void)
1642 {
1643         PixmapFolders *pf;
1644
1645         pf = g_new0(PixmapFolders, 1);
1646
1647         pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
1648         pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
1649         pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
1650         pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
1651
1652         return pf;
1653 }
1654
1655 void folder_icons_free(PixmapFolders *pf)
1656 {
1657         if (!pf) return;
1658
1659         g_object_unref(pf->close);
1660         g_object_unref(pf->open);
1661         g_object_unref(pf->deny);
1662         g_object_unref(pf->parent);
1663
1664         g_free(pf);
1665 }
1666
1667 /*
1668  *-----------------------------------------------------------------------------
1669  * sidebars
1670  *-----------------------------------------------------------------------------
1671  */
1672
1673 static void layout_bar_info_destroyed(GtkWidget *widget, gpointer data)
1674 {
1675         LayoutWindow *lw = data;
1676
1677         lw->bar_info = NULL;
1678
1679         if (lw->utility_box)
1680                 {
1681                 /* destroyed from within itself */
1682                 lw->bar_info_enabled = FALSE;
1683                 layout_util_sync_views(lw);
1684                 }
1685 }
1686
1687 static GList *layout_bar_info_list_cb(gpointer data)
1688 {
1689         LayoutWindow *lw = data;
1690
1691         return layout_selection_list(lw);
1692 }
1693
1694 static void layout_bar_info_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1695 {
1696         LayoutWindow *lw = data;
1697
1698         if (!lw->bar_info) return;
1699         
1700         options->panels.info.width = lw->bar_info_width = allocation->width;
1701 }
1702
1703 static void layout_bar_info_new(LayoutWindow *lw)
1704 {
1705         if (!lw->utility_box) return;
1706
1707         lw->bar_info = bar_info_new(layout_image_get_fd(lw), FALSE, lw->utility_box);
1708         bar_info_set_selection_func(lw->bar_info, layout_bar_info_list_cb, lw);
1709         bar_info_selection(lw->bar_info, layout_selection_count(lw, NULL) - 1);
1710         g_signal_connect(G_OBJECT(lw->bar_info), "destroy",
1711                          G_CALLBACK(layout_bar_info_destroyed), lw);
1712         g_signal_connect(G_OBJECT(lw->bar_info), "size_allocate",
1713                          G_CALLBACK(layout_bar_info_sized), lw);
1714
1715         options->panels.info.enabled = lw->bar_info_enabled = TRUE;
1716         gtk_widget_set_size_request(lw->bar_info, lw->bar_info_width, -1);
1717
1718         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_info, FALSE, FALSE, 0);
1719         gtk_widget_show(lw->bar_info);
1720 }
1721
1722 static void layout_bar_info_close(LayoutWindow *lw)
1723 {
1724         if (lw->bar_info)
1725                 {
1726                 bar_info_close(lw->bar_info);
1727                 lw->bar_info = NULL;
1728                 }
1729         options->panels.info.enabled = lw->bar_info_enabled = FALSE;
1730 }
1731
1732 void layout_bar_info_toggle(LayoutWindow *lw)
1733 {
1734         if (lw->bar_info_enabled)
1735                 {
1736                 layout_bar_info_close(lw);
1737                 }
1738         else
1739                 {
1740                 layout_bar_info_new(lw);
1741                 }
1742 }
1743
1744 static void layout_bar_info_new_image(LayoutWindow *lw)
1745 {
1746         if (!lw->bar_info || !lw->bar_info_enabled) return;
1747
1748         bar_info_set(lw->bar_info, layout_image_get_fd(lw));
1749 }
1750
1751 static void layout_bar_info_new_selection(LayoutWindow *lw, gint count)
1752 {
1753         if (!lw->bar_info || !lw->bar_info_enabled) return;
1754
1755         bar_info_selection(lw->bar_info, count - 1);
1756 }
1757
1758 static void layout_bar_info_maint_renamed(LayoutWindow *lw)
1759 {
1760         if (!lw->bar_info || !lw->bar_info_enabled) return;
1761
1762         bar_info_maint_renamed(lw->bar_info, layout_image_get_fd(lw));
1763 }
1764
1765 static void layout_bar_exif_destroyed(GtkWidget *widget, gpointer data)
1766 {
1767         LayoutWindow *lw = data;
1768
1769         if (lw->bar_exif)
1770                 {
1771                 lw->bar_exif_advanced = bar_exif_is_advanced(lw->bar_exif);
1772                 }
1773
1774         lw->bar_exif = NULL;
1775         if (lw->utility_box)
1776                 {
1777                 /* destroyed from within itself */
1778                 lw->bar_exif_enabled = FALSE;
1779                 layout_util_sync_views(lw);
1780                 }
1781 }
1782
1783 static void layout_bar_exif_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1784 {
1785         LayoutWindow *lw = data;
1786
1787         if (!lw->bar_exif) return;
1788         
1789         options->panels.exif.width = lw->bar_exif_width = allocation->width;
1790 }
1791
1792 static void layout_bar_exif_new(LayoutWindow *lw)
1793 {
1794         if (!lw->utility_box) return;
1795
1796         lw->bar_exif = bar_exif_new(TRUE, layout_image_get_fd(lw),
1797                                     lw->bar_exif_advanced, lw->utility_box);
1798         g_signal_connect(G_OBJECT(lw->bar_exif), "destroy",
1799                          G_CALLBACK(layout_bar_exif_destroyed), lw);
1800         g_signal_connect(G_OBJECT(lw->bar_exif), "size_allocate",
1801                          G_CALLBACK(layout_bar_exif_sized), lw);
1802
1803         options->panels.exif.enabled = lw->bar_exif_enabled = TRUE;
1804         gtk_widget_set_size_request(lw->bar_exif, lw->bar_exif_width, -1);
1805
1806         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_exif, FALSE, FALSE, 0);
1807         if (lw->bar_info) gtk_box_reorder_child(GTK_BOX(lw->utility_box), lw->bar_exif, 1);
1808         gtk_widget_show(lw->bar_exif);
1809 }
1810
1811 static void layout_bar_exif_close(LayoutWindow *lw)
1812 {
1813         if (lw->bar_exif)
1814                 {
1815                 bar_exif_close(lw->bar_exif);
1816                 lw->bar_exif = NULL;
1817                 }
1818         options->panels.exif.enabled = lw->bar_exif_enabled = FALSE;
1819 }
1820
1821 void layout_bar_exif_toggle(LayoutWindow *lw)
1822 {
1823         if (lw->bar_exif_enabled)
1824                 {
1825                 layout_bar_exif_close(lw);
1826                 }
1827         else
1828                 {
1829                 layout_bar_exif_new(lw);
1830                 }
1831 }
1832
1833 static void layout_bar_exif_new_image(LayoutWindow *lw)
1834 {
1835         if (!lw->bar_exif || !lw->bar_exif_enabled) return;
1836
1837         bar_exif_set(lw->bar_exif, layout_image_get_fd(lw));
1838 }
1839
1840 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
1841 {
1842         LayoutWindow *lw = data;
1843
1844         lw->bar_sort = NULL;
1845
1846         if (lw->utility_box)
1847                 {
1848                 /* destroyed from within itself */
1849                 lw->bar_sort_enabled = FALSE;
1850
1851                 layout_util_sync_views(lw);
1852                 }
1853 }
1854
1855 static void layout_bar_sort_new(LayoutWindow *lw)
1856 {
1857         if (!lw->utility_box) return;
1858
1859         lw->bar_sort = bar_sort_new(lw);
1860         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
1861                          G_CALLBACK(layout_bar_sort_destroyed), lw);
1862         options->panels.sort.enabled = lw->bar_sort_enabled = TRUE;
1863
1864         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
1865         gtk_widget_show(lw->bar_sort);
1866 }
1867
1868 static void layout_bar_sort_close(LayoutWindow *lw)
1869 {
1870         if (lw->bar_sort)
1871                 {
1872                 bar_sort_close(lw->bar_sort);
1873                 lw->bar_sort = NULL;
1874                 }
1875         options->panels.sort.enabled = lw->bar_sort_enabled = FALSE;
1876 }
1877
1878 void layout_bar_sort_toggle(LayoutWindow *lw)
1879 {
1880         if (lw->bar_sort_enabled)
1881                 {
1882                 layout_bar_sort_close(lw);
1883                 }
1884         else
1885                 {
1886                 layout_bar_sort_new(lw);
1887                 }
1888 }
1889
1890 void layout_bars_new_image(LayoutWindow *lw)
1891 {
1892         layout_bar_info_new_image(lw);
1893         layout_bar_exif_new_image(lw);
1894 }
1895
1896 void layout_bars_new_selection(LayoutWindow *lw, gint count)
1897 {
1898         layout_bar_info_new_selection(lw, count);
1899 }
1900
1901 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
1902 {
1903         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
1904         gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
1905         gtk_widget_show(image);
1906
1907         if (lw->bar_sort_enabled)
1908                 {
1909                 layout_bar_sort_new(lw);
1910                 }
1911
1912         if (lw->bar_info_enabled)
1913                 {
1914                 layout_bar_info_new(lw);
1915                 }
1916
1917         if (lw->bar_exif_enabled)
1918                 {
1919                 layout_bar_exif_new(lw);
1920                 }
1921
1922         return lw->utility_box;
1923 }
1924
1925 void layout_bars_close(LayoutWindow *lw)
1926 {
1927         layout_bar_sort_close(lw);
1928         layout_bar_exif_close(lw);
1929         layout_bar_info_close(lw);
1930 }
1931
1932 void layout_bars_maint_renamed(LayoutWindow *lw)
1933 {
1934         layout_bar_info_maint_renamed(lw);
1935 }