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, see <http://www.gnu.org/licenses/>.
21 #include "gtkpathbar.h"
28 #include "gtkiconfactory.h"
29 #include "gtkicontheme.h"
34 #include "gtkmarshalers.h"
35 #include "gtksettings.h"
36 #include "gtktogglebutton.h"
37 #include "gtkwidgetpath.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 GtkWidgetPath *gtk_path_bar_get_path_for_child (GtkContainer *container,
107 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
108 GdkEventScroll *event);
109 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
110 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
111 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
112 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
113 GdkEventButton *event,
114 GtkPathBar *path_bar);
115 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
116 GdkEventButton *event,
117 GtkPathBar *path_bar);
118 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
119 GdkEventButton *event,
120 GtkPathBar *path_bar);
121 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
122 GdkEventButton *event,
123 GtkPathBar *path_bar);
124 static void gtk_path_bar_grab_notify (GtkWidget *widget,
125 gboolean was_grabbed);
126 static void gtk_path_bar_state_changed (GtkWidget *widget,
127 GtkStateType previous_state);
128 static void gtk_path_bar_style_updated (GtkWidget *widget);
129 static void gtk_path_bar_screen_changed (GtkWidget *widget,
130 GdkScreen *previous_screen);
131 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
132 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
133 ButtonData *button_data,
134 gboolean current_dir);
137 on_slider_unmap (GtkWidget *widget,
138 GtkPathBar *path_bar)
140 if (path_bar->timer &&
141 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
142 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
143 gtk_path_bar_stop_scrolling (path_bar);
147 get_slider_button (GtkPathBar *path_bar,
148 GtkArrowType arrow_type)
153 gtk_widget_push_composite_child ();
155 button = gtk_button_new ();
156 atk_obj = gtk_widget_get_accessible (button);
157 if (arrow_type == GTK_ARROW_LEFT)
158 atk_object_set_name (atk_obj, _("Up Path"));
160 atk_object_set_name (atk_obj, _("Down Path"));
162 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
163 gtk_widget_add_events (button, GDK_SCROLL_MASK);
164 gtk_container_add (GTK_CONTAINER (button),
165 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
166 gtk_container_add (GTK_CONTAINER (path_bar), button);
167 gtk_widget_show_all (button);
169 g_signal_connect (G_OBJECT (button), "unmap",
170 G_CALLBACK (on_slider_unmap), path_bar);
172 gtk_widget_pop_composite_child ();
178 gtk_path_bar_init (GtkPathBar *path_bar)
180 GtkStyleContext *context;
182 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
183 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
185 path_bar->get_info_cancellable = NULL;
187 path_bar->spacing = 0;
188 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
189 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
190 path_bar->icon_size = FALLBACK_ICON_SIZE;
192 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
193 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
194 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
195 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
197 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
198 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
199 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
200 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
202 g_signal_connect (path_bar->up_slider_button, "button-press-event",
203 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
204 g_signal_connect (path_bar->up_slider_button, "button-release-event",
205 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
206 g_signal_connect (path_bar->down_slider_button, "button-press-event",
207 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
208 g_signal_connect (path_bar->down_slider_button, "button-release-event",
209 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
211 context = gtk_widget_get_style_context (GTK_WIDGET (path_bar));
212 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
216 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
218 GObjectClass *gobject_class;
219 GtkWidgetClass *widget_class;
220 GtkContainerClass *container_class;
222 gobject_class = (GObjectClass *) path_bar_class;
223 widget_class = (GtkWidgetClass *) path_bar_class;
224 container_class = (GtkContainerClass *) path_bar_class;
226 gobject_class->finalize = gtk_path_bar_finalize;
227 gobject_class->dispose = gtk_path_bar_dispose;
229 widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
230 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
231 widget_class->realize = gtk_path_bar_realize;
232 widget_class->unrealize = gtk_path_bar_unrealize;
233 widget_class->map = gtk_path_bar_map;
234 widget_class->unmap = gtk_path_bar_unmap;
235 widget_class->size_allocate = gtk_path_bar_size_allocate;
236 widget_class->style_updated = gtk_path_bar_style_updated;
237 widget_class->screen_changed = gtk_path_bar_screen_changed;
238 widget_class->grab_notify = gtk_path_bar_grab_notify;
239 widget_class->state_changed = gtk_path_bar_state_changed;
240 widget_class->scroll_event = gtk_path_bar_scroll;
242 container_class->add = gtk_path_bar_add;
243 container_class->forall = gtk_path_bar_forall;
244 container_class->remove = gtk_path_bar_remove;
245 container_class->get_path_for_child = gtk_path_bar_get_path_for_child;
246 gtk_container_class_handle_border_width (container_class);
248 /* container_class->child_type = gtk_path_bar_child_type;*/
250 path_bar_signals [PATH_CLICKED] =
251 g_signal_new (I_("path-clicked"),
252 G_OBJECT_CLASS_TYPE (gobject_class),
254 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
256 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
265 gtk_path_bar_finalize (GObject *object)
267 GtkPathBar *path_bar;
269 path_bar = GTK_PATH_BAR (object);
271 gtk_path_bar_stop_scrolling (path_bar);
273 g_list_free (path_bar->button_list);
274 if (path_bar->root_file)
275 g_object_unref (path_bar->root_file);
276 if (path_bar->home_file)
277 g_object_unref (path_bar->home_file);
278 if (path_bar->desktop_file)
279 g_object_unref (path_bar->desktop_file);
281 if (path_bar->root_icon)
282 g_object_unref (path_bar->root_icon);
283 if (path_bar->home_icon)
284 g_object_unref (path_bar->home_icon);
285 if (path_bar->desktop_icon)
286 g_object_unref (path_bar->desktop_icon);
288 if (path_bar->file_system)
289 g_object_unref (path_bar->file_system);
291 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
294 /* Removes the settings signal handler. It's safe to call multiple times */
296 remove_settings_signal (GtkPathBar *path_bar,
299 if (path_bar->settings_signal_id)
301 GtkSettings *settings;
303 settings = gtk_settings_get_for_screen (screen);
304 g_signal_handler_disconnect (settings,
305 path_bar->settings_signal_id);
306 path_bar->settings_signal_id = 0;
311 gtk_path_bar_dispose (GObject *object)
313 GtkPathBar *path_bar = GTK_PATH_BAR (object);
315 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
317 if (path_bar->get_info_cancellable)
318 g_cancellable_cancel (path_bar->get_info_cancellable);
319 path_bar->get_info_cancellable = NULL;
321 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
326 * Ideally, our size is determined by another widget, and we are just filling
330 gtk_path_bar_get_preferred_width (GtkWidget *widget,
334 ButtonData *button_data;
335 GtkPathBar *path_bar;
339 gint child_min, child_nat;
341 path_bar = GTK_PATH_BAR (widget);
343 *minimum = *natural = 0;
346 for (list = path_bar->button_list; list; list = list->next)
348 button_data = BUTTON_DATA (list->data);
349 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
350 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
351 height = MAX (height, child_height);
353 if (button_data->type == NORMAL_BUTTON)
355 /* Use 2*Height as button width because of ellipsized label. */
356 child_min = MAX (child_min, child_height * 2);
357 child_nat = MAX (child_min, child_height * 2);
360 *minimum = MAX (*minimum, child_min);
361 *natural = MAX (*natural, child_nat);
364 /* Add space for slider, if we have more than one path */
365 /* Theoretically, the slider could be bigger than the other button. But we're
366 * not going to worry about that now.
368 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
369 if (path_bar->button_list && path_bar->button_list->next != NULL)
371 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
372 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
377 gtk_path_bar_get_preferred_height (GtkWidget *widget,
381 ButtonData *button_data;
382 GtkPathBar *path_bar;
384 gint child_min, child_nat;
386 path_bar = GTK_PATH_BAR (widget);
388 *minimum = *natural = 0;
390 for (list = path_bar->button_list; list; list = list->next)
392 button_data = BUTTON_DATA (list->data);
393 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
395 *minimum = MAX (*minimum, child_min);
396 *natural = MAX (*natural, child_nat);
401 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
403 if (path_bar->button_list)
407 button = BUTTON_DATA (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->down_slider_button, FALSE);
414 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
416 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
417 if (gtk_widget_get_child_visible (button))
419 gtk_path_bar_stop_scrolling (path_bar);
420 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
423 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
428 gtk_path_bar_map (GtkWidget *widget)
430 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
432 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
436 gtk_path_bar_unmap (GtkWidget *widget)
438 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
439 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
441 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
445 gtk_path_bar_realize (GtkWidget *widget)
447 GtkPathBar *path_bar;
448 GtkAllocation allocation;
450 GdkWindowAttr attributes;
451 gint attributes_mask;
453 gtk_widget_set_realized (widget, TRUE);
455 path_bar = GTK_PATH_BAR (widget);
456 window = gtk_widget_get_parent_window (widget);
457 gtk_widget_set_window (widget, window);
458 g_object_ref (window);
460 gtk_widget_get_allocation (widget, &allocation);
462 attributes.window_type = GDK_WINDOW_CHILD;
463 attributes.x = allocation.x;
464 attributes.y = allocation.y;
465 attributes.width = allocation.width;
466 attributes.height = allocation.height;
467 attributes.wclass = GDK_INPUT_ONLY;
468 attributes.event_mask = gtk_widget_get_events (widget);
469 attributes.event_mask |= GDK_SCROLL_MASK;
470 attributes_mask = GDK_WA_X | GDK_WA_Y;
472 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
473 &attributes, attributes_mask);
474 gdk_window_set_user_data (path_bar->event_window, widget);
478 gtk_path_bar_unrealize (GtkWidget *widget)
480 GtkPathBar *path_bar;
482 path_bar = GTK_PATH_BAR (widget);
484 gdk_window_set_user_data (path_bar->event_window, NULL);
485 gdk_window_destroy (path_bar->event_window);
486 path_bar->event_window = NULL;
488 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
492 child_ordering_changed (GtkPathBar *path_bar)
496 if (path_bar->up_slider_button)
497 gtk_widget_reset_style (path_bar->up_slider_button);
498 if (path_bar->down_slider_button)
499 gtk_widget_reset_style (path_bar->down_slider_button);
501 for (l = path_bar->button_list; l; l = l->next)
503 ButtonData *data = l->data;
505 gtk_widget_reset_style (data->button);
509 /* This is a tad complicated
512 gtk_path_bar_size_allocate (GtkWidget *widget,
513 GtkAllocation *allocation)
516 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
517 GtkTextDirection direction;
518 GtkAllocation child_allocation;
519 GList *list, *first_button;
521 gint allocation_width;
522 gboolean need_sliders = FALSE;
523 gint up_slider_offset = 0;
524 GtkRequisition child_requisition;
526 gtk_widget_set_allocation (widget, allocation);
528 if (gtk_widget_get_realized (widget))
529 gdk_window_move_resize (path_bar->event_window,
530 allocation->x, allocation->y,
531 allocation->width, allocation->height);
533 /* No path is set; we don't have to allocate anything. */
534 if (path_bar->button_list == NULL)
537 direction = gtk_widget_get_direction (widget);
538 allocation_width = allocation->width;
540 /* First, we check to see if we need the scrollbars. */
541 if (path_bar->fake_root)
542 width = path_bar->spacing + path_bar->slider_width;
546 for (list = path_bar->button_list; list; list = list->next)
548 child = BUTTON_DATA (list->data)->button;
550 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
552 width += child_requisition.width + path_bar->spacing;
553 if (list == path_bar->fake_root)
557 if (width <= allocation_width)
559 if (path_bar->fake_root)
560 first_button = path_bar->fake_root;
562 first_button = g_list_last (path_bar->button_list);
566 gboolean reached_end = FALSE;
567 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
569 if (path_bar->first_scrolled_button)
570 first_button = path_bar->first_scrolled_button;
572 first_button = path_bar->button_list;
575 /* To see how much space we have, and how many buttons we can display.
576 * We start at the first button, count forward until hit the new
577 * button, then count backwards.
579 /* Count down the path chain towards the end. */
580 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
581 &child_requisition, NULL);
583 width = child_requisition.width;
584 list = first_button->prev;
585 while (list && !reached_end)
587 child = BUTTON_DATA (list->data)->button;
589 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
591 if (width + child_requisition.width +
592 path_bar->spacing + slider_space > allocation_width)
594 else if (list == path_bar->fake_root)
597 width += child_requisition.width + path_bar->spacing;
602 /* Finally, we walk up, seeing how many of the previous buttons we can
604 while (first_button->next && !reached_end)
606 child = BUTTON_DATA (first_button->next->data)->button;
608 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
610 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
616 width += child_requisition.width + path_bar->spacing;
617 if (first_button == path_bar->fake_root)
619 first_button = first_button->next;
624 /* Now, we allocate space to the buttons */
625 child_allocation.y = allocation->y;
626 child_allocation.height = allocation->height;
628 if (direction == GTK_TEXT_DIR_RTL)
630 child_allocation.x = allocation->x + allocation->width;
631 if (need_sliders || path_bar->fake_root)
633 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
634 up_slider_offset = allocation->width - path_bar->slider_width;
639 child_allocation.x = allocation->x;
640 if (need_sliders || path_bar->fake_root)
642 up_slider_offset = 0;
643 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
647 for (list = first_button; list; list = list->prev)
649 GtkAllocation widget_allocation;
650 ButtonData *button_data;
652 button_data = BUTTON_DATA (list->data);
653 child = button_data->button;
655 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
657 child_allocation.width = MIN (child_requisition.width,
658 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
660 if (direction == GTK_TEXT_DIR_RTL)
661 child_allocation.x -= child_allocation.width;
663 /* Check to see if we've don't have any more space to allocate buttons */
664 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
666 gtk_widget_get_allocation (widget, &widget_allocation);
667 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
670 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
672 gtk_widget_get_allocation (widget, &widget_allocation);
673 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
674 widget_allocation.x + allocation_width)
678 if (child_allocation.width < child_requisition.width)
680 if (!gtk_widget_get_has_tooltip (child))
681 gtk_widget_set_tooltip_text (child, button_data->dir_name);
683 else if (gtk_widget_get_has_tooltip (child))
684 gtk_widget_set_tooltip_text (child, NULL);
686 gtk_widget_set_child_visible (child, TRUE);
687 gtk_widget_size_allocate (child, &child_allocation);
689 if (direction == GTK_TEXT_DIR_RTL)
690 child_allocation.x -= path_bar->spacing;
692 child_allocation.x += child_allocation.width + path_bar->spacing;
694 /* Now we go hide all the widgets that don't fit */
697 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
700 for (list = first_button->next; list; list = list->next)
702 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
705 if (need_sliders || path_bar->fake_root)
707 child_allocation.width = path_bar->slider_width;
708 child_allocation.x = up_slider_offset + allocation->x;
709 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
711 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
712 gtk_widget_show_all (path_bar->up_slider_button);
715 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
719 child_allocation.width = path_bar->slider_width;
721 if (direction == GTK_TEXT_DIR_RTL)
722 child_allocation.x = 0;
724 child_allocation.x = allocation->width - path_bar->slider_width;
726 child_allocation.x += allocation->x;
728 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
730 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
731 gtk_widget_show_all (path_bar->down_slider_button);
732 gtk_path_bar_update_slider_buttons (path_bar);
735 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
737 child_ordering_changed (path_bar);
741 gtk_path_bar_style_updated (GtkWidget *widget)
743 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
745 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
749 gtk_path_bar_screen_changed (GtkWidget *widget,
750 GdkScreen *previous_screen)
752 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
753 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
755 /* We might nave a new settings, so we remove the old one */
757 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
759 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
763 gtk_path_bar_scroll (GtkWidget *widget,
764 GdkEventScroll *event)
766 switch (event->direction)
768 case GDK_SCROLL_RIGHT:
769 case GDK_SCROLL_DOWN:
770 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
772 case GDK_SCROLL_LEFT:
774 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
776 case GDK_SCROLL_SMOOTH:
784 gtk_path_bar_add (GtkContainer *container,
788 gtk_widget_set_parent (widget, GTK_WIDGET (container));
792 gtk_path_bar_remove_1 (GtkContainer *container,
795 gboolean was_visible = gtk_widget_get_visible (widget);
796 gtk_widget_unparent (widget);
798 gtk_widget_queue_resize (GTK_WIDGET (container));
802 gtk_path_bar_remove (GtkContainer *container,
805 GtkPathBar *path_bar;
808 path_bar = GTK_PATH_BAR (container);
810 if (widget == path_bar->up_slider_button)
812 gtk_path_bar_remove_1 (container, widget);
813 path_bar->up_slider_button = NULL;
817 if (widget == path_bar->down_slider_button)
819 gtk_path_bar_remove_1 (container, widget);
820 path_bar->down_slider_button = NULL;
824 children = path_bar->button_list;
827 if (widget == BUTTON_DATA (children->data)->button)
829 gtk_path_bar_remove_1 (container, widget);
830 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
831 g_list_free (children);
835 children = children->next;
840 gtk_path_bar_forall (GtkContainer *container,
841 gboolean include_internals,
842 GtkCallback callback,
843 gpointer callback_data)
845 GtkPathBar *path_bar;
848 g_return_if_fail (callback != NULL);
849 path_bar = GTK_PATH_BAR (container);
851 children = path_bar->button_list;
855 child = BUTTON_DATA (children->data)->button;
856 children = children->next;
858 (* callback) (child, callback_data);
861 if (path_bar->up_slider_button)
862 (* callback) (path_bar->up_slider_button, callback_data);
864 if (path_bar->down_slider_button)
865 (* callback) (path_bar->down_slider_button, callback_data);
868 static GtkWidgetPath *
869 gtk_path_bar_get_path_for_child (GtkContainer *container,
872 GtkPathBar *path_bar = GTK_PATH_BAR (container);
875 path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
877 if (gtk_widget_get_visible (child) &&
878 gtk_widget_get_child_visible (child))
880 GtkWidgetPath *sibling_path;
881 GList *visible_children;
885 /* 1. Build the list of visible children, in visually left-to-right order
886 * (i.e. independently of the widget's direction). Note that our
887 * button_list is stored in innermost-to-outermost path order!
890 visible_children = NULL;
892 if (gtk_widget_get_visible (path_bar->down_slider_button) &&
893 gtk_widget_get_child_visible (path_bar->down_slider_button))
894 visible_children = g_list_prepend (visible_children, path_bar->down_slider_button);
896 for (l = path_bar->button_list; l; l = l->next)
898 ButtonData *data = l->data;
900 if (gtk_widget_get_visible (data->button) &&
901 gtk_widget_get_child_visible (data->button))
902 visible_children = g_list_prepend (visible_children, data->button);
905 if (gtk_widget_get_visible (path_bar->up_slider_button) &&
906 gtk_widget_get_child_visible (path_bar->up_slider_button))
907 visible_children = g_list_prepend (visible_children, path_bar->up_slider_button);
909 if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
910 visible_children = g_list_reverse (visible_children);
912 /* 2. Find the index of the child within that list */
916 for (l = visible_children; l; l = l->next)
918 GtkWidget *button = l->data;
926 /* 3. Build the path */
928 sibling_path = gtk_widget_path_new ();
930 for (l = visible_children; l; l = l->next)
931 gtk_widget_path_append_for_widget (sibling_path, l->data);
933 gtk_widget_path_append_with_siblings (path, sibling_path, pos);
935 g_list_free (visible_children);
936 gtk_widget_path_unref (sibling_path);
939 gtk_widget_path_append_for_widget (path, child);
945 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
947 GtkAllocation allocation, button_allocation;
949 GList *down_button = NULL;
950 gint space_available;
952 if (path_bar->ignore_click)
954 path_bar->ignore_click = FALSE;
958 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
960 /* Return if the last button is already visible */
964 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
966 /* We find the button at the 'down' end that we have to make
968 for (list = path_bar->button_list; list; list = list->next)
970 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
977 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
978 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
980 space_available = (allocation.width
981 - 2 * path_bar->spacing - 2 * path_bar->slider_width
982 - button_allocation.width);
983 path_bar->first_scrolled_button = down_button;
985 /* We have space_available free space that's not being used.
986 * So we walk down from the end, adding buttons until we use all free space.
988 while (space_available > 0)
990 path_bar->first_scrolled_button = down_button;
991 down_button = down_button->next;
994 space_available -= (button_allocation.width
995 + path_bar->spacing);
1000 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
1004 if (path_bar->ignore_click)
1006 path_bar->ignore_click = FALSE;
1010 list = g_list_last (path_bar->button_list);
1012 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1014 /* Return if the first button is already visible */
1018 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1020 for ( ; list; list = list->prev)
1022 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
1024 if (list->prev == path_bar->fake_root)
1025 path_bar->fake_root = NULL;
1026 path_bar->first_scrolled_button = list;
1033 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
1035 gboolean retval = FALSE;
1037 if (path_bar->timer)
1039 if (path_bar->scrolling_up)
1040 gtk_path_bar_scroll_up (path_bar);
1041 else if (path_bar->scrolling_down)
1042 gtk_path_bar_scroll_down (path_bar);
1044 if (path_bar->need_timer)
1046 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
1049 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
1051 path_bar->need_timer = FALSE;
1053 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
1054 (GSourceFunc)gtk_path_bar_scroll_timeout,
1065 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
1067 if (path_bar->timer)
1069 g_source_remove (path_bar->timer);
1070 path_bar->timer = 0;
1071 path_bar->need_timer = FALSE;
1076 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
1077 GdkEventButton *event,
1078 GtkPathBar *path_bar)
1081 GList *up_button = NULL;
1083 if (event->type != GDK_FOCUS_CHANGE)
1086 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
1088 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1095 /* don't let the focus vanish */
1096 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
1097 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
1098 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
1104 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
1105 GdkEventButton *event,
1106 GtkPathBar *path_bar)
1109 GList *down_button = NULL;
1111 if (event->type != GDK_FOCUS_CHANGE)
1114 for (list = path_bar->button_list; list; list = list->next)
1116 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1123 /* don't let the focus vanish */
1124 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1125 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1126 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1132 gtk_path_bar_slider_button_press (GtkWidget *widget,
1133 GdkEventButton *event,
1134 GtkPathBar *path_bar)
1136 if (event->type != GDK_BUTTON_PRESS || event->button != GDK_BUTTON_PRIMARY)
1139 path_bar->ignore_click = FALSE;
1141 if (widget == path_bar->up_slider_button)
1143 path_bar->scrolling_down = FALSE;
1144 path_bar->scrolling_up = TRUE;
1145 gtk_path_bar_scroll_up (path_bar);
1147 else if (widget == path_bar->down_slider_button)
1149 path_bar->scrolling_up = FALSE;
1150 path_bar->scrolling_down = TRUE;
1151 gtk_path_bar_scroll_down (path_bar);
1154 if (!path_bar->timer)
1156 GtkSettings *settings = gtk_widget_get_settings (widget);
1159 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1161 path_bar->need_timer = TRUE;
1162 path_bar->timer = gdk_threads_add_timeout (timeout,
1163 (GSourceFunc)gtk_path_bar_scroll_timeout,
1171 gtk_path_bar_slider_button_release (GtkWidget *widget,
1172 GdkEventButton *event,
1173 GtkPathBar *path_bar)
1175 if (event->type != GDK_BUTTON_RELEASE)
1178 path_bar->ignore_click = TRUE;
1179 gtk_path_bar_stop_scrolling (path_bar);
1185 gtk_path_bar_grab_notify (GtkWidget *widget,
1186 gboolean was_grabbed)
1189 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1193 gtk_path_bar_state_changed (GtkWidget *widget,
1194 GtkStateType previous_state)
1196 if (!gtk_widget_is_sensitive (widget))
1197 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1201 /* Changes the icons wherever it is needed */
1203 reload_icons (GtkPathBar *path_bar)
1207 if (path_bar->root_icon)
1209 g_object_unref (path_bar->root_icon);
1210 path_bar->root_icon = NULL;
1212 if (path_bar->home_icon)
1214 g_object_unref (path_bar->home_icon);
1215 path_bar->home_icon = NULL;
1217 if (path_bar->desktop_icon)
1219 g_object_unref (path_bar->desktop_icon);
1220 path_bar->desktop_icon = NULL;
1223 for (list = path_bar->button_list; list; list = list->next)
1225 ButtonData *button_data;
1226 gboolean current_dir;
1228 button_data = BUTTON_DATA (list->data);
1229 if (button_data->type != NORMAL_BUTTON)
1231 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1232 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1239 change_icon_theme (GtkPathBar *path_bar)
1241 GtkSettings *settings;
1244 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1246 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1247 path_bar->icon_size = MAX (width, height);
1249 path_bar->icon_size = FALLBACK_ICON_SIZE;
1251 reload_icons (path_bar);
1253 /* Callback used when a GtkSettings value changes */
1255 settings_notify_cb (GObject *object,
1257 GtkPathBar *path_bar)
1261 name = g_param_spec_get_name (pspec);
1263 if (! strcmp (name, "gtk-icon-theme-name") ||
1264 ! strcmp (name, "gtk-icon-sizes"))
1265 change_icon_theme (path_bar);
1269 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1271 GtkSettings *settings;
1273 if (path_bar->settings_signal_id)
1276 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1277 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1279 change_icon_theme (path_bar);
1282 /* Public functions and their helpers */
1284 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1286 while (path_bar->button_list != NULL)
1288 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1290 path_bar->first_scrolled_button = NULL;
1291 path_bar->fake_root = NULL;
1295 button_clicked_cb (GtkWidget *button,
1298 ButtonData *button_data;
1299 GtkPathBar *path_bar;
1301 gboolean child_is_hidden;
1304 button_data = BUTTON_DATA (data);
1305 if (button_data->ignore_changes)
1308 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1310 button_list = g_list_find (path_bar->button_list, button_data);
1311 g_assert (button_list != NULL);
1313 g_signal_handlers_block_by_func (button,
1314 G_CALLBACK (button_clicked_cb), data);
1315 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1316 g_signal_handlers_unblock_by_func (button,
1317 G_CALLBACK (button_clicked_cb), data);
1319 if (button_list->prev)
1321 ButtonData *child_data;
1323 child_data = BUTTON_DATA (button_list->prev->data);
1324 child_file = child_data->file;
1325 child_is_hidden = child_data->file_is_hidden;
1330 child_is_hidden = FALSE;
1333 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1334 button_data->file, child_file, child_is_hidden);
1337 struct SetButtonImageData
1339 GtkPathBar *path_bar;
1340 ButtonData *button_data;
1344 set_button_image_get_info_cb (GCancellable *cancellable,
1346 const GError *error,
1349 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1351 struct SetButtonImageData *data = user_data;
1353 if (cancellable != data->button_data->cancellable)
1356 data->button_data->cancellable = NULL;
1358 if (!data->button_data->button)
1360 g_free (data->button_data);
1364 if (cancelled || error)
1367 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1368 data->path_bar->icon_size);
1369 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1371 switch (data->button_data->type)
1374 if (data->path_bar->home_icon)
1375 g_object_unref (pixbuf);
1377 data->path_bar->home_icon = pixbuf;
1380 case DESKTOP_BUTTON:
1381 if (data->path_bar->desktop_icon)
1382 g_object_unref (pixbuf);
1384 data->path_bar->desktop_icon = pixbuf;
1393 g_object_unref (cancellable);
1397 set_button_image (GtkPathBar *path_bar,
1398 ButtonData *button_data)
1400 GtkFileSystemVolume *volume;
1401 struct SetButtonImageData *data;
1403 switch (button_data->type)
1407 if (path_bar->root_icon != NULL)
1409 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1413 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1417 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1418 GTK_WIDGET (path_bar),
1419 path_bar->icon_size,
1421 _gtk_file_system_volume_unref (volume);
1423 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1427 if (path_bar->home_icon != NULL)
1429 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1433 data = g_new0 (struct SetButtonImageData, 1);
1434 data->path_bar = path_bar;
1435 data->button_data = button_data;
1437 if (button_data->cancellable)
1438 g_cancellable_cancel (button_data->cancellable);
1440 button_data->cancellable =
1441 _gtk_file_system_get_info (path_bar->file_system,
1442 path_bar->home_file,
1444 set_button_image_get_info_cb,
1448 case DESKTOP_BUTTON:
1449 if (path_bar->desktop_icon != NULL)
1451 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1455 data = g_new0 (struct SetButtonImageData, 1);
1456 data->path_bar = path_bar;
1457 data->button_data = button_data;
1459 if (button_data->cancellable)
1460 g_cancellable_cancel (button_data->cancellable);
1462 button_data->cancellable =
1463 _gtk_file_system_get_info (path_bar->file_system,
1464 path_bar->desktop_file,
1466 set_button_image_get_info_cb,
1475 button_data_free (ButtonData *button_data)
1477 if (button_data->file)
1478 g_object_unref (button_data->file);
1479 button_data->file = NULL;
1481 g_free (button_data->dir_name);
1482 button_data->dir_name = NULL;
1484 button_data->button = NULL;
1486 if (button_data->cancellable)
1487 g_cancellable_cancel (button_data->cancellable);
1489 g_free (button_data);
1493 get_dir_name (ButtonData *button_data)
1495 return button_data->dir_name;
1498 /* We always want to request the same size for the label, whether
1499 * or not the contents are bold
1502 set_label_size_request (GtkWidget *widget,
1503 ButtonData *button_data)
1505 const gchar *dir_name = get_dir_name (button_data);
1506 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1507 gint width, height, bold_width, bold_height;
1510 pango_layout_get_pixel_size (layout, &width, &height);
1512 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1513 pango_layout_set_markup (layout, markup, -1);
1516 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1518 gtk_widget_set_size_request (widget,
1519 MAX (width, bold_width),
1520 MAX (height, bold_height));
1521 g_object_unref (layout);
1525 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1526 ButtonData *button_data,
1527 gboolean current_dir)
1529 const gchar *dir_name = get_dir_name (button_data);
1531 if (button_data->label != NULL)
1537 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1538 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1543 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1547 if (button_data->image != NULL)
1549 set_button_image (path_bar, button_data);
1552 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1554 button_data->ignore_changes = TRUE;
1555 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1556 button_data->ignore_changes = FALSE;
1561 find_button_type (GtkPathBar *path_bar,
1564 if (path_bar->root_file != NULL &&
1565 g_file_equal (file, path_bar->root_file))
1567 if (path_bar->home_file != NULL &&
1568 g_file_equal (file, path_bar->home_file))
1570 if (path_bar->desktop_file != NULL &&
1571 g_file_equal (file, path_bar->desktop_file))
1572 return DESKTOP_BUTTON;
1574 return NORMAL_BUTTON;
1578 button_drag_data_get_cb (GtkWidget *widget,
1579 GdkDragContext *context,
1580 GtkSelectionData *selection_data,
1585 ButtonData *button_data;
1590 uris[0] = g_file_get_uri (button_data->file);
1593 gtk_selection_data_set_uris (selection_data, uris);
1599 make_directory_button (GtkPathBar *path_bar,
1600 const char *dir_name,
1602 gboolean current_dir,
1603 gboolean file_is_hidden)
1606 GtkWidget *child = NULL;
1607 ButtonData *button_data;
1609 file_is_hidden = !! file_is_hidden;
1610 /* Is it a special button? */
1611 button_data = g_new0 (ButtonData, 1);
1613 button_data->type = find_button_type (path_bar, file);
1614 button_data->button = gtk_toggle_button_new ();
1615 atk_obj = gtk_widget_get_accessible (button_data->button);
1616 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1617 gtk_widget_add_events (button_data->button, GDK_SCROLL_MASK);
1619 switch (button_data->type)
1622 button_data->image = gtk_image_new ();
1623 child = button_data->image;
1624 button_data->label = NULL;
1625 atk_object_set_name (atk_obj, _("File System Root"));
1628 case DESKTOP_BUTTON:
1629 button_data->image = gtk_image_new ();
1630 button_data->label = gtk_label_new (NULL);
1631 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1632 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1633 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
1637 button_data->label = gtk_label_new (NULL);
1638 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1639 child = button_data->label;
1640 button_data->image = NULL;
1643 button_data->dir_name = g_strdup (dir_name);
1644 button_data->file = g_object_ref (file);
1645 button_data->file_is_hidden = file_is_hidden;
1648 * The following function ensures that the alignment will always
1649 * request the same size whether the button's text is bold or not.
1651 if (button_data->label)
1652 set_label_size_request (button_data->label, button_data);
1654 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1655 gtk_widget_show_all (button_data->button);
1657 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1659 g_signal_connect (button_data->button, "clicked",
1660 G_CALLBACK (button_clicked_cb),
1662 g_object_weak_ref (G_OBJECT (button_data->button),
1663 (GWeakNotify) button_data_free, button_data);
1665 gtk_drag_source_set (button_data->button,
1669 gtk_drag_source_add_uri_targets (button_data->button);
1670 g_signal_connect (button_data->button, "drag-data-get",
1671 G_CALLBACK (button_drag_data_get_cb), button_data);
1677 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1681 GList *current_path = NULL;
1682 gboolean need_new_fake_root = FALSE;
1684 for (list = path_bar->button_list; list; list = list->next)
1686 ButtonData *button_data;
1688 button_data = list->data;
1689 if (g_file_equal (file, button_data->file))
1691 current_path = list;
1694 if (list == path_bar->fake_root)
1695 need_new_fake_root = TRUE;
1700 if (need_new_fake_root)
1702 path_bar->fake_root = NULL;
1703 for (list = current_path; list; list = list->next)
1705 ButtonData *button_data;
1707 button_data = list->data;
1708 if (BUTTON_IS_FAKE_ROOT (button_data))
1710 path_bar->fake_root = list;
1716 for (list = path_bar->button_list; list; list = list->next)
1718 gtk_path_bar_update_button_appearance (path_bar,
1719 BUTTON_DATA (list->data),
1720 (list == current_path) ? TRUE : FALSE);
1723 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1725 path_bar->first_scrolled_button = current_path;
1726 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1739 GtkPathBar *path_bar;
1742 gboolean first_directory;
1746 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1753 gtk_path_bar_clear_buttons (info->path_bar);
1754 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1755 info->path_bar->fake_root = info->fake_root;
1757 for (l = info->path_bar->button_list; l; l = l->next)
1759 GtkWidget *button = BUTTON_DATA (l->data)->button;
1760 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1763 child_ordering_changed (info->path_bar);
1769 for (l = info->new_buttons; l; l = l->next)
1771 ButtonData *button_data;
1773 button_data = BUTTON_DATA (l->data);
1774 gtk_widget_destroy (button_data->button);
1777 g_list_free (info->new_buttons);
1781 g_object_unref (info->file);
1782 if (info->parent_file)
1783 g_object_unref (info->parent_file);
1789 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1791 const GError *error,
1794 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1795 struct SetFileInfo *file_info = data;
1796 ButtonData *button_data;
1797 const gchar *display_name;
1800 if (cancellable != file_info->path_bar->get_info_cancellable)
1802 gtk_path_bar_set_file_finish (file_info, FALSE);
1803 g_object_unref (cancellable);
1807 g_object_unref (cancellable);
1808 file_info->path_bar->get_info_cancellable = NULL;
1810 if (cancelled || !info)
1812 gtk_path_bar_set_file_finish (file_info, FALSE);
1816 display_name = g_file_info_get_display_name (info);
1817 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1819 gtk_widget_push_composite_child ();
1820 button_data = make_directory_button (file_info->path_bar, display_name,
1822 file_info->first_directory, is_hidden);
1823 gtk_widget_pop_composite_child ();
1824 g_object_unref (file_info->file);
1826 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1828 if (BUTTON_IS_FAKE_ROOT (button_data))
1829 file_info->fake_root = file_info->new_buttons;
1831 /* We have assigned the info for the innermost button, i.e. the deepest directory.
1832 * Now, go on to fetch the info for this directory's parent.
1835 file_info->file = file_info->parent_file;
1836 file_info->first_directory = FALSE;
1838 if (!file_info->file)
1840 /* No parent? Okay, we are done. */
1841 gtk_path_bar_set_file_finish (file_info, TRUE);
1845 file_info->parent_file = g_file_get_parent (file_info->file);
1847 /* Recurse asynchronously */
1848 file_info->path_bar->get_info_cancellable =
1849 _gtk_file_system_get_info (file_info->path_bar->file_system,
1851 "standard::display-name,standard::is-hidden,standard::is-backup",
1852 gtk_path_bar_get_info_callback,
1857 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1859 const gboolean keep_trail)
1861 struct SetFileInfo *info;
1863 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1864 g_return_if_fail (G_IS_FILE (file));
1866 /* Check whether the new path is already present in the pathbar as buttons.
1867 * This could be a parent directory or a previous selected subdirectory.
1869 if (keep_trail && gtk_path_bar_check_parent_path (path_bar, file))
1872 info = g_new0 (struct SetFileInfo, 1);
1873 info->file = g_object_ref (file);
1874 info->path_bar = path_bar;
1875 info->first_directory = TRUE;
1876 info->parent_file = g_file_get_parent (info->file);
1878 if (path_bar->get_info_cancellable)
1879 g_cancellable_cancel (path_bar->get_info_cancellable);
1881 path_bar->get_info_cancellable =
1882 _gtk_file_system_get_info (path_bar->file_system,
1884 "standard::display-name,standard::is-hidden,standard::is-backup",
1885 gtk_path_bar_get_info_callback,
1889 /* FIXME: This should be a construct-only property */
1891 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1892 GtkFileSystem *file_system)
1896 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1898 g_assert (path_bar->file_system == NULL);
1900 path_bar->file_system = g_object_ref (file_system);
1902 home = g_get_home_dir ();
1905 const gchar *desktop;
1907 path_bar->home_file = g_file_new_for_path (home);
1908 /* FIXME: Need file system backend specific way of getting the
1911 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1912 if (desktop != NULL)
1913 path_bar->desktop_file = g_file_new_for_path (desktop);
1915 path_bar->desktop_file = NULL;
1919 path_bar->home_file = NULL;
1920 path_bar->desktop_file = NULL;
1922 path_bar->root_file = g_file_new_for_path ("/");
1927 * @path_bar: a #GtkPathBar
1929 * If the selected button in the pathbar is not the furthest button "up" (in the
1930 * root direction), act as if the user clicked on the next button up.
1933 _gtk_path_bar_up (GtkPathBar *path_bar)
1937 for (l = path_bar->button_list; l; l = l->next)
1939 GtkWidget *button = BUTTON_DATA (l->data)->button;
1940 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1944 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1945 button_clicked_cb (next_button, l->next->data);
1953 * _gtk_path_bar_down:
1954 * @path_bar: a #GtkPathBar
1956 * If the selected button in the pathbar is not the furthest button "down" (in the
1957 * leaf direction), act as if the user clicked on the next button down.
1960 _gtk_path_bar_down (GtkPathBar *path_bar)
1964 for (l = path_bar->button_list; l; l = l->next)
1966 GtkWidget *button = BUTTON_DATA (l->data)->button;
1967 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1971 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1972 button_clicked_cb (prev_button, l->prev->data);