1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
3 * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkpathbar.h"
27 #include "gtktogglebutton.h"
28 #include "gtkalignment.h"
33 #include "gtkicontheme.h"
34 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
53 #define BUTTON_DATA(x) ((ButtonData *)(x))
55 #define SCROLL_DELAY_FACTOR 5
57 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
59 /* Icon size for if we can't get it from the theme */
60 #define FALLBACK_ICON_SIZE 16
62 typedef struct _ButtonData ButtonData;
72 GCancellable *cancellable;
73 guint ignore_changes : 1;
74 guint file_is_hidden : 1;
76 /* This macro is used to check if a button can be used as a fake root.
77 * All buttons in front of a fake root are automatically hidden when in a
78 * directory below a fake root and replaced with the "<" arrow button.
80 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
82 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
84 static void gtk_path_bar_finalize (GObject *object);
85 static void gtk_path_bar_dispose (GObject *object);
86 static void gtk_path_bar_realize (GtkWidget *widget);
87 static void gtk_path_bar_unrealize (GtkWidget *widget);
88 static void gtk_path_bar_size_request (GtkWidget *widget,
89 GtkRequisition *requisition);
90 static void gtk_path_bar_map (GtkWidget *widget);
91 static void gtk_path_bar_unmap (GtkWidget *widget);
92 static void gtk_path_bar_size_allocate (GtkWidget *widget,
93 GtkAllocation *allocation);
94 static void gtk_path_bar_add (GtkContainer *container,
96 static void gtk_path_bar_remove (GtkContainer *container,
98 static void gtk_path_bar_forall (GtkContainer *container,
99 gboolean include_internals,
100 GtkCallback callback,
101 gpointer callback_data);
102 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
103 GdkEventScroll *event);
104 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
105 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
106 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
107 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
108 GdkEventButton *event,
109 GtkPathBar *path_bar);
110 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
111 GdkEventButton *event,
112 GtkPathBar *path_bar);
113 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
114 GdkEventButton *event,
115 GtkPathBar *path_bar);
116 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
117 GdkEventButton *event,
118 GtkPathBar *path_bar);
119 static void gtk_path_bar_grab_notify (GtkWidget *widget,
120 gboolean was_grabbed);
121 static void gtk_path_bar_state_changed (GtkWidget *widget,
122 GtkStateType previous_state);
123 static void gtk_path_bar_style_set (GtkWidget *widget,
124 GtkStyle *previous_style);
125 static void gtk_path_bar_screen_changed (GtkWidget *widget,
126 GdkScreen *previous_screen);
127 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
128 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
129 ButtonData *button_data,
130 gboolean current_dir);
133 on_slider_unmap (GtkWidget *widget,
134 GtkPathBar *path_bar)
136 if (path_bar->timer &&
137 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
138 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
139 gtk_path_bar_stop_scrolling (path_bar);
143 get_slider_button (GtkPathBar *path_bar,
144 GtkArrowType arrow_type)
149 gtk_widget_push_composite_child ();
151 button = gtk_button_new ();
152 atk_obj = gtk_widget_get_accessible (button);
153 if (arrow_type == GTK_ARROW_LEFT)
154 atk_object_set_name (atk_obj, _("Up Path"));
156 atk_object_set_name (atk_obj, _("Down Path"));
158 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
159 gtk_container_add (GTK_CONTAINER (button),
160 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
161 gtk_container_add (GTK_CONTAINER (path_bar), button);
162 gtk_widget_show_all (button);
164 g_signal_connect (G_OBJECT (button), "unmap",
165 G_CALLBACK (on_slider_unmap), path_bar);
167 gtk_widget_pop_composite_child ();
173 gtk_path_bar_init (GtkPathBar *path_bar)
175 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
176 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
178 path_bar->get_info_cancellable = NULL;
180 path_bar->spacing = 0;
181 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
182 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
183 path_bar->icon_size = FALLBACK_ICON_SIZE;
185 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
186 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
187 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
188 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
190 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
191 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
192 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
193 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
195 g_signal_connect (path_bar->up_slider_button, "button-press-event",
196 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
197 g_signal_connect (path_bar->up_slider_button, "button-release-event",
198 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
199 g_signal_connect (path_bar->down_slider_button, "button-press-event",
200 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
201 g_signal_connect (path_bar->down_slider_button, "button-release-event",
202 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
206 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
208 GObjectClass *gobject_class;
209 GtkObjectClass *object_class;
210 GtkWidgetClass *widget_class;
211 GtkContainerClass *container_class;
213 gobject_class = (GObjectClass *) path_bar_class;
214 object_class = (GtkObjectClass *) path_bar_class;
215 widget_class = (GtkWidgetClass *) path_bar_class;
216 container_class = (GtkContainerClass *) path_bar_class;
218 gobject_class->finalize = gtk_path_bar_finalize;
219 gobject_class->dispose = gtk_path_bar_dispose;
221 widget_class->size_request = gtk_path_bar_size_request;
222 widget_class->realize = gtk_path_bar_realize;
223 widget_class->unrealize = gtk_path_bar_unrealize;
224 widget_class->map = gtk_path_bar_map;
225 widget_class->unmap = gtk_path_bar_unmap;
226 widget_class->size_allocate = gtk_path_bar_size_allocate;
227 widget_class->style_set = gtk_path_bar_style_set;
228 widget_class->screen_changed = gtk_path_bar_screen_changed;
229 widget_class->grab_notify = gtk_path_bar_grab_notify;
230 widget_class->state_changed = gtk_path_bar_state_changed;
231 widget_class->scroll_event = gtk_path_bar_scroll;
233 container_class->add = gtk_path_bar_add;
234 container_class->forall = gtk_path_bar_forall;
235 container_class->remove = gtk_path_bar_remove;
237 /* container_class->child_type = gtk_path_bar_child_type;*/
239 path_bar_signals [PATH_CLICKED] =
240 g_signal_new (I_("path-clicked"),
241 G_OBJECT_CLASS_TYPE (object_class),
243 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
245 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
254 gtk_path_bar_finalize (GObject *object)
256 GtkPathBar *path_bar;
258 path_bar = GTK_PATH_BAR (object);
260 gtk_path_bar_stop_scrolling (path_bar);
262 g_list_free (path_bar->button_list);
263 if (path_bar->root_file)
264 g_object_unref (path_bar->root_file);
265 if (path_bar->home_file)
266 g_object_unref (path_bar->home_file);
267 if (path_bar->desktop_file)
268 g_object_unref (path_bar->desktop_file);
270 if (path_bar->root_icon)
271 g_object_unref (path_bar->root_icon);
272 if (path_bar->home_icon)
273 g_object_unref (path_bar->home_icon);
274 if (path_bar->desktop_icon)
275 g_object_unref (path_bar->desktop_icon);
277 if (path_bar->file_system)
278 g_object_unref (path_bar->file_system);
280 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
283 /* Removes the settings signal handler. It's safe to call multiple times */
285 remove_settings_signal (GtkPathBar *path_bar,
288 if (path_bar->settings_signal_id)
290 GtkSettings *settings;
292 settings = gtk_settings_get_for_screen (screen);
293 g_signal_handler_disconnect (settings,
294 path_bar->settings_signal_id);
295 path_bar->settings_signal_id = 0;
300 gtk_path_bar_dispose (GObject *object)
302 GtkPathBar *path_bar = GTK_PATH_BAR (object);
304 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
306 if (path_bar->get_info_cancellable)
307 g_cancellable_cancel (path_bar->get_info_cancellable);
308 path_bar->get_info_cancellable = NULL;
310 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
315 * Ideally, our size is determined by another widget, and we are just filling
319 gtk_path_bar_size_request (GtkWidget *widget,
320 GtkRequisition *requisition)
322 ButtonData *button_data;
323 GtkPathBar *path_bar;
324 GtkRequisition child_requisition;
328 path_bar = GTK_PATH_BAR (widget);
330 requisition->width = 0;
331 requisition->height = 0;
333 for (list = path_bar->button_list; list; list = list->next)
335 button_data = BUTTON_DATA (list->data);
336 gtk_widget_get_preferred_size (button_data->button,
337 &child_requisition, NULL);
339 if (button_data->type == NORMAL_BUTTON)
340 /* Use 2*Height as button width because of ellipsized label. */
341 requisition->width = MAX (child_requisition.height * 2, requisition->width);
343 requisition->width = MAX (child_requisition.width, requisition->width);
345 requisition->height = MAX (child_requisition.height, requisition->height);
348 /* Add space for slider, if we have more than one path */
349 /* Theoretically, the slider could be bigger than the other button. But we're
350 * not going to worry about that now.
352 path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
353 if (path_bar->button_list && path_bar->button_list->next != NULL)
354 requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
356 gtk_widget_get_preferred_size (path_bar->up_slider_button,
357 &child_requisition, NULL);
358 gtk_widget_get_preferred_size (path_bar->down_slider_button,
359 &child_requisition, NULL);
361 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
362 requisition->width += border_width * 2;
363 requisition->height += border_width * 2;
367 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
369 if (path_bar->button_list)
373 button = BUTTON_DATA (path_bar->button_list->data)->button;
374 if (gtk_widget_get_child_visible (button))
376 gtk_path_bar_stop_scrolling (path_bar);
377 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
380 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
382 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
383 if (gtk_widget_get_child_visible (button))
385 gtk_path_bar_stop_scrolling (path_bar);
386 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
389 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
394 gtk_path_bar_map (GtkWidget *widget)
396 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
398 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
402 gtk_path_bar_unmap (GtkWidget *widget)
404 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
405 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
407 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
411 gtk_path_bar_realize (GtkWidget *widget)
413 GtkPathBar *path_bar;
414 GtkAllocation allocation;
416 GdkWindowAttr attributes;
417 gint attributes_mask;
419 gtk_widget_set_realized (widget, TRUE);
421 path_bar = GTK_PATH_BAR (widget);
422 window = gtk_widget_get_parent_window (widget);
423 gtk_widget_set_window (widget, window);
424 g_object_ref (window);
426 gtk_widget_get_allocation (widget, &allocation);
428 attributes.window_type = GDK_WINDOW_CHILD;
429 attributes.x = allocation.x;
430 attributes.y = allocation.y;
431 attributes.width = allocation.width;
432 attributes.height = allocation.height;
433 attributes.wclass = GDK_INPUT_ONLY;
434 attributes.event_mask = gtk_widget_get_events (widget);
435 attributes.event_mask |= GDK_SCROLL_MASK;
436 attributes_mask = GDK_WA_X | GDK_WA_Y;
438 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
439 &attributes, attributes_mask);
440 gdk_window_set_user_data (path_bar->event_window, widget);
442 gtk_widget_style_attach (widget);
446 gtk_path_bar_unrealize (GtkWidget *widget)
448 GtkPathBar *path_bar;
450 path_bar = GTK_PATH_BAR (widget);
452 gdk_window_set_user_data (path_bar->event_window, NULL);
453 gdk_window_destroy (path_bar->event_window);
454 path_bar->event_window = NULL;
456 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
459 /* This is a tad complicated
462 gtk_path_bar_size_allocate (GtkWidget *widget,
463 GtkAllocation *allocation)
466 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
467 GtkTextDirection direction;
468 GtkAllocation child_allocation;
469 GList *list, *first_button;
471 gint allocation_width;
473 gboolean need_sliders = FALSE;
474 gint up_slider_offset = 0;
475 GtkRequisition child_requisition;
477 gtk_widget_set_allocation (widget, allocation);
479 if (gtk_widget_get_realized (widget))
480 gdk_window_move_resize (path_bar->event_window,
481 allocation->x, allocation->y,
482 allocation->width, allocation->height);
484 /* No path is set; we don't have to allocate anything. */
485 if (path_bar->button_list == NULL)
488 direction = gtk_widget_get_direction (widget);
489 border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar));
490 allocation_width = allocation->width - 2 * border_width;
492 /* First, we check to see if we need the scrollbars. */
493 if (path_bar->fake_root)
494 width = path_bar->spacing + path_bar->slider_width;
498 for (list = path_bar->button_list; list; list = list->next)
500 child = BUTTON_DATA (list->data)->button;
502 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
504 width += child_requisition.width + path_bar->spacing;
505 if (list == path_bar->fake_root)
509 if (width <= allocation_width)
511 if (path_bar->fake_root)
512 first_button = path_bar->fake_root;
514 first_button = g_list_last (path_bar->button_list);
518 gboolean reached_end = FALSE;
519 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
521 if (path_bar->first_scrolled_button)
522 first_button = path_bar->first_scrolled_button;
524 first_button = path_bar->button_list;
527 /* To see how much space we have, and how many buttons we can display.
528 * We start at the first button, count forward until hit the new
529 * button, then count backwards.
531 /* Count down the path chain towards the end. */
532 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
533 &child_requisition, NULL);
535 width = child_requisition.width;
536 list = first_button->prev;
537 while (list && !reached_end)
539 child = BUTTON_DATA (list->data)->button;
541 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
543 if (width + child_requisition.width +
544 path_bar->spacing + slider_space > allocation_width)
546 else if (list == path_bar->fake_root)
549 width += child_requisition.width + path_bar->spacing;
554 /* Finally, we walk up, seeing how many of the previous buttons we can
556 while (first_button->next && !reached_end)
558 child = BUTTON_DATA (first_button->next->data)->button;
560 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
562 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
568 width += child_requisition.width + path_bar->spacing;
569 if (first_button == path_bar->fake_root)
571 first_button = first_button->next;
576 /* Now, we allocate space to the buttons */
577 child_allocation.y = allocation->y + border_width;
578 child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
580 if (direction == GTK_TEXT_DIR_RTL)
582 child_allocation.x = allocation->x + allocation->width - border_width;
583 if (need_sliders || path_bar->fake_root)
585 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
586 up_slider_offset = allocation->width - border_width - path_bar->slider_width;
591 child_allocation.x = allocation->x + border_width;
592 if (need_sliders || path_bar->fake_root)
594 up_slider_offset = border_width;
595 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
599 for (list = first_button; list; list = list->prev)
601 GtkAllocation widget_allocation;
602 ButtonData *button_data;
604 button_data = BUTTON_DATA (list->data);
605 child = button_data->button;
607 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
609 child_allocation.width = MIN (child_requisition.width,
610 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
612 if (direction == GTK_TEXT_DIR_RTL)
613 child_allocation.x -= child_allocation.width;
615 /* Check to see if we've don't have any more space to allocate buttons */
616 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
618 gtk_widget_get_allocation (widget, &widget_allocation);
619 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x + border_width)
622 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
624 gtk_widget_get_allocation (widget, &widget_allocation);
625 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
626 widget_allocation.x + border_width + allocation_width)
630 if (child_allocation.width < child_requisition.width)
632 if (!gtk_widget_get_has_tooltip (child))
633 gtk_widget_set_tooltip_text (child, button_data->dir_name);
635 else if (gtk_widget_get_has_tooltip (child))
636 gtk_widget_set_tooltip_text (child, NULL);
638 gtk_widget_set_child_visible (child, TRUE);
639 gtk_widget_size_allocate (child, &child_allocation);
641 if (direction == GTK_TEXT_DIR_RTL)
642 child_allocation.x -= path_bar->spacing;
644 child_allocation.x += child_allocation.width + path_bar->spacing;
646 /* Now we go hide all the widgets that don't fit */
649 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
652 for (list = first_button->next; list; list = list->next)
654 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
657 if (need_sliders || path_bar->fake_root)
659 child_allocation.width = path_bar->slider_width;
660 child_allocation.x = up_slider_offset + allocation->x;
661 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
663 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
664 gtk_widget_show_all (path_bar->up_slider_button);
667 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
671 child_allocation.width = path_bar->slider_width;
673 if (direction == GTK_TEXT_DIR_RTL)
674 child_allocation.x = border_width;
676 child_allocation.x = allocation->width - border_width - path_bar->slider_width;
678 child_allocation.x += allocation->x;
680 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
682 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
683 gtk_widget_show_all (path_bar->down_slider_button);
684 gtk_path_bar_update_slider_buttons (path_bar);
687 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
691 gtk_path_bar_style_set (GtkWidget *widget,
692 GtkStyle *previous_style)
694 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
696 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
700 gtk_path_bar_screen_changed (GtkWidget *widget,
701 GdkScreen *previous_screen)
703 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
704 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
706 /* We might nave a new settings, so we remove the old one */
708 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
710 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
714 gtk_path_bar_scroll (GtkWidget *widget,
715 GdkEventScroll *event)
717 switch (event->direction)
719 case GDK_SCROLL_RIGHT:
720 case GDK_SCROLL_DOWN:
721 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
723 case GDK_SCROLL_LEFT:
725 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
733 gtk_path_bar_add (GtkContainer *container,
736 gtk_widget_set_parent (widget, GTK_WIDGET (container));
740 gtk_path_bar_remove_1 (GtkContainer *container,
743 gboolean was_visible = gtk_widget_get_visible (widget);
744 gtk_widget_unparent (widget);
746 gtk_widget_queue_resize (GTK_WIDGET (container));
750 gtk_path_bar_remove (GtkContainer *container,
753 GtkPathBar *path_bar;
756 path_bar = GTK_PATH_BAR (container);
758 if (widget == path_bar->up_slider_button)
760 gtk_path_bar_remove_1 (container, widget);
761 path_bar->up_slider_button = NULL;
765 if (widget == path_bar->down_slider_button)
767 gtk_path_bar_remove_1 (container, widget);
768 path_bar->down_slider_button = NULL;
772 children = path_bar->button_list;
775 if (widget == BUTTON_DATA (children->data)->button)
777 gtk_path_bar_remove_1 (container, widget);
778 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
779 g_list_free (children);
783 children = children->next;
788 gtk_path_bar_forall (GtkContainer *container,
789 gboolean include_internals,
790 GtkCallback callback,
791 gpointer callback_data)
793 GtkPathBar *path_bar;
796 g_return_if_fail (callback != NULL);
797 path_bar = GTK_PATH_BAR (container);
799 children = path_bar->button_list;
803 child = BUTTON_DATA (children->data)->button;
804 children = children->next;
806 (* callback) (child, callback_data);
809 if (path_bar->up_slider_button)
810 (* callback) (path_bar->up_slider_button, callback_data);
812 if (path_bar->down_slider_button)
813 (* callback) (path_bar->down_slider_button, callback_data);
817 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
819 GtkAllocation allocation, button_allocation;
821 GList *down_button = NULL;
822 gint space_available;
824 if (path_bar->ignore_click)
826 path_bar->ignore_click = FALSE;
830 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
832 /* Return if the last button is already visible */
836 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
838 /* We find the button at the 'down' end that we have to make
840 for (list = path_bar->button_list; list; list = list->next)
842 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
849 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
850 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
852 space_available = (allocation.width
853 - 2 * gtk_container_get_border_width (GTK_CONTAINER (path_bar))
854 - 2 * path_bar->spacing - 2 * path_bar->slider_width
855 - button_allocation.width);
856 path_bar->first_scrolled_button = down_button;
858 /* We have space_available free space that's not being used.
859 * So we walk down from the end, adding buttons until we use all free space.
861 while (space_available > 0)
863 path_bar->first_scrolled_button = down_button;
864 down_button = down_button->next;
867 space_available -= (button_allocation.width
868 + path_bar->spacing);
873 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
877 if (path_bar->ignore_click)
879 path_bar->ignore_click = FALSE;
883 list = g_list_last (path_bar->button_list);
885 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
887 /* Return if the first button is already visible */
891 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
893 for ( ; list; list = list->prev)
895 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
897 if (list->prev == path_bar->fake_root)
898 path_bar->fake_root = NULL;
899 path_bar->first_scrolled_button = list;
906 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
908 gboolean retval = FALSE;
912 if (path_bar->scrolling_up)
913 gtk_path_bar_scroll_up (path_bar);
914 else if (path_bar->scrolling_down)
915 gtk_path_bar_scroll_down (path_bar);
917 if (path_bar->need_timer)
919 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
922 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
924 path_bar->need_timer = FALSE;
926 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
927 (GSourceFunc)gtk_path_bar_scroll_timeout,
938 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
942 g_source_remove (path_bar->timer);
944 path_bar->need_timer = FALSE;
949 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
950 GdkEventButton *event,
951 GtkPathBar *path_bar)
954 GList *up_button = NULL;
956 if (event->type != GDK_FOCUS_CHANGE)
959 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
961 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
968 /* don't let the focus vanish */
969 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
970 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
971 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
977 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
978 GdkEventButton *event,
979 GtkPathBar *path_bar)
982 GList *down_button = NULL;
984 if (event->type != GDK_FOCUS_CHANGE)
987 for (list = path_bar->button_list; list; list = list->next)
989 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
996 /* don't let the focus vanish */
997 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
998 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
999 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1005 gtk_path_bar_slider_button_press (GtkWidget *widget,
1006 GdkEventButton *event,
1007 GtkPathBar *path_bar)
1009 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1012 path_bar->ignore_click = FALSE;
1014 if (widget == path_bar->up_slider_button)
1016 path_bar->scrolling_down = FALSE;
1017 path_bar->scrolling_up = TRUE;
1018 gtk_path_bar_scroll_up (path_bar);
1020 else if (widget == path_bar->down_slider_button)
1022 path_bar->scrolling_up = FALSE;
1023 path_bar->scrolling_down = TRUE;
1024 gtk_path_bar_scroll_down (path_bar);
1027 if (!path_bar->timer)
1029 GtkSettings *settings = gtk_widget_get_settings (widget);
1032 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1034 path_bar->need_timer = TRUE;
1035 path_bar->timer = gdk_threads_add_timeout (timeout,
1036 (GSourceFunc)gtk_path_bar_scroll_timeout,
1044 gtk_path_bar_slider_button_release (GtkWidget *widget,
1045 GdkEventButton *event,
1046 GtkPathBar *path_bar)
1048 if (event->type != GDK_BUTTON_RELEASE)
1051 path_bar->ignore_click = TRUE;
1052 gtk_path_bar_stop_scrolling (path_bar);
1058 gtk_path_bar_grab_notify (GtkWidget *widget,
1059 gboolean was_grabbed)
1062 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1066 gtk_path_bar_state_changed (GtkWidget *widget,
1067 GtkStateType previous_state)
1069 if (!gtk_widget_is_sensitive (widget))
1070 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1074 /* Changes the icons wherever it is needed */
1076 reload_icons (GtkPathBar *path_bar)
1080 if (path_bar->root_icon)
1082 g_object_unref (path_bar->root_icon);
1083 path_bar->root_icon = NULL;
1085 if (path_bar->home_icon)
1087 g_object_unref (path_bar->home_icon);
1088 path_bar->home_icon = NULL;
1090 if (path_bar->desktop_icon)
1092 g_object_unref (path_bar->desktop_icon);
1093 path_bar->desktop_icon = NULL;
1096 for (list = path_bar->button_list; list; list = list->next)
1098 ButtonData *button_data;
1099 gboolean current_dir;
1101 button_data = BUTTON_DATA (list->data);
1102 if (button_data->type != NORMAL_BUTTON)
1104 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1105 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1112 change_icon_theme (GtkPathBar *path_bar)
1114 GtkSettings *settings;
1117 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1119 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1120 path_bar->icon_size = MAX (width, height);
1122 path_bar->icon_size = FALLBACK_ICON_SIZE;
1124 reload_icons (path_bar);
1126 /* Callback used when a GtkSettings value changes */
1128 settings_notify_cb (GObject *object,
1130 GtkPathBar *path_bar)
1134 name = g_param_spec_get_name (pspec);
1136 if (! strcmp (name, "gtk-icon-theme-name") ||
1137 ! strcmp (name, "gtk-icon-sizes"))
1138 change_icon_theme (path_bar);
1142 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1144 GtkSettings *settings;
1146 if (path_bar->settings_signal_id)
1149 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1150 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1152 change_icon_theme (path_bar);
1155 /* Public functions and their helpers */
1157 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1159 while (path_bar->button_list != NULL)
1161 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1163 path_bar->first_scrolled_button = NULL;
1164 path_bar->fake_root = NULL;
1168 button_clicked_cb (GtkWidget *button,
1171 ButtonData *button_data;
1172 GtkPathBar *path_bar;
1174 gboolean child_is_hidden;
1177 button_data = BUTTON_DATA (data);
1178 if (button_data->ignore_changes)
1181 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1183 button_list = g_list_find (path_bar->button_list, button_data);
1184 g_assert (button_list != NULL);
1186 g_signal_handlers_block_by_func (button,
1187 G_CALLBACK (button_clicked_cb), data);
1188 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1189 g_signal_handlers_unblock_by_func (button,
1190 G_CALLBACK (button_clicked_cb), data);
1192 if (button_list->prev)
1194 ButtonData *child_data;
1196 child_data = BUTTON_DATA (button_list->prev->data);
1197 child_file = child_data->file;
1198 child_is_hidden = child_data->file_is_hidden;
1203 child_is_hidden = FALSE;
1206 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1207 button_data->file, child_file, child_is_hidden);
1210 struct SetButtonImageData
1212 GtkPathBar *path_bar;
1213 ButtonData *button_data;
1217 set_button_image_get_info_cb (GCancellable *cancellable,
1219 const GError *error,
1222 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1224 struct SetButtonImageData *data = user_data;
1226 if (cancellable != data->button_data->cancellable)
1229 data->button_data->cancellable = NULL;
1231 if (!data->button_data->button)
1233 g_free (data->button_data);
1237 if (cancelled || error)
1240 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1241 data->path_bar->icon_size);
1242 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1244 switch (data->button_data->type)
1247 if (data->path_bar->home_icon)
1248 g_object_unref (pixbuf);
1250 data->path_bar->home_icon = pixbuf;
1253 case DESKTOP_BUTTON:
1254 if (data->path_bar->desktop_icon)
1255 g_object_unref (pixbuf);
1257 data->path_bar->desktop_icon = pixbuf;
1266 g_object_unref (cancellable);
1270 set_button_image (GtkPathBar *path_bar,
1271 ButtonData *button_data)
1273 GtkFileSystemVolume *volume;
1274 struct SetButtonImageData *data;
1276 switch (button_data->type)
1280 if (path_bar->root_icon != NULL)
1282 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1286 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1290 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1291 GTK_WIDGET (path_bar),
1292 path_bar->icon_size,
1294 _gtk_file_system_volume_unref (volume);
1296 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1300 if (path_bar->home_icon != NULL)
1302 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1306 data = g_new0 (struct SetButtonImageData, 1);
1307 data->path_bar = path_bar;
1308 data->button_data = button_data;
1310 if (button_data->cancellable)
1311 g_cancellable_cancel (button_data->cancellable);
1313 button_data->cancellable =
1314 _gtk_file_system_get_info (path_bar->file_system,
1315 path_bar->home_file,
1317 set_button_image_get_info_cb,
1321 case DESKTOP_BUTTON:
1322 if (path_bar->desktop_icon != NULL)
1324 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1328 data = g_new0 (struct SetButtonImageData, 1);
1329 data->path_bar = path_bar;
1330 data->button_data = button_data;
1332 if (button_data->cancellable)
1333 g_cancellable_cancel (button_data->cancellable);
1335 button_data->cancellable =
1336 _gtk_file_system_get_info (path_bar->file_system,
1337 path_bar->desktop_file,
1339 set_button_image_get_info_cb,
1348 button_data_free (ButtonData *button_data)
1350 if (button_data->file)
1351 g_object_unref (button_data->file);
1352 button_data->file = NULL;
1354 g_free (button_data->dir_name);
1355 button_data->dir_name = NULL;
1357 button_data->button = NULL;
1359 if (button_data->cancellable)
1360 g_cancellable_cancel (button_data->cancellable);
1362 g_free (button_data);
1366 get_dir_name (ButtonData *button_data)
1368 return button_data->dir_name;
1371 /* We always want to request the same size for the label, whether
1372 * or not the contents are bold
1375 label_size_request_cb (GtkWidget *widget,
1376 GtkRequisition *requisition,
1377 ButtonData *button_data)
1379 const gchar *dir_name = get_dir_name (button_data);
1380 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1381 gint bold_width, bold_height;
1384 pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1386 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1387 pango_layout_set_markup (layout, markup, -1);
1390 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1391 requisition->width = MAX (requisition->width, bold_width);
1392 requisition->height = MAX (requisition->height, bold_height);
1394 g_object_unref (layout);
1398 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1399 ButtonData *button_data,
1400 gboolean current_dir)
1402 const gchar *dir_name = get_dir_name (button_data);
1404 if (button_data->label != NULL)
1410 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1411 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1416 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1420 if (button_data->image != NULL)
1422 set_button_image (path_bar, button_data);
1425 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1427 button_data->ignore_changes = TRUE;
1428 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1429 button_data->ignore_changes = FALSE;
1434 find_button_type (GtkPathBar *path_bar,
1437 if (path_bar->root_file != NULL &&
1438 g_file_equal (file, path_bar->root_file))
1440 if (path_bar->home_file != NULL &&
1441 g_file_equal (file, path_bar->home_file))
1443 if (path_bar->desktop_file != NULL &&
1444 g_file_equal (file, path_bar->desktop_file))
1445 return DESKTOP_BUTTON;
1447 return NORMAL_BUTTON;
1451 button_drag_data_get_cb (GtkWidget *widget,
1452 GdkDragContext *context,
1453 GtkSelectionData *selection_data,
1458 ButtonData *button_data;
1459 GtkPathBar *path_bar;
1463 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
1465 uris[0] = g_file_get_uri (button_data->file);
1468 gtk_selection_data_set_uris (selection_data, uris);
1473 make_directory_button (GtkPathBar *path_bar,
1474 const char *dir_name,
1476 gboolean current_dir,
1477 gboolean file_is_hidden)
1480 GtkWidget *child = NULL;
1481 GtkWidget *label_alignment = NULL;
1482 ButtonData *button_data;
1484 file_is_hidden = !! file_is_hidden;
1485 /* Is it a special button? */
1486 button_data = g_new0 (ButtonData, 1);
1488 button_data->type = find_button_type (path_bar, file);
1489 button_data->button = gtk_toggle_button_new ();
1490 atk_obj = gtk_widget_get_accessible (button_data->button);
1491 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1493 switch (button_data->type)
1496 button_data->image = gtk_image_new ();
1497 child = button_data->image;
1498 button_data->label = NULL;
1499 atk_object_set_name (atk_obj, _("File System Root"));
1502 case DESKTOP_BUTTON:
1503 button_data->image = gtk_image_new ();
1504 button_data->label = gtk_label_new (NULL);
1505 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1506 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1507 child = gtk_hbox_new (FALSE, 2);
1508 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1509 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1513 button_data->label = gtk_label_new (NULL);
1514 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1515 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1516 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1517 child = label_alignment;
1518 button_data->image = NULL;
1521 /* label_alignment is created because we can't override size-request
1522 * on label itself and still have the contents of the label centered
1523 * properly in the label's requisition
1525 if (label_alignment)
1526 g_signal_connect (label_alignment, "size-request",
1527 G_CALLBACK (label_size_request_cb), button_data);
1529 button_data->dir_name = g_strdup (dir_name);
1530 button_data->file = g_object_ref (file);
1531 button_data->file_is_hidden = file_is_hidden;
1533 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1534 gtk_widget_show_all (button_data->button);
1536 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1538 g_signal_connect (button_data->button, "clicked",
1539 G_CALLBACK (button_clicked_cb),
1541 g_object_weak_ref (G_OBJECT (button_data->button),
1542 (GWeakNotify) button_data_free, button_data);
1544 gtk_drag_source_set (button_data->button,
1548 gtk_drag_source_add_uri_targets (button_data->button);
1549 g_signal_connect (button_data->button, "drag-data-get",
1550 G_CALLBACK (button_drag_data_get_cb), button_data);
1556 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1558 GtkFileSystem *file_system)
1561 GList *current_path = NULL;
1562 gboolean need_new_fake_root = FALSE;
1564 for (list = path_bar->button_list; list; list = list->next)
1566 ButtonData *button_data;
1568 button_data = list->data;
1569 if (g_file_equal (file, button_data->file))
1571 current_path = list;
1574 if (list == path_bar->fake_root)
1575 need_new_fake_root = TRUE;
1580 if (need_new_fake_root)
1582 path_bar->fake_root = NULL;
1583 for (list = current_path; list; list = list->next)
1585 ButtonData *button_data;
1587 button_data = list->data;
1588 if (BUTTON_IS_FAKE_ROOT (button_data))
1590 path_bar->fake_root = list;
1596 for (list = path_bar->button_list; list; list = list->next)
1598 gtk_path_bar_update_button_appearance (path_bar,
1599 BUTTON_DATA (list->data),
1600 (list == current_path) ? TRUE : FALSE);
1603 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1605 path_bar->first_scrolled_button = current_path;
1606 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1619 GtkPathBar *path_bar;
1622 gboolean first_directory;
1626 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1633 gtk_path_bar_clear_buttons (info->path_bar);
1634 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1635 info->path_bar->fake_root = info->fake_root;
1637 for (l = info->path_bar->button_list; l; l = l->next)
1639 GtkWidget *button = BUTTON_DATA (l->data)->button;
1640 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1647 for (l = info->new_buttons; l; l = l->next)
1649 ButtonData *button_data;
1651 button_data = BUTTON_DATA (l->data);
1652 gtk_widget_destroy (button_data->button);
1655 g_list_free (info->new_buttons);
1659 g_object_unref (info->file);
1660 if (info->parent_file)
1661 g_object_unref (info->parent_file);
1666 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1668 const GError *error,
1671 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1672 struct SetFileInfo *file_info = data;
1673 ButtonData *button_data;
1674 const gchar *display_name;
1677 if (cancellable != file_info->path_bar->get_info_cancellable)
1679 gtk_path_bar_set_file_finish (file_info, FALSE);
1680 g_object_unref (cancellable);
1684 g_object_unref (cancellable);
1685 file_info->path_bar->get_info_cancellable = NULL;
1687 if (cancelled || !info)
1689 gtk_path_bar_set_file_finish (file_info, FALSE);
1693 display_name = g_file_info_get_display_name (info);
1694 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1696 gtk_widget_push_composite_child ();
1697 button_data = make_directory_button (file_info->path_bar, display_name,
1699 file_info->first_directory, is_hidden);
1700 gtk_widget_pop_composite_child ();
1701 g_object_unref (file_info->file);
1703 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1705 if (BUTTON_IS_FAKE_ROOT (button_data))
1706 file_info->fake_root = file_info->new_buttons;
1708 file_info->file = file_info->parent_file;
1709 file_info->first_directory = FALSE;
1711 if (!file_info->file)
1713 gtk_path_bar_set_file_finish (file_info, TRUE);
1717 file_info->parent_file = g_file_get_parent (file_info->file);
1719 file_info->path_bar->get_info_cancellable =
1720 _gtk_file_system_get_info (file_info->path_bar->file_system,
1722 "standard::display-name,standard::is-hidden,standard::is-backup",
1723 gtk_path_bar_get_info_callback,
1728 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1730 const gboolean keep_trail,
1733 struct SetFileInfo *info;
1736 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1737 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1741 /* Check whether the new path is already present in the pathbar as buttons.
1742 * This could be a parent directory or a previous selected subdirectory.
1745 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1748 info = g_new0 (struct SetFileInfo, 1);
1749 info->file = g_object_ref (file);
1750 info->path_bar = path_bar;
1751 info->first_directory = TRUE;
1752 info->parent_file = g_file_get_parent (info->file);
1754 if (path_bar->get_info_cancellable)
1755 g_cancellable_cancel (path_bar->get_info_cancellable);
1757 path_bar->get_info_cancellable =
1758 _gtk_file_system_get_info (path_bar->file_system,
1760 "standard::display-name,standard::is-hidden,standard::is-backup",
1761 gtk_path_bar_get_info_callback,
1767 /* FIXME: This should be a construct-only property */
1769 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1770 GtkFileSystem *file_system)
1774 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1776 g_assert (path_bar->file_system == NULL);
1778 path_bar->file_system = g_object_ref (file_system);
1780 home = g_get_home_dir ();
1783 const gchar *desktop;
1785 path_bar->home_file = g_file_new_for_path (home);
1786 /* FIXME: Need file system backend specific way of getting the
1789 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1790 if (desktop != NULL)
1791 path_bar->desktop_file = g_file_new_for_path (desktop);
1793 path_bar->desktop_file = NULL;
1797 path_bar->home_file = NULL;
1798 path_bar->desktop_file = NULL;
1800 path_bar->root_file = g_file_new_for_path ("/");
1805 * @path_bar: a #GtkPathBar
1807 * If the selected button in the pathbar is not the furthest button "up" (in the
1808 * root direction), act as if the user clicked on the next button up.
1811 _gtk_path_bar_up (GtkPathBar *path_bar)
1815 for (l = path_bar->button_list; l; l = l->next)
1817 GtkWidget *button = BUTTON_DATA (l->data)->button;
1818 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1822 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1823 button_clicked_cb (next_button, l->next->data);
1831 * _gtk_path_bar_down:
1832 * @path_bar: a #GtkPathBar
1834 * If the selected button in the pathbar is not the furthest button "down" (in the
1835 * leaf direction), act as if the user clicked on the next button down.
1838 _gtk_path_bar_down (GtkPathBar *path_bar)
1842 for (l = path_bar->button_list; l; l = l->next)
1844 GtkWidget *button = BUTTON_DATA (l->data)->button;
1845 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1849 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1850 button_clicked_cb (prev_button, l->prev->data);