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"
32 #include "gtkicontheme.h"
33 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
52 #define BUTTON_DATA(x) ((ButtonData *)(x))
54 #define SCROLL_DELAY_FACTOR 5
56 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
58 /* Icon size for if we can't get it from the theme */
59 #define FALLBACK_ICON_SIZE 16
61 typedef struct _ButtonData ButtonData;
71 GCancellable *cancellable;
72 guint ignore_changes : 1;
73 guint file_is_hidden : 1;
75 /* This macro is used to check if a button can be used as a fake root.
76 * All buttons in front of a fake root are automatically hidden when in a
77 * directory below a fake root and replaced with the "<" arrow button.
79 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
81 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
83 static void gtk_path_bar_finalize (GObject *object);
84 static void gtk_path_bar_dispose (GObject *object);
85 static void gtk_path_bar_realize (GtkWidget *widget);
86 static void gtk_path_bar_unrealize (GtkWidget *widget);
87 static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
90 static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
93 static void gtk_path_bar_map (GtkWidget *widget);
94 static void gtk_path_bar_unmap (GtkWidget *widget);
95 static void gtk_path_bar_size_allocate (GtkWidget *widget,
96 GtkAllocation *allocation);
97 static void gtk_path_bar_add (GtkContainer *container,
99 static void gtk_path_bar_remove (GtkContainer *container,
101 static void gtk_path_bar_forall (GtkContainer *container,
102 gboolean include_internals,
103 GtkCallback callback,
104 gpointer callback_data);
105 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
106 GdkEventScroll *event);
107 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
108 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
109 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
110 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
111 GdkEventButton *event,
112 GtkPathBar *path_bar);
113 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
114 GdkEventButton *event,
115 GtkPathBar *path_bar);
116 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
117 GdkEventButton *event,
118 GtkPathBar *path_bar);
119 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
120 GdkEventButton *event,
121 GtkPathBar *path_bar);
122 static void gtk_path_bar_grab_notify (GtkWidget *widget,
123 gboolean was_grabbed);
124 static void gtk_path_bar_state_changed (GtkWidget *widget,
125 GtkStateType previous_state);
126 static void gtk_path_bar_style_updated (GtkWidget *widget);
127 static void gtk_path_bar_screen_changed (GtkWidget *widget,
128 GdkScreen *previous_screen);
129 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
130 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
131 ButtonData *button_data,
132 gboolean current_dir);
135 on_slider_unmap (GtkWidget *widget,
136 GtkPathBar *path_bar)
138 if (path_bar->timer &&
139 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
140 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
141 gtk_path_bar_stop_scrolling (path_bar);
145 get_slider_button (GtkPathBar *path_bar,
146 GtkArrowType arrow_type)
151 gtk_widget_push_composite_child ();
153 button = gtk_button_new ();
154 atk_obj = gtk_widget_get_accessible (button);
155 if (arrow_type == GTK_ARROW_LEFT)
156 atk_object_set_name (atk_obj, _("Up Path"));
158 atk_object_set_name (atk_obj, _("Down Path"));
160 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
161 gtk_container_add (GTK_CONTAINER (button),
162 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
163 gtk_container_add (GTK_CONTAINER (path_bar), button);
164 gtk_widget_show_all (button);
166 g_signal_connect (G_OBJECT (button), "unmap",
167 G_CALLBACK (on_slider_unmap), path_bar);
169 gtk_widget_pop_composite_child ();
175 gtk_path_bar_init (GtkPathBar *path_bar)
177 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
178 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
180 path_bar->get_info_cancellable = NULL;
182 path_bar->spacing = 0;
183 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
184 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
185 path_bar->icon_size = FALLBACK_ICON_SIZE;
187 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
188 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
189 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
190 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
192 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
193 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
194 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
195 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
197 g_signal_connect (path_bar->up_slider_button, "button-press-event",
198 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
199 g_signal_connect (path_bar->up_slider_button, "button-release-event",
200 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
201 g_signal_connect (path_bar->down_slider_button, "button-press-event",
202 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
203 g_signal_connect (path_bar->down_slider_button, "button-release-event",
204 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
208 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
210 GObjectClass *gobject_class;
211 GtkWidgetClass *widget_class;
212 GtkContainerClass *container_class;
214 gobject_class = (GObjectClass *) 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->get_preferred_width = gtk_path_bar_get_preferred_width;
222 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
223 widget_class->realize = gtk_path_bar_realize;
224 widget_class->unrealize = gtk_path_bar_unrealize;
225 widget_class->map = gtk_path_bar_map;
226 widget_class->unmap = gtk_path_bar_unmap;
227 widget_class->size_allocate = gtk_path_bar_size_allocate;
228 widget_class->style_updated = gtk_path_bar_style_updated;
229 widget_class->screen_changed = gtk_path_bar_screen_changed;
230 widget_class->grab_notify = gtk_path_bar_grab_notify;
231 widget_class->state_changed = gtk_path_bar_state_changed;
232 widget_class->scroll_event = gtk_path_bar_scroll;
234 container_class->add = gtk_path_bar_add;
235 container_class->forall = gtk_path_bar_forall;
236 container_class->remove = gtk_path_bar_remove;
237 gtk_container_class_handle_border_width (container_class);
239 /* container_class->child_type = gtk_path_bar_child_type;*/
241 path_bar_signals [PATH_CLICKED] =
242 g_signal_new (I_("path-clicked"),
243 G_OBJECT_CLASS_TYPE (gobject_class),
245 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
247 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
256 gtk_path_bar_finalize (GObject *object)
258 GtkPathBar *path_bar;
260 path_bar = GTK_PATH_BAR (object);
262 gtk_path_bar_stop_scrolling (path_bar);
264 g_list_free (path_bar->button_list);
265 if (path_bar->root_file)
266 g_object_unref (path_bar->root_file);
267 if (path_bar->home_file)
268 g_object_unref (path_bar->home_file);
269 if (path_bar->desktop_file)
270 g_object_unref (path_bar->desktop_file);
272 if (path_bar->root_icon)
273 g_object_unref (path_bar->root_icon);
274 if (path_bar->home_icon)
275 g_object_unref (path_bar->home_icon);
276 if (path_bar->desktop_icon)
277 g_object_unref (path_bar->desktop_icon);
279 if (path_bar->file_system)
280 g_object_unref (path_bar->file_system);
282 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
285 /* Removes the settings signal handler. It's safe to call multiple times */
287 remove_settings_signal (GtkPathBar *path_bar,
290 if (path_bar->settings_signal_id)
292 GtkSettings *settings;
294 settings = gtk_settings_get_for_screen (screen);
295 g_signal_handler_disconnect (settings,
296 path_bar->settings_signal_id);
297 path_bar->settings_signal_id = 0;
302 gtk_path_bar_dispose (GObject *object)
304 GtkPathBar *path_bar = GTK_PATH_BAR (object);
306 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
308 if (path_bar->get_info_cancellable)
309 g_cancellable_cancel (path_bar->get_info_cancellable);
310 path_bar->get_info_cancellable = NULL;
312 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
317 * Ideally, our size is determined by another widget, and we are just filling
321 gtk_path_bar_get_preferred_width (GtkWidget *widget,
325 ButtonData *button_data;
326 GtkPathBar *path_bar;
330 gint child_min, child_nat;
332 path_bar = GTK_PATH_BAR (widget);
334 *minimum = *natural = 0;
337 for (list = path_bar->button_list; list; list = list->next)
339 button_data = BUTTON_DATA (list->data);
340 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
341 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
342 height = MAX (height, child_height);
344 if (button_data->type == NORMAL_BUTTON)
346 /* Use 2*Height as button width because of ellipsized label. */
347 child_min = MAX (child_min, child_height * 2);
348 child_nat = MAX (child_min, child_height * 2);
351 *minimum = MAX (*minimum, child_min);
352 *natural = MAX (*natural, child_nat);
355 /* Add space for slider, if we have more than one path */
356 /* Theoretically, the slider could be bigger than the other button. But we're
357 * not going to worry about that now.
359 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
360 if (path_bar->button_list && path_bar->button_list->next != NULL)
362 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
363 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
368 gtk_path_bar_get_preferred_height (GtkWidget *widget,
372 ButtonData *button_data;
373 GtkPathBar *path_bar;
375 gint child_min, child_nat;
377 path_bar = GTK_PATH_BAR (widget);
379 *minimum = *natural = 0;
381 for (list = path_bar->button_list; list; list = list->next)
383 button_data = BUTTON_DATA (list->data);
384 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
386 *minimum = MAX (*minimum, child_min);
387 *natural = MAX (*natural, child_nat);
392 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
394 if (path_bar->button_list)
398 button = BUTTON_DATA (path_bar->button_list->data)->button;
399 if (gtk_widget_get_child_visible (button))
401 gtk_path_bar_stop_scrolling (path_bar);
402 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
405 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
407 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
408 if (gtk_widget_get_child_visible (button))
410 gtk_path_bar_stop_scrolling (path_bar);
411 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
414 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
419 gtk_path_bar_map (GtkWidget *widget)
421 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
423 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
427 gtk_path_bar_unmap (GtkWidget *widget)
429 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
430 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
432 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
436 gtk_path_bar_realize (GtkWidget *widget)
438 GtkPathBar *path_bar;
439 GtkAllocation allocation;
441 GdkWindowAttr attributes;
442 gint attributes_mask;
444 gtk_widget_set_realized (widget, TRUE);
446 path_bar = GTK_PATH_BAR (widget);
447 window = gtk_widget_get_parent_window (widget);
448 gtk_widget_set_window (widget, window);
449 g_object_ref (window);
451 gtk_widget_get_allocation (widget, &allocation);
453 attributes.window_type = GDK_WINDOW_CHILD;
454 attributes.x = allocation.x;
455 attributes.y = allocation.y;
456 attributes.width = allocation.width;
457 attributes.height = allocation.height;
458 attributes.wclass = GDK_INPUT_ONLY;
459 attributes.event_mask = gtk_widget_get_events (widget);
460 attributes.event_mask |= GDK_SCROLL_MASK;
461 attributes_mask = GDK_WA_X | GDK_WA_Y;
463 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
464 &attributes, attributes_mask);
465 gdk_window_set_user_data (path_bar->event_window, widget);
469 gtk_path_bar_unrealize (GtkWidget *widget)
471 GtkPathBar *path_bar;
473 path_bar = GTK_PATH_BAR (widget);
475 gdk_window_set_user_data (path_bar->event_window, NULL);
476 gdk_window_destroy (path_bar->event_window);
477 path_bar->event_window = NULL;
479 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
482 /* This is a tad complicated
485 gtk_path_bar_size_allocate (GtkWidget *widget,
486 GtkAllocation *allocation)
489 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
490 GtkTextDirection direction;
491 GtkAllocation child_allocation;
492 GList *list, *first_button;
494 gint allocation_width;
495 gboolean need_sliders = FALSE;
496 gint up_slider_offset = 0;
497 GtkRequisition child_requisition;
499 gtk_widget_set_allocation (widget, allocation);
501 if (gtk_widget_get_realized (widget))
502 gdk_window_move_resize (path_bar->event_window,
503 allocation->x, allocation->y,
504 allocation->width, allocation->height);
506 /* No path is set; we don't have to allocate anything. */
507 if (path_bar->button_list == NULL)
510 direction = gtk_widget_get_direction (widget);
511 allocation_width = allocation->width;
513 /* First, we check to see if we need the scrollbars. */
514 if (path_bar->fake_root)
515 width = path_bar->spacing + path_bar->slider_width;
519 for (list = path_bar->button_list; list; list = list->next)
521 child = BUTTON_DATA (list->data)->button;
523 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
525 width += child_requisition.width + path_bar->spacing;
526 if (list == path_bar->fake_root)
530 if (width <= allocation_width)
532 if (path_bar->fake_root)
533 first_button = path_bar->fake_root;
535 first_button = g_list_last (path_bar->button_list);
539 gboolean reached_end = FALSE;
540 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
542 if (path_bar->first_scrolled_button)
543 first_button = path_bar->first_scrolled_button;
545 first_button = path_bar->button_list;
548 /* To see how much space we have, and how many buttons we can display.
549 * We start at the first button, count forward until hit the new
550 * button, then count backwards.
552 /* Count down the path chain towards the end. */
553 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
554 &child_requisition, NULL);
556 width = child_requisition.width;
557 list = first_button->prev;
558 while (list && !reached_end)
560 child = BUTTON_DATA (list->data)->button;
562 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
564 if (width + child_requisition.width +
565 path_bar->spacing + slider_space > allocation_width)
567 else if (list == path_bar->fake_root)
570 width += child_requisition.width + path_bar->spacing;
575 /* Finally, we walk up, seeing how many of the previous buttons we can
577 while (first_button->next && !reached_end)
579 child = BUTTON_DATA (first_button->next->data)->button;
581 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
583 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
589 width += child_requisition.width + path_bar->spacing;
590 if (first_button == path_bar->fake_root)
592 first_button = first_button->next;
597 /* Now, we allocate space to the buttons */
598 child_allocation.y = allocation->y;
599 child_allocation.height = allocation->height;
601 if (direction == GTK_TEXT_DIR_RTL)
603 child_allocation.x = allocation->x + allocation->width;
604 if (need_sliders || path_bar->fake_root)
606 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
607 up_slider_offset = allocation->width - path_bar->slider_width;
612 child_allocation.x = allocation->x;
613 if (need_sliders || path_bar->fake_root)
615 up_slider_offset = 0;
616 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
620 for (list = first_button; list; list = list->prev)
622 GtkAllocation widget_allocation;
623 ButtonData *button_data;
625 button_data = BUTTON_DATA (list->data);
626 child = button_data->button;
628 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
630 child_allocation.width = MIN (child_requisition.width,
631 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
633 if (direction == GTK_TEXT_DIR_RTL)
634 child_allocation.x -= child_allocation.width;
636 /* Check to see if we've don't have any more space to allocate buttons */
637 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
639 gtk_widget_get_allocation (widget, &widget_allocation);
640 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
643 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
645 gtk_widget_get_allocation (widget, &widget_allocation);
646 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
647 widget_allocation.x + allocation_width)
651 if (child_allocation.width < child_requisition.width)
653 if (!gtk_widget_get_has_tooltip (child))
654 gtk_widget_set_tooltip_text (child, button_data->dir_name);
656 else if (gtk_widget_get_has_tooltip (child))
657 gtk_widget_set_tooltip_text (child, NULL);
659 gtk_widget_set_child_visible (child, TRUE);
660 gtk_widget_size_allocate (child, &child_allocation);
662 if (direction == GTK_TEXT_DIR_RTL)
663 child_allocation.x -= path_bar->spacing;
665 child_allocation.x += child_allocation.width + path_bar->spacing;
667 /* Now we go hide all the widgets that don't fit */
670 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
673 for (list = first_button->next; list; list = list->next)
675 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
678 if (need_sliders || path_bar->fake_root)
680 child_allocation.width = path_bar->slider_width;
681 child_allocation.x = up_slider_offset + allocation->x;
682 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
684 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
685 gtk_widget_show_all (path_bar->up_slider_button);
688 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
692 child_allocation.width = path_bar->slider_width;
694 if (direction == GTK_TEXT_DIR_RTL)
695 child_allocation.x = 0;
697 child_allocation.x = allocation->width - path_bar->slider_width;
699 child_allocation.x += allocation->x;
701 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
703 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
704 gtk_widget_show_all (path_bar->down_slider_button);
705 gtk_path_bar_update_slider_buttons (path_bar);
708 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
712 gtk_path_bar_style_updated (GtkWidget *widget)
714 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
716 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
720 gtk_path_bar_screen_changed (GtkWidget *widget,
721 GdkScreen *previous_screen)
723 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
724 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
726 /* We might nave a new settings, so we remove the old one */
728 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
730 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
734 gtk_path_bar_scroll (GtkWidget *widget,
735 GdkEventScroll *event)
737 switch (event->direction)
739 case GDK_SCROLL_RIGHT:
740 case GDK_SCROLL_DOWN:
741 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
743 case GDK_SCROLL_LEFT:
745 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
753 gtk_path_bar_add (GtkContainer *container,
756 gtk_widget_set_parent (widget, GTK_WIDGET (container));
760 gtk_path_bar_remove_1 (GtkContainer *container,
763 gboolean was_visible = gtk_widget_get_visible (widget);
764 gtk_widget_unparent (widget);
766 gtk_widget_queue_resize (GTK_WIDGET (container));
770 gtk_path_bar_remove (GtkContainer *container,
773 GtkPathBar *path_bar;
776 path_bar = GTK_PATH_BAR (container);
778 if (widget == path_bar->up_slider_button)
780 gtk_path_bar_remove_1 (container, widget);
781 path_bar->up_slider_button = NULL;
785 if (widget == path_bar->down_slider_button)
787 gtk_path_bar_remove_1 (container, widget);
788 path_bar->down_slider_button = NULL;
792 children = path_bar->button_list;
795 if (widget == BUTTON_DATA (children->data)->button)
797 gtk_path_bar_remove_1 (container, widget);
798 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
799 g_list_free (children);
803 children = children->next;
808 gtk_path_bar_forall (GtkContainer *container,
809 gboolean include_internals,
810 GtkCallback callback,
811 gpointer callback_data)
813 GtkPathBar *path_bar;
816 g_return_if_fail (callback != NULL);
817 path_bar = GTK_PATH_BAR (container);
819 children = path_bar->button_list;
823 child = BUTTON_DATA (children->data)->button;
824 children = children->next;
826 (* callback) (child, callback_data);
829 if (path_bar->up_slider_button)
830 (* callback) (path_bar->up_slider_button, callback_data);
832 if (path_bar->down_slider_button)
833 (* callback) (path_bar->down_slider_button, callback_data);
837 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
839 GtkAllocation allocation, button_allocation;
841 GList *down_button = NULL;
842 gint space_available;
844 if (path_bar->ignore_click)
846 path_bar->ignore_click = FALSE;
850 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
852 /* Return if the last button is already visible */
856 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
858 /* We find the button at the 'down' end that we have to make
860 for (list = path_bar->button_list; list; list = list->next)
862 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
869 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
870 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
872 space_available = (allocation.width
873 - 2 * path_bar->spacing - 2 * path_bar->slider_width
874 - button_allocation.width);
875 path_bar->first_scrolled_button = down_button;
877 /* We have space_available free space that's not being used.
878 * So we walk down from the end, adding buttons until we use all free space.
880 while (space_available > 0)
882 path_bar->first_scrolled_button = down_button;
883 down_button = down_button->next;
886 space_available -= (button_allocation.width
887 + path_bar->spacing);
892 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
896 if (path_bar->ignore_click)
898 path_bar->ignore_click = FALSE;
902 list = g_list_last (path_bar->button_list);
904 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
906 /* Return if the first button is already visible */
910 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
912 for ( ; list; list = list->prev)
914 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
916 if (list->prev == path_bar->fake_root)
917 path_bar->fake_root = NULL;
918 path_bar->first_scrolled_button = list;
925 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
927 gboolean retval = FALSE;
931 if (path_bar->scrolling_up)
932 gtk_path_bar_scroll_up (path_bar);
933 else if (path_bar->scrolling_down)
934 gtk_path_bar_scroll_down (path_bar);
936 if (path_bar->need_timer)
938 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
941 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
943 path_bar->need_timer = FALSE;
945 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
946 (GSourceFunc)gtk_path_bar_scroll_timeout,
957 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
961 g_source_remove (path_bar->timer);
963 path_bar->need_timer = FALSE;
968 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
969 GdkEventButton *event,
970 GtkPathBar *path_bar)
973 GList *up_button = NULL;
975 if (event->type != GDK_FOCUS_CHANGE)
978 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
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->up_slider_button)) ||
989 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
990 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
996 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
997 GdkEventButton *event,
998 GtkPathBar *path_bar)
1001 GList *down_button = NULL;
1003 if (event->type != GDK_FOCUS_CHANGE)
1006 for (list = path_bar->button_list; list; list = list->next)
1008 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1015 /* don't let the focus vanish */
1016 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1017 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1018 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1024 gtk_path_bar_slider_button_press (GtkWidget *widget,
1025 GdkEventButton *event,
1026 GtkPathBar *path_bar)
1028 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1031 path_bar->ignore_click = FALSE;
1033 if (widget == path_bar->up_slider_button)
1035 path_bar->scrolling_down = FALSE;
1036 path_bar->scrolling_up = TRUE;
1037 gtk_path_bar_scroll_up (path_bar);
1039 else if (widget == path_bar->down_slider_button)
1041 path_bar->scrolling_up = FALSE;
1042 path_bar->scrolling_down = TRUE;
1043 gtk_path_bar_scroll_down (path_bar);
1046 if (!path_bar->timer)
1048 GtkSettings *settings = gtk_widget_get_settings (widget);
1051 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1053 path_bar->need_timer = TRUE;
1054 path_bar->timer = gdk_threads_add_timeout (timeout,
1055 (GSourceFunc)gtk_path_bar_scroll_timeout,
1063 gtk_path_bar_slider_button_release (GtkWidget *widget,
1064 GdkEventButton *event,
1065 GtkPathBar *path_bar)
1067 if (event->type != GDK_BUTTON_RELEASE)
1070 path_bar->ignore_click = TRUE;
1071 gtk_path_bar_stop_scrolling (path_bar);
1077 gtk_path_bar_grab_notify (GtkWidget *widget,
1078 gboolean was_grabbed)
1081 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1085 gtk_path_bar_state_changed (GtkWidget *widget,
1086 GtkStateType previous_state)
1088 if (!gtk_widget_is_sensitive (widget))
1089 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1093 /* Changes the icons wherever it is needed */
1095 reload_icons (GtkPathBar *path_bar)
1099 if (path_bar->root_icon)
1101 g_object_unref (path_bar->root_icon);
1102 path_bar->root_icon = NULL;
1104 if (path_bar->home_icon)
1106 g_object_unref (path_bar->home_icon);
1107 path_bar->home_icon = NULL;
1109 if (path_bar->desktop_icon)
1111 g_object_unref (path_bar->desktop_icon);
1112 path_bar->desktop_icon = NULL;
1115 for (list = path_bar->button_list; list; list = list->next)
1117 ButtonData *button_data;
1118 gboolean current_dir;
1120 button_data = BUTTON_DATA (list->data);
1121 if (button_data->type != NORMAL_BUTTON)
1123 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1124 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1131 change_icon_theme (GtkPathBar *path_bar)
1133 GtkSettings *settings;
1136 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1138 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1139 path_bar->icon_size = MAX (width, height);
1141 path_bar->icon_size = FALLBACK_ICON_SIZE;
1143 reload_icons (path_bar);
1145 /* Callback used when a GtkSettings value changes */
1147 settings_notify_cb (GObject *object,
1149 GtkPathBar *path_bar)
1153 name = g_param_spec_get_name (pspec);
1155 if (! strcmp (name, "gtk-icon-theme-name") ||
1156 ! strcmp (name, "gtk-icon-sizes"))
1157 change_icon_theme (path_bar);
1161 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1163 GtkSettings *settings;
1165 if (path_bar->settings_signal_id)
1168 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1169 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1171 change_icon_theme (path_bar);
1174 /* Public functions and their helpers */
1176 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1178 while (path_bar->button_list != NULL)
1180 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1182 path_bar->first_scrolled_button = NULL;
1183 path_bar->fake_root = NULL;
1187 button_clicked_cb (GtkWidget *button,
1190 ButtonData *button_data;
1191 GtkPathBar *path_bar;
1193 gboolean child_is_hidden;
1196 button_data = BUTTON_DATA (data);
1197 if (button_data->ignore_changes)
1200 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1202 button_list = g_list_find (path_bar->button_list, button_data);
1203 g_assert (button_list != NULL);
1205 g_signal_handlers_block_by_func (button,
1206 G_CALLBACK (button_clicked_cb), data);
1207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1208 g_signal_handlers_unblock_by_func (button,
1209 G_CALLBACK (button_clicked_cb), data);
1211 if (button_list->prev)
1213 ButtonData *child_data;
1215 child_data = BUTTON_DATA (button_list->prev->data);
1216 child_file = child_data->file;
1217 child_is_hidden = child_data->file_is_hidden;
1222 child_is_hidden = FALSE;
1225 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1226 button_data->file, child_file, child_is_hidden);
1229 struct SetButtonImageData
1231 GtkPathBar *path_bar;
1232 ButtonData *button_data;
1236 set_button_image_get_info_cb (GCancellable *cancellable,
1238 const GError *error,
1241 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1243 struct SetButtonImageData *data = user_data;
1245 if (cancellable != data->button_data->cancellable)
1248 data->button_data->cancellable = NULL;
1250 if (!data->button_data->button)
1252 g_free (data->button_data);
1256 if (cancelled || error)
1259 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1260 data->path_bar->icon_size);
1261 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1263 switch (data->button_data->type)
1266 if (data->path_bar->home_icon)
1267 g_object_unref (pixbuf);
1269 data->path_bar->home_icon = pixbuf;
1272 case DESKTOP_BUTTON:
1273 if (data->path_bar->desktop_icon)
1274 g_object_unref (pixbuf);
1276 data->path_bar->desktop_icon = pixbuf;
1285 g_object_unref (cancellable);
1289 set_button_image (GtkPathBar *path_bar,
1290 ButtonData *button_data)
1292 GtkFileSystemVolume *volume;
1293 struct SetButtonImageData *data;
1295 switch (button_data->type)
1299 if (path_bar->root_icon != NULL)
1301 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1305 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1309 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1310 GTK_WIDGET (path_bar),
1311 path_bar->icon_size,
1313 _gtk_file_system_volume_unref (volume);
1315 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1319 if (path_bar->home_icon != NULL)
1321 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1325 data = g_new0 (struct SetButtonImageData, 1);
1326 data->path_bar = path_bar;
1327 data->button_data = button_data;
1329 if (button_data->cancellable)
1330 g_cancellable_cancel (button_data->cancellable);
1332 button_data->cancellable =
1333 _gtk_file_system_get_info (path_bar->file_system,
1334 path_bar->home_file,
1336 set_button_image_get_info_cb,
1340 case DESKTOP_BUTTON:
1341 if (path_bar->desktop_icon != NULL)
1343 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1347 data = g_new0 (struct SetButtonImageData, 1);
1348 data->path_bar = path_bar;
1349 data->button_data = button_data;
1351 if (button_data->cancellable)
1352 g_cancellable_cancel (button_data->cancellable);
1354 button_data->cancellable =
1355 _gtk_file_system_get_info (path_bar->file_system,
1356 path_bar->desktop_file,
1358 set_button_image_get_info_cb,
1367 button_data_free (ButtonData *button_data)
1369 if (button_data->file)
1370 g_object_unref (button_data->file);
1371 button_data->file = NULL;
1373 g_free (button_data->dir_name);
1374 button_data->dir_name = NULL;
1376 button_data->button = NULL;
1378 if (button_data->cancellable)
1379 g_cancellable_cancel (button_data->cancellable);
1381 g_free (button_data);
1385 get_dir_name (ButtonData *button_data)
1387 return button_data->dir_name;
1390 /* We always want to request the same size for the label, whether
1391 * or not the contents are bold
1394 set_label_size_request (GtkWidget *widget,
1395 ButtonData *button_data)
1397 const gchar *dir_name = get_dir_name (button_data);
1398 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1399 gint width, height, bold_width, bold_height;
1402 pango_layout_get_pixel_size (layout, &width, &height);
1404 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1405 pango_layout_set_markup (layout, markup, -1);
1408 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1410 gtk_widget_set_size_request (widget,
1411 MAX (width, bold_width),
1412 MAX (height, bold_height));
1413 g_object_unref (layout);
1417 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1418 ButtonData *button_data,
1419 gboolean current_dir)
1421 const gchar *dir_name = get_dir_name (button_data);
1423 if (button_data->label != NULL)
1429 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1430 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1435 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1439 if (button_data->image != NULL)
1441 set_button_image (path_bar, button_data);
1444 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1446 button_data->ignore_changes = TRUE;
1447 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1448 button_data->ignore_changes = FALSE;
1453 find_button_type (GtkPathBar *path_bar,
1456 if (path_bar->root_file != NULL &&
1457 g_file_equal (file, path_bar->root_file))
1459 if (path_bar->home_file != NULL &&
1460 g_file_equal (file, path_bar->home_file))
1462 if (path_bar->desktop_file != NULL &&
1463 g_file_equal (file, path_bar->desktop_file))
1464 return DESKTOP_BUTTON;
1466 return NORMAL_BUTTON;
1470 button_drag_data_get_cb (GtkWidget *widget,
1471 GdkDragContext *context,
1472 GtkSelectionData *selection_data,
1477 ButtonData *button_data;
1482 uris[0] = g_file_get_uri (button_data->file);
1485 gtk_selection_data_set_uris (selection_data, uris);
1491 make_directory_button (GtkPathBar *path_bar,
1492 const char *dir_name,
1494 gboolean current_dir,
1495 gboolean file_is_hidden)
1498 GtkWidget *child = NULL;
1499 ButtonData *button_data;
1501 file_is_hidden = !! file_is_hidden;
1502 /* Is it a special button? */
1503 button_data = g_new0 (ButtonData, 1);
1505 button_data->type = find_button_type (path_bar, file);
1506 button_data->button = gtk_toggle_button_new ();
1507 atk_obj = gtk_widget_get_accessible (button_data->button);
1508 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1510 switch (button_data->type)
1513 button_data->image = gtk_image_new ();
1514 child = button_data->image;
1515 button_data->label = NULL;
1516 atk_object_set_name (atk_obj, _("File System Root"));
1519 case DESKTOP_BUTTON:
1520 button_data->image = gtk_image_new ();
1521 button_data->label = gtk_label_new (NULL);
1522 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1523 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1524 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
1528 button_data->label = gtk_label_new (NULL);
1529 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1530 child = button_data->label;
1531 button_data->image = NULL;
1534 button_data->dir_name = g_strdup (dir_name);
1535 button_data->file = g_object_ref (file);
1536 button_data->file_is_hidden = file_is_hidden;
1539 * The following function ensures that the alignment will always
1540 * request the same size whether the button's text is bold or not.
1542 if (button_data->label)
1543 set_label_size_request (button_data->label, button_data);
1545 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1546 gtk_widget_show_all (button_data->button);
1548 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1550 g_signal_connect (button_data->button, "clicked",
1551 G_CALLBACK (button_clicked_cb),
1553 g_object_weak_ref (G_OBJECT (button_data->button),
1554 (GWeakNotify) button_data_free, button_data);
1556 gtk_drag_source_set (button_data->button,
1560 gtk_drag_source_add_uri_targets (button_data->button);
1561 g_signal_connect (button_data->button, "drag-data-get",
1562 G_CALLBACK (button_drag_data_get_cb), button_data);
1568 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1570 GtkFileSystem *file_system)
1573 GList *current_path = NULL;
1574 gboolean need_new_fake_root = FALSE;
1576 for (list = path_bar->button_list; list; list = list->next)
1578 ButtonData *button_data;
1580 button_data = list->data;
1581 if (g_file_equal (file, button_data->file))
1583 current_path = list;
1586 if (list == path_bar->fake_root)
1587 need_new_fake_root = TRUE;
1592 if (need_new_fake_root)
1594 path_bar->fake_root = NULL;
1595 for (list = current_path; list; list = list->next)
1597 ButtonData *button_data;
1599 button_data = list->data;
1600 if (BUTTON_IS_FAKE_ROOT (button_data))
1602 path_bar->fake_root = list;
1608 for (list = path_bar->button_list; list; list = list->next)
1610 gtk_path_bar_update_button_appearance (path_bar,
1611 BUTTON_DATA (list->data),
1612 (list == current_path) ? TRUE : FALSE);
1615 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1617 path_bar->first_scrolled_button = current_path;
1618 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1631 GtkPathBar *path_bar;
1634 gboolean first_directory;
1638 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1645 gtk_path_bar_clear_buttons (info->path_bar);
1646 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1647 info->path_bar->fake_root = info->fake_root;
1649 for (l = info->path_bar->button_list; l; l = l->next)
1651 GtkWidget *button = BUTTON_DATA (l->data)->button;
1652 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1659 for (l = info->new_buttons; l; l = l->next)
1661 ButtonData *button_data;
1663 button_data = BUTTON_DATA (l->data);
1664 gtk_widget_destroy (button_data->button);
1667 g_list_free (info->new_buttons);
1671 g_object_unref (info->file);
1672 if (info->parent_file)
1673 g_object_unref (info->parent_file);
1678 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1680 const GError *error,
1683 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1684 struct SetFileInfo *file_info = data;
1685 ButtonData *button_data;
1686 const gchar *display_name;
1689 if (cancellable != file_info->path_bar->get_info_cancellable)
1691 gtk_path_bar_set_file_finish (file_info, FALSE);
1692 g_object_unref (cancellable);
1696 g_object_unref (cancellable);
1697 file_info->path_bar->get_info_cancellable = NULL;
1699 if (cancelled || !info)
1701 gtk_path_bar_set_file_finish (file_info, FALSE);
1705 display_name = g_file_info_get_display_name (info);
1706 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1708 gtk_widget_push_composite_child ();
1709 button_data = make_directory_button (file_info->path_bar, display_name,
1711 file_info->first_directory, is_hidden);
1712 gtk_widget_pop_composite_child ();
1713 g_object_unref (file_info->file);
1715 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1717 if (BUTTON_IS_FAKE_ROOT (button_data))
1718 file_info->fake_root = file_info->new_buttons;
1720 file_info->file = file_info->parent_file;
1721 file_info->first_directory = FALSE;
1723 if (!file_info->file)
1725 gtk_path_bar_set_file_finish (file_info, TRUE);
1729 file_info->parent_file = g_file_get_parent (file_info->file);
1731 file_info->path_bar->get_info_cancellable =
1732 _gtk_file_system_get_info (file_info->path_bar->file_system,
1734 "standard::display-name,standard::is-hidden,standard::is-backup",
1735 gtk_path_bar_get_info_callback,
1740 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1742 const gboolean keep_trail,
1745 struct SetFileInfo *info;
1747 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1748 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1750 /* Check whether the new path is already present in the pathbar as buttons.
1751 * This could be a parent directory or a previous selected subdirectory.
1754 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1757 info = g_new0 (struct SetFileInfo, 1);
1758 info->file = g_object_ref (file);
1759 info->path_bar = path_bar;
1760 info->first_directory = TRUE;
1761 info->parent_file = g_file_get_parent (info->file);
1763 if (path_bar->get_info_cancellable)
1764 g_cancellable_cancel (path_bar->get_info_cancellable);
1766 path_bar->get_info_cancellable =
1767 _gtk_file_system_get_info (path_bar->file_system,
1769 "standard::display-name,standard::is-hidden,standard::is-backup",
1770 gtk_path_bar_get_info_callback,
1776 /* FIXME: This should be a construct-only property */
1778 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1779 GtkFileSystem *file_system)
1783 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1785 g_assert (path_bar->file_system == NULL);
1787 path_bar->file_system = g_object_ref (file_system);
1789 home = g_get_home_dir ();
1792 const gchar *desktop;
1794 path_bar->home_file = g_file_new_for_path (home);
1795 /* FIXME: Need file system backend specific way of getting the
1798 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1799 if (desktop != NULL)
1800 path_bar->desktop_file = g_file_new_for_path (desktop);
1802 path_bar->desktop_file = NULL;
1806 path_bar->home_file = NULL;
1807 path_bar->desktop_file = NULL;
1809 path_bar->root_file = g_file_new_for_path ("/");
1814 * @path_bar: a #GtkPathBar
1816 * If the selected button in the pathbar is not the furthest button "up" (in the
1817 * root direction), act as if the user clicked on the next button up.
1820 _gtk_path_bar_up (GtkPathBar *path_bar)
1824 for (l = path_bar->button_list; l; l = l->next)
1826 GtkWidget *button = BUTTON_DATA (l->data)->button;
1827 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1831 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1832 button_clicked_cb (next_button, l->next->data);
1840 * _gtk_path_bar_down:
1841 * @path_bar: a #GtkPathBar
1843 * If the selected button in the pathbar is not the furthest button "down" (in the
1844 * leaf direction), act as if the user clicked on the next button down.
1847 _gtk_path_bar_down (GtkPathBar *path_bar)
1851 for (l = path_bar->button_list; l; l = l->next)
1853 GtkWidget *button = BUTTON_DATA (l->data)->button;
1854 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1858 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1859 button_clicked_cb (prev_button, l->prev->data);