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