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