Sat Dec 2 16:44:48 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 "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_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
500 {
501         LayoutWindow *lw = data;
502
503         layout_views_set(lw, lw->tree_view, (gtk_radio_action_get_current_value(action) == 1));
504 }
505
506 static void layout_menu_tree_cb(GtkToggleAction *action, gpointer data)
507 {
508         LayoutWindow *lw = data;
509
510         layout_views_set(lw, gtk_toggle_action_get_active(action), lw->icon_view);
511 }
512
513 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
514 {
515         LayoutWindow *lw = data;
516
517         layout_image_full_screen_toggle(lw);
518 }
519
520 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
521 {
522         LayoutWindow *lw = data;
523
524         layout_refresh(lw);
525 }
526
527 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
528 {
529         LayoutWindow *lw = data;
530
531         if (lw->tools_float != gtk_toggle_action_get_active(action))
532                 {
533                 layout_tools_float_toggle(lw);
534                 }
535 }
536
537 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
538 {
539         LayoutWindow *lw = data;
540
541         layout_tools_hide_toggle(lw);
542 }
543
544 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
545 {
546         LayoutWindow *lw = data;
547
548         if (lw->toolbar_hidden != gtk_toggle_action_get_active(action))
549                 {
550                 layout_toolbar_toggle(lw);
551                 }
552 }
553
554 static void layout_menu_bar_info_cb(GtkToggleAction *action, gpointer data)
555 {
556         LayoutWindow *lw = data;
557
558         if (lw->bar_info_enabled != gtk_toggle_action_get_active(action))
559                 {
560                 layout_bar_info_toggle(lw);
561                 }
562 }
563
564 static void layout_menu_bar_exif_cb(GtkToggleAction *action, gpointer data)
565 {
566         LayoutWindow *lw = data;
567
568         if (lw->bar_exif_enabled != gtk_toggle_action_get_active(action))
569                 {
570                 layout_bar_exif_toggle(lw);
571                 }
572 }
573
574 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
575 {
576         LayoutWindow *lw = data;
577
578         if (lw->bar_sort_enabled != gtk_toggle_action_get_active(action))
579                 {
580                 layout_bar_sort_toggle(lw);
581                 }
582 }
583
584 static void layout_menu_slideshow_cb(GtkAction *action, gpointer data)
585 {
586         LayoutWindow *lw = data;
587
588         layout_image_slideshow_toggle(lw);
589 }
590
591 static void layout_menu_help_cb(GtkAction *action, gpointer data)
592 {
593         help_window_show("html_contents");
594 }
595
596 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
597 {
598         help_window_show("documentation");
599 }
600
601 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
602 {
603         help_window_show("release_notes");
604 }
605
606 static void layout_menu_about_cb(GtkAction *action, gpointer data)
607 {
608         show_about_window();
609 }
610
611 /*
612  *-----------------------------------------------------------------------------
613  * edit menu
614  *-----------------------------------------------------------------------------
615  */ 
616
617 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
618 {
619         LayoutWindow *lw = data;
620         GList *list;
621         gint n;
622
623         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "edit_index"));
624
625         list = layout_selection_list(lw);
626         start_editor_from_path_list(n, list);
627         path_list_free(list);
628 }
629
630 static void layout_menu_edit_update(LayoutWindow *lw)
631 {
632         gint i;
633
634         /* main edit menu */
635
636         if (!lw->action_group) return;
637
638         for (i = 0; i < 10; i++)
639                 {
640                 gchar *key;
641                 GtkAction *action;
642
643                 key = g_strdup_printf("Editor%d", i);
644
645                 action = gtk_action_group_get_action(lw->action_group, key);
646                 g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i));
647
648                 if (editor_command[i] && strlen(editor_command[i]) > 0)
649                         {
650                         gchar *text;
651
652                         if (editor_name[i] && strlen(editor_name[i]) > 0)
653                                 {
654                                 text = g_strdup_printf(_("in %s..."), editor_name[i]);
655                                 }
656                         else
657                                 {
658                                 text = g_strdup(_("in (unknown)..."));
659                                 }
660                         g_object_set(action, "label", text,
661                                              "sensitive", TRUE, NULL);
662                         g_free(text);
663                         }
664                 else
665                         {
666                         g_object_set(action, "label", _("empty"),
667                                              "sensitive", FALSE, NULL);
668                         }
669
670                 g_free(key);
671                 }
672 }
673
674 void layout_edit_update_all(void)
675 {
676         GList *work;
677
678         work = layout_window_list;
679         while (work)
680                 {
681                 LayoutWindow *lw = work->data;
682                 work = work->next;
683
684                 layout_menu_edit_update(lw);
685                 }
686 }
687
688 /*
689  *-----------------------------------------------------------------------------
690  * recent menu
691  *-----------------------------------------------------------------------------
692  */
693
694 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
695 {
696         gint n;
697         gchar *path;
698
699         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
700
701         path = g_list_nth_data(history_list_get_by_key("recent"), n);
702
703         if (!path) return;
704
705         /* make a copy of it */
706         path = g_strdup(path);
707         collection_window_new(path);
708         g_free(path);
709 }
710
711 static void layout_menu_recent_update(LayoutWindow *lw)
712 {
713         GtkWidget *menu;
714         GtkWidget *recent;
715         GtkWidget *item;
716         GList *list;
717         gint n;
718
719         if (!lw->ui_manager) return;
720
721         list = history_list_get_by_key("recent");
722         n = 0;
723
724         menu = gtk_menu_new();
725
726         while (list)
727                 {
728                 item = menu_item_add_simple(menu, filename_from_path((gchar *)list->data),
729                                             G_CALLBACK(layout_menu_recent_cb), lw);
730                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
731                 list = list->next;
732                 n++;
733                 }
734
735         if (n == 0)
736                 {
737                 menu_item_add(menu, _("Empty"), NULL, NULL);
738                 }
739
740         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
741         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
742         gtk_widget_set_sensitive(recent, (n != 0));
743 }
744
745 void layout_recent_update_all(void)
746 {
747         GList *work;
748
749         work = layout_window_list;
750         while (work)
751                 {
752                 LayoutWindow *lw = work->data;
753                 work = work->next;
754
755                 layout_menu_recent_update(lw);
756                 }
757 }
758
759 void layout_recent_add_path(const gchar *path)
760 {
761         if (!path) return;
762
763         history_list_add_to_key("recent", path, recent_list_max);
764
765         layout_recent_update_all();
766 }
767
768 /*
769  *-----------------------------------------------------------------------------
770  * menu
771  *-----------------------------------------------------------------------------
772  */ 
773
774 #define CB G_CALLBACK
775
776 static GtkActionEntry menu_entries[] = {
777   { "FileMenu",         NULL,           N_("_File") },
778   { "EditMenu",         NULL,           N_("_Edit") },
779   { "AdjustMenu",       NULL,           N_("_Adjust") },
780   { "ViewMenu",         NULL,           N_("_View") },
781   { "HelpMenu",         NULL,           N_("_Help") },
782
783   { "NewWindow",        GTK_STOCK_NEW,  N_("New _window"),      NULL,           NULL,   CB(layout_menu_new_window_cb) },
784   { "NewCollection",    GTK_STOCK_INDEX,N_("_New collection"),  "C",            NULL,   CB(layout_menu_new_cb) },
785   { "OpenCollection",   GTK_STOCK_OPEN, N_("_Open collection..."),"O",          NULL,   CB(layout_menu_open_cb) },
786   { "OpenRecent",       NULL,           N_("Open _recent") },
787   { "Search",           GTK_STOCK_FIND, N_("_Search..."),       "F3",           NULL,   CB(layout_menu_search_cb) },
788   { "FindDupes",        GTK_STOCK_FIND, N_("_Find duplicates..."),"D",          NULL,   CB(layout_menu_dupes_cb) },
789   { "PanView",          NULL,           N_("Pan _view"),        "<control>J",   NULL,   CB(layout_menu_pan_cb) },
790   { "Print",            GTK_STOCK_PRINT,N_("_Print..."),        "<shift>P",     NULL,   CB(layout_menu_print_cb) },
791   { "NewFolder",        NULL,           N_("N_ew folder..."),   "<control>F",   NULL,   CB(layout_menu_dir_cb) },
792   { "Copy",             NULL,           N_("_Copy..."),         "<control>C",   NULL,   CB(layout_menu_copy_cb) },
793   { "Move",             NULL,           N_("_Move..."),         "<control>M",   NULL,   CB(layout_menu_move_cb) },
794   { "Rename",           NULL,           N_("_Rename..."),       "<control>R",   NULL,   CB(layout_menu_rename_cb) },
795   { "Delete",   GTK_STOCK_DELETE,       N_("_Delete..."),       "<control>D",   NULL,   CB(layout_menu_delete_cb) },
796   { "CloseWindow",      GTK_STOCK_CLOSE,N_("C_lose window"),    "<control>W",   NULL,   CB(layout_menu_close_cb) },
797   { "Quit",             GTK_STOCK_QUIT, N_("_Quit"),            "<control>Q",   NULL,   CB(layout_menu_exit_cb) },
798
799   { "Editor0",          NULL,           "editor0",              "<control>1",   NULL,   CB(layout_menu_edit_cb) },
800   { "Editor1",          NULL,           "editor1",              "<control>2",   NULL,   CB(layout_menu_edit_cb) },
801   { "Editor2",          NULL,           "editor2",              "<control>3",   NULL,   CB(layout_menu_edit_cb) },
802   { "Editor3",          NULL,           "editor3",              "<control>4",   NULL,   CB(layout_menu_edit_cb) },
803   { "Editor4",          NULL,           "editor4",              "<control>5",   NULL,   CB(layout_menu_edit_cb) },
804   { "Editor5",          NULL,           "editor5",              "<control>6",   NULL,   CB(layout_menu_edit_cb) },
805   { "Editor6",          NULL,           "editor6",              "<control>7",   NULL,   CB(layout_menu_edit_cb) },
806   { "Editor7",          NULL,           "editor7",              "<control>8",   NULL,   CB(layout_menu_edit_cb) },
807   { "Editor8",          NULL,           "editor8",              "<control>9",   NULL,   CB(layout_menu_edit_cb) },
808   { "Editor9",          NULL,           "editor9",              "<control>0",   NULL,   CB(layout_menu_edit_cb) },
809   { "RotateCW",         NULL,   N_("_Rotate clockwise"),        "bracketright", NULL,   CB(layout_menu_alter_90_cb) },
810   { "RotateCCW",        NULL,   N_("Rotate _counterclockwise"), "bracketleft",  NULL,   CB(layout_menu_alter_90cc_cb) },
811   { "Rotate180",        NULL,           N_("Rotate 1_80"),      "<shift>R",     NULL,   CB(layout_menu_alter_180_cb) },
812   { "Mirror",           NULL,           N_("_Mirror"),          "<shift>M",     NULL,   CB(layout_menu_alter_mirror_cb) },
813   { "Flip",             NULL,           N_("_Flip"),            "<shift>F",     NULL,   CB(layout_menu_alter_flip_cb) },
814   { "Grayscale",        NULL,           N_("_Grayscale"),       "<shift>G",     NULL,   CB(layout_menu_alter_desaturate_cb) },
815   { "Properties",GTK_STOCK_PROPERTIES,  N_("_Properties"),      "<control>P",   NULL,   CB(layout_menu_info_cb) },
816   { "SelectAll",        NULL,           N_("Select _all"),      "<control>A",   NULL,   CB(layout_menu_select_all_cb) },
817   { "SelectNone",       NULL,           N_("Select _none"), "<control><shift>A",NULL,   CB(layout_menu_unselect_all_cb) },
818   { "Preferences",GTK_STOCK_PREFERENCES,N_("P_references..."),  "<control>O",   NULL,   CB(layout_menu_config_cb) },
819   { "Maintenance",      NULL,           N_("_Thumbnail maintenance..."),NULL,   NULL,   CB(layout_menu_remove_thumb_cb) },
820   { "Wallpaper",        NULL,           N_("Set as _wallpaper"),NULL,           NULL,   CB(layout_menu_wallpaper_cb) },
821
822   { "ZoomIn",   GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "equal",        NULL,   CB(layout_menu_zoom_in_cb) },
823   { "ZoomOut",  GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "minus",        NULL,   CB(layout_menu_zoom_out_cb) },
824   { "Zoom100",  GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "Z",            NULL,   CB(layout_menu_zoom_1_1_cb) },
825   { "ZoomFit",  GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "X",            NULL,   CB(layout_menu_zoom_fit_cb) },
826   { "FullScreen",       NULL,           N_("F_ull screen"),     "F",            NULL,   CB(layout_menu_fullscreen_cb) },
827   { "HideTools",        NULL,           N_("_Hide file list"),  "<control>H",   NULL,   CB(layout_menu_hide_cb) },
828   { "SlideShow",        NULL,           N_("Toggle _slideshow"),"S",            NULL,   CB(layout_menu_slideshow_cb) },
829   { "Refresh",  GTK_STOCK_REFRESH,      N_("_Refresh"),         "R",            NULL,   CB(layout_menu_refresh_cb) },
830
831   { "HelpContents",     GTK_STOCK_HELP, N_("_Contents"),        "F1",           NULL,   CB(layout_menu_help_cb) },
832   { "HelpShortcuts",    NULL,           N_("_Keyboard shortcuts"),NULL,         NULL,   CB(layout_menu_help_keys_cb) },
833   { "HelpNotes",        NULL,           N_("_Release notes"),   NULL,           NULL,   CB(layout_menu_notes_cb) },
834   { "About",            NULL,           N_("_About"),           NULL,           NULL,   CB(layout_menu_about_cb) }
835 };
836
837 static GtkToggleActionEntry menu_toggle_entries[] = {
838   { "Thumbnails",       NULL,           N_("_Thumbnails"),      "T",            NULL,   CB(layout_menu_thumb_cb) },
839   { "FolderTree",       NULL,           N_("Tr_ee"),            "<control>T",   NULL,   CB(layout_menu_tree_cb) },
840   { "FloatTools",       NULL,           N_("_Float file list"), "L",            NULL,   CB(layout_menu_float_cb) },
841   { "HideToolbar",      NULL,           N_("Hide tool_bar"),    NULL,           NULL,   CB(layout_menu_toolbar_cb) },
842   { "SBarKeywords",     NULL,           N_("_Keywords"),        "<control>K",   NULL,   CB(layout_menu_bar_info_cb) },
843   { "SBarExif",         NULL,           N_("E_xif data"),       "<control>E",   NULL,   CB(layout_menu_bar_exif_cb) },
844   { "SBarSort",         NULL,           N_("Sort _manager"),    "<control>S",   NULL,   CB(layout_menu_bar_sort_cb) }
845 };
846
847 static GtkRadioActionEntry menu_radio_entries[] = {
848   { "ViewList",         NULL,           N_("_List"),            "<control>L",   NULL,   0 },
849   { "ViewIcons",        NULL,           N_("I_cons"),           "<control>I",   NULL,   1 }
850 };
851
852 #undef CB
853
854 static const char *menu_ui_description =
855 "<ui>"
856 "  <menubar name='MainMenu'>"
857 "    <menu action='FileMenu'>"
858 "      <menuitem action='NewWindow'/>"
859 "      <menuitem action='NewCollection'/>"
860 "      <menuitem action='OpenCollection'/>"
861 "      <menuitem action='OpenRecent'/>"
862 "      <separator/>"
863 "      <menuitem action='Search'/>"
864 "      <menuitem action='FindDupes'/>"
865 "      <menuitem action='PanView'/>"
866 "      <separator/>"
867 "      <menuitem action='Print'/>"
868 "      <menuitem action='NewFolder'/>"
869 "      <separator/>"
870 "      <menuitem action='Copy'/>"
871 "      <menuitem action='Move'/>"
872 "      <menuitem action='Rename'/>"
873 "      <menuitem action='Delete'/>"
874 "      <separator/>"
875 "      <menuitem action='CloseWindow'/>"
876 "      <menuitem action='Quit'/>"
877 "    </menu>"
878 "    <menu action='EditMenu'>"
879 "      <menuitem action='Editor0'/>"
880 "      <menuitem action='Editor1'/>"
881 "      <menuitem action='Editor2'/>"
882 "      <menuitem action='Editor3'/>"
883 "      <menuitem action='Editor4'/>"
884 "      <menuitem action='Editor5'/>"
885 "      <menuitem action='Editor6'/>"
886 "      <menuitem action='Editor7'/>"
887 "      <menuitem action='Editor8'/>"
888 "      <menuitem action='Editor9'/>"
889 "      <separator/>"
890 "      <menu action='AdjustMenu'>"
891 "        <menuitem action='RotateCW'/>"
892 "        <menuitem action='RotateCCW'/>"
893 "        <menuitem action='Rotate180'/>"
894 "        <menuitem action='Mirror'/>"
895 "        <menuitem action='Flip'/>"
896 "        <menuitem action='Grayscale'/>"
897 "      </menu>"
898 "      <menuitem action='Properties'/>"
899 "      <separator/>"
900 "      <menuitem action='SelectAll'/>"
901 "      <menuitem action='SelectNone'/>"
902 "      <separator/>"
903 "      <menuitem action='Preferences'/>"
904 "      <menuitem action='Maintenance'/>"
905 "      <separator/>"
906 "      <menuitem action='Wallpaper'/>"
907 "    </menu>"
908 "    <menu action='ViewMenu'>"
909 "      <separator/>"
910 "      <menuitem action='ZoomIn'/>"
911 "      <menuitem action='ZoomOut'/>"
912 "      <menuitem action='Zoom100'/>"
913 "      <menuitem action='ZoomFit'/>"
914 "      <separator/>"
915 "      <menuitem action='Thumbnails'/>"
916 "      <menuitem action='ViewList'/>"
917 "      <menuitem action='ViewIcons'/>"
918 "      <separator/>"
919 "      <menuitem action='FolderTree'/>"
920 "      <menuitem action='FullScreen'/>"
921 "      <separator/>"
922 "      <menuitem action='FloatTools'/>"
923 "      <menuitem action='HideTools'/>"
924 "      <menuitem action='HideToolbar'/>"
925 "      <separator/>"
926 "      <menuitem action='SBarKeywords'/>"
927 "      <menuitem action='SBarExif'/>"
928 "      <menuitem action='SBarSort'/>"
929 "      <separator/>"
930 "      <menuitem action='SlideShow'/>"
931 "      <menuitem action='Refresh'/>"
932 "    </menu>"
933 "    <menu action='HelpMenu'>"
934 "      <separator/>"
935 "      <menuitem action='HelpContents'/>"
936 "      <menuitem action='HelpShortcuts'/>"
937 "      <menuitem action='HelpNotes'/>"
938 "      <separator/>"
939 "      <menuitem action='About'/>"
940 "    </menu>"
941 "  </menubar>"
942 "</ui>";
943
944
945 static gchar *menu_translate(const gchar *path, gpointer data)
946 {
947         return _(path);
948 }
949
950 void layout_actions_setup(LayoutWindow *lw)
951 {
952         GError *error;
953
954         if (lw->ui_manager) return;
955
956         lw->action_group = gtk_action_group_new ("MenuActions");
957         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
958
959         gtk_action_group_add_actions(lw->action_group,
960                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
961         gtk_action_group_add_toggle_actions(lw->action_group,
962                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
963         gtk_action_group_add_radio_actions(lw->action_group,
964                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
965                                            0, G_CALLBACK(layout_menu_list_cb), lw);
966
967         lw->ui_manager = gtk_ui_manager_new();
968         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
969         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
970
971         error = NULL;
972         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
973                 {
974                 g_message ("building menus failed: %s", error->message);
975                 g_error_free (error);
976                 exit (EXIT_FAILURE);
977                 }
978 }
979
980 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
981 {
982         GtkAccelGroup *group;
983
984         if (!lw->ui_manager) return;
985
986         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
987         gtk_window_add_accel_group(GTK_WINDOW(window), group);
988 }
989
990 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
991 {
992         return gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
993 }
994
995
996 /*
997  *-----------------------------------------------------------------------------
998  * toolbar
999  *-----------------------------------------------------------------------------
1000  */ 
1001
1002 static void layout_button_thumb_cb(GtkWidget *widget, gpointer data)
1003 {
1004         LayoutWindow *lw = data;
1005
1006         layout_thumb_set(lw, gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)));
1007 }
1008
1009 static void layout_button_home_cb(GtkWidget *widget, gpointer data)
1010 {
1011         LayoutWindow *lw = data;
1012         const gchar *path = homedir();
1013
1014         if (path) layout_set_path(lw, path);
1015 }
1016
1017 static void layout_button_refresh_cb(GtkWidget *widget, gpointer data)
1018 {
1019         LayoutWindow *lw = data;
1020
1021         layout_refresh(lw);
1022 }
1023
1024 static void layout_button_zoom_in_cb(GtkWidget *widget, gpointer data)
1025 {
1026         LayoutWindow *lw = data;
1027
1028         layout_image_zoom_adjust(lw, get_zoom_increment());
1029 }
1030
1031 static void layout_button_zoom_out_cb(GtkWidget *widget, gpointer data)
1032 {
1033         LayoutWindow *lw = data;
1034
1035         layout_image_zoom_adjust(lw, -get_zoom_increment());
1036 }
1037
1038 static void layout_button_zoom_fit_cb(GtkWidget *widget, gpointer data)
1039 {
1040         LayoutWindow *lw = data;
1041
1042         layout_image_zoom_set(lw, 0.0);
1043 }
1044
1045 static void layout_button_zoom_1_1_cb(GtkWidget *widget, gpointer data)
1046 {
1047         LayoutWindow *lw = data;
1048
1049         layout_image_zoom_set(lw, 1.0);
1050 }
1051
1052 static void layout_button_config_cb(GtkWidget *widget, gpointer data)
1053 {
1054         show_config_window();
1055 }
1056
1057 static void layout_button_float_cb(GtkWidget *widget, gpointer data)
1058 {
1059         LayoutWindow *lw = data;
1060
1061         layout_tools_float_toggle(lw);
1062 }
1063
1064 static void layout_button_custom_icon(GtkWidget *button, const gchar *key)
1065 {
1066         GtkWidget *icon;
1067         GdkPixbuf *pixbuf;
1068
1069         pixbuf = pixbuf_inline(key);
1070         if (!pixbuf) return;
1071
1072         icon = gtk_image_new_from_pixbuf(pixbuf);
1073         g_object_unref(pixbuf);
1074
1075         pref_toolbar_button_set_icon(button, icon, NULL);
1076         gtk_widget_show(icon);
1077 }
1078
1079 GtkWidget *layout_button_bar(LayoutWindow *lw)
1080 {
1081         GtkWidget *box;
1082         GtkWidget *button;
1083
1084         box =  pref_toolbar_new(NULL, GTK_TOOLBAR_ICONS);
1085
1086         button = pref_toolbar_button(box, NULL, _("_Thumbnails"), TRUE,
1087                                      _("Show thumbnails"), G_CALLBACK(layout_button_thumb_cb), lw);
1088         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_THUMB);
1089         lw->thumb_button = button;
1090
1091         pref_toolbar_button(box, GTK_STOCK_HOME, NULL, FALSE,
1092                             _("Change to home folder"), G_CALLBACK(layout_button_home_cb), lw);
1093         pref_toolbar_button(box, GTK_STOCK_REFRESH, NULL, FALSE,
1094                             _("Refresh file list"), G_CALLBACK(layout_button_refresh_cb), lw);
1095         pref_toolbar_button(box, GTK_STOCK_ZOOM_IN, NULL, FALSE,
1096                             _("Zoom in"), G_CALLBACK(layout_button_zoom_in_cb), lw);
1097         pref_toolbar_button(box, GTK_STOCK_ZOOM_OUT, NULL, FALSE,
1098                             _("Zoom out"), G_CALLBACK(layout_button_zoom_out_cb), lw);
1099         pref_toolbar_button(box, GTK_STOCK_ZOOM_FIT, NULL, FALSE,
1100                             _("Fit image to window"), G_CALLBACK(layout_button_zoom_fit_cb), lw);
1101         pref_toolbar_button(box, GTK_STOCK_ZOOM_100, NULL, FALSE,
1102                             _("Set zoom 1:1"), G_CALLBACK(layout_button_zoom_1_1_cb), lw);
1103         pref_toolbar_button(box, GTK_STOCK_PREFERENCES, NULL, FALSE,
1104                             _("Configure options"), G_CALLBACK(layout_button_config_cb), lw);
1105         button = pref_toolbar_button(box, NULL, _("_Float"), FALSE,
1106                                      _("Float Controls"), G_CALLBACK(layout_button_float_cb), lw);
1107         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_FLOAT);
1108
1109         return box;
1110 }
1111
1112 /*
1113  *-----------------------------------------------------------------------------
1114  * misc
1115  *-----------------------------------------------------------------------------
1116  */
1117
1118 static void layout_util_sync_views(LayoutWindow *lw)
1119 {
1120         GtkAction *action;
1121
1122         if (!lw->action_group) return;
1123
1124         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
1125         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tree_view);
1126
1127         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
1128         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->icon_view);
1129
1130         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
1131         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tools_float);
1132
1133         action = gtk_action_group_get_action(lw->action_group, "SBarKeywords");
1134         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_info_enabled);
1135
1136         action = gtk_action_group_get_action(lw->action_group, "SBarExif");
1137         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_exif_enabled);
1138
1139         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
1140         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_sort_enabled);
1141
1142         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
1143         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->toolbar_hidden);
1144 }
1145
1146 void layout_util_sync_thumb(LayoutWindow *lw)
1147 {
1148         GtkAction *action;
1149
1150         if (!lw->action_group) return;
1151
1152         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
1153         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->thumbs_enabled);
1154         g_object_set(action, "sensitive", !lw->icon_view, NULL);
1155
1156         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->thumbs_enabled);
1157         gtk_widget_set_sensitive(lw->thumb_button, !lw->icon_view);
1158 }
1159
1160 void layout_util_sync(LayoutWindow *lw)
1161 {
1162         layout_util_sync_views(lw);
1163         layout_util_sync_thumb(lw);
1164         layout_menu_recent_update(lw);
1165         layout_menu_edit_update(lw);
1166 }
1167
1168 /*
1169  *-----------------------------------------------------------------------------
1170  * icons (since all the toolbar icons are included here, best place as any)
1171  *-----------------------------------------------------------------------------
1172  */
1173
1174 PixmapFolders *folder_icons_new(void)
1175 {
1176         PixmapFolders *pf;
1177
1178         pf = g_new0(PixmapFolders, 1);
1179
1180         pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
1181         pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
1182         pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
1183         pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
1184
1185         return pf;
1186 }
1187
1188 void folder_icons_free(PixmapFolders *pf)
1189 {
1190         if (!pf) return;
1191
1192         g_object_unref(pf->close);
1193         g_object_unref(pf->open);
1194         g_object_unref(pf->deny);
1195         g_object_unref(pf->parent);
1196
1197         g_free(pf);
1198 }
1199
1200 /*
1201  *-----------------------------------------------------------------------------
1202  * sidebars
1203  *-----------------------------------------------------------------------------
1204  */
1205
1206 #define SIDEBAR_WIDTH 288
1207
1208 static void layout_bar_info_destroyed(GtkWidget *widget, gpointer data)
1209 {
1210         LayoutWindow *lw = data;
1211
1212         lw->bar_info = NULL;
1213
1214         if (lw->utility_box)
1215                 {
1216                 /* destroyed from within itself */
1217                 lw->bar_info_enabled = FALSE;
1218                 layout_util_sync_views(lw);
1219                 }
1220 }
1221
1222 static GList *layout_bar_info_list_cb(gpointer data)
1223 {
1224         LayoutWindow *lw = data;
1225
1226         return layout_selection_list(lw);
1227 }
1228
1229 static void layout_bar_info_new(LayoutWindow *lw)
1230 {
1231         if (!lw->utility_box) return;
1232                                                                                                                     
1233         lw->bar_info = bar_info_new(layout_image_get_path(lw), FALSE, lw->utility_box);
1234         bar_info_set_selection_func(lw->bar_info, layout_bar_info_list_cb, lw);
1235         bar_info_selection(lw->bar_info, layout_selection_count(lw, NULL) - 1);
1236         bar_info_size_request(lw->bar_info, SIDEBAR_WIDTH * 3 / 4);
1237         g_signal_connect(G_OBJECT(lw->bar_info), "destroy",
1238                          G_CALLBACK(layout_bar_info_destroyed), lw);
1239         lw->bar_info_enabled = TRUE;
1240
1241         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_info, FALSE, FALSE, 0);
1242         gtk_widget_show(lw->bar_info);
1243 }
1244                                                                                                                     
1245 static void layout_bar_info_close(LayoutWindow *lw)
1246 {
1247         if (lw->bar_info)
1248                 {
1249                 bar_info_close(lw->bar_info);
1250                 lw->bar_info = NULL;
1251                 }
1252         lw->bar_info_enabled = FALSE;
1253 }
1254
1255 void layout_bar_info_toggle(LayoutWindow *lw)
1256 {
1257         if (lw->bar_info_enabled)
1258                 {
1259                 layout_bar_info_close(lw);
1260                 }
1261         else
1262                 {
1263                 layout_bar_info_new(lw);
1264                 }
1265 }
1266
1267 static void layout_bar_info_new_image(LayoutWindow *lw)
1268 {
1269         if (!lw->bar_info || !lw->bar_info_enabled) return;
1270
1271         bar_info_set(lw->bar_info, layout_image_get_path(lw));
1272 }
1273
1274 static void layout_bar_info_new_selection(LayoutWindow *lw, gint count)
1275 {
1276         if (!lw->bar_info || !lw->bar_info_enabled) return;
1277
1278         bar_info_selection(lw->bar_info, count - 1);
1279 }
1280
1281 static void layout_bar_info_maint_renamed(LayoutWindow *lw)
1282 {
1283         if (!lw->bar_info || !lw->bar_info_enabled) return;
1284
1285         bar_info_maint_renamed(lw->bar_info, layout_image_get_path(lw));
1286 }
1287
1288 static void layout_bar_exif_destroyed(GtkWidget *widget, gpointer data)
1289 {
1290         LayoutWindow *lw = data;
1291
1292         if (lw->bar_exif)
1293                 {
1294                 lw->bar_exif_advanced = bar_exif_is_advanced(lw->bar_exif);
1295                 }
1296
1297         lw->bar_exif = NULL;
1298         if (lw->utility_box)
1299                 {
1300                 /* destroyed from within itself */
1301                 lw->bar_exif_enabled = FALSE;
1302                 layout_util_sync_views(lw);
1303                 }
1304 }
1305
1306 static void layout_bar_exif_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1307 {
1308         LayoutWindow *lw = data;
1309
1310         if (lw->bar_exif)
1311                 {
1312                 lw->bar_exif_size = allocation->width;
1313                 }
1314 }
1315
1316 static void layout_bar_exif_new(LayoutWindow *lw)
1317 {
1318         if (!lw->utility_box) return;
1319
1320         lw->bar_exif = bar_exif_new(TRUE, layout_image_get_path(lw),
1321                                     lw->bar_exif_advanced, lw->utility_box);
1322         g_signal_connect(G_OBJECT(lw->bar_exif), "destroy",
1323                          G_CALLBACK(layout_bar_exif_destroyed), lw);
1324         g_signal_connect(G_OBJECT(lw->bar_exif), "size_allocate",
1325                          G_CALLBACK(layout_bar_exif_sized), lw);
1326         lw->bar_exif_enabled = TRUE;
1327
1328         if (lw->bar_exif_size < 1) lw->bar_exif_size = SIDEBAR_WIDTH;
1329         gtk_widget_set_size_request(lw->bar_exif, lw->bar_exif_size, -1);
1330         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_exif, FALSE, FALSE, 0);
1331         if (lw->bar_info) gtk_box_reorder_child(GTK_BOX(lw->utility_box), lw->bar_exif, 1);
1332         gtk_widget_show(lw->bar_exif);
1333 }
1334
1335 static void layout_bar_exif_close(LayoutWindow *lw)
1336 {
1337         if (lw->bar_exif)
1338                 {
1339                 bar_exif_close(lw->bar_exif);
1340                 lw->bar_exif = NULL;
1341                 }
1342         lw->bar_exif_enabled = FALSE;
1343 }
1344
1345 void layout_bar_exif_toggle(LayoutWindow *lw)
1346 {
1347         if (lw->bar_exif_enabled)
1348                 {
1349                 layout_bar_exif_close(lw);
1350                 }
1351         else
1352                 {
1353                 layout_bar_exif_new(lw);
1354                 }
1355 }
1356
1357 static void layout_bar_exif_new_image(LayoutWindow *lw)
1358 {
1359         if (!lw->bar_exif || !lw->bar_exif_enabled) return;
1360
1361         bar_exif_set(lw->bar_exif, layout_image_get_path(lw));
1362 }
1363
1364 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
1365 {
1366         LayoutWindow *lw = data;
1367
1368         lw->bar_sort = NULL;
1369
1370         if (lw->utility_box)
1371                 {
1372                 /* destroyed from within itself */
1373                 lw->bar_sort_enabled = FALSE;
1374
1375                 layout_util_sync_views(lw);
1376                 }
1377 }
1378
1379 static void layout_bar_sort_new(LayoutWindow *lw)
1380 {
1381         if (!lw->utility_box) return;
1382
1383         lw->bar_sort = bar_sort_new(lw);
1384         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
1385                          G_CALLBACK(layout_bar_sort_destroyed), lw);
1386         lw->bar_sort_enabled = TRUE;
1387
1388         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
1389         gtk_widget_show(lw->bar_sort);
1390 }
1391
1392 static void layout_bar_sort_close(LayoutWindow *lw)
1393 {
1394         if (lw->bar_sort)
1395                 {
1396                 bar_sort_close(lw->bar_sort);
1397                 lw->bar_sort = NULL;
1398                 }
1399         lw->bar_sort_enabled = FALSE;
1400 }
1401
1402 void layout_bar_sort_toggle(LayoutWindow *lw)
1403 {
1404         if (lw->bar_sort_enabled)
1405                 {
1406                 layout_bar_sort_close(lw);
1407                 }
1408         else
1409                 {
1410                 layout_bar_sort_new(lw);
1411                 }
1412 }
1413
1414 void layout_bars_new_image(LayoutWindow *lw)
1415 {
1416         layout_bar_info_new_image(lw);
1417         layout_bar_exif_new_image(lw);
1418 }
1419
1420 void layout_bars_new_selection(LayoutWindow *lw, gint count)
1421 {
1422         layout_bar_info_new_selection(lw, count);
1423 }
1424
1425 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
1426 {
1427         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
1428         gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
1429         gtk_widget_show(image);
1430
1431         if (lw->bar_sort_enabled)
1432                 {
1433                 layout_bar_sort_new(lw);
1434                 }
1435
1436         if (lw->bar_info_enabled)
1437                 {
1438                 layout_bar_info_new(lw);
1439                 }
1440
1441         if (lw->bar_exif_enabled)
1442                 {
1443                 layout_bar_exif_new(lw);
1444                 }
1445
1446         return lw->utility_box;
1447 }
1448
1449 void layout_bars_close(LayoutWindow *lw)
1450 {
1451         layout_bar_sort_close(lw);
1452         layout_bar_exif_close(lw);
1453         layout_bar_info_close(lw);
1454 }
1455
1456 void layout_bars_maint_renamed(LayoutWindow *lw)
1457 {
1458         layout_bar_info_maint_renamed(lw);
1459 }
1460