]> Pileus Git - ~andy/gtk/blob - gtk/gtkpathbar.c
Improve navigation to parent folders. (#318444, Andrei Yurkevich)
[~andy/gtk] / gtk / gtkpathbar.c
1 /* gtkpathbar.c
2  * Copyright (C) 2004  Red Hat, Inc.,  Jonathan Blandford <jrb@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <config.h>
21 #include <string.h>
22 #include "gtkpathbar.h"
23 #include "gtktogglebutton.h"
24 #include "gtkalignment.h"
25 #include "gtkarrow.h"
26 #include "gtkdnd.h"
27 #include "gtkimage.h"
28 #include "gtkintl.h"
29 #include "gtkicontheme.h"
30 #include "gtkiconfactory.h"
31 #include "gtklabel.h"
32 #include "gtkhbox.h"
33 #include "gtkmain.h"
34 #include "gtkmarshalers.h"
35 #include "gtkalias.h"
36
37 enum {
38   PATH_CLICKED,
39   LAST_SIGNAL
40 };
41
42 typedef enum {
43   NORMAL_BUTTON,
44   ROOT_BUTTON,
45   HOME_BUTTON,
46   DESKTOP_BUTTON
47 } ButtonType;
48
49 #define BUTTON_DATA(x) ((ButtonData *)(x))
50
51 #define SCROLL_TIMEOUT           150
52 #define INITIAL_SCROLL_TIMEOUT   300
53
54 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
55
56 /* Icon size for if we can't get it from the theme */
57 #define FALLBACK_ICON_SIZE 16
58
59 typedef struct _ButtonData ButtonData;
60
61 struct _ButtonData
62 {
63   GtkWidget *button;
64   ButtonType type;
65   char *dir_name;
66   GtkFilePath *path;
67   GtkWidget *image;
68   GtkWidget *label;
69   guint ignore_changes : 1;
70   guint file_is_hidden : 1;
71 };
72 /* This macro is used to check if a button can be used as a fake root.
73  * All buttons in front of a fake root are automatically hidden when in a
74  * directory below a fake root and replaced with the "<" arrow button.
75  */
76 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
77
78 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER);
79
80 static void gtk_path_bar_finalize                 (GObject          *object);
81 static void gtk_path_bar_dispose                  (GObject          *object);
82 static void gtk_path_bar_size_request             (GtkWidget        *widget,
83                                                    GtkRequisition   *requisition);
84 static void gtk_path_bar_unmap                    (GtkWidget          *widget);
85 static void gtk_path_bar_size_allocate            (GtkWidget        *widget,
86                                                    GtkAllocation    *allocation);
87 static void gtk_path_bar_add                      (GtkContainer     *container,
88                                                    GtkWidget        *widget);
89 static void gtk_path_bar_remove                   (GtkContainer     *container,
90                                                    GtkWidget        *widget);
91 static void gtk_path_bar_forall                   (GtkContainer     *container,
92                                                    gboolean          include_internals,
93                                                    GtkCallback       callback,
94                                                    gpointer          callback_data);
95 static void gtk_path_bar_scroll_up                (GtkWidget        *button,
96                                                    GtkPathBar       *path_bar);
97 static void gtk_path_bar_scroll_down              (GtkWidget        *button,
98                                                    GtkPathBar       *path_bar);
99 static void gtk_path_bar_stop_scrolling           (GtkPathBar       *path_bar);
100 static gboolean gtk_path_bar_slider_button_press  (GtkWidget        *widget,
101                                                    GdkEventButton   *event,
102                                                    GtkPathBar       *path_bar);
103 static gboolean gtk_path_bar_slider_button_release(GtkWidget        *widget,
104                                                    GdkEventButton   *event,
105                                                    GtkPathBar       *path_bar);
106 static void gtk_path_bar_grab_notify              (GtkWidget        *widget,
107                                                    gboolean          was_grabbed);
108 static void gtk_path_bar_state_changed            (GtkWidget        *widget,
109                                                    GtkStateType      previous_state);
110 static void gtk_path_bar_style_set                (GtkWidget        *widget,
111                                                    GtkStyle         *previous_style);
112 static void gtk_path_bar_screen_changed           (GtkWidget        *widget,
113                                                    GdkScreen        *previous_screen);
114 static void gtk_path_bar_check_icon_theme         (GtkPathBar       *path_bar);
115 static void gtk_path_bar_update_button_appearance (GtkPathBar       *path_bar,
116                                                    ButtonData       *button_data,
117                                                    gboolean          current_dir);
118
119 static GtkWidget *
120 get_slider_button (GtkPathBar  *path_bar,
121                    GtkArrowType arrow_type)
122 {
123   GtkWidget *button;
124
125   gtk_widget_push_composite_child ();
126
127   button = gtk_button_new ();
128   gtk_button_set_focus_on_click (button, FALSE);
129   gtk_container_add (GTK_CONTAINER (button), gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
130   gtk_container_add (GTK_CONTAINER (path_bar), button);
131   gtk_widget_show_all (button);
132
133   gtk_widget_pop_composite_child ();
134
135   return button;
136 }
137
138 static void
139 gtk_path_bar_init (GtkPathBar *path_bar)
140 {
141   GTK_WIDGET_SET_FLAGS (path_bar, GTK_NO_WINDOW);
142   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
143
144   path_bar->spacing = 3;
145   path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
146   path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
147   path_bar->icon_size = FALLBACK_ICON_SIZE;
148   
149   g_signal_connect (path_bar->up_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
150   g_signal_connect (path_bar->down_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
151
152   g_signal_connect (path_bar->up_slider_button, "button_press_event", G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
153   g_signal_connect (path_bar->up_slider_button, "button_release_event", G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
154   g_signal_connect (path_bar->down_slider_button, "button_press_event", G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
155   g_signal_connect (path_bar->down_slider_button, "button_release_event", G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
156 }
157
158 static void
159 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
160 {
161   GObjectClass *gobject_class;
162   GtkObjectClass *object_class;
163   GtkWidgetClass *widget_class;
164   GtkContainerClass *container_class;
165
166   gobject_class = (GObjectClass *) path_bar_class;
167   object_class = (GtkObjectClass *) path_bar_class;
168   widget_class = (GtkWidgetClass *) path_bar_class;
169   container_class = (GtkContainerClass *) path_bar_class;
170
171   gobject_class->finalize = gtk_path_bar_finalize;
172   gobject_class->dispose = gtk_path_bar_dispose;
173
174   widget_class->size_request = gtk_path_bar_size_request;
175   widget_class->unmap = gtk_path_bar_unmap;
176   widget_class->size_allocate = gtk_path_bar_size_allocate;
177   widget_class->style_set = gtk_path_bar_style_set;
178   widget_class->screen_changed = gtk_path_bar_screen_changed;
179   widget_class->grab_notify = gtk_path_bar_grab_notify;
180   widget_class->state_changed = gtk_path_bar_state_changed;
181
182   container_class->add = gtk_path_bar_add;
183   container_class->forall = gtk_path_bar_forall;
184   container_class->remove = gtk_path_bar_remove;
185   /* FIXME: */
186   /*  container_class->child_type = gtk_path_bar_child_type;*/
187
188   path_bar_signals [PATH_CLICKED] =
189     g_signal_new (I_("path-clicked"),
190                   G_OBJECT_CLASS_TYPE (object_class),
191                   G_SIGNAL_RUN_FIRST,
192                   G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
193                   NULL, NULL,
194                   _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
195                   G_TYPE_NONE, 3,
196                   G_TYPE_POINTER,
197                   G_TYPE_POINTER,
198                   G_TYPE_BOOLEAN);
199 }
200
201
202 static void
203 gtk_path_bar_finalize (GObject *object)
204 {
205   GtkPathBar *path_bar;
206
207   path_bar = GTK_PATH_BAR (object);
208
209   gtk_path_bar_stop_scrolling (path_bar);
210
211   g_list_free (path_bar->button_list);
212   if (path_bar->root_path)
213     gtk_file_path_free (path_bar->root_path);
214   if (path_bar->home_path)
215     gtk_file_path_free (path_bar->home_path);
216   if (path_bar->desktop_path)
217     gtk_file_path_free (path_bar->desktop_path);
218
219   if (path_bar->root_icon)
220     g_object_unref (path_bar->root_icon);
221   if (path_bar->home_icon)
222     g_object_unref (path_bar->home_icon);
223   if (path_bar->desktop_icon)
224     g_object_unref (path_bar->desktop_icon);
225
226   if (path_bar->file_system)
227     g_object_unref (path_bar->file_system);
228
229   G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
230 }
231
232 /* Removes the settings signal handler.  It's safe to call multiple times */
233 static void
234 remove_settings_signal (GtkPathBar *path_bar,
235                         GdkScreen  *screen)
236 {
237   if (path_bar->settings_signal_id)
238     {
239       GtkSettings *settings;
240
241       settings = gtk_settings_get_for_screen (screen);
242       g_signal_handler_disconnect (settings,
243                                    path_bar->settings_signal_id);
244       path_bar->settings_signal_id = 0;
245     }
246 }
247
248 static void
249 gtk_path_bar_dispose (GObject *object)
250 {
251   remove_settings_signal (GTK_PATH_BAR (object),
252                           gtk_widget_get_screen (GTK_WIDGET (object)));
253
254   G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
255 }
256
257 /* Size requisition:
258  * 
259  * Ideally, our size is determined by another widget, and we are just filling
260  * available space.
261  */
262 static void
263 gtk_path_bar_size_request (GtkWidget      *widget,
264                            GtkRequisition *requisition)
265 {
266   ButtonData *button_data;
267   GtkPathBar *path_bar;
268   GtkRequisition child_requisition;
269   GList *list;
270
271   path_bar = GTK_PATH_BAR (widget);
272
273   requisition->width = 0;
274   requisition->height = 0;
275
276   for (list = path_bar->button_list; list; list = list->next)
277     {
278       button_data = BUTTON_DATA (list->data);
279       gtk_widget_size_request (button_data->button, &child_requisition);
280       requisition->width = MAX (child_requisition.width, requisition->width);
281       requisition->height = MAX (child_requisition.height, requisition->height);
282     }
283
284   /* Add space for slider, if we have more than one path */
285   /* Theoretically, the slider could be bigger than the other button.  But we're
286    * not going to worry about that now.
287    */
288   path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
289   if (path_bar->button_list && path_bar->button_list->next != NULL)
290     requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
291
292   gtk_widget_size_request (path_bar->up_slider_button, &child_requisition);
293   gtk_widget_size_request (path_bar->down_slider_button, &child_requisition);
294
295   requisition->width += GTK_CONTAINER (widget)->border_width * 2;
296   requisition->height += GTK_CONTAINER (widget)->border_width * 2;
297
298   widget->requisition = *requisition;
299 }
300
301 static void
302 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
303 {
304   if (path_bar->button_list)
305     {
306       GtkWidget *button;
307
308       button = BUTTON_DATA (path_bar->button_list->data)->button;
309       if (gtk_widget_get_child_visible (button))
310         gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
311       else
312         gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
313
314       button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
315       if (gtk_widget_get_child_visible (button))
316         gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
317       else
318         gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
319     }
320 }
321
322 static void
323 gtk_path_bar_unmap (GtkWidget *widget)
324 {
325   gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
326
327   GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
328 }
329
330 /* This is a tad complicated
331  */
332 static void
333 gtk_path_bar_size_allocate (GtkWidget     *widget,
334                             GtkAllocation *allocation)
335 {
336   GtkWidget *child;
337   GtkPathBar *path_bar = GTK_PATH_BAR (widget);
338   GtkTextDirection direction;
339   GtkAllocation child_allocation;
340   GList *list, *first_button;
341   gint width;
342   gint allocation_width;
343   gint border_width;
344   gboolean need_sliders = FALSE;
345   gint up_slider_offset = 0;
346   gint down_slider_offset = 0;
347
348   widget->allocation = *allocation;
349
350   /* No path is set; we don't have to allocate anything. */
351   if (path_bar->button_list == NULL)
352     return;
353
354   direction = gtk_widget_get_direction (widget);
355   border_width = (gint) GTK_CONTAINER (path_bar)->border_width;
356   allocation_width = allocation->width - 2 * border_width;
357
358   /* First, we check to see if we need the scrollbars. */
359   if (path_bar->fake_root)
360     width = path_bar->spacing + path_bar->slider_width;
361   else
362       width = 0;
363
364   for (list = path_bar->button_list; list; list = list->next)
365     {
366       child = BUTTON_DATA (list->data)->button;
367
368       width += child->requisition.width + path_bar->spacing;
369       if (list == path_bar->fake_root)
370         break;
371     }
372
373   if (width <= allocation_width)
374     {
375       if (path_bar->fake_root)
376         first_button = path_bar->fake_root;
377       else
378         first_button = g_list_last (path_bar->button_list);
379     }
380   else
381     {
382       gboolean reached_end = FALSE;
383       gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
384
385       if (path_bar->first_scrolled_button)
386         first_button = path_bar->first_scrolled_button;
387       else
388         first_button = path_bar->button_list;
389       need_sliders = TRUE;
390       
391       /* To see how much space we have, and how many buttons we can display.
392        * We start at the first button, count forward until hit the new
393        * button, then count backwards.
394        */
395       /* Count down the path chain towards the end. */
396       width = BUTTON_DATA (first_button->data)->button->requisition.width;
397       list = first_button->prev;
398       while (list && !reached_end)
399         {
400           child = BUTTON_DATA (list->data)->button;
401
402           if (width + child->requisition.width +
403               path_bar->spacing + slider_space > allocation_width)
404             reached_end = TRUE;
405           else if (list == path_bar->fake_root)
406             break;
407           else
408             width += child->requisition.width + path_bar->spacing;
409
410           list = list->prev;
411         }
412
413       /* Finally, we walk up, seeing how many of the previous buttons we can
414        * add */
415       while (first_button->next && !reached_end)
416         {
417           child = BUTTON_DATA (first_button->next->data)->button;
418
419           if (width + child->requisition.width + path_bar->spacing + slider_space > allocation_width)
420             {
421               reached_end = TRUE;
422             }
423           else
424             {
425               width += child->requisition.width + path_bar->spacing;
426               if (first_button == path_bar->fake_root)
427                 break;
428               first_button = first_button->next;
429             }
430         }
431     }
432
433   /* Now, we allocate space to the buttons */
434   child_allocation.y = allocation->y + border_width;
435   child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
436
437   if (direction == GTK_TEXT_DIR_RTL)
438     {
439       child_allocation.x = allocation->x + allocation->width - border_width;
440       if (need_sliders || path_bar->fake_root)
441         {
442           child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
443           up_slider_offset = allocation->width - border_width - path_bar->slider_width;
444         }
445     }
446   else
447     {
448       child_allocation.x = allocation->x + border_width;
449       if (need_sliders || path_bar->fake_root)
450         {
451           up_slider_offset = border_width;
452           child_allocation.x += (path_bar->spacing + path_bar->slider_width);
453         }
454     }
455
456   for (list = first_button; list; list = list->prev)
457     {
458       child = BUTTON_DATA (list->data)->button;
459
460       child_allocation.width = child->requisition.width;
461       if (direction == GTK_TEXT_DIR_RTL)
462         child_allocation.x -= child_allocation.width;
463
464       /* Check to see if we've don't have any more space to allocate buttons */
465       if (need_sliders && direction == GTK_TEXT_DIR_RTL)
466         {
467           if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width)
468             break;
469         }
470       else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
471         {
472           if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
473               widget->allocation.x + border_width + allocation_width)
474             break;
475         }
476
477       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, TRUE);
478       gtk_widget_size_allocate (child, &child_allocation);
479
480       if (direction == GTK_TEXT_DIR_RTL)
481         {
482           child_allocation.x -= path_bar->spacing;
483           down_slider_offset = child_allocation.x - widget->allocation.x - path_bar->slider_width;
484           down_slider_offset = border_width;
485         }
486       else
487         {
488           down_slider_offset = child_allocation.x - widget->allocation.x;
489           down_slider_offset = allocation->width - border_width - path_bar->slider_width;
490           child_allocation.x += child_allocation.width + path_bar->spacing;
491         }
492     }
493   /* Now we go hide all the widgets that don't fit */
494   while (list)
495     {
496       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
497       list = list->prev;
498     }
499   for (list = first_button->next; list; list = list->next)
500     {
501       gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
502     }
503
504   if (need_sliders || path_bar->fake_root)
505     {
506       child_allocation.width = path_bar->slider_width;
507       child_allocation.x = up_slider_offset + allocation->x;
508       gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
509
510       gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
511       gtk_widget_show_all (path_bar->up_slider_button);
512     }
513   else
514     gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
515       
516   if (need_sliders)
517     {
518       child_allocation.width = path_bar->slider_width;
519       child_allocation.x = down_slider_offset + allocation->x;
520       gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
521
522       gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
523       gtk_widget_show_all (path_bar->down_slider_button);
524       gtk_path_bar_update_slider_buttons (path_bar);
525     }
526   else
527     gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
528 }
529
530 static void
531 gtk_path_bar_style_set (GtkWidget *widget,
532                         GtkStyle  *previous_style)
533 {
534   if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set)
535     GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
536
537   gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
538 }
539
540 static void
541 gtk_path_bar_screen_changed (GtkWidget *widget,
542                              GdkScreen *previous_screen)
543 {
544   if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
545     GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
546
547   /* We might nave a new settings, so we remove the old one */
548   if (previous_screen)
549     remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
550
551   gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
552 }
553
554 static void
555 gtk_path_bar_add (GtkContainer *container,
556                   GtkWidget    *widget)
557 {
558   gtk_widget_set_parent (widget, GTK_WIDGET (container));
559 }
560
561 static void
562 gtk_path_bar_remove_1 (GtkContainer *container,
563                        GtkWidget    *widget)
564 {
565   gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
566   gtk_widget_unparent (widget);
567   if (was_visible)
568     gtk_widget_queue_resize (GTK_WIDGET (container));
569 }
570
571 static void
572 gtk_path_bar_remove (GtkContainer *container,
573                      GtkWidget    *widget)
574 {
575   GtkPathBar *path_bar;
576   GList *children;
577
578   path_bar = GTK_PATH_BAR (container);
579
580   if (widget == path_bar->up_slider_button)
581     {
582       gtk_path_bar_remove_1 (container, widget);
583       path_bar->up_slider_button = NULL;
584       return;
585     }
586
587   if (widget == path_bar->down_slider_button)
588     {
589       gtk_path_bar_remove_1 (container, widget);
590       path_bar->down_slider_button = NULL;
591       return;
592     }
593
594   children = path_bar->button_list;
595   while (children)
596     {
597       if (widget == BUTTON_DATA (children->data)->button)
598         {
599           gtk_path_bar_remove_1 (container, widget);
600           path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
601           g_list_free (children);
602           return;
603         }
604       
605       children = children->next;
606     }
607 }
608
609 static void
610 gtk_path_bar_forall (GtkContainer *container,
611                      gboolean      include_internals,
612                      GtkCallback   callback,
613                      gpointer      callback_data)
614 {
615   GtkPathBar *path_bar;
616   GList *children;
617
618   g_return_if_fail (callback != NULL);
619   path_bar = GTK_PATH_BAR (container);
620
621   children = path_bar->button_list;
622   while (children)
623     {
624       GtkWidget *child;
625       child = BUTTON_DATA (children->data)->button;
626       children = children->next;
627
628       (* callback) (child, callback_data);
629     }
630
631   if (path_bar->up_slider_button)
632     (* callback) (path_bar->up_slider_button, callback_data);
633
634   if (path_bar->down_slider_button)
635     (* callback) (path_bar->down_slider_button, callback_data);
636 }
637
638 static void
639 gtk_path_bar_scroll_down (GtkWidget *button, GtkPathBar *path_bar)
640 {
641   GList *list;
642   GList *down_button = NULL;
643   GList *up_button = NULL;
644   gint space_available;
645   gint space_needed;
646   gint border_width;
647   GtkTextDirection direction;
648
649   if (path_bar->ignore_click)
650     {
651       path_bar->ignore_click = FALSE;
652       return;   
653     }
654
655   gtk_widget_queue_resize (GTK_WIDGET (path_bar));
656
657   border_width = GTK_CONTAINER (path_bar)->border_width;
658   direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
659   
660   /* We find the button at the 'down' end that we have to make
661    * visible */
662   for (list = path_bar->button_list; list; list = list->next)
663     {
664       if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
665         {
666           down_button = list;
667           break;
668         }
669     }
670   
671   /* Find the last visible button on the 'up' end
672    */
673   for (list = g_list_last (path_bar->button_list); list; list = list->prev)
674     {
675       if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
676         {
677           up_button = list;
678           break;
679         }
680     }
681
682   space_needed = BUTTON_DATA (down_button->data)->button->allocation.width + path_bar->spacing;
683   if (direction == GTK_TEXT_DIR_RTL)
684     space_available = path_bar->down_slider_button->allocation.x - GTK_WIDGET (path_bar)->allocation.x;
685   else
686     space_available = (GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width - border_width) -
687       (path_bar->down_slider_button->allocation.x + path_bar->down_slider_button->allocation.width);
688
689   /* We have space_available extra space that's not being used.  We
690    * need space_needed space to make the button fit.  So we walk down
691    * from the end, removing buttons until we get all the space we
692    * need. */
693   while (space_available < space_needed)
694     {
695       space_available += BUTTON_DATA (up_button->data)->button->allocation.width + path_bar->spacing;
696       up_button = up_button->prev;
697       path_bar->first_scrolled_button = up_button;
698     }
699 }
700
701 static void
702 gtk_path_bar_scroll_up (GtkWidget *button, GtkPathBar *path_bar)
703 {
704   GList *list;
705
706   if (path_bar->ignore_click)
707     {
708       path_bar->ignore_click = FALSE;
709       return;   
710     }
711
712   gtk_widget_queue_resize (GTK_WIDGET (path_bar));
713
714   for (list = g_list_last (path_bar->button_list); list; list = list->prev)
715     {
716       if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
717         {
718           if (list->prev == path_bar->fake_root)
719             path_bar->fake_root = NULL;
720           path_bar->first_scrolled_button = list;
721           return;
722         }
723     }
724 }
725
726 static gboolean
727 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
728 {
729   gboolean retval = FALSE;
730
731   GDK_THREADS_ENTER ();
732
733   if (path_bar->timer)
734     {
735       if (path_bar->scrolling_up)
736         gtk_path_bar_scroll_up (path_bar->up_slider_button, path_bar);
737       else 
738         gtk_path_bar_scroll_down (path_bar->down_slider_button, path_bar);
739
740       if (path_bar->need_timer) 
741         {
742           path_bar->need_timer = FALSE;
743
744           path_bar->timer = g_timeout_add (SCROLL_TIMEOUT,
745                                            (GSourceFunc)gtk_path_bar_scroll_timeout,
746                                            path_bar);
747           
748         }
749       else
750         retval = TRUE;
751       
752     }
753
754   GDK_THREADS_LEAVE ();
755
756   return retval;
757 }
758
759 static void 
760 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
761 {
762   if (path_bar->timer)
763     {
764       g_source_remove (path_bar->timer);
765       path_bar->timer = 0;
766       path_bar->need_timer = FALSE;
767     }
768 }
769
770 static gboolean
771 gtk_path_bar_slider_button_press (GtkWidget      *widget, 
772                                   GdkEventButton *event,
773                                   GtkPathBar     *path_bar)
774 {
775   if (event->type != GDK_BUTTON_PRESS || event->button != 1)
776     return FALSE;
777
778   path_bar->ignore_click = FALSE;
779
780   if (widget == path_bar->up_slider_button)
781     {
782       path_bar->scrolling_up = TRUE;
783       gtk_path_bar_scroll_up (path_bar->up_slider_button, path_bar);
784     }
785   else if (widget == path_bar->down_slider_button)
786     {
787       path_bar->scrolling_up = FALSE;
788       gtk_path_bar_scroll_down (path_bar->down_slider_button, path_bar);
789     }
790
791   if (!path_bar->timer)
792     {
793       path_bar->need_timer = TRUE;
794       path_bar->timer = g_timeout_add (INITIAL_SCROLL_TIMEOUT,
795                                        (GSourceFunc)gtk_path_bar_scroll_timeout,
796                                        path_bar);
797     }
798
799   return FALSE;
800 }
801
802 static gboolean
803 gtk_path_bar_slider_button_release (GtkWidget      *widget, 
804                                     GdkEventButton *event,
805                                     GtkPathBar     *path_bar)
806 {
807   if (event->type != GDK_BUTTON_RELEASE)
808     return FALSE;
809
810   path_bar->ignore_click = TRUE;
811   gtk_path_bar_stop_scrolling (path_bar);
812
813   return FALSE;
814 }
815
816 static void
817 gtk_path_bar_grab_notify (GtkWidget *widget,
818                           gboolean   was_grabbed)
819 {
820   if (!was_grabbed)
821     gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
822 }
823
824 static void
825 gtk_path_bar_state_changed (GtkWidget    *widget,
826                             GtkStateType  previous_state)
827 {
828   if (!GTK_WIDGET_IS_SENSITIVE (widget)) 
829     gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
830 }
831
832
833 /* Changes the icons wherever it is needed */
834 static void
835 reload_icons (GtkPathBar *path_bar)
836 {
837   GList *list;
838
839   if (path_bar->root_icon)
840     {
841       g_object_unref (path_bar->root_icon);
842       path_bar->root_icon = NULL;
843     }
844   if (path_bar->home_icon)
845     {
846       g_object_unref (path_bar->home_icon);
847       path_bar->home_icon = NULL;
848     }
849   if (path_bar->desktop_icon)
850     {
851       g_object_unref (path_bar->desktop_icon);
852       path_bar->desktop_icon = NULL;
853     }
854
855   for (list = path_bar->button_list; list; list = list->next)
856     {
857       ButtonData *button_data;
858       gboolean current_dir;
859
860       button_data = BUTTON_DATA (list->data);
861       if (button_data->type != NORMAL_BUTTON)
862         {
863           current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
864           gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
865         }
866     }
867   
868 }
869
870 static void
871 change_icon_theme (GtkPathBar *path_bar)
872 {
873   GtkSettings *settings;
874   gint width, height;
875
876   settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
877
878   if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
879     path_bar->icon_size = MAX (width, height);
880   else
881     path_bar->icon_size = FALLBACK_ICON_SIZE;
882
883   reload_icons (path_bar);
884 }
885 /* Callback used when a GtkSettings value changes */
886 static void
887 settings_notify_cb (GObject    *object,
888                     GParamSpec *pspec,
889                     GtkPathBar *path_bar)
890 {
891   const char *name;
892
893   name = g_param_spec_get_name (pspec);
894
895   if (! strcmp (name, "gtk-icon-theme-name") ||
896       ! strcmp (name, "gtk-icon-sizes"))
897     change_icon_theme (path_bar);
898 }
899
900 static void
901 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
902 {
903   GtkSettings *settings;
904
905   if (path_bar->settings_signal_id)
906     return;
907
908   settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
909   path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
910
911   change_icon_theme (path_bar);
912 }
913
914 /* Public functions and their helpers */
915 static void
916 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
917 {
918   while (path_bar->button_list != NULL)
919     {
920       gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
921     }
922   path_bar->first_scrolled_button = NULL;
923   path_bar->fake_root = NULL;
924 }
925
926 static void
927 button_clicked_cb (GtkWidget *button,
928                    gpointer   data)
929 {
930   ButtonData *button_data;
931   GtkPathBar *path_bar;
932   GList *button_list;
933   gboolean child_is_hidden;
934
935   button_data = BUTTON_DATA (data);
936   if (button_data->ignore_changes)
937     return;
938
939   path_bar = GTK_PATH_BAR (button->parent);
940
941   button_list = g_list_find (path_bar->button_list, button_data);
942   g_assert (button_list != NULL);
943
944   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
945
946   GtkFilePath *child_path;
947   if (button_list->prev)
948     {
949       ButtonData *child_data;
950
951       child_data = BUTTON_DATA (button_list->prev->data);
952       child_path = child_data->path;
953       child_is_hidden = child_data->file_is_hidden;
954     }
955   else
956     {
957       child_path = NULL;
958       child_is_hidden = FALSE;
959     }
960
961   g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
962                  button_data->path, child_path, child_is_hidden);
963 }
964
965 static GdkPixbuf *
966 get_button_image (GtkPathBar *path_bar,
967                   ButtonType  button_type)
968 {
969   GtkFileSystemVolume *volume;
970
971   switch (button_type)
972     {
973     case ROOT_BUTTON:
974
975       if (path_bar->root_icon != NULL)
976         return path_bar->root_icon;
977       
978       volume = gtk_file_system_get_volume_for_path (path_bar->file_system, path_bar->root_path);
979       if (volume == NULL)
980         return NULL;
981
982       path_bar->root_icon = gtk_file_system_volume_render_icon (path_bar->file_system,
983                                                                 volume,
984                                                                 GTK_WIDGET (path_bar),
985                                                                 path_bar->icon_size,
986                                                                 NULL);
987       gtk_file_system_volume_free (path_bar->file_system, volume);
988
989       return path_bar->root_icon;
990     case HOME_BUTTON:
991       if (path_bar->home_icon != NULL)
992         return path_bar->home_icon;
993
994       path_bar->home_icon = gtk_file_system_render_icon (path_bar->file_system,
995                                                          path_bar->home_path,
996                                                          GTK_WIDGET (path_bar),
997                                                          path_bar->icon_size,
998                                                          NULL);
999       return path_bar->home_icon;
1000     case DESKTOP_BUTTON:
1001       if (path_bar->desktop_icon != NULL)
1002         return path_bar->desktop_icon;
1003
1004       path_bar->desktop_icon = gtk_file_system_render_icon (path_bar->file_system,
1005                                                             path_bar->desktop_path,
1006                                                             GTK_WIDGET (path_bar),
1007                                                             path_bar->icon_size,
1008                                                             NULL);
1009       return path_bar->desktop_icon;
1010     default:
1011       return NULL;
1012     }
1013   
1014   return NULL;
1015 }
1016
1017 static void
1018 button_data_free (ButtonData *button_data)
1019 {
1020   gtk_file_path_free (button_data->path);
1021   g_free (button_data->dir_name);
1022   g_free (button_data);
1023 }
1024
1025 static const char *
1026 get_dir_name (ButtonData *button_data)
1027 {
1028   return button_data->dir_name;
1029 }
1030
1031 /* We always want to request the same size for the label, whether
1032  * or not the contents are bold
1033  */
1034 static void
1035 label_size_request_cb (GtkWidget      *widget,
1036                        GtkRequisition *requisition,
1037                        ButtonData     *button_data)
1038 {
1039   const gchar *dir_name = get_dir_name (button_data);
1040   PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1041   gint bold_width, bold_height;
1042   gchar *markup;
1043
1044   pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1045   
1046   markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1047   pango_layout_set_markup (layout, markup, -1);
1048   g_free (markup);
1049
1050   pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1051   requisition->width = MAX (requisition->width, bold_width);
1052   requisition->height = MAX (requisition->height, bold_height);
1053   
1054   g_object_unref (layout);
1055 }
1056
1057 static void
1058 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1059                                        ButtonData *button_data,
1060                                        gboolean    current_dir)
1061 {
1062   const gchar *dir_name = get_dir_name (button_data);
1063
1064   if (button_data->label != NULL)
1065     {
1066       if (current_dir)
1067         {
1068           char *markup;
1069
1070           markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1071           gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1072           g_free (markup);
1073         }
1074       else
1075         {
1076           gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1077         }
1078     }
1079
1080   if (button_data->image != NULL)
1081     {
1082       GdkPixbuf *pixbuf;
1083       pixbuf = get_button_image (path_bar, button_data->type);
1084       gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), pixbuf);
1085     }
1086
1087   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1088     {
1089       button_data->ignore_changes = TRUE;
1090       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1091       button_data->ignore_changes = FALSE;
1092     }
1093 }
1094
1095 static ButtonType
1096 find_button_type (GtkPathBar  *path_bar,
1097                   GtkFilePath *path)
1098 {
1099   if (path_bar->root_path != NULL &&
1100       ! gtk_file_path_compare (path, path_bar->root_path))
1101     return ROOT_BUTTON;
1102   if (path_bar->home_path != NULL &&
1103       ! gtk_file_path_compare (path, path_bar->home_path))
1104     return HOME_BUTTON;
1105   if (path_bar->desktop_path != NULL &&
1106       ! gtk_file_path_compare (path, path_bar->desktop_path))
1107     return DESKTOP_BUTTON;
1108
1109  return NORMAL_BUTTON;
1110 }
1111
1112 static void
1113 button_drag_data_get_cb (GtkWidget          *widget,
1114                          GdkDragContext     *context,
1115                          GtkSelectionData   *selection_data,
1116                          guint               info,
1117                          guint               time_,
1118                          gpointer            data)
1119 {
1120   ButtonData *button_data;
1121   GtkPathBar *path_bar;
1122   char *uri;
1123   char *uri_list;
1124
1125   button_data = data;
1126   path_bar = GTK_PATH_BAR (widget->parent); /* the button's parent *is* the path bar */
1127
1128   uri = gtk_file_system_path_to_uri (path_bar->file_system, button_data->path);
1129   uri_list = g_strconcat (uri, "\r\n", NULL);
1130   g_free (uri);
1131
1132   gtk_selection_data_set (selection_data,
1133                           selection_data->target,
1134                           8,
1135                           uri_list,
1136                           strlen (uri_list));
1137   g_free (uri_list);
1138 }
1139
1140 static ButtonData *
1141 make_directory_button (GtkPathBar  *path_bar,
1142                        const char  *dir_name,
1143                        GtkFilePath *path,
1144                        gboolean     current_dir,
1145                        gboolean     file_is_hidden)
1146 {
1147   const GtkTargetEntry targets[] = {
1148     { "text/uri-list", 0, 0 }
1149   };
1150
1151   GtkWidget *child = NULL;
1152   GtkWidget *label_alignment = NULL;
1153   ButtonData *button_data;
1154
1155   file_is_hidden = !! file_is_hidden;
1156   /* Is it a special button? */
1157   button_data = g_new0 (ButtonData, 1);
1158
1159   button_data->type = find_button_type (path_bar, path);
1160   button_data->button = gtk_toggle_button_new ();
1161   gtk_button_set_focus_on_click (button_data->button, FALSE);
1162
1163   switch (button_data->type)
1164     {
1165     case ROOT_BUTTON:
1166       button_data->image = gtk_image_new ();
1167       child = button_data->image;
1168       button_data->label = NULL;
1169       break;
1170     case HOME_BUTTON:
1171     case DESKTOP_BUTTON:
1172       button_data->image = gtk_image_new ();
1173       button_data->label = gtk_label_new (NULL);
1174       label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1175       gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1176       child = gtk_hbox_new (FALSE, 2);
1177       gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1178       gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1179       break;
1180     case NORMAL_BUTTON:
1181     default:
1182       button_data->label = gtk_label_new (NULL);
1183       label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1184       gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1185       child = label_alignment;
1186       button_data->image = NULL;
1187     }
1188
1189   /* label_alignment is created because we can't override size-request
1190    * on label itself and still have the contents of the label centered
1191    * properly in the label's requisition
1192    */
1193   if (label_alignment)
1194     g_signal_connect (label_alignment, "size-request",
1195                       G_CALLBACK (label_size_request_cb), button_data);
1196
1197   button_data->dir_name = g_strdup (dir_name);
1198   button_data->path = gtk_file_path_new_dup (gtk_file_path_get_string (path));
1199   button_data->file_is_hidden = file_is_hidden;
1200                           
1201   gtk_container_add (GTK_CONTAINER (button_data->button), child);
1202   gtk_widget_show_all (button_data->button);
1203
1204   gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1205
1206   g_signal_connect (button_data->button, "clicked",
1207                     G_CALLBACK (button_clicked_cb),
1208                     button_data);
1209   g_object_weak_ref (G_OBJECT (button_data->button),
1210                      (GWeakNotify) button_data_free, button_data);
1211
1212   gtk_drag_source_set (button_data->button,
1213                        GDK_BUTTON1_MASK,
1214                        targets,
1215                        G_N_ELEMENTS (targets),
1216                        GDK_ACTION_COPY);
1217   g_signal_connect (button_data->button, "drag-data-get",
1218                     G_CALLBACK (button_drag_data_get_cb), button_data);
1219
1220   return button_data;
1221 }
1222
1223 static gboolean
1224 gtk_path_bar_check_parent_path (GtkPathBar         *path_bar,
1225                                 const GtkFilePath  *file_path,
1226                                 GtkFileSystem      *file_system)
1227 {
1228   GList *list;
1229   GList *current_path = NULL;
1230   gboolean need_new_fake_root = FALSE;
1231
1232   for (list = path_bar->button_list; list; list = list->next)
1233     {
1234       ButtonData *button_data;
1235
1236       button_data = list->data;
1237       if (! gtk_file_path_compare (file_path, button_data->path))
1238         {
1239           current_path = list;
1240           break;
1241         }
1242       if (list == path_bar->fake_root)
1243         need_new_fake_root = TRUE;
1244     }
1245
1246   if (current_path)
1247     {
1248       if (need_new_fake_root)
1249         {
1250           path_bar->fake_root = NULL;
1251           for (list = current_path; list; list = list->next)
1252             {
1253               ButtonData *button_data;
1254
1255               button_data = list->data;
1256               if (BUTTON_IS_FAKE_ROOT (button_data))
1257                 {
1258                   path_bar->fake_root = list;
1259                   break;
1260                 }
1261             }
1262         }
1263
1264       for (list = path_bar->button_list; list; list = list->next)
1265         {
1266           gtk_path_bar_update_button_appearance (path_bar,
1267                                                  BUTTON_DATA (list->data),
1268                                                  (list == current_path) ? TRUE : FALSE);
1269         }
1270
1271       if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1272         {
1273           path_bar->first_scrolled_button = current_path;
1274           gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1275         }
1276
1277       return TRUE;
1278     }
1279   return FALSE;
1280 }
1281
1282 gboolean
1283 _gtk_path_bar_set_path (GtkPathBar         *path_bar,
1284                         const GtkFilePath  *file_path,
1285                         const gboolean      keep_trail,     
1286                         GError            **error)
1287 {
1288   GtkFilePath *path;
1289   gboolean first_directory = TRUE;
1290   gboolean result;
1291   GList *new_buttons = NULL;
1292   GList *fake_root = NULL;
1293
1294   g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1295   g_return_val_if_fail (file_path != NULL, FALSE);
1296
1297   result = TRUE;
1298
1299   /* Check whether the new path is already present in the pathbar as buttons.
1300    * This could be a parent directory or a previous selected subdirectory.
1301    */
1302   if (keep_trail &&
1303       gtk_path_bar_check_parent_path (path_bar, file_path, path_bar->file_system))
1304     return TRUE;
1305
1306   path = gtk_file_path_copy (file_path);
1307
1308   gtk_widget_push_composite_child ();
1309
1310   while (path != NULL)
1311     {
1312       GtkFilePath *parent_path = NULL;
1313       ButtonData *button_data;
1314       const gchar *display_name;
1315       gboolean is_hidden;
1316       GtkFileFolder *file_folder;
1317       GtkFileInfo *file_info;
1318       gboolean valid;
1319
1320       valid = gtk_file_system_get_parent (path_bar->file_system,
1321                                           path,
1322                                           &parent_path,
1323                                           error);
1324       if (!valid)
1325         {
1326           result = FALSE;
1327           gtk_file_path_free (path);
1328           break;
1329         }
1330
1331       file_folder = gtk_file_system_get_folder (path_bar->file_system,
1332                                                 parent_path ? parent_path : path,
1333                                                 GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_HIDDEN,
1334                                                 NULL);
1335       if (!file_folder)
1336         {
1337           result = FALSE;
1338           gtk_file_path_free (parent_path);
1339           gtk_file_path_free (path);
1340           break;
1341         }
1342
1343       file_info = gtk_file_folder_get_info (file_folder, parent_path ? path : NULL, error);
1344       g_object_unref (file_folder);
1345
1346       if (!file_info)
1347         {
1348           result = FALSE;
1349           gtk_file_path_free (parent_path);
1350           gtk_file_path_free (path);
1351           break;
1352         }
1353
1354       display_name = gtk_file_info_get_display_name (file_info);
1355       is_hidden = gtk_file_info_get_is_hidden (file_info);
1356
1357       button_data = make_directory_button (path_bar, display_name, path, first_directory, is_hidden);
1358       gtk_file_info_free (file_info);
1359       gtk_file_path_free (path);
1360
1361       new_buttons = g_list_prepend (new_buttons, button_data);
1362
1363       if (BUTTON_IS_FAKE_ROOT (button_data))
1364         fake_root = new_buttons;
1365
1366       path = parent_path;
1367       first_directory = FALSE;
1368     }
1369
1370   if (result)
1371     {
1372       GList *l;
1373
1374       gtk_path_bar_clear_buttons (path_bar);
1375       path_bar->button_list = g_list_reverse (new_buttons);
1376       path_bar->fake_root = fake_root;
1377
1378       for (l = path_bar->button_list; l; l = l->next)
1379         {
1380           GtkWidget *button = BUTTON_DATA (l->data)->button;
1381           gtk_container_add (GTK_CONTAINER (path_bar), button);
1382         }
1383     }
1384   else
1385     {
1386       GList *l;
1387
1388       for (l = new_buttons; l; l = l->next)
1389         {
1390           ButtonData *button_data;
1391
1392           button_data = BUTTON_DATA (l->data);
1393           gtk_widget_destroy (button_data->button);
1394         }
1395
1396       g_list_free (new_buttons);
1397     }
1398
1399   gtk_widget_pop_composite_child ();
1400
1401   return result;
1402 }
1403
1404 /* FIXME: This should be a construct-only property */
1405 void
1406 _gtk_path_bar_set_file_system (GtkPathBar    *path_bar,
1407                                GtkFileSystem *file_system)
1408 {
1409   const char *home;
1410   char *desktop;
1411
1412   g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1413
1414   g_assert (path_bar->file_system == NULL);
1415
1416   path_bar->file_system = g_object_ref (file_system);
1417
1418   home = g_get_home_dir ();
1419   if (home != NULL)
1420     {
1421       path_bar->home_path = gtk_file_system_filename_to_path (path_bar->file_system, home);
1422       /* FIXME: Need file system backend specific way of getting the
1423        * Desktop path.
1424        */
1425       desktop = g_build_filename (home, "Desktop", NULL);
1426       path_bar->desktop_path = gtk_file_system_filename_to_path (path_bar->file_system, desktop);
1427       g_free (desktop);
1428     }
1429   else
1430     {
1431       path_bar->home_path = NULL;
1432       path_bar->desktop_path = NULL;
1433     }
1434   path_bar->root_path = gtk_file_system_filename_to_path (path_bar->file_system, "/");
1435 }
1436
1437 /**
1438  * _gtk_path_bar_up:
1439  * @path_bar: a #GtkPathBar
1440  * 
1441  * If the selected button in the pathbar is not the furthest button "up" (in the
1442  * root direction), act as if the user clicked on the next button up.
1443  **/
1444 void
1445 _gtk_path_bar_up (GtkPathBar *path_bar)
1446 {
1447   GList *l;
1448
1449   for (l = path_bar->button_list; l; l = l->next)
1450     {
1451       GtkWidget *button = BUTTON_DATA (l->data)->button;
1452       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1453         {
1454           if (l->next)
1455             {
1456               GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1457               button_clicked_cb (next_button, l->next->data);
1458             }
1459           break;
1460         }
1461     }
1462 }
1463
1464 /**
1465  * _gtk_path_bar_down:
1466  * @path_bar: a #GtkPathBar
1467  * 
1468  * If the selected button in the pathbar is not the furthest button "down" (in the
1469  * leaf direction), act as if the user clicked on the next button down.
1470  **/
1471 void
1472 _gtk_path_bar_down (GtkPathBar *path_bar)
1473 {
1474   GList *l;
1475
1476   for (l = path_bar->button_list; l; l = l->next)
1477     {
1478       GtkWidget *button = BUTTON_DATA (l->data)->button;
1479       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1480         {
1481           if (l->prev)
1482             {
1483               GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1484               button_clicked_cb (prev_button, l->prev->data);
1485             }
1486           break;
1487         }
1488     }
1489 }