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;
235 /* container_class->child_type = gtk_path_bar_child_type;*/
237 path_bar_signals [PATH_CLICKED] =
238 g_signal_new (I_("path-clicked"),
239 G_OBJECT_CLASS_TYPE (gobject_class),
241 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
243 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
252 gtk_path_bar_finalize (GObject *object)
254 GtkPathBar *path_bar;
256 path_bar = GTK_PATH_BAR (object);
258 gtk_path_bar_stop_scrolling (path_bar);
260 g_list_free (path_bar->button_list);
261 if (path_bar->root_file)
262 g_object_unref (path_bar->root_file);
263 if (path_bar->home_file)
264 g_object_unref (path_bar->home_file);
265 if (path_bar->desktop_file)
266 g_object_unref (path_bar->desktop_file);
268 if (path_bar->root_icon)
269 g_object_unref (path_bar->root_icon);
270 if (path_bar->home_icon)
271 g_object_unref (path_bar->home_icon);
272 if (path_bar->desktop_icon)
273 g_object_unref (path_bar->desktop_icon);
275 if (path_bar->file_system)
276 g_object_unref (path_bar->file_system);
278 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
281 /* Removes the settings signal handler. It's safe to call multiple times */
283 remove_settings_signal (GtkPathBar *path_bar,
286 if (path_bar->settings_signal_id)
288 GtkSettings *settings;
290 settings = gtk_settings_get_for_screen (screen);
291 g_signal_handler_disconnect (settings,
292 path_bar->settings_signal_id);
293 path_bar->settings_signal_id = 0;
298 gtk_path_bar_dispose (GObject *object)
300 GtkPathBar *path_bar = GTK_PATH_BAR (object);
302 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
304 if (path_bar->get_info_cancellable)
305 g_cancellable_cancel (path_bar->get_info_cancellable);
306 path_bar->get_info_cancellable = NULL;
308 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
313 * Ideally, our size is determined by another widget, and we are just filling
317 gtk_path_bar_size_request (GtkWidget *widget,
318 GtkRequisition *requisition)
320 ButtonData *button_data;
321 GtkPathBar *path_bar;
322 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);
359 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
360 requisition->width += border_width * 2;
361 requisition->height += border_width * 2;
365 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
367 if (path_bar->button_list)
371 button = BUTTON_DATA (path_bar->button_list->data)->button;
372 if (gtk_widget_get_child_visible (button))
374 gtk_path_bar_stop_scrolling (path_bar);
375 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
378 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
380 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
381 if (gtk_widget_get_child_visible (button))
383 gtk_path_bar_stop_scrolling (path_bar);
384 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
387 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
392 gtk_path_bar_map (GtkWidget *widget)
394 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
396 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
400 gtk_path_bar_unmap (GtkWidget *widget)
402 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
403 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
405 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
409 gtk_path_bar_realize (GtkWidget *widget)
411 GtkPathBar *path_bar;
412 GtkAllocation allocation;
414 GdkWindowAttr attributes;
415 gint attributes_mask;
417 gtk_widget_set_realized (widget, TRUE);
419 path_bar = GTK_PATH_BAR (widget);
420 window = gtk_widget_get_parent_window (widget);
421 gtk_widget_set_window (widget, window);
422 g_object_ref (window);
424 gtk_widget_get_allocation (widget, &allocation);
426 attributes.window_type = GDK_WINDOW_CHILD;
427 attributes.x = allocation.x;
428 attributes.y = allocation.y;
429 attributes.width = allocation.width;
430 attributes.height = allocation.height;
431 attributes.wclass = GDK_INPUT_ONLY;
432 attributes.event_mask = gtk_widget_get_events (widget);
433 attributes.event_mask |= GDK_SCROLL_MASK;
434 attributes_mask = GDK_WA_X | GDK_WA_Y;
436 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
437 &attributes, attributes_mask);
438 gdk_window_set_user_data (path_bar->event_window, widget);
440 gtk_widget_style_attach (widget);
444 gtk_path_bar_unrealize (GtkWidget *widget)
446 GtkPathBar *path_bar;
448 path_bar = GTK_PATH_BAR (widget);
450 gdk_window_set_user_data (path_bar->event_window, NULL);
451 gdk_window_destroy (path_bar->event_window);
452 path_bar->event_window = NULL;
454 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
457 /* This is a tad complicated
460 gtk_path_bar_size_allocate (GtkWidget *widget,
461 GtkAllocation *allocation)
464 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
465 GtkTextDirection direction;
466 GtkAllocation child_allocation;
467 GList *list, *first_button;
469 gint allocation_width;
471 gboolean need_sliders = FALSE;
472 gint up_slider_offset = 0;
473 GtkRequisition child_requisition;
475 gtk_widget_set_allocation (widget, allocation);
477 if (gtk_widget_get_realized (widget))
478 gdk_window_move_resize (path_bar->event_window,
479 allocation->x, allocation->y,
480 allocation->width, allocation->height);
482 /* No path is set; we don't have to allocate anything. */
483 if (path_bar->button_list == NULL)
486 direction = gtk_widget_get_direction (widget);
487 border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar));
488 allocation_width = allocation->width - 2 * border_width;
490 /* First, we check to see if we need the scrollbars. */
491 if (path_bar->fake_root)
492 width = path_bar->spacing + path_bar->slider_width;
496 for (list = path_bar->button_list; list; list = list->next)
498 child = BUTTON_DATA (list->data)->button;
500 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
502 width += child_requisition.width + path_bar->spacing;
503 if (list == path_bar->fake_root)
507 if (width <= allocation_width)
509 if (path_bar->fake_root)
510 first_button = path_bar->fake_root;
512 first_button = g_list_last (path_bar->button_list);
516 gboolean reached_end = FALSE;
517 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
519 if (path_bar->first_scrolled_button)
520 first_button = path_bar->first_scrolled_button;
522 first_button = path_bar->button_list;
525 /* To see how much space we have, and how many buttons we can display.
526 * We start at the first button, count forward until hit the new
527 * button, then count backwards.
529 /* Count down the path chain towards the end. */
530 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
531 &child_requisition, NULL);
533 width = child_requisition.width;
534 list = first_button->prev;
535 while (list && !reached_end)
537 child = BUTTON_DATA (list->data)->button;
539 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
541 if (width + child_requisition.width +
542 path_bar->spacing + slider_space > allocation_width)
544 else if (list == path_bar->fake_root)
547 width += child_requisition.width + path_bar->spacing;
552 /* Finally, we walk up, seeing how many of the previous buttons we can
554 while (first_button->next && !reached_end)
556 child = BUTTON_DATA (first_button->next->data)->button;
558 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
560 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
566 width += child_requisition.width + path_bar->spacing;
567 if (first_button == path_bar->fake_root)
569 first_button = first_button->next;
574 /* Now, we allocate space to the buttons */
575 child_allocation.y = allocation->y + border_width;
576 child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
578 if (direction == GTK_TEXT_DIR_RTL)
580 child_allocation.x = allocation->x + allocation->width - border_width;
581 if (need_sliders || path_bar->fake_root)
583 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
584 up_slider_offset = allocation->width - border_width - path_bar->slider_width;
589 child_allocation.x = allocation->x + border_width;
590 if (need_sliders || path_bar->fake_root)
592 up_slider_offset = border_width;
593 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
597 for (list = first_button; list; list = list->prev)
599 GtkAllocation widget_allocation;
600 ButtonData *button_data;
602 button_data = BUTTON_DATA (list->data);
603 child = button_data->button;
605 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
607 child_allocation.width = MIN (child_requisition.width,
608 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
610 if (direction == GTK_TEXT_DIR_RTL)
611 child_allocation.x -= child_allocation.width;
613 /* Check to see if we've don't have any more space to allocate buttons */
614 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
616 gtk_widget_get_allocation (widget, &widget_allocation);
617 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x + border_width)
620 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
622 gtk_widget_get_allocation (widget, &widget_allocation);
623 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
624 widget_allocation.x + border_width + allocation_width)
628 if (child_allocation.width < child_requisition.width)
630 if (!gtk_widget_get_has_tooltip (child))
631 gtk_widget_set_tooltip_text (child, button_data->dir_name);
633 else if (gtk_widget_get_has_tooltip (child))
634 gtk_widget_set_tooltip_text (child, NULL);
636 gtk_widget_set_child_visible (child, TRUE);
637 gtk_widget_size_allocate (child, &child_allocation);
639 if (direction == GTK_TEXT_DIR_RTL)
640 child_allocation.x -= path_bar->spacing;
642 child_allocation.x += child_allocation.width + path_bar->spacing;
644 /* Now we go hide all the widgets that don't fit */
647 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
650 for (list = first_button->next; list; list = list->next)
652 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
655 if (need_sliders || path_bar->fake_root)
657 child_allocation.width = path_bar->slider_width;
658 child_allocation.x = up_slider_offset + allocation->x;
659 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
661 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
662 gtk_widget_show_all (path_bar->up_slider_button);
665 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
669 child_allocation.width = path_bar->slider_width;
671 if (direction == GTK_TEXT_DIR_RTL)
672 child_allocation.x = border_width;
674 child_allocation.x = allocation->width - border_width - path_bar->slider_width;
676 child_allocation.x += allocation->x;
678 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
680 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
681 gtk_widget_show_all (path_bar->down_slider_button);
682 gtk_path_bar_update_slider_buttons (path_bar);
685 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
689 gtk_path_bar_style_set (GtkWidget *widget,
690 GtkStyle *previous_style)
692 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
694 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
698 gtk_path_bar_screen_changed (GtkWidget *widget,
699 GdkScreen *previous_screen)
701 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
702 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
704 /* We might nave a new settings, so we remove the old one */
706 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
708 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
712 gtk_path_bar_scroll (GtkWidget *widget,
713 GdkEventScroll *event)
715 switch (event->direction)
717 case GDK_SCROLL_RIGHT:
718 case GDK_SCROLL_DOWN:
719 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
721 case GDK_SCROLL_LEFT:
723 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
731 gtk_path_bar_add (GtkContainer *container,
734 gtk_widget_set_parent (widget, GTK_WIDGET (container));
738 gtk_path_bar_remove_1 (GtkContainer *container,
741 gboolean was_visible = gtk_widget_get_visible (widget);
742 gtk_widget_unparent (widget);
744 gtk_widget_queue_resize (GTK_WIDGET (container));
748 gtk_path_bar_remove (GtkContainer *container,
751 GtkPathBar *path_bar;
754 path_bar = GTK_PATH_BAR (container);
756 if (widget == path_bar->up_slider_button)
758 gtk_path_bar_remove_1 (container, widget);
759 path_bar->up_slider_button = NULL;
763 if (widget == path_bar->down_slider_button)
765 gtk_path_bar_remove_1 (container, widget);
766 path_bar->down_slider_button = NULL;
770 children = path_bar->button_list;
773 if (widget == BUTTON_DATA (children->data)->button)
775 gtk_path_bar_remove_1 (container, widget);
776 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
777 g_list_free (children);
781 children = children->next;
786 gtk_path_bar_forall (GtkContainer *container,
787 gboolean include_internals,
788 GtkCallback callback,
789 gpointer callback_data)
791 GtkPathBar *path_bar;
794 g_return_if_fail (callback != NULL);
795 path_bar = GTK_PATH_BAR (container);
797 children = path_bar->button_list;
801 child = BUTTON_DATA (children->data)->button;
802 children = children->next;
804 (* callback) (child, callback_data);
807 if (path_bar->up_slider_button)
808 (* callback) (path_bar->up_slider_button, callback_data);
810 if (path_bar->down_slider_button)
811 (* callback) (path_bar->down_slider_button, callback_data);
815 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
817 GtkAllocation allocation, button_allocation;
819 GList *down_button = NULL;
820 gint space_available;
822 if (path_bar->ignore_click)
824 path_bar->ignore_click = FALSE;
828 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
830 /* Return if the last button is already visible */
834 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
836 /* We find the button at the 'down' end that we have to make
838 for (list = path_bar->button_list; list; list = list->next)
840 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
847 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
848 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
850 space_available = (allocation.width
851 - 2 * gtk_container_get_border_width (GTK_CONTAINER (path_bar))
852 - 2 * path_bar->spacing - 2 * path_bar->slider_width
853 - button_allocation.width);
854 path_bar->first_scrolled_button = down_button;
856 /* We have space_available free space that's not being used.
857 * So we walk down from the end, adding buttons until we use all free space.
859 while (space_available > 0)
861 path_bar->first_scrolled_button = down_button;
862 down_button = down_button->next;
865 space_available -= (button_allocation.width
866 + path_bar->spacing);
871 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
875 if (path_bar->ignore_click)
877 path_bar->ignore_click = FALSE;
881 list = g_list_last (path_bar->button_list);
883 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
885 /* Return if the first button is already visible */
889 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
891 for ( ; list; list = list->prev)
893 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
895 if (list->prev == path_bar->fake_root)
896 path_bar->fake_root = NULL;
897 path_bar->first_scrolled_button = list;
904 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
906 gboolean retval = FALSE;
910 if (path_bar->scrolling_up)
911 gtk_path_bar_scroll_up (path_bar);
912 else if (path_bar->scrolling_down)
913 gtk_path_bar_scroll_down (path_bar);
915 if (path_bar->need_timer)
917 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
920 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
922 path_bar->need_timer = FALSE;
924 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
925 (GSourceFunc)gtk_path_bar_scroll_timeout,
936 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
940 g_source_remove (path_bar->timer);
942 path_bar->need_timer = FALSE;
947 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
948 GdkEventButton *event,
949 GtkPathBar *path_bar)
952 GList *up_button = NULL;
954 if (event->type != GDK_FOCUS_CHANGE)
957 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
959 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
966 /* don't let the focus vanish */
967 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
968 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
969 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
975 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
976 GdkEventButton *event,
977 GtkPathBar *path_bar)
980 GList *down_button = NULL;
982 if (event->type != GDK_FOCUS_CHANGE)
985 for (list = path_bar->button_list; list; list = list->next)
987 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
994 /* don't let the focus vanish */
995 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
996 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
997 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1003 gtk_path_bar_slider_button_press (GtkWidget *widget,
1004 GdkEventButton *event,
1005 GtkPathBar *path_bar)
1007 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1010 path_bar->ignore_click = FALSE;
1012 if (widget == path_bar->up_slider_button)
1014 path_bar->scrolling_down = FALSE;
1015 path_bar->scrolling_up = TRUE;
1016 gtk_path_bar_scroll_up (path_bar);
1018 else if (widget == path_bar->down_slider_button)
1020 path_bar->scrolling_up = FALSE;
1021 path_bar->scrolling_down = TRUE;
1022 gtk_path_bar_scroll_down (path_bar);
1025 if (!path_bar->timer)
1027 GtkSettings *settings = gtk_widget_get_settings (widget);
1030 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1032 path_bar->need_timer = TRUE;
1033 path_bar->timer = gdk_threads_add_timeout (timeout,
1034 (GSourceFunc)gtk_path_bar_scroll_timeout,
1042 gtk_path_bar_slider_button_release (GtkWidget *widget,
1043 GdkEventButton *event,
1044 GtkPathBar *path_bar)
1046 if (event->type != GDK_BUTTON_RELEASE)
1049 path_bar->ignore_click = TRUE;
1050 gtk_path_bar_stop_scrolling (path_bar);
1056 gtk_path_bar_grab_notify (GtkWidget *widget,
1057 gboolean was_grabbed)
1060 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1064 gtk_path_bar_state_changed (GtkWidget *widget,
1065 GtkStateType previous_state)
1067 if (!gtk_widget_is_sensitive (widget))
1068 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1072 /* Changes the icons wherever it is needed */
1074 reload_icons (GtkPathBar *path_bar)
1078 if (path_bar->root_icon)
1080 g_object_unref (path_bar->root_icon);
1081 path_bar->root_icon = NULL;
1083 if (path_bar->home_icon)
1085 g_object_unref (path_bar->home_icon);
1086 path_bar->home_icon = NULL;
1088 if (path_bar->desktop_icon)
1090 g_object_unref (path_bar->desktop_icon);
1091 path_bar->desktop_icon = NULL;
1094 for (list = path_bar->button_list; list; list = list->next)
1096 ButtonData *button_data;
1097 gboolean current_dir;
1099 button_data = BUTTON_DATA (list->data);
1100 if (button_data->type != NORMAL_BUTTON)
1102 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1103 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1110 change_icon_theme (GtkPathBar *path_bar)
1112 GtkSettings *settings;
1115 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1117 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1118 path_bar->icon_size = MAX (width, height);
1120 path_bar->icon_size = FALLBACK_ICON_SIZE;
1122 reload_icons (path_bar);
1124 /* Callback used when a GtkSettings value changes */
1126 settings_notify_cb (GObject *object,
1128 GtkPathBar *path_bar)
1132 name = g_param_spec_get_name (pspec);
1134 if (! strcmp (name, "gtk-icon-theme-name") ||
1135 ! strcmp (name, "gtk-icon-sizes"))
1136 change_icon_theme (path_bar);
1140 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1142 GtkSettings *settings;
1144 if (path_bar->settings_signal_id)
1147 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1148 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1150 change_icon_theme (path_bar);
1153 /* Public functions and their helpers */
1155 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1157 while (path_bar->button_list != NULL)
1159 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1161 path_bar->first_scrolled_button = NULL;
1162 path_bar->fake_root = NULL;
1166 button_clicked_cb (GtkWidget *button,
1169 ButtonData *button_data;
1170 GtkPathBar *path_bar;
1172 gboolean child_is_hidden;
1175 button_data = BUTTON_DATA (data);
1176 if (button_data->ignore_changes)
1179 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1181 button_list = g_list_find (path_bar->button_list, button_data);
1182 g_assert (button_list != NULL);
1184 g_signal_handlers_block_by_func (button,
1185 G_CALLBACK (button_clicked_cb), data);
1186 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1187 g_signal_handlers_unblock_by_func (button,
1188 G_CALLBACK (button_clicked_cb), data);
1190 if (button_list->prev)
1192 ButtonData *child_data;
1194 child_data = BUTTON_DATA (button_list->prev->data);
1195 child_file = child_data->file;
1196 child_is_hidden = child_data->file_is_hidden;
1201 child_is_hidden = FALSE;
1204 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1205 button_data->file, child_file, child_is_hidden);
1208 struct SetButtonImageData
1210 GtkPathBar *path_bar;
1211 ButtonData *button_data;
1215 set_button_image_get_info_cb (GCancellable *cancellable,
1217 const GError *error,
1220 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1222 struct SetButtonImageData *data = user_data;
1224 if (cancellable != data->button_data->cancellable)
1227 data->button_data->cancellable = NULL;
1229 if (!data->button_data->button)
1231 g_free (data->button_data);
1235 if (cancelled || error)
1238 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1239 data->path_bar->icon_size);
1240 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1242 switch (data->button_data->type)
1245 if (data->path_bar->home_icon)
1246 g_object_unref (pixbuf);
1248 data->path_bar->home_icon = pixbuf;
1251 case DESKTOP_BUTTON:
1252 if (data->path_bar->desktop_icon)
1253 g_object_unref (pixbuf);
1255 data->path_bar->desktop_icon = pixbuf;
1264 g_object_unref (cancellable);
1268 set_button_image (GtkPathBar *path_bar,
1269 ButtonData *button_data)
1271 GtkFileSystemVolume *volume;
1272 struct SetButtonImageData *data;
1274 switch (button_data->type)
1278 if (path_bar->root_icon != NULL)
1280 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1284 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1288 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1289 GTK_WIDGET (path_bar),
1290 path_bar->icon_size,
1292 _gtk_file_system_volume_unref (volume);
1294 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1298 if (path_bar->home_icon != NULL)
1300 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1304 data = g_new0 (struct SetButtonImageData, 1);
1305 data->path_bar = path_bar;
1306 data->button_data = button_data;
1308 if (button_data->cancellable)
1309 g_cancellable_cancel (button_data->cancellable);
1311 button_data->cancellable =
1312 _gtk_file_system_get_info (path_bar->file_system,
1313 path_bar->home_file,
1315 set_button_image_get_info_cb,
1319 case DESKTOP_BUTTON:
1320 if (path_bar->desktop_icon != NULL)
1322 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1326 data = g_new0 (struct SetButtonImageData, 1);
1327 data->path_bar = path_bar;
1328 data->button_data = button_data;
1330 if (button_data->cancellable)
1331 g_cancellable_cancel (button_data->cancellable);
1333 button_data->cancellable =
1334 _gtk_file_system_get_info (path_bar->file_system,
1335 path_bar->desktop_file,
1337 set_button_image_get_info_cb,
1346 button_data_free (ButtonData *button_data)
1348 if (button_data->file)
1349 g_object_unref (button_data->file);
1350 button_data->file = NULL;
1352 g_free (button_data->dir_name);
1353 button_data->dir_name = NULL;
1355 button_data->button = NULL;
1357 if (button_data->cancellable)
1358 g_cancellable_cancel (button_data->cancellable);
1360 g_free (button_data);
1364 get_dir_name (ButtonData *button_data)
1366 return button_data->dir_name;
1369 /* We always want to request the same size for the label, whether
1370 * or not the contents are bold
1373 label_size_request_cb (GtkWidget *widget,
1374 GtkRequisition *requisition,
1375 ButtonData *button_data)
1377 const gchar *dir_name = get_dir_name (button_data);
1378 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1379 gint bold_width, bold_height;
1382 pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1384 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1385 pango_layout_set_markup (layout, markup, -1);
1388 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1389 requisition->width = MAX (requisition->width, bold_width);
1390 requisition->height = MAX (requisition->height, bold_height);
1392 g_object_unref (layout);
1396 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1397 ButtonData *button_data,
1398 gboolean current_dir)
1400 const gchar *dir_name = get_dir_name (button_data);
1402 if (button_data->label != NULL)
1408 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1409 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1414 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1418 if (button_data->image != NULL)
1420 set_button_image (path_bar, button_data);
1423 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1425 button_data->ignore_changes = TRUE;
1426 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1427 button_data->ignore_changes = FALSE;
1432 find_button_type (GtkPathBar *path_bar,
1435 if (path_bar->root_file != NULL &&
1436 g_file_equal (file, path_bar->root_file))
1438 if (path_bar->home_file != NULL &&
1439 g_file_equal (file, path_bar->home_file))
1441 if (path_bar->desktop_file != NULL &&
1442 g_file_equal (file, path_bar->desktop_file))
1443 return DESKTOP_BUTTON;
1445 return NORMAL_BUTTON;
1449 button_drag_data_get_cb (GtkWidget *widget,
1450 GdkDragContext *context,
1451 GtkSelectionData *selection_data,
1456 ButtonData *button_data;
1457 GtkPathBar *path_bar;
1461 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
1463 uris[0] = g_file_get_uri (button_data->file);
1466 gtk_selection_data_set_uris (selection_data, uris);
1471 make_directory_button (GtkPathBar *path_bar,
1472 const char *dir_name,
1474 gboolean current_dir,
1475 gboolean file_is_hidden)
1478 GtkWidget *child = NULL;
1479 GtkWidget *label_alignment = NULL;
1480 ButtonData *button_data;
1482 file_is_hidden = !! file_is_hidden;
1483 /* Is it a special button? */
1484 button_data = g_new0 (ButtonData, 1);
1486 button_data->type = find_button_type (path_bar, file);
1487 button_data->button = gtk_toggle_button_new ();
1488 atk_obj = gtk_widget_get_accessible (button_data->button);
1489 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1491 switch (button_data->type)
1494 button_data->image = gtk_image_new ();
1495 child = button_data->image;
1496 button_data->label = NULL;
1497 atk_object_set_name (atk_obj, _("File System Root"));
1500 case DESKTOP_BUTTON:
1501 button_data->image = gtk_image_new ();
1502 button_data->label = gtk_label_new (NULL);
1503 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1504 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1505 child = gtk_hbox_new (FALSE, 2);
1506 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1507 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1511 button_data->label = gtk_label_new (NULL);
1512 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1513 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1514 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1515 child = label_alignment;
1516 button_data->image = NULL;
1519 /* label_alignment is created because we can't override size-request
1520 * on label itself and still have the contents of the label centered
1521 * properly in the label's requisition
1523 if (label_alignment)
1524 g_signal_connect (label_alignment, "size-request",
1525 G_CALLBACK (label_size_request_cb), button_data);
1527 button_data->dir_name = g_strdup (dir_name);
1528 button_data->file = g_object_ref (file);
1529 button_data->file_is_hidden = file_is_hidden;
1531 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1532 gtk_widget_show_all (button_data->button);
1534 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1536 g_signal_connect (button_data->button, "clicked",
1537 G_CALLBACK (button_clicked_cb),
1539 g_object_weak_ref (G_OBJECT (button_data->button),
1540 (GWeakNotify) button_data_free, button_data);
1542 gtk_drag_source_set (button_data->button,
1546 gtk_drag_source_add_uri_targets (button_data->button);
1547 g_signal_connect (button_data->button, "drag-data-get",
1548 G_CALLBACK (button_drag_data_get_cb), button_data);
1554 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1556 GtkFileSystem *file_system)
1559 GList *current_path = NULL;
1560 gboolean need_new_fake_root = FALSE;
1562 for (list = path_bar->button_list; list; list = list->next)
1564 ButtonData *button_data;
1566 button_data = list->data;
1567 if (g_file_equal (file, button_data->file))
1569 current_path = list;
1572 if (list == path_bar->fake_root)
1573 need_new_fake_root = TRUE;
1578 if (need_new_fake_root)
1580 path_bar->fake_root = NULL;
1581 for (list = current_path; list; list = list->next)
1583 ButtonData *button_data;
1585 button_data = list->data;
1586 if (BUTTON_IS_FAKE_ROOT (button_data))
1588 path_bar->fake_root = list;
1594 for (list = path_bar->button_list; list; list = list->next)
1596 gtk_path_bar_update_button_appearance (path_bar,
1597 BUTTON_DATA (list->data),
1598 (list == current_path) ? TRUE : FALSE);
1601 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1603 path_bar->first_scrolled_button = current_path;
1604 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1617 GtkPathBar *path_bar;
1620 gboolean first_directory;
1624 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1631 gtk_path_bar_clear_buttons (info->path_bar);
1632 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1633 info->path_bar->fake_root = info->fake_root;
1635 for (l = info->path_bar->button_list; l; l = l->next)
1637 GtkWidget *button = BUTTON_DATA (l->data)->button;
1638 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1645 for (l = info->new_buttons; l; l = l->next)
1647 ButtonData *button_data;
1649 button_data = BUTTON_DATA (l->data);
1650 gtk_widget_destroy (button_data->button);
1653 g_list_free (info->new_buttons);
1657 g_object_unref (info->file);
1658 if (info->parent_file)
1659 g_object_unref (info->parent_file);
1664 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1666 const GError *error,
1669 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1670 struct SetFileInfo *file_info = data;
1671 ButtonData *button_data;
1672 const gchar *display_name;
1675 if (cancellable != file_info->path_bar->get_info_cancellable)
1677 gtk_path_bar_set_file_finish (file_info, FALSE);
1678 g_object_unref (cancellable);
1682 g_object_unref (cancellable);
1683 file_info->path_bar->get_info_cancellable = NULL;
1685 if (cancelled || !info)
1687 gtk_path_bar_set_file_finish (file_info, FALSE);
1691 display_name = g_file_info_get_display_name (info);
1692 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1694 gtk_widget_push_composite_child ();
1695 button_data = make_directory_button (file_info->path_bar, display_name,
1697 file_info->first_directory, is_hidden);
1698 gtk_widget_pop_composite_child ();
1699 g_object_unref (file_info->file);
1701 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1703 if (BUTTON_IS_FAKE_ROOT (button_data))
1704 file_info->fake_root = file_info->new_buttons;
1706 file_info->file = file_info->parent_file;
1707 file_info->first_directory = FALSE;
1709 if (!file_info->file)
1711 gtk_path_bar_set_file_finish (file_info, TRUE);
1715 file_info->parent_file = g_file_get_parent (file_info->file);
1717 file_info->path_bar->get_info_cancellable =
1718 _gtk_file_system_get_info (file_info->path_bar->file_system,
1720 "standard::display-name,standard::is-hidden,standard::is-backup",
1721 gtk_path_bar_get_info_callback,
1726 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1728 const gboolean keep_trail,
1731 struct SetFileInfo *info;
1734 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1735 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1739 /* Check whether the new path is already present in the pathbar as buttons.
1740 * This could be a parent directory or a previous selected subdirectory.
1743 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1746 info = g_new0 (struct SetFileInfo, 1);
1747 info->file = g_object_ref (file);
1748 info->path_bar = path_bar;
1749 info->first_directory = TRUE;
1750 info->parent_file = g_file_get_parent (info->file);
1752 if (path_bar->get_info_cancellable)
1753 g_cancellable_cancel (path_bar->get_info_cancellable);
1755 path_bar->get_info_cancellable =
1756 _gtk_file_system_get_info (path_bar->file_system,
1758 "standard::display-name,standard::is-hidden,standard::is-backup",
1759 gtk_path_bar_get_info_callback,
1765 /* FIXME: This should be a construct-only property */
1767 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1768 GtkFileSystem *file_system)
1772 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1774 g_assert (path_bar->file_system == NULL);
1776 path_bar->file_system = g_object_ref (file_system);
1778 home = g_get_home_dir ();
1781 const gchar *desktop;
1783 path_bar->home_file = g_file_new_for_path (home);
1784 /* FIXME: Need file system backend specific way of getting the
1787 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1788 if (desktop != NULL)
1789 path_bar->desktop_file = g_file_new_for_path (desktop);
1791 path_bar->desktop_file = NULL;
1795 path_bar->home_file = NULL;
1796 path_bar->desktop_file = NULL;
1798 path_bar->root_file = g_file_new_for_path ("/");
1803 * @path_bar: a #GtkPathBar
1805 * If the selected button in the pathbar is not the furthest button "up" (in the
1806 * root direction), act as if the user clicked on the next button up.
1809 _gtk_path_bar_up (GtkPathBar *path_bar)
1813 for (l = path_bar->button_list; l; l = l->next)
1815 GtkWidget *button = BUTTON_DATA (l->data)->button;
1816 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1820 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1821 button_clicked_cb (next_button, l->next->data);
1829 * _gtk_path_bar_down:
1830 * @path_bar: a #GtkPathBar
1832 * If the selected button in the pathbar is not the furthest button "down" (in the
1833 * leaf direction), act as if the user clicked on the next button down.
1836 _gtk_path_bar_down (GtkPathBar *path_bar)
1840 for (l = path_bar->button_list; l; l = l->next)
1842 GtkWidget *button = BUTTON_DATA (l->data)->button;
1843 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1847 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1848 button_clicked_cb (prev_button, l->prev->data);