1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
3 * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkpathbar.h"
27 #include "gtktogglebutton.h"
32 #include "gtkicontheme.h"
33 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
52 #define BUTTON_DATA(x) ((ButtonData *)(x))
54 #define SCROLL_DELAY_FACTOR 5
56 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
58 /* Icon size for if we can't get it from the theme */
59 #define FALLBACK_ICON_SIZE 16
61 typedef struct _ButtonData ButtonData;
71 GCancellable *cancellable;
72 guint ignore_changes : 1;
73 guint file_is_hidden : 1;
75 /* This macro is used to check if a button can be used as a fake root.
76 * All buttons in front of a fake root are automatically hidden when in a
77 * directory below a fake root and replaced with the "<" arrow button.
79 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
81 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
83 static void gtk_path_bar_finalize (GObject *object);
84 static void gtk_path_bar_dispose (GObject *object);
85 static void gtk_path_bar_realize (GtkWidget *widget);
86 static void gtk_path_bar_unrealize (GtkWidget *widget);
87 static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
90 static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
93 static void gtk_path_bar_map (GtkWidget *widget);
94 static void gtk_path_bar_unmap (GtkWidget *widget);
95 static void gtk_path_bar_size_allocate (GtkWidget *widget,
96 GtkAllocation *allocation);
97 static void gtk_path_bar_add (GtkContainer *container,
99 static void gtk_path_bar_remove (GtkContainer *container,
101 static void gtk_path_bar_forall (GtkContainer *container,
102 gboolean include_internals,
103 GtkCallback callback,
104 gpointer callback_data);
105 static 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_container_add (GTK_CONTAINER (button),
164 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
165 gtk_container_add (GTK_CONTAINER (path_bar), button);
166 gtk_widget_show_all (button);
168 g_signal_connect (G_OBJECT (button), "unmap",
169 G_CALLBACK (on_slider_unmap), path_bar);
171 gtk_widget_pop_composite_child ();
177 gtk_path_bar_init (GtkPathBar *path_bar)
179 GtkStyleContext *context;
181 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
182 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
184 path_bar->get_info_cancellable = NULL;
186 path_bar->spacing = 0;
187 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
188 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
189 path_bar->icon_size = FALLBACK_ICON_SIZE;
191 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
192 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
193 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
194 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
196 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
197 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
198 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
199 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
201 g_signal_connect (path_bar->up_slider_button, "button-press-event",
202 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
203 g_signal_connect (path_bar->up_slider_button, "button-release-event",
204 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
205 g_signal_connect (path_bar->down_slider_button, "button-press-event",
206 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
207 g_signal_connect (path_bar->down_slider_button, "button-release-event",
208 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
210 context = gtk_widget_get_style_context (GTK_WIDGET (path_bar));
211 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
215 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
217 GObjectClass *gobject_class;
218 GtkWidgetClass *widget_class;
219 GtkContainerClass *container_class;
221 gobject_class = (GObjectClass *) path_bar_class;
222 widget_class = (GtkWidgetClass *) path_bar_class;
223 container_class = (GtkContainerClass *) path_bar_class;
225 gobject_class->finalize = gtk_path_bar_finalize;
226 gobject_class->dispose = gtk_path_bar_dispose;
228 widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
229 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
230 widget_class->realize = gtk_path_bar_realize;
231 widget_class->unrealize = gtk_path_bar_unrealize;
232 widget_class->map = gtk_path_bar_map;
233 widget_class->unmap = gtk_path_bar_unmap;
234 widget_class->size_allocate = gtk_path_bar_size_allocate;
235 widget_class->style_updated = gtk_path_bar_style_updated;
236 widget_class->screen_changed = gtk_path_bar_screen_changed;
237 widget_class->grab_notify = gtk_path_bar_grab_notify;
238 widget_class->state_changed = gtk_path_bar_state_changed;
239 widget_class->scroll_event = gtk_path_bar_scroll;
241 container_class->add = gtk_path_bar_add;
242 container_class->forall = gtk_path_bar_forall;
243 container_class->remove = gtk_path_bar_remove;
244 container_class->get_path_for_child = gtk_path_bar_get_path_for_child;
245 gtk_container_class_handle_border_width (container_class);
247 /* container_class->child_type = gtk_path_bar_child_type;*/
249 path_bar_signals [PATH_CLICKED] =
250 g_signal_new (I_("path-clicked"),
251 G_OBJECT_CLASS_TYPE (gobject_class),
253 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
255 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
264 gtk_path_bar_finalize (GObject *object)
266 GtkPathBar *path_bar;
268 path_bar = GTK_PATH_BAR (object);
270 gtk_path_bar_stop_scrolling (path_bar);
272 g_list_free (path_bar->button_list);
273 if (path_bar->root_file)
274 g_object_unref (path_bar->root_file);
275 if (path_bar->home_file)
276 g_object_unref (path_bar->home_file);
277 if (path_bar->desktop_file)
278 g_object_unref (path_bar->desktop_file);
280 if (path_bar->root_icon)
281 g_object_unref (path_bar->root_icon);
282 if (path_bar->home_icon)
283 g_object_unref (path_bar->home_icon);
284 if (path_bar->desktop_icon)
285 g_object_unref (path_bar->desktop_icon);
287 if (path_bar->file_system)
288 g_object_unref (path_bar->file_system);
290 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
293 /* Removes the settings signal handler. It's safe to call multiple times */
295 remove_settings_signal (GtkPathBar *path_bar,
298 if (path_bar->settings_signal_id)
300 GtkSettings *settings;
302 settings = gtk_settings_get_for_screen (screen);
303 g_signal_handler_disconnect (settings,
304 path_bar->settings_signal_id);
305 path_bar->settings_signal_id = 0;
310 gtk_path_bar_dispose (GObject *object)
312 GtkPathBar *path_bar = GTK_PATH_BAR (object);
314 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
316 if (path_bar->get_info_cancellable)
317 g_cancellable_cancel (path_bar->get_info_cancellable);
318 path_bar->get_info_cancellable = NULL;
320 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
325 * Ideally, our size is determined by another widget, and we are just filling
329 gtk_path_bar_get_preferred_width (GtkWidget *widget,
333 ButtonData *button_data;
334 GtkPathBar *path_bar;
338 gint child_min, child_nat;
340 path_bar = GTK_PATH_BAR (widget);
342 *minimum = *natural = 0;
345 for (list = path_bar->button_list; list; list = list->next)
347 button_data = BUTTON_DATA (list->data);
348 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
349 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
350 height = MAX (height, child_height);
352 if (button_data->type == NORMAL_BUTTON)
354 /* Use 2*Height as button width because of ellipsized label. */
355 child_min = MAX (child_min, child_height * 2);
356 child_nat = MAX (child_min, child_height * 2);
359 *minimum = MAX (*minimum, child_min);
360 *natural = MAX (*natural, child_nat);
363 /* Add space for slider, if we have more than one path */
364 /* Theoretically, the slider could be bigger than the other button. But we're
365 * not going to worry about that now.
367 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
368 if (path_bar->button_list && path_bar->button_list->next != NULL)
370 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
371 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
376 gtk_path_bar_get_preferred_height (GtkWidget *widget,
380 ButtonData *button_data;
381 GtkPathBar *path_bar;
383 gint child_min, child_nat;
385 path_bar = GTK_PATH_BAR (widget);
387 *minimum = *natural = 0;
389 for (list = path_bar->button_list; list; list = list->next)
391 button_data = BUTTON_DATA (list->data);
392 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
394 *minimum = MAX (*minimum, child_min);
395 *natural = MAX (*natural, child_nat);
400 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
402 if (path_bar->button_list)
406 button = BUTTON_DATA (path_bar->button_list->data)->button;
407 if (gtk_widget_get_child_visible (button))
409 gtk_path_bar_stop_scrolling (path_bar);
410 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
413 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
415 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
416 if (gtk_widget_get_child_visible (button))
418 gtk_path_bar_stop_scrolling (path_bar);
419 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
422 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
427 gtk_path_bar_map (GtkWidget *widget)
429 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
431 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
435 gtk_path_bar_unmap (GtkWidget *widget)
437 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
438 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
440 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
444 gtk_path_bar_realize (GtkWidget *widget)
446 GtkPathBar *path_bar;
447 GtkAllocation allocation;
449 GdkWindowAttr attributes;
450 gint attributes_mask;
452 gtk_widget_set_realized (widget, TRUE);
454 path_bar = GTK_PATH_BAR (widget);
455 window = gtk_widget_get_parent_window (widget);
456 gtk_widget_set_window (widget, window);
457 g_object_ref (window);
459 gtk_widget_get_allocation (widget, &allocation);
461 attributes.window_type = GDK_WINDOW_CHILD;
462 attributes.x = allocation.x;
463 attributes.y = allocation.y;
464 attributes.width = allocation.width;
465 attributes.height = allocation.height;
466 attributes.wclass = GDK_INPUT_ONLY;
467 attributes.event_mask = gtk_widget_get_events (widget);
468 attributes.event_mask |= GDK_SCROLL_MASK;
469 attributes_mask = GDK_WA_X | GDK_WA_Y;
471 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
472 &attributes, attributes_mask);
473 gdk_window_set_user_data (path_bar->event_window, widget);
477 gtk_path_bar_unrealize (GtkWidget *widget)
479 GtkPathBar *path_bar;
481 path_bar = GTK_PATH_BAR (widget);
483 gdk_window_set_user_data (path_bar->event_window, NULL);
484 gdk_window_destroy (path_bar->event_window);
485 path_bar->event_window = NULL;
487 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
491 child_ordering_changed (GtkPathBar *path_bar)
495 if (path_bar->up_slider_button)
496 gtk_widget_reset_style (path_bar->up_slider_button);
497 if (path_bar->down_slider_button)
498 gtk_widget_reset_style (path_bar->down_slider_button);
500 for (l = path_bar->button_list; l; l = l->next)
502 ButtonData *data = l->data;
504 gtk_widget_reset_style (data->button);
508 /* This is a tad complicated
511 gtk_path_bar_size_allocate (GtkWidget *widget,
512 GtkAllocation *allocation)
515 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
516 GtkTextDirection direction;
517 GtkAllocation child_allocation;
518 GList *list, *first_button;
520 gint allocation_width;
521 gboolean need_sliders = FALSE;
522 gint up_slider_offset = 0;
523 GtkRequisition child_requisition;
525 gtk_widget_set_allocation (widget, allocation);
527 if (gtk_widget_get_realized (widget))
528 gdk_window_move_resize (path_bar->event_window,
529 allocation->x, allocation->y,
530 allocation->width, allocation->height);
532 /* No path is set; we don't have to allocate anything. */
533 if (path_bar->button_list == NULL)
536 direction = gtk_widget_get_direction (widget);
537 allocation_width = allocation->width;
539 /* First, we check to see if we need the scrollbars. */
540 if (path_bar->fake_root)
541 width = path_bar->spacing + path_bar->slider_width;
545 for (list = path_bar->button_list; list; list = list->next)
547 child = BUTTON_DATA (list->data)->button;
549 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
551 width += child_requisition.width + path_bar->spacing;
552 if (list == path_bar->fake_root)
556 if (width <= allocation_width)
558 if (path_bar->fake_root)
559 first_button = path_bar->fake_root;
561 first_button = g_list_last (path_bar->button_list);
565 gboolean reached_end = FALSE;
566 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
568 if (path_bar->first_scrolled_button)
569 first_button = path_bar->first_scrolled_button;
571 first_button = path_bar->button_list;
574 /* To see how much space we have, and how many buttons we can display.
575 * We start at the first button, count forward until hit the new
576 * button, then count backwards.
578 /* Count down the path chain towards the end. */
579 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
580 &child_requisition, NULL);
582 width = child_requisition.width;
583 list = first_button->prev;
584 while (list && !reached_end)
586 child = BUTTON_DATA (list->data)->button;
588 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
590 if (width + child_requisition.width +
591 path_bar->spacing + slider_space > allocation_width)
593 else if (list == path_bar->fake_root)
596 width += child_requisition.width + path_bar->spacing;
601 /* Finally, we walk up, seeing how many of the previous buttons we can
603 while (first_button->next && !reached_end)
605 child = BUTTON_DATA (first_button->next->data)->button;
607 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
609 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
615 width += child_requisition.width + path_bar->spacing;
616 if (first_button == path_bar->fake_root)
618 first_button = first_button->next;
623 /* Now, we allocate space to the buttons */
624 child_allocation.y = allocation->y;
625 child_allocation.height = allocation->height;
627 if (direction == GTK_TEXT_DIR_RTL)
629 child_allocation.x = allocation->x + allocation->width;
630 if (need_sliders || path_bar->fake_root)
632 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
633 up_slider_offset = allocation->width - path_bar->slider_width;
638 child_allocation.x = allocation->x;
639 if (need_sliders || path_bar->fake_root)
641 up_slider_offset = 0;
642 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
646 for (list = first_button; list; list = list->prev)
648 GtkAllocation widget_allocation;
649 ButtonData *button_data;
651 button_data = BUTTON_DATA (list->data);
652 child = button_data->button;
654 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
656 child_allocation.width = MIN (child_requisition.width,
657 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
659 if (direction == GTK_TEXT_DIR_RTL)
660 child_allocation.x -= child_allocation.width;
662 /* Check to see if we've don't have any more space to allocate buttons */
663 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
665 gtk_widget_get_allocation (widget, &widget_allocation);
666 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
669 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
671 gtk_widget_get_allocation (widget, &widget_allocation);
672 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
673 widget_allocation.x + allocation_width)
677 if (child_allocation.width < child_requisition.width)
679 if (!gtk_widget_get_has_tooltip (child))
680 gtk_widget_set_tooltip_text (child, button_data->dir_name);
682 else if (gtk_widget_get_has_tooltip (child))
683 gtk_widget_set_tooltip_text (child, NULL);
685 gtk_widget_set_child_visible (child, TRUE);
686 gtk_widget_size_allocate (child, &child_allocation);
688 if (direction == GTK_TEXT_DIR_RTL)
689 child_allocation.x -= path_bar->spacing;
691 child_allocation.x += child_allocation.width + path_bar->spacing;
693 /* Now we go hide all the widgets that don't fit */
696 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
699 for (list = first_button->next; list; list = list->next)
701 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
704 if (need_sliders || path_bar->fake_root)
706 child_allocation.width = path_bar->slider_width;
707 child_allocation.x = up_slider_offset + allocation->x;
708 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
710 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
711 gtk_widget_show_all (path_bar->up_slider_button);
714 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
718 child_allocation.width = path_bar->slider_width;
720 if (direction == GTK_TEXT_DIR_RTL)
721 child_allocation.x = 0;
723 child_allocation.x = allocation->width - path_bar->slider_width;
725 child_allocation.x += allocation->x;
727 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
729 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
730 gtk_widget_show_all (path_bar->down_slider_button);
731 gtk_path_bar_update_slider_buttons (path_bar);
734 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
736 child_ordering_changed (path_bar);
740 gtk_path_bar_style_updated (GtkWidget *widget)
742 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
744 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
748 gtk_path_bar_screen_changed (GtkWidget *widget,
749 GdkScreen *previous_screen)
751 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
752 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
754 /* We might nave a new settings, so we remove the old one */
756 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
758 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
762 gtk_path_bar_scroll (GtkWidget *widget,
763 GdkEventScroll *event)
765 switch (event->direction)
767 case GDK_SCROLL_RIGHT:
768 case GDK_SCROLL_DOWN:
769 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
771 case GDK_SCROLL_LEFT:
773 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
781 gtk_path_bar_add (GtkContainer *container,
785 gtk_widget_set_parent (widget, GTK_WIDGET (container));
789 gtk_path_bar_remove_1 (GtkContainer *container,
792 gboolean was_visible = gtk_widget_get_visible (widget);
793 gtk_widget_unparent (widget);
795 gtk_widget_queue_resize (GTK_WIDGET (container));
799 gtk_path_bar_remove (GtkContainer *container,
802 GtkPathBar *path_bar;
805 path_bar = GTK_PATH_BAR (container);
807 if (widget == path_bar->up_slider_button)
809 gtk_path_bar_remove_1 (container, widget);
810 path_bar->up_slider_button = NULL;
814 if (widget == path_bar->down_slider_button)
816 gtk_path_bar_remove_1 (container, widget);
817 path_bar->down_slider_button = NULL;
821 children = path_bar->button_list;
824 if (widget == BUTTON_DATA (children->data)->button)
826 gtk_path_bar_remove_1 (container, widget);
827 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
828 g_list_free (children);
832 children = children->next;
837 gtk_path_bar_forall (GtkContainer *container,
838 gboolean include_internals,
839 GtkCallback callback,
840 gpointer callback_data)
842 GtkPathBar *path_bar;
845 g_return_if_fail (callback != NULL);
846 path_bar = GTK_PATH_BAR (container);
848 children = path_bar->button_list;
852 child = BUTTON_DATA (children->data)->button;
853 children = children->next;
855 (* callback) (child, callback_data);
858 if (path_bar->up_slider_button)
859 (* callback) (path_bar->up_slider_button, callback_data);
861 if (path_bar->down_slider_button)
862 (* callback) (path_bar->down_slider_button, callback_data);
865 static GtkWidgetPath *
866 gtk_path_bar_get_path_for_child (GtkContainer *container,
869 GtkPathBar *path_bar = GTK_PATH_BAR (container);
872 path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
874 if (gtk_widget_get_visible (child) &&
875 gtk_widget_get_child_visible (child))
877 GtkWidgetPath *sibling_path;
878 GList *visible_children;
882 /* 1. Build the list of visible children, in visually left-to-right order
883 * (i.e. independently of the widget's direction). Note that our
884 * button_list is stored in innermost-to-outermost path order!
887 visible_children = NULL;
889 if (gtk_widget_get_visible (path_bar->down_slider_button) &&
890 gtk_widget_get_child_visible (path_bar->down_slider_button))
891 visible_children = g_list_prepend (visible_children, path_bar->down_slider_button);
893 for (l = path_bar->button_list; l; l = l->next)
895 ButtonData *data = l->data;
897 if (gtk_widget_get_visible (data->button) &&
898 gtk_widget_get_child_visible (data->button))
899 visible_children = g_list_prepend (visible_children, data->button);
902 if (gtk_widget_get_visible (path_bar->up_slider_button) &&
903 gtk_widget_get_child_visible (path_bar->up_slider_button))
904 visible_children = g_list_prepend (visible_children, path_bar->up_slider_button);
906 if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
907 visible_children = g_list_reverse (visible_children);
909 /* 2. Find the index of the child within that list */
913 for (l = visible_children; l; l = l->next)
915 GtkWidget *button = l->data;
923 /* 3. Build the path */
925 sibling_path = gtk_widget_path_new ();
927 for (l = visible_children; l; l = l->next)
928 gtk_widget_path_append_for_widget (sibling_path, l->data);
930 gtk_widget_path_append_with_siblings (path, sibling_path, pos);
932 g_list_free (visible_children);
933 gtk_widget_path_unref (sibling_path);
936 gtk_widget_path_append_for_widget (path, child);
942 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
944 GtkAllocation allocation, button_allocation;
946 GList *down_button = NULL;
947 gint space_available;
949 if (path_bar->ignore_click)
951 path_bar->ignore_click = FALSE;
955 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
957 /* Return if the last button is already visible */
961 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
963 /* We find the button at the 'down' end that we have to make
965 for (list = path_bar->button_list; list; list = list->next)
967 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
974 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
975 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
977 space_available = (allocation.width
978 - 2 * path_bar->spacing - 2 * path_bar->slider_width
979 - button_allocation.width);
980 path_bar->first_scrolled_button = down_button;
982 /* We have space_available free space that's not being used.
983 * So we walk down from the end, adding buttons until we use all free space.
985 while (space_available > 0)
987 path_bar->first_scrolled_button = down_button;
988 down_button = down_button->next;
991 space_available -= (button_allocation.width
992 + path_bar->spacing);
997 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
1001 if (path_bar->ignore_click)
1003 path_bar->ignore_click = FALSE;
1007 list = g_list_last (path_bar->button_list);
1009 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1011 /* Return if the first button is already visible */
1015 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1017 for ( ; list; list = list->prev)
1019 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
1021 if (list->prev == path_bar->fake_root)
1022 path_bar->fake_root = NULL;
1023 path_bar->first_scrolled_button = list;
1030 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
1032 gboolean retval = FALSE;
1034 if (path_bar->timer)
1036 if (path_bar->scrolling_up)
1037 gtk_path_bar_scroll_up (path_bar);
1038 else if (path_bar->scrolling_down)
1039 gtk_path_bar_scroll_down (path_bar);
1041 if (path_bar->need_timer)
1043 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
1046 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
1048 path_bar->need_timer = FALSE;
1050 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
1051 (GSourceFunc)gtk_path_bar_scroll_timeout,
1062 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
1064 if (path_bar->timer)
1066 g_source_remove (path_bar->timer);
1067 path_bar->timer = 0;
1068 path_bar->need_timer = FALSE;
1073 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
1074 GdkEventButton *event,
1075 GtkPathBar *path_bar)
1078 GList *up_button = NULL;
1080 if (event->type != GDK_FOCUS_CHANGE)
1083 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
1085 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1092 /* don't let the focus vanish */
1093 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
1094 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
1095 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
1101 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
1102 GdkEventButton *event,
1103 GtkPathBar *path_bar)
1106 GList *down_button = NULL;
1108 if (event->type != GDK_FOCUS_CHANGE)
1111 for (list = path_bar->button_list; list; list = list->next)
1113 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1120 /* don't let the focus vanish */
1121 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1122 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1123 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1129 gtk_path_bar_slider_button_press (GtkWidget *widget,
1130 GdkEventButton *event,
1131 GtkPathBar *path_bar)
1133 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1136 path_bar->ignore_click = FALSE;
1138 if (widget == path_bar->up_slider_button)
1140 path_bar->scrolling_down = FALSE;
1141 path_bar->scrolling_up = TRUE;
1142 gtk_path_bar_scroll_up (path_bar);
1144 else if (widget == path_bar->down_slider_button)
1146 path_bar->scrolling_up = FALSE;
1147 path_bar->scrolling_down = TRUE;
1148 gtk_path_bar_scroll_down (path_bar);
1151 if (!path_bar->timer)
1153 GtkSettings *settings = gtk_widget_get_settings (widget);
1156 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1158 path_bar->need_timer = TRUE;
1159 path_bar->timer = gdk_threads_add_timeout (timeout,
1160 (GSourceFunc)gtk_path_bar_scroll_timeout,
1168 gtk_path_bar_slider_button_release (GtkWidget *widget,
1169 GdkEventButton *event,
1170 GtkPathBar *path_bar)
1172 if (event->type != GDK_BUTTON_RELEASE)
1175 path_bar->ignore_click = TRUE;
1176 gtk_path_bar_stop_scrolling (path_bar);
1182 gtk_path_bar_grab_notify (GtkWidget *widget,
1183 gboolean was_grabbed)
1186 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1190 gtk_path_bar_state_changed (GtkWidget *widget,
1191 GtkStateType previous_state)
1193 if (!gtk_widget_is_sensitive (widget))
1194 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1198 /* Changes the icons wherever it is needed */
1200 reload_icons (GtkPathBar *path_bar)
1204 if (path_bar->root_icon)
1206 g_object_unref (path_bar->root_icon);
1207 path_bar->root_icon = NULL;
1209 if (path_bar->home_icon)
1211 g_object_unref (path_bar->home_icon);
1212 path_bar->home_icon = NULL;
1214 if (path_bar->desktop_icon)
1216 g_object_unref (path_bar->desktop_icon);
1217 path_bar->desktop_icon = NULL;
1220 for (list = path_bar->button_list; list; list = list->next)
1222 ButtonData *button_data;
1223 gboolean current_dir;
1225 button_data = BUTTON_DATA (list->data);
1226 if (button_data->type != NORMAL_BUTTON)
1228 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1229 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1236 change_icon_theme (GtkPathBar *path_bar)
1238 GtkSettings *settings;
1241 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1243 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1244 path_bar->icon_size = MAX (width, height);
1246 path_bar->icon_size = FALLBACK_ICON_SIZE;
1248 reload_icons (path_bar);
1250 /* Callback used when a GtkSettings value changes */
1252 settings_notify_cb (GObject *object,
1254 GtkPathBar *path_bar)
1258 name = g_param_spec_get_name (pspec);
1260 if (! strcmp (name, "gtk-icon-theme-name") ||
1261 ! strcmp (name, "gtk-icon-sizes"))
1262 change_icon_theme (path_bar);
1266 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1268 GtkSettings *settings;
1270 if (path_bar->settings_signal_id)
1273 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1274 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1276 change_icon_theme (path_bar);
1279 /* Public functions and their helpers */
1281 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1283 while (path_bar->button_list != NULL)
1285 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1287 path_bar->first_scrolled_button = NULL;
1288 path_bar->fake_root = NULL;
1292 button_clicked_cb (GtkWidget *button,
1295 ButtonData *button_data;
1296 GtkPathBar *path_bar;
1298 gboolean child_is_hidden;
1301 button_data = BUTTON_DATA (data);
1302 if (button_data->ignore_changes)
1305 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1307 button_list = g_list_find (path_bar->button_list, button_data);
1308 g_assert (button_list != NULL);
1310 g_signal_handlers_block_by_func (button,
1311 G_CALLBACK (button_clicked_cb), data);
1312 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1313 g_signal_handlers_unblock_by_func (button,
1314 G_CALLBACK (button_clicked_cb), data);
1316 if (button_list->prev)
1318 ButtonData *child_data;
1320 child_data = BUTTON_DATA (button_list->prev->data);
1321 child_file = child_data->file;
1322 child_is_hidden = child_data->file_is_hidden;
1327 child_is_hidden = FALSE;
1330 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1331 button_data->file, child_file, child_is_hidden);
1334 struct SetButtonImageData
1336 GtkPathBar *path_bar;
1337 ButtonData *button_data;
1341 set_button_image_get_info_cb (GCancellable *cancellable,
1343 const GError *error,
1346 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1348 struct SetButtonImageData *data = user_data;
1350 if (cancellable != data->button_data->cancellable)
1353 data->button_data->cancellable = NULL;
1355 if (!data->button_data->button)
1357 g_free (data->button_data);
1361 if (cancelled || error)
1364 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1365 data->path_bar->icon_size);
1366 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1368 switch (data->button_data->type)
1371 if (data->path_bar->home_icon)
1372 g_object_unref (pixbuf);
1374 data->path_bar->home_icon = pixbuf;
1377 case DESKTOP_BUTTON:
1378 if (data->path_bar->desktop_icon)
1379 g_object_unref (pixbuf);
1381 data->path_bar->desktop_icon = pixbuf;
1390 g_object_unref (cancellable);
1394 set_button_image (GtkPathBar *path_bar,
1395 ButtonData *button_data)
1397 GtkFileSystemVolume *volume;
1398 struct SetButtonImageData *data;
1400 switch (button_data->type)
1404 if (path_bar->root_icon != NULL)
1406 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1410 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1414 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1415 GTK_WIDGET (path_bar),
1416 path_bar->icon_size,
1418 _gtk_file_system_volume_unref (volume);
1420 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1424 if (path_bar->home_icon != NULL)
1426 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1430 data = g_new0 (struct SetButtonImageData, 1);
1431 data->path_bar = path_bar;
1432 data->button_data = button_data;
1434 if (button_data->cancellable)
1435 g_cancellable_cancel (button_data->cancellable);
1437 button_data->cancellable =
1438 _gtk_file_system_get_info (path_bar->file_system,
1439 path_bar->home_file,
1441 set_button_image_get_info_cb,
1445 case DESKTOP_BUTTON:
1446 if (path_bar->desktop_icon != NULL)
1448 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1452 data = g_new0 (struct SetButtonImageData, 1);
1453 data->path_bar = path_bar;
1454 data->button_data = button_data;
1456 if (button_data->cancellable)
1457 g_cancellable_cancel (button_data->cancellable);
1459 button_data->cancellable =
1460 _gtk_file_system_get_info (path_bar->file_system,
1461 path_bar->desktop_file,
1463 set_button_image_get_info_cb,
1472 button_data_free (ButtonData *button_data)
1474 if (button_data->file)
1475 g_object_unref (button_data->file);
1476 button_data->file = NULL;
1478 g_free (button_data->dir_name);
1479 button_data->dir_name = NULL;
1481 button_data->button = NULL;
1483 if (button_data->cancellable)
1484 g_cancellable_cancel (button_data->cancellable);
1486 g_free (button_data);
1490 get_dir_name (ButtonData *button_data)
1492 return button_data->dir_name;
1495 /* We always want to request the same size for the label, whether
1496 * or not the contents are bold
1499 set_label_size_request (GtkWidget *widget,
1500 ButtonData *button_data)
1502 const gchar *dir_name = get_dir_name (button_data);
1503 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1504 gint width, height, bold_width, bold_height;
1507 pango_layout_get_pixel_size (layout, &width, &height);
1509 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1510 pango_layout_set_markup (layout, markup, -1);
1513 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1515 gtk_widget_set_size_request (widget,
1516 MAX (width, bold_width),
1517 MAX (height, bold_height));
1518 g_object_unref (layout);
1522 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1523 ButtonData *button_data,
1524 gboolean current_dir)
1526 const gchar *dir_name = get_dir_name (button_data);
1528 if (button_data->label != NULL)
1534 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1535 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1540 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1544 if (button_data->image != NULL)
1546 set_button_image (path_bar, button_data);
1549 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1551 button_data->ignore_changes = TRUE;
1552 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1553 button_data->ignore_changes = FALSE;
1558 find_button_type (GtkPathBar *path_bar,
1561 if (path_bar->root_file != NULL &&
1562 g_file_equal (file, path_bar->root_file))
1564 if (path_bar->home_file != NULL &&
1565 g_file_equal (file, path_bar->home_file))
1567 if (path_bar->desktop_file != NULL &&
1568 g_file_equal (file, path_bar->desktop_file))
1569 return DESKTOP_BUTTON;
1571 return NORMAL_BUTTON;
1575 button_drag_data_get_cb (GtkWidget *widget,
1576 GdkDragContext *context,
1577 GtkSelectionData *selection_data,
1582 ButtonData *button_data;
1587 uris[0] = g_file_get_uri (button_data->file);
1590 gtk_selection_data_set_uris (selection_data, uris);
1596 make_directory_button (GtkPathBar *path_bar,
1597 const char *dir_name,
1599 gboolean current_dir,
1600 gboolean file_is_hidden)
1603 GtkWidget *child = NULL;
1604 ButtonData *button_data;
1606 file_is_hidden = !! file_is_hidden;
1607 /* Is it a special button? */
1608 button_data = g_new0 (ButtonData, 1);
1610 button_data->type = find_button_type (path_bar, file);
1611 button_data->button = gtk_toggle_button_new ();
1612 atk_obj = gtk_widget_get_accessible (button_data->button);
1613 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1615 switch (button_data->type)
1618 button_data->image = gtk_image_new ();
1619 child = button_data->image;
1620 button_data->label = NULL;
1621 atk_object_set_name (atk_obj, _("File System Root"));
1624 case DESKTOP_BUTTON:
1625 button_data->image = gtk_image_new ();
1626 button_data->label = gtk_label_new (NULL);
1627 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1628 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1629 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
1633 button_data->label = gtk_label_new (NULL);
1634 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1635 child = button_data->label;
1636 button_data->image = NULL;
1639 button_data->dir_name = g_strdup (dir_name);
1640 button_data->file = g_object_ref (file);
1641 button_data->file_is_hidden = file_is_hidden;
1644 * The following function ensures that the alignment will always
1645 * request the same size whether the button's text is bold or not.
1647 if (button_data->label)
1648 set_label_size_request (button_data->label, button_data);
1650 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1651 gtk_widget_show_all (button_data->button);
1653 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1655 g_signal_connect (button_data->button, "clicked",
1656 G_CALLBACK (button_clicked_cb),
1658 g_object_weak_ref (G_OBJECT (button_data->button),
1659 (GWeakNotify) button_data_free, button_data);
1661 gtk_drag_source_set (button_data->button,
1665 gtk_drag_source_add_uri_targets (button_data->button);
1666 g_signal_connect (button_data->button, "drag-data-get",
1667 G_CALLBACK (button_drag_data_get_cb), button_data);
1673 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1677 GList *current_path = NULL;
1678 gboolean need_new_fake_root = FALSE;
1680 for (list = path_bar->button_list; list; list = list->next)
1682 ButtonData *button_data;
1684 button_data = list->data;
1685 if (g_file_equal (file, button_data->file))
1687 current_path = list;
1690 if (list == path_bar->fake_root)
1691 need_new_fake_root = TRUE;
1696 if (need_new_fake_root)
1698 path_bar->fake_root = NULL;
1699 for (list = current_path; list; list = list->next)
1701 ButtonData *button_data;
1703 button_data = list->data;
1704 if (BUTTON_IS_FAKE_ROOT (button_data))
1706 path_bar->fake_root = list;
1712 for (list = path_bar->button_list; list; list = list->next)
1714 gtk_path_bar_update_button_appearance (path_bar,
1715 BUTTON_DATA (list->data),
1716 (list == current_path) ? TRUE : FALSE);
1719 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1721 path_bar->first_scrolled_button = current_path;
1722 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1735 GtkPathBar *path_bar;
1738 gboolean first_directory;
1742 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1749 gtk_path_bar_clear_buttons (info->path_bar);
1750 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1751 info->path_bar->fake_root = info->fake_root;
1753 for (l = info->path_bar->button_list; l; l = l->next)
1755 GtkWidget *button = BUTTON_DATA (l->data)->button;
1756 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1759 child_ordering_changed (info->path_bar);
1765 for (l = info->new_buttons; l; l = l->next)
1767 ButtonData *button_data;
1769 button_data = BUTTON_DATA (l->data);
1770 gtk_widget_destroy (button_data->button);
1773 g_list_free (info->new_buttons);
1777 g_object_unref (info->file);
1778 if (info->parent_file)
1779 g_object_unref (info->parent_file);
1785 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1787 const GError *error,
1790 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1791 struct SetFileInfo *file_info = data;
1792 ButtonData *button_data;
1793 const gchar *display_name;
1796 if (cancellable != file_info->path_bar->get_info_cancellable)
1798 gtk_path_bar_set_file_finish (file_info, FALSE);
1799 g_object_unref (cancellable);
1803 g_object_unref (cancellable);
1804 file_info->path_bar->get_info_cancellable = NULL;
1806 if (cancelled || !info)
1808 gtk_path_bar_set_file_finish (file_info, FALSE);
1812 display_name = g_file_info_get_display_name (info);
1813 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1815 gtk_widget_push_composite_child ();
1816 button_data = make_directory_button (file_info->path_bar, display_name,
1818 file_info->first_directory, is_hidden);
1819 gtk_widget_pop_composite_child ();
1820 g_object_unref (file_info->file);
1822 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1824 if (BUTTON_IS_FAKE_ROOT (button_data))
1825 file_info->fake_root = file_info->new_buttons;
1827 /* We have assigned the info for the innermost button, i.e. the deepest directory.
1828 * Now, go on to fetch the info for this directory's parent.
1831 file_info->file = file_info->parent_file;
1832 file_info->first_directory = FALSE;
1834 if (!file_info->file)
1836 /* No parent? Okay, we are done. */
1837 gtk_path_bar_set_file_finish (file_info, TRUE);
1841 file_info->parent_file = g_file_get_parent (file_info->file);
1843 /* Recurse asynchronously */
1844 file_info->path_bar->get_info_cancellable =
1845 _gtk_file_system_get_info (file_info->path_bar->file_system,
1847 "standard::display-name,standard::is-hidden,standard::is-backup",
1848 gtk_path_bar_get_info_callback,
1853 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1855 const gboolean keep_trail,
1858 struct SetFileInfo *info;
1860 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1861 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1863 /* Check whether the new path is already present in the pathbar as buttons.
1864 * This could be a parent directory or a previous selected subdirectory.
1866 if (keep_trail && gtk_path_bar_check_parent_path (path_bar, file))
1869 info = g_new0 (struct SetFileInfo, 1);
1870 info->file = g_object_ref (file);
1871 info->path_bar = path_bar;
1872 info->first_directory = TRUE;
1873 info->parent_file = g_file_get_parent (info->file);
1875 if (path_bar->get_info_cancellable)
1876 g_cancellable_cancel (path_bar->get_info_cancellable);
1878 path_bar->get_info_cancellable =
1879 _gtk_file_system_get_info (path_bar->file_system,
1881 "standard::display-name,standard::is-hidden,standard::is-backup",
1882 gtk_path_bar_get_info_callback,
1888 /* FIXME: This should be a construct-only property */
1890 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1891 GtkFileSystem *file_system)
1895 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1897 g_assert (path_bar->file_system == NULL);
1899 path_bar->file_system = g_object_ref (file_system);
1901 home = g_get_home_dir ();
1904 const gchar *desktop;
1906 path_bar->home_file = g_file_new_for_path (home);
1907 /* FIXME: Need file system backend specific way of getting the
1910 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1911 if (desktop != NULL)
1912 path_bar->desktop_file = g_file_new_for_path (desktop);
1914 path_bar->desktop_file = NULL;
1918 path_bar->home_file = NULL;
1919 path_bar->desktop_file = NULL;
1921 path_bar->root_file = g_file_new_for_path ("/");
1926 * @path_bar: a #GtkPathBar
1928 * If the selected button in the pathbar is not the furthest button "up" (in the
1929 * root direction), act as if the user clicked on the next button up.
1932 _gtk_path_bar_up (GtkPathBar *path_bar)
1936 for (l = path_bar->button_list; l; l = l->next)
1938 GtkWidget *button = BUTTON_DATA (l->data)->button;
1939 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1943 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1944 button_clicked_cb (next_button, l->next->data);
1952 * _gtk_path_bar_down:
1953 * @path_bar: a #GtkPathBar
1955 * If the selected button in the pathbar is not the furthest button "down" (in the
1956 * leaf direction), act as if the user clicked on the next button down.
1959 _gtk_path_bar_down (GtkPathBar *path_bar)
1963 for (l = path_bar->button_list; l; l = l->next)
1965 GtkWidget *button = BUTTON_DATA (l->data)->button;
1966 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1970 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1971 button_clicked_cb (prev_button, l->prev->data);