moved some actions to menu and accels
[geeqie.git] / src / layout_util.c
1 /*
2  * GQview
3  * (C) 2004 John Ellis
4  *
5  * Author: John Ellis
6  *
7  * This software is released under the GNU General Public License (GNU GPL).
8  * Please read the included file COPYING for more information.
9  * This software comes with no warranty of any kind, use at your own risk!
10  */
11
12
13 #include "gqview.h"
14 #include "layout_util.h"
15
16 #include "bar_info.h"
17 #include "bar_exif.h"
18 #include "bar_sort.h"
19 #include "cache_maint.h"
20 #include "collect.h"
21 #include "collect-dlg.h"
22 #include "dupe.h"
23 #include "editors.h"
24 #include "img-view.h"
25 #include "info.h"
26 #include "layout_image.h"
27 #include "pan-view.h"
28 #include "pixbuf_util.h"
29 #include "preferences.h"
30 #include "print.h"
31 #include "search.h"
32 #include "utilops.h"
33 #include "ui_bookmark.h"
34 #include "ui_fileops.h"
35 #include "ui_menu.h"
36 #include "ui_misc.h"
37 #include "ui_tabcomp.h"
38
39 #include <gdk/gdkkeysyms.h> /* for keyboard values */
40
41
42 #define MENU_EDIT_ACTION_OFFSET 16
43
44
45 /*
46  *-----------------------------------------------------------------------------
47  * keyboard handler
48  *-----------------------------------------------------------------------------
49  */
50
51 static guint tree_key_overrides[] = {
52         GDK_Page_Up,    GDK_KP_Page_Up,
53         GDK_Page_Down,  GDK_KP_Page_Down,
54         GDK_Home,       GDK_KP_Home,
55         GDK_End,        GDK_KP_End
56 };
57
58 static gint layout_key_match(guint keyval)
59 {
60         gint i;
61
62         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
63                 {
64                 if (keyval == tree_key_overrides[i]) return TRUE;
65                 }
66
67         return FALSE;
68 }
69
70 static gint layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
71 {
72         LayoutWindow *lw = data;
73         gint stop_signal = FALSE;
74         gint x = 0;
75         gint y = 0;
76
77         if (lw->path_entry && GTK_WIDGET_HAS_FOCUS(lw->path_entry))
78                 {
79                 if (event->keyval == GDK_Escape && lw->path)
80                         {
81                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->path);
82                         }
83
84                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
85                  * so when the some widgets have focus, give them priority (HACK)
86                  */
87                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
88                         {
89                         return TRUE;
90                         }
91                 }
92         if (lw->vdt && GTK_WIDGET_HAS_FOCUS(lw->vdt->treeview) &&
93             !layout_key_match(event->keyval) &&
94             gtk_widget_event(lw->vdt->treeview, (GdkEvent *)event))
95                 {
96                 return TRUE;
97                 }
98         if (lw->bar_info &&
99             bar_info_event(lw->bar_info, (GdkEvent *)event))
100                 {
101                 return TRUE;
102                 }
103
104         if (lw->image &&
105             (GTK_WIDGET_HAS_FOCUS(lw->image->widget) || (lw->tools && widget == lw->window)) )
106                 {
107                 stop_signal = TRUE;
108                 switch (event->keyval)
109                         {
110                         case GDK_Left: case GDK_KP_Left:
111                                 x -= 1;
112                                 break;
113                         case GDK_Right: case GDK_KP_Right:
114                                 x += 1;
115                                 break;
116                         case GDK_Up: case GDK_KP_Up:
117                                 y -= 1;
118                                 break;
119                         case GDK_Down: case GDK_KP_Down:
120                                 y += 1;
121                                 break;
122                         default:
123                                 stop_signal = FALSE;
124                                 break;
125                         }
126
127                 if (!stop_signal &&
128                     !(event->state & GDK_CONTROL_MASK))
129                         {
130                         stop_signal = TRUE;
131                         switch (event->keyval)
132                                 {
133                                 case GDK_Menu:
134                                         layout_image_menu_popup(lw);
135                                         break;
136                                 default:
137                                         stop_signal = FALSE;
138                                         break;
139                                 }
140                         }
141                 }
142
143         if (x != 0 || y!= 0)
144                 {
145                 if (event->state & GDK_SHIFT_MASK)
146                         {
147                         x *= 3;
148                         y *= 3;
149                         }
150
151                 keyboard_scroll_calc(&x, &y, event);
152                 layout_image_scroll(lw, x, y);
153                 }
154
155         if (stop_signal) return stop_signal;
156
157         if (event->state & GDK_CONTROL_MASK)
158                 {
159                 stop_signal = FALSE;
160                 }
161         else
162                 {
163                 stop_signal = TRUE;
164                 switch (event->keyval)
165                         {
166                         case '+': case GDK_KP_Add:
167                                 layout_image_zoom_adjust(lw, get_zoom_increment());
168                                 break;
169                         case GDK_KP_Subtract:
170                                 layout_image_zoom_adjust(lw, -get_zoom_increment());
171                                 break;
172                         case GDK_KP_Multiply:
173                                 layout_image_zoom_set(lw, 0.0);
174                                 break;
175                         case GDK_KP_Divide:
176                                 layout_image_zoom_set(lw, 1.0);
177                                 break;
178                         case GDK_Page_Up: case GDK_KP_Page_Up:
179                                 layout_image_prev(lw);
180                                 break;
181                         case GDK_Page_Down: case GDK_KP_Page_Down:
182                                 layout_image_next(lw);
183                                 break;
184                         case GDK_Delete: case GDK_KP_Delete:
185                                 if (enable_delete_key)
186                                         {
187                                         file_util_delete(NULL, layout_selection_list(lw), widget);
188                                         }
189                                 break;
190                         case GDK_Escape:
191                                 /* FIXME:interrupting thumbs no longer allowed */
192 #if 0
193                                 interrupt_thumbs();
194 #endif
195                                 break;
196                         case 'P': case 'p':
197                                 if (!event->state & GDK_SHIFT_MASK)
198                                         {
199                                         layout_image_slideshow_pause_toggle(lw);
200                                         }
201                                 else
202                                         {
203                                         stop_signal = FALSE;
204                                         }
205                                 break;
206                         case 'V': case 'v':
207                         case GDK_F11:
208                                 layout_image_full_screen_toggle(lw);
209                                 break;
210                         default:
211                                 stop_signal = FALSE;
212                                 break;
213                         }
214                 }
215
216 #if 0
217         if (stop_signal) g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
218 #endif
219
220         return stop_signal;
221 }
222
223 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
224 {
225         g_signal_connect(G_OBJECT(window), "key_press_event",
226                          G_CALLBACK(layout_key_press_cb), lw);
227 }
228
229 /*
230  *-----------------------------------------------------------------------------
231  * menu callbacks
232  *-----------------------------------------------------------------------------
233  */
234
235 static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
236 {
237         LayoutWindow *lw = data;
238         LayoutWindow *nw;
239
240         nw = layout_new(NULL, FALSE, FALSE);
241         layout_sort_set(nw, file_sort_method, file_sort_ascending);
242         layout_set_path(nw, layout_get_path(lw));
243 }
244
245 static void layout_menu_new_cb(GtkAction *action, gpointer data)
246 {
247         collection_window_new(NULL);
248 }
249
250 static void layout_menu_open_cb(GtkAction *action, gpointer data)
251 {
252         collection_dialog_load(NULL);
253 }
254
255 static void layout_menu_search_cb(GtkAction *action, gpointer data)
256 {
257         LayoutWindow *lw = data;
258
259         search_new(lw->path, layout_image_get_path(lw));
260 }
261
262 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
263 {
264         dupe_window_new(DUPE_MATCH_NAME);
265 }
266
267 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
268 {
269         LayoutWindow *lw = data;
270
271         pan_window_new(layout_get_path(lw));
272 }
273
274 static void layout_menu_print_cb(GtkAction *action, gpointer data)
275 {
276         LayoutWindow *lw = data;
277
278         print_window_new(layout_image_get_fd(lw), layout_selection_list(lw), layout_list(lw), lw->window);
279 }
280
281 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
282 {
283         LayoutWindow *lw = data;
284
285         file_util_create_dir(lw->path, lw->window);
286 }
287
288 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
289 {
290         LayoutWindow *lw = data;
291
292         file_util_copy(NULL, layout_selection_list(lw), NULL, lw->window);
293 }
294
295 static void layout_menu_move_cb(GtkAction *action, gpointer data)
296 {
297         LayoutWindow *lw = data;
298
299         file_util_move(NULL, layout_selection_list(lw), NULL, lw->window);
300 }
301
302 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
303 {
304         LayoutWindow *lw = data;
305
306         file_util_rename(NULL, layout_selection_list(lw), lw->window);
307 }
308
309 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
310 {
311         LayoutWindow *lw = data;
312
313         file_util_delete(NULL, layout_selection_list(lw), lw->window);
314 }
315
316 static void layout_menu_close_cb(GtkAction *action, gpointer data)
317 {
318         LayoutWindow *lw = data;
319
320         layout_close(lw);
321 }
322
323 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
324 {
325         exit_gqview();
326 }
327
328 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
329 {
330         LayoutWindow *lw = data;
331
332         layout_image_alter(lw, ALTER_ROTATE_90);
333 }
334
335 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
336 {
337         LayoutWindow *lw = data;
338
339         layout_image_alter(lw, ALTER_ROTATE_90_CC);
340 }
341
342 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
343 {
344         LayoutWindow *lw = data;
345
346         layout_image_alter(lw, ALTER_ROTATE_180);
347 }
348
349 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
350 {
351         LayoutWindow *lw = data;
352
353         layout_image_alter(lw, ALTER_MIRROR);
354 }
355
356 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
357 {
358         LayoutWindow *lw = data;
359
360         layout_image_alter(lw, ALTER_FLIP);
361 }
362
363 static void layout_menu_alter_desaturate_cb(GtkAction *action, gpointer data)
364 {
365         LayoutWindow *lw = data;
366
367         layout_image_alter(lw, ALTER_DESATURATE);
368 }
369
370 static void layout_menu_info_cb(GtkAction *action, gpointer data)
371 {
372         LayoutWindow *lw = data;
373         GList *list;
374         FileData *fd = NULL;
375
376         list = layout_selection_list(lw);
377         if (!list) fd = layout_image_get_fd(lw);
378
379         info_window_new(fd, list);
380 }
381
382 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
383 {
384         LayoutWindow *lw = data;
385
386         layout_select_all(lw);
387 }
388
389 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
390 {
391         LayoutWindow *lw = data;
392
393         layout_select_none(lw);
394 }
395
396 static void layout_menu_config_cb(GtkAction *action, gpointer data)
397 {
398         show_config_window();
399 }
400
401 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
402 {
403         cache_manager_show();
404 }
405
406 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
407 {
408         LayoutWindow *lw = data;
409
410         layout_image_to_root(lw);
411 }
412
413 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
414 {
415         LayoutWindow *lw = data;
416
417         layout_image_zoom_adjust(lw, get_zoom_increment());
418 }
419
420 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
421 {
422         LayoutWindow *lw = data;
423
424         layout_image_zoom_adjust(lw, -get_zoom_increment());
425 }
426
427 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
428 {
429         LayoutWindow *lw = data;
430
431         layout_image_zoom_set(lw, 1.0);
432 }
433
434 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
435 {
436         LayoutWindow *lw = data;
437
438         layout_image_zoom_set(lw, 0.0);
439 }
440
441 static void layout_menu_zoom_fit_hor_cb(GtkAction *action, gpointer data)
442 {
443         LayoutWindow *lw = data;
444
445         layout_image_zoom_set_fill_geometry(lw, TRUE);
446 }
447
448 static void layout_menu_zoom_fit_vert_cb(GtkAction *action, gpointer data)
449 {
450         LayoutWindow *lw = data;
451
452         layout_image_zoom_set_fill_geometry(lw, FALSE);
453 }
454
455 static void layout_menu_zoom_2_1_cb(GtkAction *action, gpointer data)
456 {
457         LayoutWindow *lw = data;
458
459         layout_image_zoom_set(lw, 2.0);
460 }
461
462 static void layout_menu_zoom_3_1_cb(GtkAction *action, gpointer data)
463 {
464         LayoutWindow *lw = data;
465
466         layout_image_zoom_set(lw, 3.0);
467 }
468 static void layout_menu_zoom_4_1_cb(GtkAction *action, gpointer data)
469 {
470         LayoutWindow *lw = data;
471
472         layout_image_zoom_set(lw, 4.0);
473 }
474
475 static void layout_menu_zoom_1_2_cb(GtkAction *action, gpointer data)
476 {
477         LayoutWindow *lw = data;
478
479         layout_image_zoom_set(lw, -2.0);
480 }
481
482 static void layout_menu_zoom_1_3_cb(GtkAction *action, gpointer data)
483 {
484         LayoutWindow *lw = data;
485
486         layout_image_zoom_set(lw, -3.0);
487 }
488
489 static void layout_menu_zoom_1_4_cb(GtkAction *action, gpointer data)
490 {
491         LayoutWindow *lw = data;
492
493         layout_image_zoom_set(lw, -4.0);
494 }
495
496
497 static void layout_menu_split_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
498 {
499         LayoutWindow *lw = data;
500         ImageSplitMode mode = gtk_radio_action_get_current_value(action);
501         
502         if (mode == lw->split_mode) mode = 0; /* toggle back */
503
504         layout_split_change(lw, mode);
505 }
506
507 static void layout_menu_connect_scroll_cb(GtkToggleAction *action, gpointer data)
508 {
509         LayoutWindow *lw = data;
510         lw->connect_scroll = gtk_toggle_action_get_active(action);
511 }
512
513 static void layout_menu_connect_zoom_cb(GtkToggleAction *action, gpointer data)
514 {
515         LayoutWindow *lw = data;
516         lw->connect_zoom = gtk_toggle_action_get_active(action);
517 }
518
519
520 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
521 {
522         LayoutWindow *lw = data;
523
524         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
525 }
526
527 static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
528 {
529         LayoutWindow *lw = data;
530
531         layout_marks_set(lw, gtk_toggle_action_get_active(action));
532 }
533
534 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
535 {
536         LayoutWindow *lw = data;
537
538         layout_views_set(lw, lw->tree_view, (gtk_radio_action_get_current_value(action) == 1));
539 }
540
541 static void layout_menu_tree_cb(GtkToggleAction *action, gpointer data)
542 {
543         LayoutWindow *lw = data;
544
545         layout_views_set(lw, gtk_toggle_action_get_active(action), lw->icon_view);
546 }
547
548 static void layout_menu_view_in_new_window_cb(GtkAction *action, gpointer data)
549 {
550         LayoutWindow *lw = data;
551
552         view_window_new(layout_image_get_fd(lw));
553 }
554
555 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
556 {
557         LayoutWindow *lw = data;
558
559         layout_image_full_screen_toggle(lw);
560 }
561
562 static void layout_menu_overlay_cb(GtkAction *action, gpointer data)
563 {
564         LayoutWindow *lw = data;
565
566         layout_image_overlay_toggle(lw);
567 }
568
569 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
570 {
571         LayoutWindow *lw = data;
572
573         layout_refresh(lw);
574 }
575
576 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
577 {
578         LayoutWindow *lw = data;
579
580         if (lw->tools_float != gtk_toggle_action_get_active(action))
581                 {
582                 layout_tools_float_toggle(lw);
583                 }
584 }
585
586 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
587 {
588         LayoutWindow *lw = data;
589
590         layout_tools_hide_toggle(lw);
591 }
592
593 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
594 {
595         LayoutWindow *lw = data;
596
597         if (lw->toolbar_hidden != gtk_toggle_action_get_active(action))
598                 {
599                 layout_toolbar_toggle(lw);
600                 }
601 }
602
603 static void layout_menu_bar_info_cb(GtkToggleAction *action, gpointer data)
604 {
605         LayoutWindow *lw = data;
606
607         if (lw->bar_info_enabled != gtk_toggle_action_get_active(action))
608                 {
609                 layout_bar_info_toggle(lw);
610                 }
611 }
612
613 static void layout_menu_bar_exif_cb(GtkToggleAction *action, gpointer data)
614 {
615         LayoutWindow *lw = data;
616
617         if (lw->bar_exif_enabled != gtk_toggle_action_get_active(action))
618                 {
619                 layout_bar_exif_toggle(lw);
620                 }
621 }
622
623 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
624 {
625         LayoutWindow *lw = data;
626
627         if (lw->bar_sort_enabled != gtk_toggle_action_get_active(action))
628                 {
629                 layout_bar_sort_toggle(lw);
630                 }
631 }
632
633 static void layout_menu_slideshow_cb(GtkAction *action, gpointer data)
634 {
635         LayoutWindow *lw = data;
636
637         layout_image_slideshow_toggle(lw);
638 }
639
640 static void layout_menu_help_cb(GtkAction *action, gpointer data)
641 {
642         help_window_show("html_contents");
643 }
644
645 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
646 {
647         help_window_show("documentation");
648 }
649
650 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
651 {
652         help_window_show("release_notes");
653 }
654
655 static void layout_menu_about_cb(GtkAction *action, gpointer data)
656 {
657         show_about_window();
658 }
659
660 /*
661  *-----------------------------------------------------------------------------
662  * go menu
663  *-----------------------------------------------------------------------------
664  */ 
665
666 static void layout_menu_image_first_cb(GtkAction *action, gpointer data)
667 {
668         LayoutWindow *lw = data;
669         layout_image_first(lw);
670 }
671
672 static void layout_menu_image_prev_cb(GtkAction *action, gpointer data)
673 {
674         LayoutWindow *lw = data;
675         layout_image_prev(lw);
676 }
677
678 static void layout_menu_image_next_cb(GtkAction *action, gpointer data)
679 {
680         LayoutWindow *lw = data;
681         layout_image_next(lw);
682 }
683
684 static void layout_menu_image_last_cb(GtkAction *action, gpointer data)
685 {
686         LayoutWindow *lw = data;
687         layout_image_last(lw);
688 }
689
690
691 /*
692  *-----------------------------------------------------------------------------
693  * edit menu
694  *-----------------------------------------------------------------------------
695  */ 
696
697 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
698 {
699         LayoutWindow *lw = data;
700         GList *list;
701         gint n;
702
703         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "edit_index"));
704
705         list = layout_selection_list(lw);
706         start_editor_from_filelist(n, list);
707         filelist_free(list);
708 }
709
710 static void layout_menu_edit_update(LayoutWindow *lw)
711 {
712         gint i;
713
714         /* main edit menu */
715
716         if (!lw->action_group) return;
717
718         for (i = 0; i < 10; i++)
719                 {
720                 gchar *key;
721                 GtkAction *action;
722
723                 key = g_strdup_printf("Editor%d", i);
724
725                 action = gtk_action_group_get_action(lw->action_group, key);
726                 g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i));
727
728                 if (editor_command[i] && strlen(editor_command[i]) > 0)
729                         {
730                         gchar *text;
731
732                         if (editor_name[i] && strlen(editor_name[i]) > 0)
733                                 {
734                                 text = g_strdup_printf(_("in %s..."), editor_name[i]);
735                                 }
736                         else
737                                 {
738                                 text = g_strdup(_("in (unknown)..."));
739                                 }
740                         g_object_set(action, "label", text,
741                                              "sensitive", TRUE, NULL);
742                         g_free(text);
743                         }
744                 else
745                         {
746                         g_object_set(action, "label", _("empty"),
747                                              "sensitive", FALSE, NULL);
748                         }
749
750                 g_free(key);
751                 }
752 }
753
754 void layout_edit_update_all(void)
755 {
756         GList *work;
757
758         work = layout_window_list;
759         while (work)
760                 {
761                 LayoutWindow *lw = work->data;
762                 work = work->next;
763
764                 layout_menu_edit_update(lw);
765                 }
766 }
767
768 /*
769  *-----------------------------------------------------------------------------
770  * recent menu
771  *-----------------------------------------------------------------------------
772  */
773
774 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
775 {
776         gint n;
777         gchar *path;
778
779         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
780
781         path = g_list_nth_data(history_list_get_by_key("recent"), n);
782
783         if (!path) return;
784
785         /* make a copy of it */
786         path = g_strdup(path);
787         collection_window_new(path);
788         g_free(path);
789 }
790
791 static void layout_menu_recent_update(LayoutWindow *lw)
792 {
793         GtkWidget *menu;
794         GtkWidget *recent;
795         GtkWidget *item;
796         GList *list;
797         gint n;
798
799         if (!lw->ui_manager) return;
800
801         list = history_list_get_by_key("recent");
802         n = 0;
803
804         menu = gtk_menu_new();
805
806         while (list)
807                 {
808                 item = menu_item_add_simple(menu, filename_from_path((gchar *)list->data),
809                                             G_CALLBACK(layout_menu_recent_cb), lw);
810                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
811                 list = list->next;
812                 n++;
813                 }
814
815         if (n == 0)
816                 {
817                 menu_item_add(menu, _("Empty"), NULL, NULL);
818                 }
819
820         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
821         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
822         gtk_widget_set_sensitive(recent, (n != 0));
823 }
824
825 void layout_recent_update_all(void)
826 {
827         GList *work;
828
829         work = layout_window_list;
830         while (work)
831                 {
832                 LayoutWindow *lw = work->data;
833                 work = work->next;
834
835                 layout_menu_recent_update(lw);
836                 }
837 }
838
839 void layout_recent_add_path(const gchar *path)
840 {
841         if (!path) return;
842
843         history_list_add_to_key("recent", path, recent_list_max);
844
845         layout_recent_update_all();
846 }
847
848 /*
849  *-----------------------------------------------------------------------------
850  * menu
851  *-----------------------------------------------------------------------------
852  */ 
853
854 #define CB G_CALLBACK
855
856 static GtkActionEntry menu_entries[] = {
857   { "FileMenu",         NULL,           N_("_File") },
858   { "GoMenu",           NULL,           N_("_Go") },
859   { "EditMenu",         NULL,           N_("_Edit") },
860   { "AdjustMenu",       NULL,           N_("_Adjust") },
861   { "ViewMenu",         NULL,           N_("_View") },
862   { "ZoomMenu",         NULL,           N_("_Zoom") },
863   { "SplitMenu",        NULL,           N_("_Split") },
864   { "HelpMenu",         NULL,           N_("_Help") },
865
866   { "FirstImage",       GTK_STOCK_GOTO_TOP,     N_("_First Image"),     "Home",         NULL,   CB(layout_menu_image_first_cb) },
867   { "PrevImage",        GTK_STOCK_GO_UP,        N_("_Previous Image"),  "BackSpace",    NULL,   CB(layout_menu_image_prev_cb) },
868   { "NextImage",        GTK_STOCK_GO_DOWN,      N_("_Next Image"),      "space",        NULL,   CB(layout_menu_image_next_cb) },
869   { "LastImage",        GTK_STOCK_GOTO_BOTTOM,  N_("_Last Image"),      "End",          NULL,   CB(layout_menu_image_last_cb) },
870
871
872   { "NewWindow",        GTK_STOCK_NEW,  N_("New _window"),      NULL,           NULL,   CB(layout_menu_new_window_cb) },
873   { "NewCollection",    GTK_STOCK_INDEX,N_("_New collection"),  "C",            NULL,   CB(layout_menu_new_cb) },
874   { "OpenCollection",   GTK_STOCK_OPEN, N_("_Open collection..."),"O",          NULL,   CB(layout_menu_open_cb) },
875   { "OpenRecent",       NULL,           N_("Open _recent") },
876   { "Search",           GTK_STOCK_FIND, N_("_Search..."),       "F3",           NULL,   CB(layout_menu_search_cb) },
877   { "FindDupes",        GTK_STOCK_FIND, N_("_Find duplicates..."),"D",          NULL,   CB(layout_menu_dupes_cb) },
878   { "PanView",          NULL,           N_("Pan _view"),        "<control>J",   NULL,   CB(layout_menu_pan_cb) },
879   { "Print",            GTK_STOCK_PRINT,N_("_Print..."),        "<shift>P",     NULL,   CB(layout_menu_print_cb) },
880   { "NewFolder",        NULL,           N_("N_ew folder..."),   "<control>F",   NULL,   CB(layout_menu_dir_cb) },
881   { "Copy",             NULL,           N_("_Copy..."),         "<control>C",   NULL,   CB(layout_menu_copy_cb) },
882   { "Move",             NULL,           N_("_Move..."),         "<control>M",   NULL,   CB(layout_menu_move_cb) },
883   { "Rename",           NULL,           N_("_Rename..."),       "<control>R",   NULL,   CB(layout_menu_rename_cb) },
884   { "Delete",   GTK_STOCK_DELETE,       N_("_Delete..."),       "<control>D",   NULL,   CB(layout_menu_delete_cb) },
885   { "CloseWindow",      GTK_STOCK_CLOSE,N_("C_lose window"),    "<control>W",   NULL,   CB(layout_menu_close_cb) },
886   { "Quit",             GTK_STOCK_QUIT, N_("_Quit"),            "<control>Q",   NULL,   CB(layout_menu_exit_cb) },
887
888   { "Editor0",          NULL,           "editor0",              "<control>1",   NULL,   CB(layout_menu_edit_cb) },
889   { "Editor1",          NULL,           "editor1",              "<control>2",   NULL,   CB(layout_menu_edit_cb) },
890   { "Editor2",          NULL,           "editor2",              "<control>3",   NULL,   CB(layout_menu_edit_cb) },
891   { "Editor3",          NULL,           "editor3",              "<control>4",   NULL,   CB(layout_menu_edit_cb) },
892   { "Editor4",          NULL,           "editor4",              "<control>5",   NULL,   CB(layout_menu_edit_cb) },
893   { "Editor5",          NULL,           "editor5",              "<control>6",   NULL,   CB(layout_menu_edit_cb) },
894   { "Editor6",          NULL,           "editor6",              "<control>7",   NULL,   CB(layout_menu_edit_cb) },
895   { "Editor7",          NULL,           "editor7",              "<control>8",   NULL,   CB(layout_menu_edit_cb) },
896   { "Editor8",          NULL,           "editor8",              "<control>9",   NULL,   CB(layout_menu_edit_cb) },
897   { "Editor9",          NULL,           "editor9",              "<control>0",   NULL,   CB(layout_menu_edit_cb) },
898   { "RotateCW",         NULL,   N_("_Rotate clockwise"),        "bracketright", NULL,   CB(layout_menu_alter_90_cb) },
899   { "RotateCCW",        NULL,   N_("Rotate _counterclockwise"), "bracketleft",  NULL,   CB(layout_menu_alter_90cc_cb) },
900   { "Rotate180",        NULL,           N_("Rotate 1_80"),      "<shift>R",     NULL,   CB(layout_menu_alter_180_cb) },
901   { "Mirror",           NULL,           N_("_Mirror"),          "<shift>M",     NULL,   CB(layout_menu_alter_mirror_cb) },
902   { "Flip",             NULL,           N_("_Flip"),            "<shift>F",     NULL,   CB(layout_menu_alter_flip_cb) },
903   { "Grayscale",        NULL,           N_("_Grayscale"),       "<shift>G",     NULL,   CB(layout_menu_alter_desaturate_cb) },
904   { "Properties",GTK_STOCK_PROPERTIES,  N_("_Properties"),      "<control>P",   NULL,   CB(layout_menu_info_cb) },
905   { "SelectAll",        NULL,           N_("Select _all"),      "<control>A",   NULL,   CB(layout_menu_select_all_cb) },
906   { "SelectNone",       NULL,           N_("Select _none"), "<control><shift>A",NULL,   CB(layout_menu_unselect_all_cb) },
907   { "Preferences",GTK_STOCK_PREFERENCES,N_("P_references..."),  "<control>O",   NULL,   CB(layout_menu_config_cb) },
908   { "Maintenance",      NULL,           N_("_Thumbnail maintenance..."),NULL,   NULL,   CB(layout_menu_remove_thumb_cb) },
909   { "Wallpaper",        NULL,           N_("Set as _wallpaper"),NULL,           NULL,   CB(layout_menu_wallpaper_cb) },
910
911   { "ZoomIn",   GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "equal",        NULL,   CB(layout_menu_zoom_in_cb) },
912   { "ZoomOut",  GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "minus",        NULL,   CB(layout_menu_zoom_out_cb) },
913   { "Zoom100",  GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "Z",            NULL,   CB(layout_menu_zoom_1_1_cb) },
914   { "ZoomFit",  GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "X",            NULL,   CB(layout_menu_zoom_fit_cb) },
915   { "ZoomFillHor",      NULL,           N_("Fit _Horizontally"),"H",            NULL,   CB(layout_menu_zoom_fit_hor_cb) },
916   { "ZoomFillVert",     NULL,           N_("Fit _Vorizontally"),"W",            NULL,   CB(layout_menu_zoom_fit_vert_cb) },
917   { "Zoom200",          NULL,           N_("Zoom _2:1"),        NULL,           NULL,   CB(layout_menu_zoom_2_1_cb) },
918   { "Zoom300",          NULL,           N_("Zoom _3:1"),        NULL,           NULL,   CB(layout_menu_zoom_3_1_cb) },
919   { "Zoom400",          NULL,           N_("Zoom _4:1"),        NULL,           NULL,   CB(layout_menu_zoom_4_1_cb) },
920   { "Zoom50",           NULL,           N_("Zoom 1:2"),         NULL,           NULL,   CB(layout_menu_zoom_1_2_cb) },
921   { "Zoom33",           NULL,           N_("Zoom 1:3"),         NULL,           NULL,   CB(layout_menu_zoom_1_3_cb) },
922   { "Zoom25",           NULL,           N_("Zoom 1:4"),         NULL,           NULL,   CB(layout_menu_zoom_1_4_cb) },
923
924
925   { "ViewInNewWindow",  NULL,           N_("_View in new window"),      "<control>V",           NULL,   CB(layout_menu_view_in_new_window_cb) },
926
927   { "FullScreen",       NULL,           N_("F_ull screen"),     "F",            NULL,   CB(layout_menu_fullscreen_cb) },
928   { "ImageOverlay",     NULL,           N_("_Image Overlay"),   "I",            NULL,   CB(layout_menu_overlay_cb) },
929   { "HideTools",        NULL,           N_("_Hide file list"),  "<control>H",   NULL,   CB(layout_menu_hide_cb) },
930   { "SlideShow",        NULL,           N_("Toggle _slideshow"),"S",            NULL,   CB(layout_menu_slideshow_cb) },
931   { "Refresh",  GTK_STOCK_REFRESH,      N_("_Refresh"),         "R",            NULL,   CB(layout_menu_refresh_cb) },
932
933   { "HelpContents",     GTK_STOCK_HELP, N_("_Contents"),        "F1",           NULL,   CB(layout_menu_help_cb) },
934   { "HelpShortcuts",    NULL,           N_("_Keyboard shortcuts"),NULL,         NULL,   CB(layout_menu_help_keys_cb) },
935   { "HelpNotes",        NULL,           N_("_Release notes"),   NULL,           NULL,   CB(layout_menu_notes_cb) },
936   { "About",            NULL,           N_("_About"),           NULL,           NULL,   CB(layout_menu_about_cb) }
937 };
938
939 static GtkToggleActionEntry menu_toggle_entries[] = {
940   { "Thumbnails",       NULL,           N_("_Thumbnails"),      "T",            NULL,   CB(layout_menu_thumb_cb) },
941   { "Marks",            NULL,           N_("_Marks"),           "M",            NULL,   CB(layout_menu_marks_cb) },  
942   { "FolderTree",       NULL,           N_("Tr_ee"),            "<control>T",   NULL,   CB(layout_menu_tree_cb) },
943   { "FloatTools",       NULL,           N_("_Float file list"), "L",            NULL,   CB(layout_menu_float_cb) },
944   { "HideToolbar",      NULL,           N_("Hide tool_bar"),    NULL,           NULL,   CB(layout_menu_toolbar_cb) },
945   { "SBarKeywords",     NULL,           N_("_Keywords"),        "<control>K",   NULL,   CB(layout_menu_bar_info_cb) },
946   { "SBarExif",         NULL,           N_("E_xif data"),       "<control>E",   NULL,   CB(layout_menu_bar_exif_cb) },
947   { "SBarSort",         NULL,           N_("Sort _manager"),    "<control>S",   NULL,   CB(layout_menu_bar_sort_cb) },
948   { "ConnectScroll",    NULL,           N_("Connected scroll"), "<control>U",   NULL,   CB(layout_menu_connect_scroll_cb) },
949   { "ConnectZoom",      NULL,           N_("Connected zoom"),   "<control>Y",   NULL,   CB(layout_menu_connect_zoom_cb) }
950 };
951
952 static GtkRadioActionEntry menu_radio_entries[] = {
953   { "ViewList",         NULL,           N_("_List"),            "<control>L",   NULL,   0 },
954   { "ViewIcons",        NULL,           N_("I_cons"),           "<control>I",   NULL,   1 }
955 };
956
957 static GtkRadioActionEntry menu_split_radio_entries[] = {
958   { "SplitHorizontal",  NULL,           N_("Horizontal"),       "E",            NULL,   SPLIT_HOR },
959   { "SplitVertical",    NULL,           N_("Vertical"),         "U",            NULL,   SPLIT_VERT },
960   { "SplitQuad",        NULL,           N_("Quad"),             "Q",            NULL,   SPLIT_QUAD },
961   { "SplitSingle",      NULL,           N_("Single"),           "Y",            NULL,   SPLIT_NONE }
962 };
963
964 #undef CB
965
966 static const char *menu_ui_description =
967 "<ui>"
968 "  <menubar name='MainMenu'>"
969 "    <menu action='FileMenu'>"
970 "      <menuitem action='NewWindow'/>"
971 "      <menuitem action='NewCollection'/>"
972 "      <menuitem action='OpenCollection'/>"
973 "      <menuitem action='OpenRecent'/>"
974 "      <separator/>"
975 "      <menuitem action='Search'/>"
976 "      <menuitem action='FindDupes'/>"
977 "      <menuitem action='PanView'/>"
978 "      <separator/>"
979 "      <menuitem action='Print'/>"
980 "      <menuitem action='NewFolder'/>"
981 "      <separator/>"
982 "      <menuitem action='Copy'/>"
983 "      <menuitem action='Move'/>"
984 "      <menuitem action='Rename'/>"
985 "      <menuitem action='Delete'/>"
986 "      <separator/>"
987 "      <menuitem action='CloseWindow'/>"
988 "      <menuitem action='Quit'/>"
989 "    </menu>"
990 "    <menu action='GoMenu'>"
991 "      <menuitem action='FirstImage'/>"
992 "      <menuitem action='PrevImage'/>"
993 "      <menuitem action='NextImage'/>"
994 "      <menuitem action='LastImage'/>"
995 "    </menu>"
996 "    <menu action='EditMenu'>"
997 "      <menuitem action='Editor0'/>"
998 "      <menuitem action='Editor1'/>"
999 "      <menuitem action='Editor2'/>"
1000 "      <menuitem action='Editor3'/>"
1001 "      <menuitem action='Editor4'/>"
1002 "      <menuitem action='Editor5'/>"
1003 "      <menuitem action='Editor6'/>"
1004 "      <menuitem action='Editor7'/>"
1005 "      <menuitem action='Editor8'/>"
1006 "      <menuitem action='Editor9'/>"
1007 "      <separator/>"
1008 "      <menu action='AdjustMenu'>"
1009 "        <menuitem action='RotateCW'/>"
1010 "        <menuitem action='RotateCCW'/>"
1011 "        <menuitem action='Rotate180'/>"
1012 "        <menuitem action='Mirror'/>"
1013 "        <menuitem action='Flip'/>"
1014 "        <menuitem action='Grayscale'/>"
1015 "      </menu>"
1016 "      <menuitem action='Properties'/>"
1017 "      <separator/>"
1018 "      <menuitem action='SelectAll'/>"
1019 "      <menuitem action='SelectNone'/>"
1020 "      <separator/>"
1021 "      <menuitem action='Preferences'/>"
1022 "      <menuitem action='Maintenance'/>"
1023 "      <separator/>"
1024 "      <menuitem action='Wallpaper'/>"
1025 "    </menu>"
1026 "    <menu action='ViewMenu'>"
1027 "      <menuitem action='ViewInNewWindow'/>"
1028 "      <separator/>"
1029 "      <menu action='ZoomMenu'>"
1030 "        <menuitem action='ZoomIn'/>"
1031 "        <menuitem action='ZoomOut'/>"
1032 "        <menuitem action='ZoomFit'/>"
1033 "        <menuitem action='ZoomFillHor'/>"
1034 "        <menuitem action='ZoomFillVert'/>"
1035 "        <menuitem action='Zoom100'/>"
1036 "        <menuitem action='Zoom200'/>"
1037 "        <menuitem action='Zoom300'/>"
1038 "        <menuitem action='Zoom400'/>"
1039 "        <menuitem action='Zoom50'/>"
1040 "        <menuitem action='Zoom33'/>"
1041 "        <menuitem action='Zoom25'/>"
1042 "      </menu>"
1043 "      <separator/>"
1044 "      <menu action='SplitMenu'>"
1045 "        <menuitem action='SplitHorizontal'/>"
1046 "        <menuitem action='SplitVertical'/>"
1047 "        <menuitem action='SplitQuad'/>"
1048 "        <menuitem action='SplitSingle'/>"
1049 "      </menu>"
1050 "      <menuitem action='ConnectScroll'/>"
1051 "      <menuitem action='ConnectZoom'/>"
1052 "      <separator/>"
1053 "      <menuitem action='Marks'/>"
1054 "      <separator/>"
1055 "      <menuitem action='Thumbnails'/>"
1056 "      <menuitem action='ViewList'/>"
1057 "      <menuitem action='ViewIcons'/>"
1058 "      <separator/>"
1059 "      <menuitem action='FolderTree'/>"
1060 "      <menuitem action='ImageOverlay'/>"
1061 "      <menuitem action='FullScreen'/>"
1062 "      <separator/>"
1063 "      <menuitem action='FloatTools'/>"
1064 "      <menuitem action='HideTools'/>"
1065 "      <menuitem action='HideToolbar'/>"
1066 "      <separator/>"
1067 "      <menuitem action='SBarKeywords'/>"
1068 "      <menuitem action='SBarExif'/>"
1069 "      <menuitem action='SBarSort'/>"
1070 "      <separator/>"
1071 "      <menuitem action='SlideShow'/>"
1072 "      <menuitem action='Refresh'/>"
1073 "    </menu>"
1074 "    <menu action='HelpMenu'>"
1075 "      <separator/>"
1076 "      <menuitem action='HelpContents'/>"
1077 "      <menuitem action='HelpShortcuts'/>"
1078 "      <menuitem action='HelpNotes'/>"
1079 "      <separator/>"
1080 "      <menuitem action='About'/>"
1081 "    </menu>"
1082 "  </menubar>"
1083 "</ui>";
1084
1085
1086 static gchar *menu_translate(const gchar *path, gpointer data)
1087 {
1088         return _(path);
1089 }
1090
1091 void layout_actions_setup(LayoutWindow *lw)
1092 {
1093         GError *error;
1094
1095         if (lw->ui_manager) return;
1096
1097         lw->action_group = gtk_action_group_new ("MenuActions");
1098         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
1099
1100         gtk_action_group_add_actions(lw->action_group,
1101                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
1102         gtk_action_group_add_toggle_actions(lw->action_group,
1103                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
1104         gtk_action_group_add_radio_actions(lw->action_group,
1105                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
1106                                            0, G_CALLBACK(layout_menu_list_cb), lw);
1107         gtk_action_group_add_radio_actions(lw->action_group,
1108                                            menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
1109                                            0, G_CALLBACK(layout_menu_split_cb), lw);
1110
1111         lw->ui_manager = gtk_ui_manager_new();
1112         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
1113         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
1114
1115         error = NULL;
1116         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
1117                 {
1118                 g_message ("building menus failed: %s", error->message);
1119                 g_error_free (error);
1120                 exit (EXIT_FAILURE);
1121                 }
1122 }
1123
1124 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
1125 {
1126         GtkAccelGroup *group;
1127
1128         if (!lw->ui_manager) return;
1129
1130         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
1131         gtk_window_add_accel_group(GTK_WINDOW(window), group);
1132 }
1133
1134 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
1135 {
1136         return gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
1137 }
1138
1139
1140 /*
1141  *-----------------------------------------------------------------------------
1142  * toolbar
1143  *-----------------------------------------------------------------------------
1144  */ 
1145
1146 static void layout_button_thumb_cb(GtkWidget *widget, gpointer data)
1147 {
1148         LayoutWindow *lw = data;
1149
1150         layout_thumb_set(lw, gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)));
1151 }
1152
1153 static void layout_button_home_cb(GtkWidget *widget, gpointer data)
1154 {
1155         LayoutWindow *lw = data;
1156         const gchar *path = homedir();
1157
1158         if (path) layout_set_path(lw, path);
1159 }
1160
1161 static void layout_button_refresh_cb(GtkWidget *widget, gpointer data)
1162 {
1163         LayoutWindow *lw = data;
1164
1165         layout_refresh(lw);
1166 }
1167
1168 static void layout_button_zoom_in_cb(GtkWidget *widget, gpointer data)
1169 {
1170         LayoutWindow *lw = data;
1171
1172         layout_image_zoom_adjust(lw, get_zoom_increment());
1173 }
1174
1175 static void layout_button_zoom_out_cb(GtkWidget *widget, gpointer data)
1176 {
1177         LayoutWindow *lw = data;
1178
1179         layout_image_zoom_adjust(lw, -get_zoom_increment());
1180 }
1181
1182 static void layout_button_zoom_fit_cb(GtkWidget *widget, gpointer data)
1183 {
1184         LayoutWindow *lw = data;
1185
1186         layout_image_zoom_set(lw, 0.0);
1187 }
1188
1189 static void layout_button_zoom_1_1_cb(GtkWidget *widget, gpointer data)
1190 {
1191         LayoutWindow *lw = data;
1192
1193         layout_image_zoom_set(lw, 1.0);
1194 }
1195
1196 static void layout_button_config_cb(GtkWidget *widget, gpointer data)
1197 {
1198         show_config_window();
1199 }
1200
1201 static void layout_button_float_cb(GtkWidget *widget, gpointer data)
1202 {
1203         LayoutWindow *lw = data;
1204
1205         layout_tools_float_toggle(lw);
1206 }
1207
1208 static void layout_button_custom_icon(GtkWidget *button, const gchar *key)
1209 {
1210         GtkWidget *icon;
1211         GdkPixbuf *pixbuf;
1212
1213         pixbuf = pixbuf_inline(key);
1214         if (!pixbuf) return;
1215
1216         icon = gtk_image_new_from_pixbuf(pixbuf);
1217         g_object_unref(pixbuf);
1218
1219         pref_toolbar_button_set_icon(button, icon, NULL);
1220         gtk_widget_show(icon);
1221 }
1222
1223 GtkWidget *layout_button_bar(LayoutWindow *lw)
1224 {
1225         GtkWidget *box;
1226         GtkWidget *button;
1227
1228         box =  pref_toolbar_new(NULL, GTK_TOOLBAR_ICONS);
1229
1230         button = pref_toolbar_button(box, NULL, _("_Thumbnails"), TRUE,
1231                                      _("Show thumbnails"), G_CALLBACK(layout_button_thumb_cb), lw);
1232         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_THUMB);
1233         lw->thumb_button = button;
1234
1235         pref_toolbar_button(box, GTK_STOCK_HOME, NULL, FALSE,
1236                             _("Change to home folder"), G_CALLBACK(layout_button_home_cb), lw);
1237         pref_toolbar_button(box, GTK_STOCK_REFRESH, NULL, FALSE,
1238                             _("Refresh file list"), G_CALLBACK(layout_button_refresh_cb), lw);
1239         pref_toolbar_button(box, GTK_STOCK_ZOOM_IN, NULL, FALSE,
1240                             _("Zoom in"), G_CALLBACK(layout_button_zoom_in_cb), lw);
1241         pref_toolbar_button(box, GTK_STOCK_ZOOM_OUT, NULL, FALSE,
1242                             _("Zoom out"), G_CALLBACK(layout_button_zoom_out_cb), lw);
1243         pref_toolbar_button(box, GTK_STOCK_ZOOM_FIT, NULL, FALSE,
1244                             _("Fit image to window"), G_CALLBACK(layout_button_zoom_fit_cb), lw);
1245         pref_toolbar_button(box, GTK_STOCK_ZOOM_100, NULL, FALSE,
1246                             _("Set zoom 1:1"), G_CALLBACK(layout_button_zoom_1_1_cb), lw);
1247         pref_toolbar_button(box, GTK_STOCK_PREFERENCES, NULL, FALSE,
1248                             _("Configure options"), G_CALLBACK(layout_button_config_cb), lw);
1249         button = pref_toolbar_button(box, NULL, _("_Float"), FALSE,
1250                                      _("Float Controls"), G_CALLBACK(layout_button_float_cb), lw);
1251         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_FLOAT);
1252
1253         return box;
1254 }
1255
1256 /*
1257  *-----------------------------------------------------------------------------
1258  * misc
1259  *-----------------------------------------------------------------------------
1260  */
1261
1262 static void layout_util_sync_views(LayoutWindow *lw)
1263 {
1264         GtkAction *action;
1265
1266         if (!lw->action_group) return;
1267
1268         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
1269         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tree_view);
1270
1271         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
1272         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->icon_view);
1273
1274         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
1275         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tools_float);
1276
1277         action = gtk_action_group_get_action(lw->action_group, "SBarKeywords");
1278         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_info_enabled);
1279
1280         action = gtk_action_group_get_action(lw->action_group, "SBarExif");
1281         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_exif_enabled);
1282
1283         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
1284         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_sort_enabled);
1285
1286         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
1287         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->toolbar_hidden);
1288 }
1289
1290 void layout_util_sync_thumb(LayoutWindow *lw)
1291 {
1292         GtkAction *action;
1293
1294         if (!lw->action_group) return;
1295
1296         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
1297         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->thumbs_enabled);
1298         g_object_set(action, "sensitive", !lw->icon_view, NULL);
1299
1300         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->thumbs_enabled);
1301         gtk_widget_set_sensitive(lw->thumb_button, !lw->icon_view);
1302 }
1303
1304 void layout_util_sync(LayoutWindow *lw)
1305 {
1306         layout_util_sync_views(lw);
1307         layout_util_sync_thumb(lw);
1308         layout_menu_recent_update(lw);
1309         layout_menu_edit_update(lw);
1310 }
1311
1312 /*
1313  *-----------------------------------------------------------------------------
1314  * icons (since all the toolbar icons are included here, best place as any)
1315  *-----------------------------------------------------------------------------
1316  */
1317
1318 PixmapFolders *folder_icons_new(void)
1319 {
1320         PixmapFolders *pf;
1321
1322         pf = g_new0(PixmapFolders, 1);
1323
1324         pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
1325         pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
1326         pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
1327         pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
1328
1329         return pf;
1330 }
1331
1332 void folder_icons_free(PixmapFolders *pf)
1333 {
1334         if (!pf) return;
1335
1336         g_object_unref(pf->close);
1337         g_object_unref(pf->open);
1338         g_object_unref(pf->deny);
1339         g_object_unref(pf->parent);
1340
1341         g_free(pf);
1342 }
1343
1344 /*
1345  *-----------------------------------------------------------------------------
1346  * sidebars
1347  *-----------------------------------------------------------------------------
1348  */
1349
1350 #define SIDEBAR_WIDTH 288
1351
1352 static void layout_bar_info_destroyed(GtkWidget *widget, gpointer data)
1353 {
1354         LayoutWindow *lw = data;
1355
1356         lw->bar_info = NULL;
1357
1358         if (lw->utility_box)
1359                 {
1360                 /* destroyed from within itself */
1361                 lw->bar_info_enabled = FALSE;
1362                 layout_util_sync_views(lw);
1363                 }
1364 }
1365
1366 static GList *layout_bar_info_list_cb(gpointer data)
1367 {
1368         LayoutWindow *lw = data;
1369
1370         return layout_selection_list(lw);
1371 }
1372
1373 static void layout_bar_info_new(LayoutWindow *lw)
1374 {
1375         if (!lw->utility_box) return;
1376                                                                                                                     
1377         lw->bar_info = bar_info_new(layout_image_get_fd(lw), FALSE, lw->utility_box);
1378         bar_info_set_selection_func(lw->bar_info, layout_bar_info_list_cb, lw);
1379         bar_info_selection(lw->bar_info, layout_selection_count(lw, NULL) - 1);
1380         bar_info_size_request(lw->bar_info, SIDEBAR_WIDTH * 3 / 4);
1381         g_signal_connect(G_OBJECT(lw->bar_info), "destroy",
1382                          G_CALLBACK(layout_bar_info_destroyed), lw);
1383         lw->bar_info_enabled = TRUE;
1384
1385         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_info, FALSE, FALSE, 0);
1386         gtk_widget_show(lw->bar_info);
1387 }
1388                                                                                                                     
1389 static void layout_bar_info_close(LayoutWindow *lw)
1390 {
1391         if (lw->bar_info)
1392                 {
1393                 bar_info_close(lw->bar_info);
1394                 lw->bar_info = NULL;
1395                 }
1396         lw->bar_info_enabled = FALSE;
1397 }
1398
1399 void layout_bar_info_toggle(LayoutWindow *lw)
1400 {
1401         if (lw->bar_info_enabled)
1402                 {
1403                 layout_bar_info_close(lw);
1404                 }
1405         else
1406                 {
1407                 layout_bar_info_new(lw);
1408                 }
1409 }
1410
1411 static void layout_bar_info_new_image(LayoutWindow *lw)
1412 {
1413         if (!lw->bar_info || !lw->bar_info_enabled) return;
1414
1415         bar_info_set(lw->bar_info, layout_image_get_fd(lw));
1416 }
1417
1418 static void layout_bar_info_new_selection(LayoutWindow *lw, gint count)
1419 {
1420         if (!lw->bar_info || !lw->bar_info_enabled) return;
1421
1422         bar_info_selection(lw->bar_info, count - 1);
1423 }
1424
1425 static void layout_bar_info_maint_renamed(LayoutWindow *lw)
1426 {
1427         if (!lw->bar_info || !lw->bar_info_enabled) return;
1428
1429         bar_info_maint_renamed(lw->bar_info, layout_image_get_fd(lw));
1430 }
1431
1432 static void layout_bar_exif_destroyed(GtkWidget *widget, gpointer data)
1433 {
1434         LayoutWindow *lw = data;
1435
1436         if (lw->bar_exif)
1437                 {
1438                 lw->bar_exif_advanced = bar_exif_is_advanced(lw->bar_exif);
1439                 }
1440
1441         lw->bar_exif = NULL;
1442         if (lw->utility_box)
1443                 {
1444                 /* destroyed from within itself */
1445                 lw->bar_exif_enabled = FALSE;
1446                 layout_util_sync_views(lw);
1447                 }
1448 }
1449
1450 static void layout_bar_exif_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1451 {
1452         LayoutWindow *lw = data;
1453
1454         if (lw->bar_exif)
1455                 {
1456                 lw->bar_exif_size = allocation->width;
1457                 }
1458 }
1459
1460 static void layout_bar_exif_new(LayoutWindow *lw)
1461 {
1462         if (!lw->utility_box) return;
1463
1464         lw->bar_exif = bar_exif_new(TRUE, layout_image_get_fd(lw),
1465                                     lw->bar_exif_advanced, lw->utility_box);
1466         g_signal_connect(G_OBJECT(lw->bar_exif), "destroy",
1467                          G_CALLBACK(layout_bar_exif_destroyed), lw);
1468         g_signal_connect(G_OBJECT(lw->bar_exif), "size_allocate",
1469                          G_CALLBACK(layout_bar_exif_sized), lw);
1470         lw->bar_exif_enabled = TRUE;
1471
1472         if (lw->bar_exif_size < 1) lw->bar_exif_size = SIDEBAR_WIDTH;
1473         gtk_widget_set_size_request(lw->bar_exif, lw->bar_exif_size, -1);
1474         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_exif, FALSE, FALSE, 0);
1475         if (lw->bar_info) gtk_box_reorder_child(GTK_BOX(lw->utility_box), lw->bar_exif, 1);
1476         gtk_widget_show(lw->bar_exif);
1477 }
1478
1479 static void layout_bar_exif_close(LayoutWindow *lw)
1480 {
1481         if (lw->bar_exif)
1482                 {
1483                 bar_exif_close(lw->bar_exif);
1484                 lw->bar_exif = NULL;
1485                 }
1486         lw->bar_exif_enabled = FALSE;
1487 }
1488
1489 void layout_bar_exif_toggle(LayoutWindow *lw)
1490 {
1491         if (lw->bar_exif_enabled)
1492                 {
1493                 layout_bar_exif_close(lw);
1494                 }
1495         else
1496                 {
1497                 layout_bar_exif_new(lw);
1498                 }
1499 }
1500
1501 static void layout_bar_exif_new_image(LayoutWindow *lw)
1502 {
1503         if (!lw->bar_exif || !lw->bar_exif_enabled) return;
1504
1505         bar_exif_set(lw->bar_exif, layout_image_get_fd(lw));
1506 }
1507
1508 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
1509 {
1510         LayoutWindow *lw = data;
1511
1512         lw->bar_sort = NULL;
1513
1514         if (lw->utility_box)
1515                 {
1516                 /* destroyed from within itself */
1517                 lw->bar_sort_enabled = FALSE;
1518
1519                 layout_util_sync_views(lw);
1520                 }
1521 }
1522
1523 static void layout_bar_sort_new(LayoutWindow *lw)
1524 {
1525         if (!lw->utility_box) return;
1526
1527         lw->bar_sort = bar_sort_new(lw);
1528         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
1529                          G_CALLBACK(layout_bar_sort_destroyed), lw);
1530         lw->bar_sort_enabled = TRUE;
1531
1532         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
1533         gtk_widget_show(lw->bar_sort);
1534 }
1535
1536 static void layout_bar_sort_close(LayoutWindow *lw)
1537 {
1538         if (lw->bar_sort)
1539                 {
1540                 bar_sort_close(lw->bar_sort);
1541                 lw->bar_sort = NULL;
1542                 }
1543         lw->bar_sort_enabled = FALSE;
1544 }
1545
1546 void layout_bar_sort_toggle(LayoutWindow *lw)
1547 {
1548         if (lw->bar_sort_enabled)
1549                 {
1550                 layout_bar_sort_close(lw);
1551                 }
1552         else
1553                 {
1554                 layout_bar_sort_new(lw);
1555                 }
1556 }
1557
1558 void layout_bars_new_image(LayoutWindow *lw)
1559 {
1560         layout_bar_info_new_image(lw);
1561         layout_bar_exif_new_image(lw);
1562 }
1563
1564 void layout_bars_new_selection(LayoutWindow *lw, gint count)
1565 {
1566         layout_bar_info_new_selection(lw, count);
1567 }
1568
1569 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
1570 {
1571         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
1572         gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
1573         gtk_widget_show(image);
1574
1575         if (lw->bar_sort_enabled)
1576                 {
1577                 layout_bar_sort_new(lw);
1578                 }
1579
1580         if (lw->bar_info_enabled)
1581                 {
1582                 layout_bar_info_new(lw);
1583                 }
1584
1585         if (lw->bar_exif_enabled)
1586                 {
1587                 layout_bar_exif_new(lw);
1588                 }
1589
1590         return lw->utility_box;
1591 }
1592
1593 void layout_bars_close(LayoutWindow *lw)
1594 {
1595         layout_bar_sort_close(lw);
1596         layout_bar_exif_close(lw);
1597         layout_bar_info_close(lw);
1598 }
1599
1600 void layout_bars_maint_renamed(LayoutWindow *lw)
1601 {
1602         layout_bar_info_maint_renamed(lw);
1603 }
1604