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_get_preferred_width (GtkWidget *widget,
91 static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
94 static void gtk_path_bar_map (GtkWidget *widget);
95 static void gtk_path_bar_unmap (GtkWidget *widget);
96 static void gtk_path_bar_size_allocate (GtkWidget *widget,
97 GtkAllocation *allocation);
98 static void gtk_path_bar_add (GtkContainer *container,
100 static void gtk_path_bar_remove (GtkContainer *container,
102 static void gtk_path_bar_forall (GtkContainer *container,
103 gboolean include_internals,
104 GtkCallback callback,
105 gpointer callback_data);
106 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
107 GdkEventScroll *event);
108 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
109 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
110 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
111 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
112 GdkEventButton *event,
113 GtkPathBar *path_bar);
114 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
115 GdkEventButton *event,
116 GtkPathBar *path_bar);
117 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
118 GdkEventButton *event,
119 GtkPathBar *path_bar);
120 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
121 GdkEventButton *event,
122 GtkPathBar *path_bar);
123 static void gtk_path_bar_grab_notify (GtkWidget *widget,
124 gboolean was_grabbed);
125 static void gtk_path_bar_state_changed (GtkWidget *widget,
126 GtkStateType previous_state);
127 static void gtk_path_bar_style_updated (GtkWidget *widget);
128 static void gtk_path_bar_screen_changed (GtkWidget *widget,
129 GdkScreen *previous_screen);
130 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
131 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
132 ButtonData *button_data,
133 gboolean current_dir);
136 on_slider_unmap (GtkWidget *widget,
137 GtkPathBar *path_bar)
139 if (path_bar->timer &&
140 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
141 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
142 gtk_path_bar_stop_scrolling (path_bar);
146 get_slider_button (GtkPathBar *path_bar,
147 GtkArrowType arrow_type)
152 gtk_widget_push_composite_child ();
154 button = gtk_button_new ();
155 atk_obj = gtk_widget_get_accessible (button);
156 if (arrow_type == GTK_ARROW_LEFT)
157 atk_object_set_name (atk_obj, _("Up Path"));
159 atk_object_set_name (atk_obj, _("Down Path"));
161 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
162 gtk_container_add (GTK_CONTAINER (button),
163 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
164 gtk_container_add (GTK_CONTAINER (path_bar), button);
165 gtk_widget_show_all (button);
167 g_signal_connect (G_OBJECT (button), "unmap",
168 G_CALLBACK (on_slider_unmap), path_bar);
170 gtk_widget_pop_composite_child ();
176 gtk_path_bar_init (GtkPathBar *path_bar)
178 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
179 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
181 path_bar->get_info_cancellable = NULL;
183 path_bar->spacing = 0;
184 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
185 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
186 path_bar->icon_size = FALLBACK_ICON_SIZE;
188 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
189 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
190 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
191 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
193 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
194 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
195 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
196 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
198 g_signal_connect (path_bar->up_slider_button, "button-press-event",
199 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
200 g_signal_connect (path_bar->up_slider_button, "button-release-event",
201 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
202 g_signal_connect (path_bar->down_slider_button, "button-press-event",
203 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
204 g_signal_connect (path_bar->down_slider_button, "button-release-event",
205 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
209 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
211 GObjectClass *gobject_class;
212 GtkWidgetClass *widget_class;
213 GtkContainerClass *container_class;
215 gobject_class = (GObjectClass *) path_bar_class;
216 widget_class = (GtkWidgetClass *) path_bar_class;
217 container_class = (GtkContainerClass *) path_bar_class;
219 gobject_class->finalize = gtk_path_bar_finalize;
220 gobject_class->dispose = gtk_path_bar_dispose;
222 widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
223 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
224 widget_class->realize = gtk_path_bar_realize;
225 widget_class->unrealize = gtk_path_bar_unrealize;
226 widget_class->map = gtk_path_bar_map;
227 widget_class->unmap = gtk_path_bar_unmap;
228 widget_class->size_allocate = gtk_path_bar_size_allocate;
229 widget_class->style_updated = gtk_path_bar_style_updated;
230 widget_class->screen_changed = gtk_path_bar_screen_changed;
231 widget_class->grab_notify = gtk_path_bar_grab_notify;
232 widget_class->state_changed = gtk_path_bar_state_changed;
233 widget_class->scroll_event = gtk_path_bar_scroll;
235 container_class->add = gtk_path_bar_add;
236 container_class->forall = gtk_path_bar_forall;
237 container_class->remove = gtk_path_bar_remove;
238 gtk_container_class_handle_border_width (container_class);
240 /* container_class->child_type = gtk_path_bar_child_type;*/
242 path_bar_signals [PATH_CLICKED] =
243 g_signal_new (I_("path-clicked"),
244 G_OBJECT_CLASS_TYPE (gobject_class),
246 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
248 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
257 gtk_path_bar_finalize (GObject *object)
259 GtkPathBar *path_bar;
261 path_bar = GTK_PATH_BAR (object);
263 gtk_path_bar_stop_scrolling (path_bar);
265 g_list_free (path_bar->button_list);
266 if (path_bar->root_file)
267 g_object_unref (path_bar->root_file);
268 if (path_bar->home_file)
269 g_object_unref (path_bar->home_file);
270 if (path_bar->desktop_file)
271 g_object_unref (path_bar->desktop_file);
273 if (path_bar->root_icon)
274 g_object_unref (path_bar->root_icon);
275 if (path_bar->home_icon)
276 g_object_unref (path_bar->home_icon);
277 if (path_bar->desktop_icon)
278 g_object_unref (path_bar->desktop_icon);
280 if (path_bar->file_system)
281 g_object_unref (path_bar->file_system);
283 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
286 /* Removes the settings signal handler. It's safe to call multiple times */
288 remove_settings_signal (GtkPathBar *path_bar,
291 if (path_bar->settings_signal_id)
293 GtkSettings *settings;
295 settings = gtk_settings_get_for_screen (screen);
296 g_signal_handler_disconnect (settings,
297 path_bar->settings_signal_id);
298 path_bar->settings_signal_id = 0;
303 gtk_path_bar_dispose (GObject *object)
305 GtkPathBar *path_bar = GTK_PATH_BAR (object);
307 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
309 if (path_bar->get_info_cancellable)
310 g_cancellable_cancel (path_bar->get_info_cancellable);
311 path_bar->get_info_cancellable = NULL;
313 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
318 * Ideally, our size is determined by another widget, and we are just filling
322 gtk_path_bar_get_preferred_width (GtkWidget *widget,
326 ButtonData *button_data;
327 GtkPathBar *path_bar;
331 gint child_min, child_nat;
333 path_bar = GTK_PATH_BAR (widget);
335 *minimum = *natural = 0;
338 for (list = path_bar->button_list; list; list = list->next)
340 button_data = BUTTON_DATA (list->data);
341 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
342 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
343 height = MAX (height, child_height);
345 if (button_data->type == NORMAL_BUTTON)
347 /* Use 2*Height as button width because of ellipsized label. */
348 child_min = MAX (child_min, child_height * 2);
349 child_nat = MAX (child_min, child_height * 2);
352 *minimum = MAX (*minimum, child_min);
353 *natural = MAX (*natural, child_nat);
356 /* Add space for slider, if we have more than one path */
357 /* Theoretically, the slider could be bigger than the other button. But we're
358 * not going to worry about that now.
360 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
361 if (path_bar->button_list && path_bar->button_list->next != NULL)
363 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
364 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
369 gtk_path_bar_get_preferred_height (GtkWidget *widget,
373 ButtonData *button_data;
374 GtkPathBar *path_bar;
376 gint child_min, child_nat;
378 path_bar = GTK_PATH_BAR (widget);
380 *minimum = *natural = 0;
382 for (list = path_bar->button_list; list; list = list->next)
384 button_data = BUTTON_DATA (list->data);
385 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
387 *minimum = MAX (*minimum, child_min);
388 *natural = MAX (*natural, child_nat);
393 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
395 if (path_bar->button_list)
399 button = BUTTON_DATA (path_bar->button_list->data)->button;
400 if (gtk_widget_get_child_visible (button))
402 gtk_path_bar_stop_scrolling (path_bar);
403 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
406 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
408 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
409 if (gtk_widget_get_child_visible (button))
411 gtk_path_bar_stop_scrolling (path_bar);
412 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
415 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
420 gtk_path_bar_map (GtkWidget *widget)
422 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
424 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
428 gtk_path_bar_unmap (GtkWidget *widget)
430 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
431 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
433 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
437 gtk_path_bar_realize (GtkWidget *widget)
439 GtkPathBar *path_bar;
440 GtkAllocation allocation;
442 GdkWindowAttr attributes;
443 gint attributes_mask;
445 gtk_widget_set_realized (widget, TRUE);
447 path_bar = GTK_PATH_BAR (widget);
448 window = gtk_widget_get_parent_window (widget);
449 gtk_widget_set_window (widget, window);
450 g_object_ref (window);
452 gtk_widget_get_allocation (widget, &allocation);
454 attributes.window_type = GDK_WINDOW_CHILD;
455 attributes.x = allocation.x;
456 attributes.y = allocation.y;
457 attributes.width = allocation.width;
458 attributes.height = allocation.height;
459 attributes.wclass = GDK_INPUT_ONLY;
460 attributes.event_mask = gtk_widget_get_events (widget);
461 attributes.event_mask |= GDK_SCROLL_MASK;
462 attributes_mask = GDK_WA_X | GDK_WA_Y;
464 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
465 &attributes, attributes_mask);
466 gdk_window_set_user_data (path_bar->event_window, widget);
470 gtk_path_bar_unrealize (GtkWidget *widget)
472 GtkPathBar *path_bar;
474 path_bar = GTK_PATH_BAR (widget);
476 gdk_window_set_user_data (path_bar->event_window, NULL);
477 gdk_window_destroy (path_bar->event_window);
478 path_bar->event_window = NULL;
480 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
483 /* This is a tad complicated
486 gtk_path_bar_size_allocate (GtkWidget *widget,
487 GtkAllocation *allocation)
490 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
491 GtkTextDirection direction;
492 GtkAllocation child_allocation;
493 GList *list, *first_button;
495 gint allocation_width;
496 gboolean need_sliders = FALSE;
497 gint up_slider_offset = 0;
498 GtkRequisition child_requisition;
500 gtk_widget_set_allocation (widget, allocation);
502 if (gtk_widget_get_realized (widget))
503 gdk_window_move_resize (path_bar->event_window,
504 allocation->x, allocation->y,
505 allocation->width, allocation->height);
507 /* No path is set; we don't have to allocate anything. */
508 if (path_bar->button_list == NULL)
511 direction = gtk_widget_get_direction (widget);
512 allocation_width = allocation->width;
514 /* First, we check to see if we need the scrollbars. */
515 if (path_bar->fake_root)
516 width = path_bar->spacing + path_bar->slider_width;
520 for (list = path_bar->button_list; list; list = list->next)
522 child = BUTTON_DATA (list->data)->button;
524 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
526 width += child_requisition.width + path_bar->spacing;
527 if (list == path_bar->fake_root)
531 if (width <= allocation_width)
533 if (path_bar->fake_root)
534 first_button = path_bar->fake_root;
536 first_button = g_list_last (path_bar->button_list);
540 gboolean reached_end = FALSE;
541 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
543 if (path_bar->first_scrolled_button)
544 first_button = path_bar->first_scrolled_button;
546 first_button = path_bar->button_list;
549 /* To see how much space we have, and how many buttons we can display.
550 * We start at the first button, count forward until hit the new
551 * button, then count backwards.
553 /* Count down the path chain towards the end. */
554 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
555 &child_requisition, NULL);
557 width = child_requisition.width;
558 list = first_button->prev;
559 while (list && !reached_end)
561 child = BUTTON_DATA (list->data)->button;
563 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
565 if (width + child_requisition.width +
566 path_bar->spacing + slider_space > allocation_width)
568 else if (list == path_bar->fake_root)
571 width += child_requisition.width + path_bar->spacing;
576 /* Finally, we walk up, seeing how many of the previous buttons we can
578 while (first_button->next && !reached_end)
580 child = BUTTON_DATA (first_button->next->data)->button;
582 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
584 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
590 width += child_requisition.width + path_bar->spacing;
591 if (first_button == path_bar->fake_root)
593 first_button = first_button->next;
598 /* Now, we allocate space to the buttons */
599 child_allocation.y = allocation->y;
600 child_allocation.height = allocation->height;
602 if (direction == GTK_TEXT_DIR_RTL)
604 child_allocation.x = allocation->x + allocation->width;
605 if (need_sliders || path_bar->fake_root)
607 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
608 up_slider_offset = allocation->width - path_bar->slider_width;
613 child_allocation.x = allocation->x;
614 if (need_sliders || path_bar->fake_root)
616 up_slider_offset = 0;
617 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
621 for (list = first_button; list; list = list->prev)
623 GtkAllocation widget_allocation;
624 ButtonData *button_data;
626 button_data = BUTTON_DATA (list->data);
627 child = button_data->button;
629 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
631 child_allocation.width = MIN (child_requisition.width,
632 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
634 if (direction == GTK_TEXT_DIR_RTL)
635 child_allocation.x -= child_allocation.width;
637 /* Check to see if we've don't have any more space to allocate buttons */
638 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
640 gtk_widget_get_allocation (widget, &widget_allocation);
641 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
644 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
646 gtk_widget_get_allocation (widget, &widget_allocation);
647 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
648 widget_allocation.x + allocation_width)
652 if (child_allocation.width < child_requisition.width)
654 if (!gtk_widget_get_has_tooltip (child))
655 gtk_widget_set_tooltip_text (child, button_data->dir_name);
657 else if (gtk_widget_get_has_tooltip (child))
658 gtk_widget_set_tooltip_text (child, NULL);
660 gtk_widget_set_child_visible (child, TRUE);
661 gtk_widget_size_allocate (child, &child_allocation);
663 if (direction == GTK_TEXT_DIR_RTL)
664 child_allocation.x -= path_bar->spacing;
666 child_allocation.x += child_allocation.width + path_bar->spacing;
668 /* Now we go hide all the widgets that don't fit */
671 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
674 for (list = first_button->next; list; list = list->next)
676 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
679 if (need_sliders || path_bar->fake_root)
681 child_allocation.width = path_bar->slider_width;
682 child_allocation.x = up_slider_offset + allocation->x;
683 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
685 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
686 gtk_widget_show_all (path_bar->up_slider_button);
689 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
693 child_allocation.width = path_bar->slider_width;
695 if (direction == GTK_TEXT_DIR_RTL)
696 child_allocation.x = 0;
698 child_allocation.x = allocation->width - path_bar->slider_width;
700 child_allocation.x += allocation->x;
702 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
704 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
705 gtk_widget_show_all (path_bar->down_slider_button);
706 gtk_path_bar_update_slider_buttons (path_bar);
709 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
713 gtk_path_bar_style_updated (GtkWidget *widget)
715 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
717 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
721 gtk_path_bar_screen_changed (GtkWidget *widget,
722 GdkScreen *previous_screen)
724 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
725 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
727 /* We might nave a new settings, so we remove the old one */
729 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
731 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
735 gtk_path_bar_scroll (GtkWidget *widget,
736 GdkEventScroll *event)
738 switch (event->direction)
740 case GDK_SCROLL_RIGHT:
741 case GDK_SCROLL_DOWN:
742 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
744 case GDK_SCROLL_LEFT:
746 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
754 gtk_path_bar_add (GtkContainer *container,
757 gtk_widget_set_parent (widget, GTK_WIDGET (container));
761 gtk_path_bar_remove_1 (GtkContainer *container,
764 gboolean was_visible = gtk_widget_get_visible (widget);
765 gtk_widget_unparent (widget);
767 gtk_widget_queue_resize (GTK_WIDGET (container));
771 gtk_path_bar_remove (GtkContainer *container,
774 GtkPathBar *path_bar;
777 path_bar = GTK_PATH_BAR (container);
779 if (widget == path_bar->up_slider_button)
781 gtk_path_bar_remove_1 (container, widget);
782 path_bar->up_slider_button = NULL;
786 if (widget == path_bar->down_slider_button)
788 gtk_path_bar_remove_1 (container, widget);
789 path_bar->down_slider_button = NULL;
793 children = path_bar->button_list;
796 if (widget == BUTTON_DATA (children->data)->button)
798 gtk_path_bar_remove_1 (container, widget);
799 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
800 g_list_free (children);
804 children = children->next;
809 gtk_path_bar_forall (GtkContainer *container,
810 gboolean include_internals,
811 GtkCallback callback,
812 gpointer callback_data)
814 GtkPathBar *path_bar;
817 g_return_if_fail (callback != NULL);
818 path_bar = GTK_PATH_BAR (container);
820 children = path_bar->button_list;
824 child = BUTTON_DATA (children->data)->button;
825 children = children->next;
827 (* callback) (child, callback_data);
830 if (path_bar->up_slider_button)
831 (* callback) (path_bar->up_slider_button, callback_data);
833 if (path_bar->down_slider_button)
834 (* callback) (path_bar->down_slider_button, callback_data);
838 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
840 GtkAllocation allocation, button_allocation;
842 GList *down_button = NULL;
843 gint space_available;
845 if (path_bar->ignore_click)
847 path_bar->ignore_click = FALSE;
851 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
853 /* Return if the last button is already visible */
857 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
859 /* We find the button at the 'down' end that we have to make
861 for (list = path_bar->button_list; list; list = list->next)
863 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
870 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
871 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
873 space_available = (allocation.width
874 - 2 * path_bar->spacing - 2 * path_bar->slider_width
875 - button_allocation.width);
876 path_bar->first_scrolled_button = down_button;
878 /* We have space_available free space that's not being used.
879 * So we walk down from the end, adding buttons until we use all free space.
881 while (space_available > 0)
883 path_bar->first_scrolled_button = down_button;
884 down_button = down_button->next;
887 space_available -= (button_allocation.width
888 + path_bar->spacing);
893 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
897 if (path_bar->ignore_click)
899 path_bar->ignore_click = FALSE;
903 list = g_list_last (path_bar->button_list);
905 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
907 /* Return if the first button is already visible */
911 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
913 for ( ; list; list = list->prev)
915 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
917 if (list->prev == path_bar->fake_root)
918 path_bar->fake_root = NULL;
919 path_bar->first_scrolled_button = list;
926 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
928 gboolean retval = FALSE;
932 if (path_bar->scrolling_up)
933 gtk_path_bar_scroll_up (path_bar);
934 else if (path_bar->scrolling_down)
935 gtk_path_bar_scroll_down (path_bar);
937 if (path_bar->need_timer)
939 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
942 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
944 path_bar->need_timer = FALSE;
946 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
947 (GSourceFunc)gtk_path_bar_scroll_timeout,
958 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
962 g_source_remove (path_bar->timer);
964 path_bar->need_timer = FALSE;
969 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
970 GdkEventButton *event,
971 GtkPathBar *path_bar)
974 GList *up_button = NULL;
976 if (event->type != GDK_FOCUS_CHANGE)
979 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
981 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
988 /* don't let the focus vanish */
989 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
990 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
991 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
997 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
998 GdkEventButton *event,
999 GtkPathBar *path_bar)
1002 GList *down_button = NULL;
1004 if (event->type != GDK_FOCUS_CHANGE)
1007 for (list = path_bar->button_list; list; list = list->next)
1009 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1016 /* don't let the focus vanish */
1017 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1018 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1019 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1025 gtk_path_bar_slider_button_press (GtkWidget *widget,
1026 GdkEventButton *event,
1027 GtkPathBar *path_bar)
1029 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1032 path_bar->ignore_click = FALSE;
1034 if (widget == path_bar->up_slider_button)
1036 path_bar->scrolling_down = FALSE;
1037 path_bar->scrolling_up = TRUE;
1038 gtk_path_bar_scroll_up (path_bar);
1040 else if (widget == path_bar->down_slider_button)
1042 path_bar->scrolling_up = FALSE;
1043 path_bar->scrolling_down = TRUE;
1044 gtk_path_bar_scroll_down (path_bar);
1047 if (!path_bar->timer)
1049 GtkSettings *settings = gtk_widget_get_settings (widget);
1052 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1054 path_bar->need_timer = TRUE;
1055 path_bar->timer = gdk_threads_add_timeout (timeout,
1056 (GSourceFunc)gtk_path_bar_scroll_timeout,
1064 gtk_path_bar_slider_button_release (GtkWidget *widget,
1065 GdkEventButton *event,
1066 GtkPathBar *path_bar)
1068 if (event->type != GDK_BUTTON_RELEASE)
1071 path_bar->ignore_click = TRUE;
1072 gtk_path_bar_stop_scrolling (path_bar);
1078 gtk_path_bar_grab_notify (GtkWidget *widget,
1079 gboolean was_grabbed)
1082 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1086 gtk_path_bar_state_changed (GtkWidget *widget,
1087 GtkStateType previous_state)
1089 if (!gtk_widget_is_sensitive (widget))
1090 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1094 /* Changes the icons wherever it is needed */
1096 reload_icons (GtkPathBar *path_bar)
1100 if (path_bar->root_icon)
1102 g_object_unref (path_bar->root_icon);
1103 path_bar->root_icon = NULL;
1105 if (path_bar->home_icon)
1107 g_object_unref (path_bar->home_icon);
1108 path_bar->home_icon = NULL;
1110 if (path_bar->desktop_icon)
1112 g_object_unref (path_bar->desktop_icon);
1113 path_bar->desktop_icon = NULL;
1116 for (list = path_bar->button_list; list; list = list->next)
1118 ButtonData *button_data;
1119 gboolean current_dir;
1121 button_data = BUTTON_DATA (list->data);
1122 if (button_data->type != NORMAL_BUTTON)
1124 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1125 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1132 change_icon_theme (GtkPathBar *path_bar)
1134 GtkSettings *settings;
1137 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1139 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1140 path_bar->icon_size = MAX (width, height);
1142 path_bar->icon_size = FALLBACK_ICON_SIZE;
1144 reload_icons (path_bar);
1146 /* Callback used when a GtkSettings value changes */
1148 settings_notify_cb (GObject *object,
1150 GtkPathBar *path_bar)
1154 name = g_param_spec_get_name (pspec);
1156 if (! strcmp (name, "gtk-icon-theme-name") ||
1157 ! strcmp (name, "gtk-icon-sizes"))
1158 change_icon_theme (path_bar);
1162 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1164 GtkSettings *settings;
1166 if (path_bar->settings_signal_id)
1169 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1170 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1172 change_icon_theme (path_bar);
1175 /* Public functions and their helpers */
1177 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1179 while (path_bar->button_list != NULL)
1181 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1183 path_bar->first_scrolled_button = NULL;
1184 path_bar->fake_root = NULL;
1188 button_clicked_cb (GtkWidget *button,
1191 ButtonData *button_data;
1192 GtkPathBar *path_bar;
1194 gboolean child_is_hidden;
1197 button_data = BUTTON_DATA (data);
1198 if (button_data->ignore_changes)
1201 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1203 button_list = g_list_find (path_bar->button_list, button_data);
1204 g_assert (button_list != NULL);
1206 g_signal_handlers_block_by_func (button,
1207 G_CALLBACK (button_clicked_cb), data);
1208 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1209 g_signal_handlers_unblock_by_func (button,
1210 G_CALLBACK (button_clicked_cb), data);
1212 if (button_list->prev)
1214 ButtonData *child_data;
1216 child_data = BUTTON_DATA (button_list->prev->data);
1217 child_file = child_data->file;
1218 child_is_hidden = child_data->file_is_hidden;
1223 child_is_hidden = FALSE;
1226 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1227 button_data->file, child_file, child_is_hidden);
1230 struct SetButtonImageData
1232 GtkPathBar *path_bar;
1233 ButtonData *button_data;
1237 set_button_image_get_info_cb (GCancellable *cancellable,
1239 const GError *error,
1242 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1244 struct SetButtonImageData *data = user_data;
1246 if (cancellable != data->button_data->cancellable)
1249 data->button_data->cancellable = NULL;
1251 if (!data->button_data->button)
1253 g_free (data->button_data);
1257 if (cancelled || error)
1260 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1261 data->path_bar->icon_size);
1262 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1264 switch (data->button_data->type)
1267 if (data->path_bar->home_icon)
1268 g_object_unref (pixbuf);
1270 data->path_bar->home_icon = pixbuf;
1273 case DESKTOP_BUTTON:
1274 if (data->path_bar->desktop_icon)
1275 g_object_unref (pixbuf);
1277 data->path_bar->desktop_icon = pixbuf;
1286 g_object_unref (cancellable);
1290 set_button_image (GtkPathBar *path_bar,
1291 ButtonData *button_data)
1293 GtkFileSystemVolume *volume;
1294 struct SetButtonImageData *data;
1296 switch (button_data->type)
1300 if (path_bar->root_icon != NULL)
1302 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1306 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1310 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1311 GTK_WIDGET (path_bar),
1312 path_bar->icon_size,
1314 _gtk_file_system_volume_unref (volume);
1316 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1320 if (path_bar->home_icon != NULL)
1322 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_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->home_file,
1337 set_button_image_get_info_cb,
1341 case DESKTOP_BUTTON:
1342 if (path_bar->desktop_icon != NULL)
1344 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1348 data = g_new0 (struct SetButtonImageData, 1);
1349 data->path_bar = path_bar;
1350 data->button_data = button_data;
1352 if (button_data->cancellable)
1353 g_cancellable_cancel (button_data->cancellable);
1355 button_data->cancellable =
1356 _gtk_file_system_get_info (path_bar->file_system,
1357 path_bar->desktop_file,
1359 set_button_image_get_info_cb,
1368 button_data_free (ButtonData *button_data)
1370 if (button_data->file)
1371 g_object_unref (button_data->file);
1372 button_data->file = NULL;
1374 g_free (button_data->dir_name);
1375 button_data->dir_name = NULL;
1377 button_data->button = NULL;
1379 if (button_data->cancellable)
1380 g_cancellable_cancel (button_data->cancellable);
1382 g_free (button_data);
1386 get_dir_name (ButtonData *button_data)
1388 return button_data->dir_name;
1391 /* We always want to request the same size for the label, whether
1392 * or not the contents are bold
1395 set_label_size_request (GtkWidget *alignment,
1396 ButtonData *button_data)
1398 const gchar *dir_name = get_dir_name (button_data);
1399 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1400 gint width, height, bold_width, bold_height;
1403 pango_layout_get_pixel_size (layout, &width, &height);
1405 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1406 pango_layout_set_markup (layout, markup, -1);
1409 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1411 gtk_widget_set_size_request (alignment,
1412 MAX (width, bold_width),
1413 MAX (height, bold_height));
1414 g_object_unref (layout);
1418 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1419 ButtonData *button_data,
1420 gboolean current_dir)
1422 const gchar *dir_name = get_dir_name (button_data);
1424 if (button_data->label != NULL)
1430 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1431 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1436 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1440 if (button_data->image != NULL)
1442 set_button_image (path_bar, button_data);
1445 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1447 button_data->ignore_changes = TRUE;
1448 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1449 button_data->ignore_changes = FALSE;
1454 find_button_type (GtkPathBar *path_bar,
1457 if (path_bar->root_file != NULL &&
1458 g_file_equal (file, path_bar->root_file))
1460 if (path_bar->home_file != NULL &&
1461 g_file_equal (file, path_bar->home_file))
1463 if (path_bar->desktop_file != NULL &&
1464 g_file_equal (file, path_bar->desktop_file))
1465 return DESKTOP_BUTTON;
1467 return NORMAL_BUTTON;
1471 button_drag_data_get_cb (GtkWidget *widget,
1472 GdkDragContext *context,
1473 GtkSelectionData *selection_data,
1478 ButtonData *button_data;
1483 uris[0] = g_file_get_uri (button_data->file);
1486 gtk_selection_data_set_uris (selection_data, uris);
1492 make_directory_button (GtkPathBar *path_bar,
1493 const char *dir_name,
1495 gboolean current_dir,
1496 gboolean file_is_hidden)
1499 GtkWidget *child = NULL;
1500 GtkWidget *label_alignment = NULL;
1501 ButtonData *button_data;
1503 file_is_hidden = !! file_is_hidden;
1504 /* Is it a special button? */
1505 button_data = g_new0 (ButtonData, 1);
1507 button_data->type = find_button_type (path_bar, file);
1508 button_data->button = gtk_toggle_button_new ();
1509 atk_obj = gtk_widget_get_accessible (button_data->button);
1510 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1512 switch (button_data->type)
1515 button_data->image = gtk_image_new ();
1516 child = button_data->image;
1517 button_data->label = NULL;
1518 atk_object_set_name (atk_obj, _("File System Root"));
1521 case DESKTOP_BUTTON:
1522 button_data->image = gtk_image_new ();
1523 button_data->label = gtk_label_new (NULL);
1524 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1525 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1526 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1527 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1528 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1532 button_data->label = gtk_label_new (NULL);
1533 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1534 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1535 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1536 child = label_alignment;
1537 button_data->image = NULL;
1540 button_data->dir_name = g_strdup (dir_name);
1541 button_data->file = g_object_ref (file);
1542 button_data->file_is_hidden = file_is_hidden;
1544 /* FIXME: Maybe we dont need this alignment at all and we can
1545 * use GtkMisc aligments or even GtkWidget:halign/valign center.
1547 * The following function ensures that the alignment will always
1548 * request the same size whether the button's text is bold or not.
1550 if (label_alignment)
1551 set_label_size_request (label_alignment, button_data);
1553 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1554 gtk_widget_show_all (button_data->button);
1556 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1558 g_signal_connect (button_data->button, "clicked",
1559 G_CALLBACK (button_clicked_cb),
1561 g_object_weak_ref (G_OBJECT (button_data->button),
1562 (GWeakNotify) button_data_free, button_data);
1564 gtk_drag_source_set (button_data->button,
1568 gtk_drag_source_add_uri_targets (button_data->button);
1569 g_signal_connect (button_data->button, "drag-data-get",
1570 G_CALLBACK (button_drag_data_get_cb), button_data);
1576 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1578 GtkFileSystem *file_system)
1581 GList *current_path = NULL;
1582 gboolean need_new_fake_root = FALSE;
1584 for (list = path_bar->button_list; list; list = list->next)
1586 ButtonData *button_data;
1588 button_data = list->data;
1589 if (g_file_equal (file, button_data->file))
1591 current_path = list;
1594 if (list == path_bar->fake_root)
1595 need_new_fake_root = TRUE;
1600 if (need_new_fake_root)
1602 path_bar->fake_root = NULL;
1603 for (list = current_path; list; list = list->next)
1605 ButtonData *button_data;
1607 button_data = list->data;
1608 if (BUTTON_IS_FAKE_ROOT (button_data))
1610 path_bar->fake_root = list;
1616 for (list = path_bar->button_list; list; list = list->next)
1618 gtk_path_bar_update_button_appearance (path_bar,
1619 BUTTON_DATA (list->data),
1620 (list == current_path) ? TRUE : FALSE);
1623 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1625 path_bar->first_scrolled_button = current_path;
1626 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1639 GtkPathBar *path_bar;
1642 gboolean first_directory;
1646 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1653 gtk_path_bar_clear_buttons (info->path_bar);
1654 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1655 info->path_bar->fake_root = info->fake_root;
1657 for (l = info->path_bar->button_list; l; l = l->next)
1659 GtkWidget *button = BUTTON_DATA (l->data)->button;
1660 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1667 for (l = info->new_buttons; l; l = l->next)
1669 ButtonData *button_data;
1671 button_data = BUTTON_DATA (l->data);
1672 gtk_widget_destroy (button_data->button);
1675 g_list_free (info->new_buttons);
1679 g_object_unref (info->file);
1680 if (info->parent_file)
1681 g_object_unref (info->parent_file);
1686 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1688 const GError *error,
1691 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1692 struct SetFileInfo *file_info = data;
1693 ButtonData *button_data;
1694 const gchar *display_name;
1697 if (cancellable != file_info->path_bar->get_info_cancellable)
1699 gtk_path_bar_set_file_finish (file_info, FALSE);
1700 g_object_unref (cancellable);
1704 g_object_unref (cancellable);
1705 file_info->path_bar->get_info_cancellable = NULL;
1707 if (cancelled || !info)
1709 gtk_path_bar_set_file_finish (file_info, FALSE);
1713 display_name = g_file_info_get_display_name (info);
1714 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1716 gtk_widget_push_composite_child ();
1717 button_data = make_directory_button (file_info->path_bar, display_name,
1719 file_info->first_directory, is_hidden);
1720 gtk_widget_pop_composite_child ();
1721 g_object_unref (file_info->file);
1723 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1725 if (BUTTON_IS_FAKE_ROOT (button_data))
1726 file_info->fake_root = file_info->new_buttons;
1728 file_info->file = file_info->parent_file;
1729 file_info->first_directory = FALSE;
1731 if (!file_info->file)
1733 gtk_path_bar_set_file_finish (file_info, TRUE);
1737 file_info->parent_file = g_file_get_parent (file_info->file);
1739 file_info->path_bar->get_info_cancellable =
1740 _gtk_file_system_get_info (file_info->path_bar->file_system,
1742 "standard::display-name,standard::is-hidden,standard::is-backup",
1743 gtk_path_bar_get_info_callback,
1748 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1750 const gboolean keep_trail,
1753 struct SetFileInfo *info;
1755 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1756 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1758 /* Check whether the new path is already present in the pathbar as buttons.
1759 * This could be a parent directory or a previous selected subdirectory.
1762 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1765 info = g_new0 (struct SetFileInfo, 1);
1766 info->file = g_object_ref (file);
1767 info->path_bar = path_bar;
1768 info->first_directory = TRUE;
1769 info->parent_file = g_file_get_parent (info->file);
1771 if (path_bar->get_info_cancellable)
1772 g_cancellable_cancel (path_bar->get_info_cancellable);
1774 path_bar->get_info_cancellable =
1775 _gtk_file_system_get_info (path_bar->file_system,
1777 "standard::display-name,standard::is-hidden,standard::is-backup",
1778 gtk_path_bar_get_info_callback,
1784 /* FIXME: This should be a construct-only property */
1786 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1787 GtkFileSystem *file_system)
1791 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1793 g_assert (path_bar->file_system == NULL);
1795 path_bar->file_system = g_object_ref (file_system);
1797 home = g_get_home_dir ();
1800 const gchar *desktop;
1802 path_bar->home_file = g_file_new_for_path (home);
1803 /* FIXME: Need file system backend specific way of getting the
1806 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1807 if (desktop != NULL)
1808 path_bar->desktop_file = g_file_new_for_path (desktop);
1810 path_bar->desktop_file = NULL;
1814 path_bar->home_file = NULL;
1815 path_bar->desktop_file = NULL;
1817 path_bar->root_file = g_file_new_for_path ("/");
1822 * @path_bar: a #GtkPathBar
1824 * If the selected button in the pathbar is not the furthest button "up" (in the
1825 * root direction), act as if the user clicked on the next button up.
1828 _gtk_path_bar_up (GtkPathBar *path_bar)
1832 for (l = path_bar->button_list; l; l = l->next)
1834 GtkWidget *button = BUTTON_DATA (l->data)->button;
1835 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1839 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1840 button_clicked_cb (next_button, l->next->data);
1848 * _gtk_path_bar_down:
1849 * @path_bar: a #GtkPathBar
1851 * If the selected button in the pathbar is not the furthest button "down" (in the
1852 * leaf direction), act as if the user clicked on the next button down.
1855 _gtk_path_bar_down (GtkPathBar *path_bar)
1859 for (l = path_bar->button_list; l; l = l->next)
1861 GtkWidget *button = BUTTON_DATA (l->data)->button;
1862 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1866 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1867 button_clicked_cb (prev_button, l->prev->data);