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 GtkWidgetClass *widget_class;
210 GtkContainerClass *container_class;
212 gobject_class = (GObjectClass *) path_bar_class;
213 widget_class = (GtkWidgetClass *) path_bar_class;
214 container_class = (GtkContainerClass *) path_bar_class;
216 gobject_class->finalize = gtk_path_bar_finalize;
217 gobject_class->dispose = gtk_path_bar_dispose;
219 widget_class->size_request = gtk_path_bar_size_request;
220 widget_class->realize = gtk_path_bar_realize;
221 widget_class->unrealize = gtk_path_bar_unrealize;
222 widget_class->map = gtk_path_bar_map;
223 widget_class->unmap = gtk_path_bar_unmap;
224 widget_class->size_allocate = gtk_path_bar_size_allocate;
225 widget_class->style_set = gtk_path_bar_style_set;
226 widget_class->screen_changed = gtk_path_bar_screen_changed;
227 widget_class->grab_notify = gtk_path_bar_grab_notify;
228 widget_class->state_changed = gtk_path_bar_state_changed;
229 widget_class->scroll_event = gtk_path_bar_scroll;
231 container_class->add = gtk_path_bar_add;
232 container_class->forall = gtk_path_bar_forall;
233 container_class->remove = gtk_path_bar_remove;
234 gtk_container_class_handle_border_width (container_class);
236 /* container_class->child_type = gtk_path_bar_child_type;*/
238 path_bar_signals [PATH_CLICKED] =
239 g_signal_new (I_("path-clicked"),
240 G_OBJECT_CLASS_TYPE (gobject_class),
242 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
244 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
253 gtk_path_bar_finalize (GObject *object)
255 GtkPathBar *path_bar;
257 path_bar = GTK_PATH_BAR (object);
259 gtk_path_bar_stop_scrolling (path_bar);
261 g_list_free (path_bar->button_list);
262 if (path_bar->root_file)
263 g_object_unref (path_bar->root_file);
264 if (path_bar->home_file)
265 g_object_unref (path_bar->home_file);
266 if (path_bar->desktop_file)
267 g_object_unref (path_bar->desktop_file);
269 if (path_bar->root_icon)
270 g_object_unref (path_bar->root_icon);
271 if (path_bar->home_icon)
272 g_object_unref (path_bar->home_icon);
273 if (path_bar->desktop_icon)
274 g_object_unref (path_bar->desktop_icon);
276 if (path_bar->file_system)
277 g_object_unref (path_bar->file_system);
279 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
282 /* Removes the settings signal handler. It's safe to call multiple times */
284 remove_settings_signal (GtkPathBar *path_bar,
287 if (path_bar->settings_signal_id)
289 GtkSettings *settings;
291 settings = gtk_settings_get_for_screen (screen);
292 g_signal_handler_disconnect (settings,
293 path_bar->settings_signal_id);
294 path_bar->settings_signal_id = 0;
299 gtk_path_bar_dispose (GObject *object)
301 GtkPathBar *path_bar = GTK_PATH_BAR (object);
303 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
305 if (path_bar->get_info_cancellable)
306 g_cancellable_cancel (path_bar->get_info_cancellable);
307 path_bar->get_info_cancellable = NULL;
309 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
314 * Ideally, our size is determined by another widget, and we are just filling
318 gtk_path_bar_size_request (GtkWidget *widget,
319 GtkRequisition *requisition)
321 ButtonData *button_data;
322 GtkPathBar *path_bar;
323 GtkRequisition child_requisition;
326 path_bar = GTK_PATH_BAR (widget);
328 requisition->width = 0;
329 requisition->height = 0;
331 for (list = path_bar->button_list; list; list = list->next)
333 button_data = BUTTON_DATA (list->data);
334 gtk_widget_get_preferred_size (button_data->button,
335 &child_requisition, NULL);
337 if (button_data->type == NORMAL_BUTTON)
338 /* Use 2*Height as button width because of ellipsized label. */
339 requisition->width = MAX (child_requisition.height * 2, requisition->width);
341 requisition->width = MAX (child_requisition.width, requisition->width);
343 requisition->height = MAX (child_requisition.height, requisition->height);
346 /* Add space for slider, if we have more than one path */
347 /* Theoretically, the slider could be bigger than the other button. But we're
348 * not going to worry about that now.
350 path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
351 if (path_bar->button_list && path_bar->button_list->next != NULL)
352 requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
354 gtk_widget_get_preferred_size (path_bar->up_slider_button,
355 &child_requisition, NULL);
356 gtk_widget_get_preferred_size (path_bar->down_slider_button,
357 &child_requisition, NULL);
361 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
363 if (path_bar->button_list)
367 button = BUTTON_DATA (path_bar->button_list->data)->button;
368 if (gtk_widget_get_child_visible (button))
370 gtk_path_bar_stop_scrolling (path_bar);
371 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
374 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
376 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
377 if (gtk_widget_get_child_visible (button))
379 gtk_path_bar_stop_scrolling (path_bar);
380 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
383 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
388 gtk_path_bar_map (GtkWidget *widget)
390 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
392 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
396 gtk_path_bar_unmap (GtkWidget *widget)
398 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
399 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
401 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
405 gtk_path_bar_realize (GtkWidget *widget)
407 GtkPathBar *path_bar;
408 GtkAllocation allocation;
410 GdkWindowAttr attributes;
411 gint attributes_mask;
413 gtk_widget_set_realized (widget, TRUE);
415 path_bar = GTK_PATH_BAR (widget);
416 window = gtk_widget_get_parent_window (widget);
417 gtk_widget_set_window (widget, window);
418 g_object_ref (window);
420 gtk_widget_get_allocation (widget, &allocation);
422 attributes.window_type = GDK_WINDOW_CHILD;
423 attributes.x = allocation.x;
424 attributes.y = allocation.y;
425 attributes.width = allocation.width;
426 attributes.height = allocation.height;
427 attributes.wclass = GDK_INPUT_ONLY;
428 attributes.event_mask = gtk_widget_get_events (widget);
429 attributes.event_mask |= GDK_SCROLL_MASK;
430 attributes_mask = GDK_WA_X | GDK_WA_Y;
432 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
433 &attributes, attributes_mask);
434 gdk_window_set_user_data (path_bar->event_window, widget);
436 gtk_widget_style_attach (widget);
440 gtk_path_bar_unrealize (GtkWidget *widget)
442 GtkPathBar *path_bar;
444 path_bar = GTK_PATH_BAR (widget);
446 gdk_window_set_user_data (path_bar->event_window, NULL);
447 gdk_window_destroy (path_bar->event_window);
448 path_bar->event_window = NULL;
450 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
453 /* This is a tad complicated
456 gtk_path_bar_size_allocate (GtkWidget *widget,
457 GtkAllocation *allocation)
460 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
461 GtkTextDirection direction;
462 GtkAllocation child_allocation;
463 GList *list, *first_button;
465 gint allocation_width;
466 gboolean need_sliders = FALSE;
467 gint up_slider_offset = 0;
468 GtkRequisition child_requisition;
470 gtk_widget_set_allocation (widget, allocation);
472 if (gtk_widget_get_realized (widget))
473 gdk_window_move_resize (path_bar->event_window,
474 allocation->x, allocation->y,
475 allocation->width, allocation->height);
477 /* No path is set; we don't have to allocate anything. */
478 if (path_bar->button_list == NULL)
481 direction = gtk_widget_get_direction (widget);
482 allocation_width = allocation->width;
484 /* First, we check to see if we need the scrollbars. */
485 if (path_bar->fake_root)
486 width = path_bar->spacing + path_bar->slider_width;
490 for (list = path_bar->button_list; list; list = list->next)
492 child = BUTTON_DATA (list->data)->button;
494 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
496 width += child_requisition.width + path_bar->spacing;
497 if (list == path_bar->fake_root)
501 if (width <= allocation_width)
503 if (path_bar->fake_root)
504 first_button = path_bar->fake_root;
506 first_button = g_list_last (path_bar->button_list);
510 gboolean reached_end = FALSE;
511 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
513 if (path_bar->first_scrolled_button)
514 first_button = path_bar->first_scrolled_button;
516 first_button = path_bar->button_list;
519 /* To see how much space we have, and how many buttons we can display.
520 * We start at the first button, count forward until hit the new
521 * button, then count backwards.
523 /* Count down the path chain towards the end. */
524 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
525 &child_requisition, NULL);
527 width = child_requisition.width;
528 list = first_button->prev;
529 while (list && !reached_end)
531 child = BUTTON_DATA (list->data)->button;
533 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
535 if (width + child_requisition.width +
536 path_bar->spacing + slider_space > allocation_width)
538 else if (list == path_bar->fake_root)
541 width += child_requisition.width + path_bar->spacing;
546 /* Finally, we walk up, seeing how many of the previous buttons we can
548 while (first_button->next && !reached_end)
550 child = BUTTON_DATA (first_button->next->data)->button;
552 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
554 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
560 width += child_requisition.width + path_bar->spacing;
561 if (first_button == path_bar->fake_root)
563 first_button = first_button->next;
568 /* Now, we allocate space to the buttons */
569 child_allocation.y = allocation->y;
570 child_allocation.height = allocation->height;
572 if (direction == GTK_TEXT_DIR_RTL)
574 child_allocation.x = allocation->x + allocation->width;
575 if (need_sliders || path_bar->fake_root)
577 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
578 up_slider_offset = allocation->width - path_bar->slider_width;
583 child_allocation.x = allocation->x;
584 if (need_sliders || path_bar->fake_root)
586 up_slider_offset = 0;
587 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
591 for (list = first_button; list; list = list->prev)
593 GtkAllocation widget_allocation;
594 ButtonData *button_data;
596 button_data = BUTTON_DATA (list->data);
597 child = button_data->button;
599 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
601 child_allocation.width = MIN (child_requisition.width,
602 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
604 if (direction == GTK_TEXT_DIR_RTL)
605 child_allocation.x -= child_allocation.width;
607 /* Check to see if we've don't have any more space to allocate buttons */
608 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
610 gtk_widget_get_allocation (widget, &widget_allocation);
611 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
614 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
616 gtk_widget_get_allocation (widget, &widget_allocation);
617 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
618 widget_allocation.x + allocation_width)
622 if (child_allocation.width < child_requisition.width)
624 if (!gtk_widget_get_has_tooltip (child))
625 gtk_widget_set_tooltip_text (child, button_data->dir_name);
627 else if (gtk_widget_get_has_tooltip (child))
628 gtk_widget_set_tooltip_text (child, NULL);
630 gtk_widget_set_child_visible (child, TRUE);
631 gtk_widget_size_allocate (child, &child_allocation);
633 if (direction == GTK_TEXT_DIR_RTL)
634 child_allocation.x -= path_bar->spacing;
636 child_allocation.x += child_allocation.width + path_bar->spacing;
638 /* Now we go hide all the widgets that don't fit */
641 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
644 for (list = first_button->next; list; list = list->next)
646 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
649 if (need_sliders || path_bar->fake_root)
651 child_allocation.width = path_bar->slider_width;
652 child_allocation.x = up_slider_offset + allocation->x;
653 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
655 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
656 gtk_widget_show_all (path_bar->up_slider_button);
659 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
663 child_allocation.width = path_bar->slider_width;
665 if (direction == GTK_TEXT_DIR_RTL)
666 child_allocation.x = 0;
668 child_allocation.x = allocation->width - path_bar->slider_width;
670 child_allocation.x += allocation->x;
672 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
674 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
675 gtk_widget_show_all (path_bar->down_slider_button);
676 gtk_path_bar_update_slider_buttons (path_bar);
679 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
683 gtk_path_bar_style_set (GtkWidget *widget,
684 GtkStyle *previous_style)
686 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
688 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
692 gtk_path_bar_screen_changed (GtkWidget *widget,
693 GdkScreen *previous_screen)
695 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
696 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
698 /* We might nave a new settings, so we remove the old one */
700 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
702 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
706 gtk_path_bar_scroll (GtkWidget *widget,
707 GdkEventScroll *event)
709 switch (event->direction)
711 case GDK_SCROLL_RIGHT:
712 case GDK_SCROLL_DOWN:
713 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
715 case GDK_SCROLL_LEFT:
717 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
725 gtk_path_bar_add (GtkContainer *container,
728 gtk_widget_set_parent (widget, GTK_WIDGET (container));
732 gtk_path_bar_remove_1 (GtkContainer *container,
735 gboolean was_visible = gtk_widget_get_visible (widget);
736 gtk_widget_unparent (widget);
738 gtk_widget_queue_resize (GTK_WIDGET (container));
742 gtk_path_bar_remove (GtkContainer *container,
745 GtkPathBar *path_bar;
748 path_bar = GTK_PATH_BAR (container);
750 if (widget == path_bar->up_slider_button)
752 gtk_path_bar_remove_1 (container, widget);
753 path_bar->up_slider_button = NULL;
757 if (widget == path_bar->down_slider_button)
759 gtk_path_bar_remove_1 (container, widget);
760 path_bar->down_slider_button = NULL;
764 children = path_bar->button_list;
767 if (widget == BUTTON_DATA (children->data)->button)
769 gtk_path_bar_remove_1 (container, widget);
770 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
771 g_list_free (children);
775 children = children->next;
780 gtk_path_bar_forall (GtkContainer *container,
781 gboolean include_internals,
782 GtkCallback callback,
783 gpointer callback_data)
785 GtkPathBar *path_bar;
788 g_return_if_fail (callback != NULL);
789 path_bar = GTK_PATH_BAR (container);
791 children = path_bar->button_list;
795 child = BUTTON_DATA (children->data)->button;
796 children = children->next;
798 (* callback) (child, callback_data);
801 if (path_bar->up_slider_button)
802 (* callback) (path_bar->up_slider_button, callback_data);
804 if (path_bar->down_slider_button)
805 (* callback) (path_bar->down_slider_button, callback_data);
809 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
811 GtkAllocation allocation, button_allocation;
813 GList *down_button = NULL;
814 gint space_available;
816 if (path_bar->ignore_click)
818 path_bar->ignore_click = FALSE;
822 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
824 /* Return if the last button is already visible */
828 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
830 /* We find the button at the 'down' end that we have to make
832 for (list = path_bar->button_list; list; list = list->next)
834 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
841 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
842 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
844 space_available = (allocation.width
845 - 2 * path_bar->spacing - 2 * path_bar->slider_width
846 - button_allocation.width);
847 path_bar->first_scrolled_button = down_button;
849 /* We have space_available free space that's not being used.
850 * So we walk down from the end, adding buttons until we use all free space.
852 while (space_available > 0)
854 path_bar->first_scrolled_button = down_button;
855 down_button = down_button->next;
858 space_available -= (button_allocation.width
859 + path_bar->spacing);
864 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
868 if (path_bar->ignore_click)
870 path_bar->ignore_click = FALSE;
874 list = g_list_last (path_bar->button_list);
876 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
878 /* Return if the first button is already visible */
882 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
884 for ( ; list; list = list->prev)
886 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
888 if (list->prev == path_bar->fake_root)
889 path_bar->fake_root = NULL;
890 path_bar->first_scrolled_button = list;
897 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
899 gboolean retval = FALSE;
903 if (path_bar->scrolling_up)
904 gtk_path_bar_scroll_up (path_bar);
905 else if (path_bar->scrolling_down)
906 gtk_path_bar_scroll_down (path_bar);
908 if (path_bar->need_timer)
910 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
913 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
915 path_bar->need_timer = FALSE;
917 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
918 (GSourceFunc)gtk_path_bar_scroll_timeout,
929 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
933 g_source_remove (path_bar->timer);
935 path_bar->need_timer = FALSE;
940 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
941 GdkEventButton *event,
942 GtkPathBar *path_bar)
945 GList *up_button = NULL;
947 if (event->type != GDK_FOCUS_CHANGE)
950 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
952 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
959 /* don't let the focus vanish */
960 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
961 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
962 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
968 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
969 GdkEventButton *event,
970 GtkPathBar *path_bar)
973 GList *down_button = NULL;
975 if (event->type != GDK_FOCUS_CHANGE)
978 for (list = path_bar->button_list; list; list = list->next)
980 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
987 /* don't let the focus vanish */
988 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
989 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
990 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
996 gtk_path_bar_slider_button_press (GtkWidget *widget,
997 GdkEventButton *event,
998 GtkPathBar *path_bar)
1000 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1003 path_bar->ignore_click = FALSE;
1005 if (widget == path_bar->up_slider_button)
1007 path_bar->scrolling_down = FALSE;
1008 path_bar->scrolling_up = TRUE;
1009 gtk_path_bar_scroll_up (path_bar);
1011 else if (widget == path_bar->down_slider_button)
1013 path_bar->scrolling_up = FALSE;
1014 path_bar->scrolling_down = TRUE;
1015 gtk_path_bar_scroll_down (path_bar);
1018 if (!path_bar->timer)
1020 GtkSettings *settings = gtk_widget_get_settings (widget);
1023 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1025 path_bar->need_timer = TRUE;
1026 path_bar->timer = gdk_threads_add_timeout (timeout,
1027 (GSourceFunc)gtk_path_bar_scroll_timeout,
1035 gtk_path_bar_slider_button_release (GtkWidget *widget,
1036 GdkEventButton *event,
1037 GtkPathBar *path_bar)
1039 if (event->type != GDK_BUTTON_RELEASE)
1042 path_bar->ignore_click = TRUE;
1043 gtk_path_bar_stop_scrolling (path_bar);
1049 gtk_path_bar_grab_notify (GtkWidget *widget,
1050 gboolean was_grabbed)
1053 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1057 gtk_path_bar_state_changed (GtkWidget *widget,
1058 GtkStateType previous_state)
1060 if (!gtk_widget_is_sensitive (widget))
1061 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1065 /* Changes the icons wherever it is needed */
1067 reload_icons (GtkPathBar *path_bar)
1071 if (path_bar->root_icon)
1073 g_object_unref (path_bar->root_icon);
1074 path_bar->root_icon = NULL;
1076 if (path_bar->home_icon)
1078 g_object_unref (path_bar->home_icon);
1079 path_bar->home_icon = NULL;
1081 if (path_bar->desktop_icon)
1083 g_object_unref (path_bar->desktop_icon);
1084 path_bar->desktop_icon = NULL;
1087 for (list = path_bar->button_list; list; list = list->next)
1089 ButtonData *button_data;
1090 gboolean current_dir;
1092 button_data = BUTTON_DATA (list->data);
1093 if (button_data->type != NORMAL_BUTTON)
1095 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1096 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1103 change_icon_theme (GtkPathBar *path_bar)
1105 GtkSettings *settings;
1108 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1110 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1111 path_bar->icon_size = MAX (width, height);
1113 path_bar->icon_size = FALLBACK_ICON_SIZE;
1115 reload_icons (path_bar);
1117 /* Callback used when a GtkSettings value changes */
1119 settings_notify_cb (GObject *object,
1121 GtkPathBar *path_bar)
1125 name = g_param_spec_get_name (pspec);
1127 if (! strcmp (name, "gtk-icon-theme-name") ||
1128 ! strcmp (name, "gtk-icon-sizes"))
1129 change_icon_theme (path_bar);
1133 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1135 GtkSettings *settings;
1137 if (path_bar->settings_signal_id)
1140 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1141 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1143 change_icon_theme (path_bar);
1146 /* Public functions and their helpers */
1148 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1150 while (path_bar->button_list != NULL)
1152 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1154 path_bar->first_scrolled_button = NULL;
1155 path_bar->fake_root = NULL;
1159 button_clicked_cb (GtkWidget *button,
1162 ButtonData *button_data;
1163 GtkPathBar *path_bar;
1165 gboolean child_is_hidden;
1168 button_data = BUTTON_DATA (data);
1169 if (button_data->ignore_changes)
1172 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1174 button_list = g_list_find (path_bar->button_list, button_data);
1175 g_assert (button_list != NULL);
1177 g_signal_handlers_block_by_func (button,
1178 G_CALLBACK (button_clicked_cb), data);
1179 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1180 g_signal_handlers_unblock_by_func (button,
1181 G_CALLBACK (button_clicked_cb), data);
1183 if (button_list->prev)
1185 ButtonData *child_data;
1187 child_data = BUTTON_DATA (button_list->prev->data);
1188 child_file = child_data->file;
1189 child_is_hidden = child_data->file_is_hidden;
1194 child_is_hidden = FALSE;
1197 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1198 button_data->file, child_file, child_is_hidden);
1201 struct SetButtonImageData
1203 GtkPathBar *path_bar;
1204 ButtonData *button_data;
1208 set_button_image_get_info_cb (GCancellable *cancellable,
1210 const GError *error,
1213 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1215 struct SetButtonImageData *data = user_data;
1217 if (cancellable != data->button_data->cancellable)
1220 data->button_data->cancellable = NULL;
1222 if (!data->button_data->button)
1224 g_free (data->button_data);
1228 if (cancelled || error)
1231 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1232 data->path_bar->icon_size);
1233 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1235 switch (data->button_data->type)
1238 if (data->path_bar->home_icon)
1239 g_object_unref (pixbuf);
1241 data->path_bar->home_icon = pixbuf;
1244 case DESKTOP_BUTTON:
1245 if (data->path_bar->desktop_icon)
1246 g_object_unref (pixbuf);
1248 data->path_bar->desktop_icon = pixbuf;
1257 g_object_unref (cancellable);
1261 set_button_image (GtkPathBar *path_bar,
1262 ButtonData *button_data)
1264 GtkFileSystemVolume *volume;
1265 struct SetButtonImageData *data;
1267 switch (button_data->type)
1271 if (path_bar->root_icon != NULL)
1273 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1277 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1281 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1282 GTK_WIDGET (path_bar),
1283 path_bar->icon_size,
1285 _gtk_file_system_volume_unref (volume);
1287 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1291 if (path_bar->home_icon != NULL)
1293 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1297 data = g_new0 (struct SetButtonImageData, 1);
1298 data->path_bar = path_bar;
1299 data->button_data = button_data;
1301 if (button_data->cancellable)
1302 g_cancellable_cancel (button_data->cancellable);
1304 button_data->cancellable =
1305 _gtk_file_system_get_info (path_bar->file_system,
1306 path_bar->home_file,
1308 set_button_image_get_info_cb,
1312 case DESKTOP_BUTTON:
1313 if (path_bar->desktop_icon != NULL)
1315 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1319 data = g_new0 (struct SetButtonImageData, 1);
1320 data->path_bar = path_bar;
1321 data->button_data = button_data;
1323 if (button_data->cancellable)
1324 g_cancellable_cancel (button_data->cancellable);
1326 button_data->cancellable =
1327 _gtk_file_system_get_info (path_bar->file_system,
1328 path_bar->desktop_file,
1330 set_button_image_get_info_cb,
1339 button_data_free (ButtonData *button_data)
1341 if (button_data->file)
1342 g_object_unref (button_data->file);
1343 button_data->file = NULL;
1345 g_free (button_data->dir_name);
1346 button_data->dir_name = NULL;
1348 button_data->button = NULL;
1350 if (button_data->cancellable)
1351 g_cancellable_cancel (button_data->cancellable);
1353 g_free (button_data);
1357 get_dir_name (ButtonData *button_data)
1359 return button_data->dir_name;
1362 /* We always want to request the same size for the label, whether
1363 * or not the contents are bold
1366 label_size_request_cb (GtkWidget *widget,
1367 GtkRequisition *requisition,
1368 ButtonData *button_data)
1370 const gchar *dir_name = get_dir_name (button_data);
1371 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1372 gint bold_width, bold_height;
1375 pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1377 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1378 pango_layout_set_markup (layout, markup, -1);
1381 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1382 requisition->width = MAX (requisition->width, bold_width);
1383 requisition->height = MAX (requisition->height, bold_height);
1385 g_object_unref (layout);
1389 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1390 ButtonData *button_data,
1391 gboolean current_dir)
1393 const gchar *dir_name = get_dir_name (button_data);
1395 if (button_data->label != NULL)
1401 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1402 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1407 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1411 if (button_data->image != NULL)
1413 set_button_image (path_bar, button_data);
1416 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1418 button_data->ignore_changes = TRUE;
1419 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1420 button_data->ignore_changes = FALSE;
1425 find_button_type (GtkPathBar *path_bar,
1428 if (path_bar->root_file != NULL &&
1429 g_file_equal (file, path_bar->root_file))
1431 if (path_bar->home_file != NULL &&
1432 g_file_equal (file, path_bar->home_file))
1434 if (path_bar->desktop_file != NULL &&
1435 g_file_equal (file, path_bar->desktop_file))
1436 return DESKTOP_BUTTON;
1438 return NORMAL_BUTTON;
1442 button_drag_data_get_cb (GtkWidget *widget,
1443 GdkDragContext *context,
1444 GtkSelectionData *selection_data,
1449 ButtonData *button_data;
1450 GtkPathBar *path_bar;
1454 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
1456 uris[0] = g_file_get_uri (button_data->file);
1459 gtk_selection_data_set_uris (selection_data, uris);
1464 make_directory_button (GtkPathBar *path_bar,
1465 const char *dir_name,
1467 gboolean current_dir,
1468 gboolean file_is_hidden)
1471 GtkWidget *child = NULL;
1472 GtkWidget *label_alignment = NULL;
1473 ButtonData *button_data;
1475 file_is_hidden = !! file_is_hidden;
1476 /* Is it a special button? */
1477 button_data = g_new0 (ButtonData, 1);
1479 button_data->type = find_button_type (path_bar, file);
1480 button_data->button = gtk_toggle_button_new ();
1481 atk_obj = gtk_widget_get_accessible (button_data->button);
1482 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1484 switch (button_data->type)
1487 button_data->image = gtk_image_new ();
1488 child = button_data->image;
1489 button_data->label = NULL;
1490 atk_object_set_name (atk_obj, _("File System Root"));
1493 case DESKTOP_BUTTON:
1494 button_data->image = gtk_image_new ();
1495 button_data->label = gtk_label_new (NULL);
1496 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1497 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1498 child = gtk_hbox_new (FALSE, 2);
1499 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1500 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1504 button_data->label = gtk_label_new (NULL);
1505 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1506 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1507 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1508 child = label_alignment;
1509 button_data->image = NULL;
1512 /* label_alignment is created because we can't override size-request
1513 * on label itself and still have the contents of the label centered
1514 * properly in the label's requisition
1516 if (label_alignment)
1517 g_signal_connect (label_alignment, "size-request",
1518 G_CALLBACK (label_size_request_cb), button_data);
1520 button_data->dir_name = g_strdup (dir_name);
1521 button_data->file = g_object_ref (file);
1522 button_data->file_is_hidden = file_is_hidden;
1524 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1525 gtk_widget_show_all (button_data->button);
1527 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1529 g_signal_connect (button_data->button, "clicked",
1530 G_CALLBACK (button_clicked_cb),
1532 g_object_weak_ref (G_OBJECT (button_data->button),
1533 (GWeakNotify) button_data_free, button_data);
1535 gtk_drag_source_set (button_data->button,
1539 gtk_drag_source_add_uri_targets (button_data->button);
1540 g_signal_connect (button_data->button, "drag-data-get",
1541 G_CALLBACK (button_drag_data_get_cb), button_data);
1547 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1549 GtkFileSystem *file_system)
1552 GList *current_path = NULL;
1553 gboolean need_new_fake_root = FALSE;
1555 for (list = path_bar->button_list; list; list = list->next)
1557 ButtonData *button_data;
1559 button_data = list->data;
1560 if (g_file_equal (file, button_data->file))
1562 current_path = list;
1565 if (list == path_bar->fake_root)
1566 need_new_fake_root = TRUE;
1571 if (need_new_fake_root)
1573 path_bar->fake_root = NULL;
1574 for (list = current_path; list; list = list->next)
1576 ButtonData *button_data;
1578 button_data = list->data;
1579 if (BUTTON_IS_FAKE_ROOT (button_data))
1581 path_bar->fake_root = list;
1587 for (list = path_bar->button_list; list; list = list->next)
1589 gtk_path_bar_update_button_appearance (path_bar,
1590 BUTTON_DATA (list->data),
1591 (list == current_path) ? TRUE : FALSE);
1594 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1596 path_bar->first_scrolled_button = current_path;
1597 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1610 GtkPathBar *path_bar;
1613 gboolean first_directory;
1617 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1624 gtk_path_bar_clear_buttons (info->path_bar);
1625 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1626 info->path_bar->fake_root = info->fake_root;
1628 for (l = info->path_bar->button_list; l; l = l->next)
1630 GtkWidget *button = BUTTON_DATA (l->data)->button;
1631 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1638 for (l = info->new_buttons; l; l = l->next)
1640 ButtonData *button_data;
1642 button_data = BUTTON_DATA (l->data);
1643 gtk_widget_destroy (button_data->button);
1646 g_list_free (info->new_buttons);
1650 g_object_unref (info->file);
1651 if (info->parent_file)
1652 g_object_unref (info->parent_file);
1657 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1659 const GError *error,
1662 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1663 struct SetFileInfo *file_info = data;
1664 ButtonData *button_data;
1665 const gchar *display_name;
1668 if (cancellable != file_info->path_bar->get_info_cancellable)
1670 gtk_path_bar_set_file_finish (file_info, FALSE);
1671 g_object_unref (cancellable);
1675 g_object_unref (cancellable);
1676 file_info->path_bar->get_info_cancellable = NULL;
1678 if (cancelled || !info)
1680 gtk_path_bar_set_file_finish (file_info, FALSE);
1684 display_name = g_file_info_get_display_name (info);
1685 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1687 gtk_widget_push_composite_child ();
1688 button_data = make_directory_button (file_info->path_bar, display_name,
1690 file_info->first_directory, is_hidden);
1691 gtk_widget_pop_composite_child ();
1692 g_object_unref (file_info->file);
1694 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1696 if (BUTTON_IS_FAKE_ROOT (button_data))
1697 file_info->fake_root = file_info->new_buttons;
1699 file_info->file = file_info->parent_file;
1700 file_info->first_directory = FALSE;
1702 if (!file_info->file)
1704 gtk_path_bar_set_file_finish (file_info, TRUE);
1708 file_info->parent_file = g_file_get_parent (file_info->file);
1710 file_info->path_bar->get_info_cancellable =
1711 _gtk_file_system_get_info (file_info->path_bar->file_system,
1713 "standard::display-name,standard::is-hidden,standard::is-backup",
1714 gtk_path_bar_get_info_callback,
1719 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1721 const gboolean keep_trail,
1724 struct SetFileInfo *info;
1727 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1728 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1732 /* Check whether the new path is already present in the pathbar as buttons.
1733 * This could be a parent directory or a previous selected subdirectory.
1736 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1739 info = g_new0 (struct SetFileInfo, 1);
1740 info->file = g_object_ref (file);
1741 info->path_bar = path_bar;
1742 info->first_directory = TRUE;
1743 info->parent_file = g_file_get_parent (info->file);
1745 if (path_bar->get_info_cancellable)
1746 g_cancellable_cancel (path_bar->get_info_cancellable);
1748 path_bar->get_info_cancellable =
1749 _gtk_file_system_get_info (path_bar->file_system,
1751 "standard::display-name,standard::is-hidden,standard::is-backup",
1752 gtk_path_bar_get_info_callback,
1758 /* FIXME: This should be a construct-only property */
1760 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1761 GtkFileSystem *file_system)
1765 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1767 g_assert (path_bar->file_system == NULL);
1769 path_bar->file_system = g_object_ref (file_system);
1771 home = g_get_home_dir ();
1774 const gchar *desktop;
1776 path_bar->home_file = g_file_new_for_path (home);
1777 /* FIXME: Need file system backend specific way of getting the
1780 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1781 if (desktop != NULL)
1782 path_bar->desktop_file = g_file_new_for_path (desktop);
1784 path_bar->desktop_file = NULL;
1788 path_bar->home_file = NULL;
1789 path_bar->desktop_file = NULL;
1791 path_bar->root_file = g_file_new_for_path ("/");
1796 * @path_bar: a #GtkPathBar
1798 * If the selected button in the pathbar is not the furthest button "up" (in the
1799 * root direction), act as if the user clicked on the next button up.
1802 _gtk_path_bar_up (GtkPathBar *path_bar)
1806 for (l = path_bar->button_list; l; l = l->next)
1808 GtkWidget *button = BUTTON_DATA (l->data)->button;
1809 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1813 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1814 button_clicked_cb (next_button, l->next->data);
1822 * _gtk_path_bar_down:
1823 * @path_bar: a #GtkPathBar
1825 * If the selected button in the pathbar is not the furthest button "down" (in the
1826 * leaf direction), act as if the user clicked on the next button down.
1829 _gtk_path_bar_down (GtkPathBar *path_bar)
1833 for (l = path_bar->button_list; l; l = l->next)
1835 GtkWidget *button = BUTTON_DATA (l->data)->button;
1836 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1840 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1841 button_clicked_cb (prev_button, l->prev->data);