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