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 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
180 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
182 path_bar->get_info_cancellable = NULL;
184 path_bar->spacing = 0;
185 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
186 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
187 path_bar->icon_size = FALLBACK_ICON_SIZE;
189 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
190 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
191 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
192 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
194 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
195 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
196 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
197 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
199 g_signal_connect (path_bar->up_slider_button, "button-press-event",
200 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
201 g_signal_connect (path_bar->up_slider_button, "button-release-event",
202 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
203 g_signal_connect (path_bar->down_slider_button, "button-press-event",
204 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
205 g_signal_connect (path_bar->down_slider_button, "button-release-event",
206 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
210 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
212 GObjectClass *gobject_class;
213 GtkWidgetClass *widget_class;
214 GtkContainerClass *container_class;
216 gobject_class = (GObjectClass *) path_bar_class;
217 widget_class = (GtkWidgetClass *) path_bar_class;
218 container_class = (GtkContainerClass *) path_bar_class;
220 gobject_class->finalize = gtk_path_bar_finalize;
221 gobject_class->dispose = gtk_path_bar_dispose;
223 widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
224 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
225 widget_class->realize = gtk_path_bar_realize;
226 widget_class->unrealize = gtk_path_bar_unrealize;
227 widget_class->map = gtk_path_bar_map;
228 widget_class->unmap = gtk_path_bar_unmap;
229 widget_class->size_allocate = gtk_path_bar_size_allocate;
230 widget_class->style_updated = gtk_path_bar_style_updated;
231 widget_class->screen_changed = gtk_path_bar_screen_changed;
232 widget_class->grab_notify = gtk_path_bar_grab_notify;
233 widget_class->state_changed = gtk_path_bar_state_changed;
234 widget_class->scroll_event = gtk_path_bar_scroll;
236 container_class->add = gtk_path_bar_add;
237 container_class->forall = gtk_path_bar_forall;
238 container_class->remove = gtk_path_bar_remove;
239 container_class->get_path_for_child = gtk_path_bar_get_path_for_child;
240 gtk_container_class_handle_border_width (container_class);
242 /* container_class->child_type = gtk_path_bar_child_type;*/
244 path_bar_signals [PATH_CLICKED] =
245 g_signal_new (I_("path-clicked"),
246 G_OBJECT_CLASS_TYPE (gobject_class),
248 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
250 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
259 gtk_path_bar_finalize (GObject *object)
261 GtkPathBar *path_bar;
263 path_bar = GTK_PATH_BAR (object);
265 gtk_path_bar_stop_scrolling (path_bar);
267 g_list_free (path_bar->button_list);
268 if (path_bar->root_file)
269 g_object_unref (path_bar->root_file);
270 if (path_bar->home_file)
271 g_object_unref (path_bar->home_file);
272 if (path_bar->desktop_file)
273 g_object_unref (path_bar->desktop_file);
275 if (path_bar->root_icon)
276 g_object_unref (path_bar->root_icon);
277 if (path_bar->home_icon)
278 g_object_unref (path_bar->home_icon);
279 if (path_bar->desktop_icon)
280 g_object_unref (path_bar->desktop_icon);
282 if (path_bar->file_system)
283 g_object_unref (path_bar->file_system);
285 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
288 /* Removes the settings signal handler. It's safe to call multiple times */
290 remove_settings_signal (GtkPathBar *path_bar,
293 if (path_bar->settings_signal_id)
295 GtkSettings *settings;
297 settings = gtk_settings_get_for_screen (screen);
298 g_signal_handler_disconnect (settings,
299 path_bar->settings_signal_id);
300 path_bar->settings_signal_id = 0;
305 gtk_path_bar_dispose (GObject *object)
307 GtkPathBar *path_bar = GTK_PATH_BAR (object);
309 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
311 if (path_bar->get_info_cancellable)
312 g_cancellable_cancel (path_bar->get_info_cancellable);
313 path_bar->get_info_cancellable = NULL;
315 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
320 * Ideally, our size is determined by another widget, and we are just filling
324 gtk_path_bar_get_preferred_width (GtkWidget *widget,
328 ButtonData *button_data;
329 GtkPathBar *path_bar;
333 gint child_min, child_nat;
335 path_bar = GTK_PATH_BAR (widget);
337 *minimum = *natural = 0;
340 for (list = path_bar->button_list; list; list = list->next)
342 button_data = BUTTON_DATA (list->data);
343 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
344 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
345 height = MAX (height, child_height);
347 if (button_data->type == NORMAL_BUTTON)
349 /* Use 2*Height as button width because of ellipsized label. */
350 child_min = MAX (child_min, child_height * 2);
351 child_nat = MAX (child_min, child_height * 2);
354 *minimum = MAX (*minimum, child_min);
355 *natural = MAX (*natural, child_nat);
358 /* Add space for slider, if we have more than one path */
359 /* Theoretically, the slider could be bigger than the other button. But we're
360 * not going to worry about that now.
362 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
363 if (path_bar->button_list && path_bar->button_list->next != NULL)
365 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
366 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
371 gtk_path_bar_get_preferred_height (GtkWidget *widget,
375 ButtonData *button_data;
376 GtkPathBar *path_bar;
378 gint child_min, child_nat;
380 path_bar = GTK_PATH_BAR (widget);
382 *minimum = *natural = 0;
384 for (list = path_bar->button_list; list; list = list->next)
386 button_data = BUTTON_DATA (list->data);
387 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
389 *minimum = MAX (*minimum, child_min);
390 *natural = MAX (*natural, child_nat);
395 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
397 if (path_bar->button_list)
401 button = BUTTON_DATA (path_bar->button_list->data)->button;
402 if (gtk_widget_get_child_visible (button))
404 gtk_path_bar_stop_scrolling (path_bar);
405 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
408 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
410 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
411 if (gtk_widget_get_child_visible (button))
413 gtk_path_bar_stop_scrolling (path_bar);
414 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
417 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
422 gtk_path_bar_map (GtkWidget *widget)
424 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
426 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
430 gtk_path_bar_unmap (GtkWidget *widget)
432 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
433 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
435 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
439 gtk_path_bar_realize (GtkWidget *widget)
441 GtkPathBar *path_bar;
442 GtkAllocation allocation;
444 GdkWindowAttr attributes;
445 gint attributes_mask;
447 gtk_widget_set_realized (widget, TRUE);
449 path_bar = GTK_PATH_BAR (widget);
450 window = gtk_widget_get_parent_window (widget);
451 gtk_widget_set_window (widget, window);
452 g_object_ref (window);
454 gtk_widget_get_allocation (widget, &allocation);
456 attributes.window_type = GDK_WINDOW_CHILD;
457 attributes.x = allocation.x;
458 attributes.y = allocation.y;
459 attributes.width = allocation.width;
460 attributes.height = allocation.height;
461 attributes.wclass = GDK_INPUT_ONLY;
462 attributes.event_mask = gtk_widget_get_events (widget);
463 attributes.event_mask |= GDK_SCROLL_MASK;
464 attributes_mask = GDK_WA_X | GDK_WA_Y;
466 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
467 &attributes, attributes_mask);
468 gdk_window_set_user_data (path_bar->event_window, widget);
472 gtk_path_bar_unrealize (GtkWidget *widget)
474 GtkPathBar *path_bar;
476 path_bar = GTK_PATH_BAR (widget);
478 gdk_window_set_user_data (path_bar->event_window, NULL);
479 gdk_window_destroy (path_bar->event_window);
480 path_bar->event_window = NULL;
482 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
486 child_ordering_changed (GtkPathBar *path_bar)
490 if (path_bar->up_slider_button)
491 gtk_widget_reset_style (path_bar->up_slider_button);
492 if (path_bar->down_slider_button)
493 gtk_widget_reset_style (path_bar->down_slider_button);
495 for (l = path_bar->button_list; l; l = l->next)
497 ButtonData *data = l->data;
499 gtk_widget_reset_style (data->button);
503 /* This is a tad complicated
506 gtk_path_bar_size_allocate (GtkWidget *widget,
507 GtkAllocation *allocation)
510 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
511 GtkTextDirection direction;
512 GtkAllocation child_allocation;
513 GList *list, *first_button;
515 gint allocation_width;
516 gboolean need_sliders = FALSE;
517 gint up_slider_offset = 0;
518 GtkRequisition child_requisition;
520 gtk_widget_set_allocation (widget, allocation);
522 if (gtk_widget_get_realized (widget))
523 gdk_window_move_resize (path_bar->event_window,
524 allocation->x, allocation->y,
525 allocation->width, allocation->height);
527 /* No path is set; we don't have to allocate anything. */
528 if (path_bar->button_list == NULL)
531 direction = gtk_widget_get_direction (widget);
532 allocation_width = allocation->width;
534 /* First, we check to see if we need the scrollbars. */
535 if (path_bar->fake_root)
536 width = path_bar->spacing + path_bar->slider_width;
540 for (list = path_bar->button_list; list; list = list->next)
542 child = BUTTON_DATA (list->data)->button;
544 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
546 width += child_requisition.width + path_bar->spacing;
547 if (list == path_bar->fake_root)
551 if (width <= allocation_width)
553 if (path_bar->fake_root)
554 first_button = path_bar->fake_root;
556 first_button = g_list_last (path_bar->button_list);
560 gboolean reached_end = FALSE;
561 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
563 if (path_bar->first_scrolled_button)
564 first_button = path_bar->first_scrolled_button;
566 first_button = path_bar->button_list;
569 /* To see how much space we have, and how many buttons we can display.
570 * We start at the first button, count forward until hit the new
571 * button, then count backwards.
573 /* Count down the path chain towards the end. */
574 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
575 &child_requisition, NULL);
577 width = child_requisition.width;
578 list = first_button->prev;
579 while (list && !reached_end)
581 child = BUTTON_DATA (list->data)->button;
583 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
585 if (width + child_requisition.width +
586 path_bar->spacing + slider_space > allocation_width)
588 else if (list == path_bar->fake_root)
591 width += child_requisition.width + path_bar->spacing;
596 /* Finally, we walk up, seeing how many of the previous buttons we can
598 while (first_button->next && !reached_end)
600 child = BUTTON_DATA (first_button->next->data)->button;
602 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
604 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
610 width += child_requisition.width + path_bar->spacing;
611 if (first_button == path_bar->fake_root)
613 first_button = first_button->next;
618 /* Now, we allocate space to the buttons */
619 child_allocation.y = allocation->y;
620 child_allocation.height = allocation->height;
622 if (direction == GTK_TEXT_DIR_RTL)
624 child_allocation.x = allocation->x + allocation->width;
625 if (need_sliders || path_bar->fake_root)
627 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
628 up_slider_offset = allocation->width - path_bar->slider_width;
633 child_allocation.x = allocation->x;
634 if (need_sliders || path_bar->fake_root)
636 up_slider_offset = 0;
637 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
641 for (list = first_button; list; list = list->prev)
643 GtkAllocation widget_allocation;
644 ButtonData *button_data;
646 button_data = BUTTON_DATA (list->data);
647 child = button_data->button;
649 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
651 child_allocation.width = MIN (child_requisition.width,
652 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
654 if (direction == GTK_TEXT_DIR_RTL)
655 child_allocation.x -= child_allocation.width;
657 /* Check to see if we've don't have any more space to allocate buttons */
658 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
660 gtk_widget_get_allocation (widget, &widget_allocation);
661 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
664 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
666 gtk_widget_get_allocation (widget, &widget_allocation);
667 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
668 widget_allocation.x + allocation_width)
672 if (child_allocation.width < child_requisition.width)
674 if (!gtk_widget_get_has_tooltip (child))
675 gtk_widget_set_tooltip_text (child, button_data->dir_name);
677 else if (gtk_widget_get_has_tooltip (child))
678 gtk_widget_set_tooltip_text (child, NULL);
680 gtk_widget_set_child_visible (child, TRUE);
681 gtk_widget_size_allocate (child, &child_allocation);
683 if (direction == GTK_TEXT_DIR_RTL)
684 child_allocation.x -= path_bar->spacing;
686 child_allocation.x += child_allocation.width + path_bar->spacing;
688 /* Now we go hide all the widgets that don't fit */
691 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
694 for (list = first_button->next; list; list = list->next)
696 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
699 if (need_sliders || path_bar->fake_root)
701 child_allocation.width = path_bar->slider_width;
702 child_allocation.x = up_slider_offset + allocation->x;
703 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
705 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
706 gtk_widget_show_all (path_bar->up_slider_button);
709 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
713 child_allocation.width = path_bar->slider_width;
715 if (direction == GTK_TEXT_DIR_RTL)
716 child_allocation.x = 0;
718 child_allocation.x = allocation->width - path_bar->slider_width;
720 child_allocation.x += allocation->x;
722 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
724 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
725 gtk_widget_show_all (path_bar->down_slider_button);
726 gtk_path_bar_update_slider_buttons (path_bar);
729 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
731 child_ordering_changed (path_bar);
735 gtk_path_bar_style_updated (GtkWidget *widget)
737 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
739 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
743 gtk_path_bar_screen_changed (GtkWidget *widget,
744 GdkScreen *previous_screen)
746 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
747 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
749 /* We might nave a new settings, so we remove the old one */
751 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
753 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
757 gtk_path_bar_scroll (GtkWidget *widget,
758 GdkEventScroll *event)
760 switch (event->direction)
762 case GDK_SCROLL_RIGHT:
763 case GDK_SCROLL_DOWN:
764 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
766 case GDK_SCROLL_LEFT:
768 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
776 gtk_path_bar_add (GtkContainer *container,
780 gtk_widget_set_parent (widget, GTK_WIDGET (container));
784 gtk_path_bar_remove_1 (GtkContainer *container,
787 gboolean was_visible = gtk_widget_get_visible (widget);
788 gtk_widget_unparent (widget);
790 gtk_widget_queue_resize (GTK_WIDGET (container));
794 gtk_path_bar_remove (GtkContainer *container,
797 GtkPathBar *path_bar;
800 path_bar = GTK_PATH_BAR (container);
802 if (widget == path_bar->up_slider_button)
804 gtk_path_bar_remove_1 (container, widget);
805 path_bar->up_slider_button = NULL;
809 if (widget == path_bar->down_slider_button)
811 gtk_path_bar_remove_1 (container, widget);
812 path_bar->down_slider_button = NULL;
816 children = path_bar->button_list;
819 if (widget == BUTTON_DATA (children->data)->button)
821 gtk_path_bar_remove_1 (container, widget);
822 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
823 g_list_free (children);
827 children = children->next;
832 gtk_path_bar_forall (GtkContainer *container,
833 gboolean include_internals,
834 GtkCallback callback,
835 gpointer callback_data)
837 GtkPathBar *path_bar;
840 g_return_if_fail (callback != NULL);
841 path_bar = GTK_PATH_BAR (container);
843 children = path_bar->button_list;
847 child = BUTTON_DATA (children->data)->button;
848 children = children->next;
850 (* callback) (child, callback_data);
853 if (path_bar->up_slider_button)
854 (* callback) (path_bar->up_slider_button, callback_data);
856 if (path_bar->down_slider_button)
857 (* callback) (path_bar->down_slider_button, callback_data);
860 static GtkWidgetPath *
861 gtk_path_bar_get_path_for_child (GtkContainer *container,
864 GtkPathBar *path_bar = GTK_PATH_BAR (container);
867 path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
869 if (gtk_widget_get_visible (child) &&
870 gtk_widget_get_child_visible (child))
872 GtkWidgetPath *sibling_path;
873 GList *visible_children;
877 /* 1. Build the list of visible children, in visually left-to-right order
878 * (i.e. independently of the widget's direction). Note that our
879 * button_list is stored in innermost-to-outermost path order!
882 visible_children = NULL;
884 if (gtk_widget_get_visible (path_bar->down_slider_button) &&
885 gtk_widget_get_child_visible (path_bar->down_slider_button))
886 visible_children = g_list_prepend (visible_children, path_bar->down_slider_button);
888 for (l = path_bar->button_list; l; l = l->next)
890 ButtonData *data = l->data;
892 if (gtk_widget_get_visible (data->button) &&
893 gtk_widget_get_child_visible (data->button))
894 visible_children = g_list_prepend (visible_children, data->button);
897 if (gtk_widget_get_visible (path_bar->up_slider_button) &&
898 gtk_widget_get_child_visible (path_bar->up_slider_button))
899 visible_children = g_list_prepend (visible_children, path_bar->up_slider_button);
901 if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
902 visible_children = g_list_reverse (visible_children);
904 /* 2. Find the index of the child within that list */
908 for (l = visible_children; l; l = l->next)
910 GtkWidget *button = l->data;
918 /* 3. Build the path */
920 sibling_path = gtk_widget_path_new ();
922 for (l = visible_children; l; l = l->next)
923 gtk_widget_path_append_for_widget (sibling_path, l->data);
925 gtk_widget_path_append_with_siblings (path, sibling_path, pos);
927 g_list_free (visible_children);
928 gtk_widget_path_unref (sibling_path);
931 gtk_widget_path_append_for_widget (path, child);
937 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
939 GtkAllocation allocation, button_allocation;
941 GList *down_button = NULL;
942 gint space_available;
944 if (path_bar->ignore_click)
946 path_bar->ignore_click = FALSE;
950 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
952 /* Return if the last button is already visible */
956 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
958 /* We find the button at the 'down' end that we have to make
960 for (list = path_bar->button_list; list; list = list->next)
962 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
969 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
970 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
972 space_available = (allocation.width
973 - 2 * path_bar->spacing - 2 * path_bar->slider_width
974 - button_allocation.width);
975 path_bar->first_scrolled_button = down_button;
977 /* We have space_available free space that's not being used.
978 * So we walk down from the end, adding buttons until we use all free space.
980 while (space_available > 0)
982 path_bar->first_scrolled_button = down_button;
983 down_button = down_button->next;
986 space_available -= (button_allocation.width
987 + path_bar->spacing);
992 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
996 if (path_bar->ignore_click)
998 path_bar->ignore_click = FALSE;
1002 list = g_list_last (path_bar->button_list);
1004 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1006 /* Return if the first button is already visible */
1010 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1012 for ( ; list; list = list->prev)
1014 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
1016 if (list->prev == path_bar->fake_root)
1017 path_bar->fake_root = NULL;
1018 path_bar->first_scrolled_button = list;
1025 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
1027 gboolean retval = FALSE;
1029 if (path_bar->timer)
1031 if (path_bar->scrolling_up)
1032 gtk_path_bar_scroll_up (path_bar);
1033 else if (path_bar->scrolling_down)
1034 gtk_path_bar_scroll_down (path_bar);
1036 if (path_bar->need_timer)
1038 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
1041 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
1043 path_bar->need_timer = FALSE;
1045 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
1046 (GSourceFunc)gtk_path_bar_scroll_timeout,
1057 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
1059 if (path_bar->timer)
1061 g_source_remove (path_bar->timer);
1062 path_bar->timer = 0;
1063 path_bar->need_timer = FALSE;
1068 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
1069 GdkEventButton *event,
1070 GtkPathBar *path_bar)
1073 GList *up_button = NULL;
1075 if (event->type != GDK_FOCUS_CHANGE)
1078 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
1080 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1087 /* don't let the focus vanish */
1088 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
1089 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
1090 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
1096 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
1097 GdkEventButton *event,
1098 GtkPathBar *path_bar)
1101 GList *down_button = NULL;
1103 if (event->type != GDK_FOCUS_CHANGE)
1106 for (list = path_bar->button_list; list; list = list->next)
1108 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1115 /* don't let the focus vanish */
1116 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1117 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1118 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1124 gtk_path_bar_slider_button_press (GtkWidget *widget,
1125 GdkEventButton *event,
1126 GtkPathBar *path_bar)
1128 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1131 path_bar->ignore_click = FALSE;
1133 if (widget == path_bar->up_slider_button)
1135 path_bar->scrolling_down = FALSE;
1136 path_bar->scrolling_up = TRUE;
1137 gtk_path_bar_scroll_up (path_bar);
1139 else if (widget == path_bar->down_slider_button)
1141 path_bar->scrolling_up = FALSE;
1142 path_bar->scrolling_down = TRUE;
1143 gtk_path_bar_scroll_down (path_bar);
1146 if (!path_bar->timer)
1148 GtkSettings *settings = gtk_widget_get_settings (widget);
1151 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1153 path_bar->need_timer = TRUE;
1154 path_bar->timer = gdk_threads_add_timeout (timeout,
1155 (GSourceFunc)gtk_path_bar_scroll_timeout,
1163 gtk_path_bar_slider_button_release (GtkWidget *widget,
1164 GdkEventButton *event,
1165 GtkPathBar *path_bar)
1167 if (event->type != GDK_BUTTON_RELEASE)
1170 path_bar->ignore_click = TRUE;
1171 gtk_path_bar_stop_scrolling (path_bar);
1177 gtk_path_bar_grab_notify (GtkWidget *widget,
1178 gboolean was_grabbed)
1181 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1185 gtk_path_bar_state_changed (GtkWidget *widget,
1186 GtkStateType previous_state)
1188 if (!gtk_widget_is_sensitive (widget))
1189 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1193 /* Changes the icons wherever it is needed */
1195 reload_icons (GtkPathBar *path_bar)
1199 if (path_bar->root_icon)
1201 g_object_unref (path_bar->root_icon);
1202 path_bar->root_icon = NULL;
1204 if (path_bar->home_icon)
1206 g_object_unref (path_bar->home_icon);
1207 path_bar->home_icon = NULL;
1209 if (path_bar->desktop_icon)
1211 g_object_unref (path_bar->desktop_icon);
1212 path_bar->desktop_icon = NULL;
1215 for (list = path_bar->button_list; list; list = list->next)
1217 ButtonData *button_data;
1218 gboolean current_dir;
1220 button_data = BUTTON_DATA (list->data);
1221 if (button_data->type != NORMAL_BUTTON)
1223 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1224 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1231 change_icon_theme (GtkPathBar *path_bar)
1233 GtkSettings *settings;
1236 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1238 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1239 path_bar->icon_size = MAX (width, height);
1241 path_bar->icon_size = FALLBACK_ICON_SIZE;
1243 reload_icons (path_bar);
1245 /* Callback used when a GtkSettings value changes */
1247 settings_notify_cb (GObject *object,
1249 GtkPathBar *path_bar)
1253 name = g_param_spec_get_name (pspec);
1255 if (! strcmp (name, "gtk-icon-theme-name") ||
1256 ! strcmp (name, "gtk-icon-sizes"))
1257 change_icon_theme (path_bar);
1261 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1263 GtkSettings *settings;
1265 if (path_bar->settings_signal_id)
1268 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1269 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1271 change_icon_theme (path_bar);
1274 /* Public functions and their helpers */
1276 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1278 while (path_bar->button_list != NULL)
1280 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1282 path_bar->first_scrolled_button = NULL;
1283 path_bar->fake_root = NULL;
1287 button_clicked_cb (GtkWidget *button,
1290 ButtonData *button_data;
1291 GtkPathBar *path_bar;
1293 gboolean child_is_hidden;
1296 button_data = BUTTON_DATA (data);
1297 if (button_data->ignore_changes)
1300 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1302 button_list = g_list_find (path_bar->button_list, button_data);
1303 g_assert (button_list != NULL);
1305 g_signal_handlers_block_by_func (button,
1306 G_CALLBACK (button_clicked_cb), data);
1307 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1308 g_signal_handlers_unblock_by_func (button,
1309 G_CALLBACK (button_clicked_cb), data);
1311 if (button_list->prev)
1313 ButtonData *child_data;
1315 child_data = BUTTON_DATA (button_list->prev->data);
1316 child_file = child_data->file;
1317 child_is_hidden = child_data->file_is_hidden;
1322 child_is_hidden = FALSE;
1325 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1326 button_data->file, child_file, child_is_hidden);
1329 struct SetButtonImageData
1331 GtkPathBar *path_bar;
1332 ButtonData *button_data;
1336 set_button_image_get_info_cb (GCancellable *cancellable,
1338 const GError *error,
1341 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1343 struct SetButtonImageData *data = user_data;
1345 if (cancellable != data->button_data->cancellable)
1348 data->button_data->cancellable = NULL;
1350 if (!data->button_data->button)
1352 g_free (data->button_data);
1356 if (cancelled || error)
1359 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1360 data->path_bar->icon_size);
1361 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1363 switch (data->button_data->type)
1366 if (data->path_bar->home_icon)
1367 g_object_unref (pixbuf);
1369 data->path_bar->home_icon = pixbuf;
1372 case DESKTOP_BUTTON:
1373 if (data->path_bar->desktop_icon)
1374 g_object_unref (pixbuf);
1376 data->path_bar->desktop_icon = pixbuf;
1385 g_object_unref (cancellable);
1389 set_button_image (GtkPathBar *path_bar,
1390 ButtonData *button_data)
1392 GtkFileSystemVolume *volume;
1393 struct SetButtonImageData *data;
1395 switch (button_data->type)
1399 if (path_bar->root_icon != NULL)
1401 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1405 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1409 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1410 GTK_WIDGET (path_bar),
1411 path_bar->icon_size,
1413 _gtk_file_system_volume_unref (volume);
1415 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1419 if (path_bar->home_icon != NULL)
1421 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1425 data = g_new0 (struct SetButtonImageData, 1);
1426 data->path_bar = path_bar;
1427 data->button_data = button_data;
1429 if (button_data->cancellable)
1430 g_cancellable_cancel (button_data->cancellable);
1432 button_data->cancellable =
1433 _gtk_file_system_get_info (path_bar->file_system,
1434 path_bar->home_file,
1436 set_button_image_get_info_cb,
1440 case DESKTOP_BUTTON:
1441 if (path_bar->desktop_icon != NULL)
1443 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1447 data = g_new0 (struct SetButtonImageData, 1);
1448 data->path_bar = path_bar;
1449 data->button_data = button_data;
1451 if (button_data->cancellable)
1452 g_cancellable_cancel (button_data->cancellable);
1454 button_data->cancellable =
1455 _gtk_file_system_get_info (path_bar->file_system,
1456 path_bar->desktop_file,
1458 set_button_image_get_info_cb,
1467 button_data_free (ButtonData *button_data)
1469 if (button_data->file)
1470 g_object_unref (button_data->file);
1471 button_data->file = NULL;
1473 g_free (button_data->dir_name);
1474 button_data->dir_name = NULL;
1476 button_data->button = NULL;
1478 if (button_data->cancellable)
1479 g_cancellable_cancel (button_data->cancellable);
1481 g_free (button_data);
1485 get_dir_name (ButtonData *button_data)
1487 return button_data->dir_name;
1490 /* We always want to request the same size for the label, whether
1491 * or not the contents are bold
1494 set_label_size_request (GtkWidget *widget,
1495 ButtonData *button_data)
1497 const gchar *dir_name = get_dir_name (button_data);
1498 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1499 gint width, height, bold_width, bold_height;
1502 pango_layout_get_pixel_size (layout, &width, &height);
1504 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1505 pango_layout_set_markup (layout, markup, -1);
1508 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1510 gtk_widget_set_size_request (widget,
1511 MAX (width, bold_width),
1512 MAX (height, bold_height));
1513 g_object_unref (layout);
1517 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1518 ButtonData *button_data,
1519 gboolean current_dir)
1521 const gchar *dir_name = get_dir_name (button_data);
1523 if (button_data->label != NULL)
1529 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1530 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1535 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1539 if (button_data->image != NULL)
1541 set_button_image (path_bar, button_data);
1544 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1546 button_data->ignore_changes = TRUE;
1547 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1548 button_data->ignore_changes = FALSE;
1553 find_button_type (GtkPathBar *path_bar,
1556 if (path_bar->root_file != NULL &&
1557 g_file_equal (file, path_bar->root_file))
1559 if (path_bar->home_file != NULL &&
1560 g_file_equal (file, path_bar->home_file))
1562 if (path_bar->desktop_file != NULL &&
1563 g_file_equal (file, path_bar->desktop_file))
1564 return DESKTOP_BUTTON;
1566 return NORMAL_BUTTON;
1570 button_drag_data_get_cb (GtkWidget *widget,
1571 GdkDragContext *context,
1572 GtkSelectionData *selection_data,
1577 ButtonData *button_data;
1582 uris[0] = g_file_get_uri (button_data->file);
1585 gtk_selection_data_set_uris (selection_data, uris);
1591 make_directory_button (GtkPathBar *path_bar,
1592 const char *dir_name,
1594 gboolean current_dir,
1595 gboolean file_is_hidden)
1598 GtkWidget *child = NULL;
1599 ButtonData *button_data;
1601 file_is_hidden = !! file_is_hidden;
1602 /* Is it a special button? */
1603 button_data = g_new0 (ButtonData, 1);
1605 button_data->type = find_button_type (path_bar, file);
1606 button_data->button = gtk_toggle_button_new ();
1607 atk_obj = gtk_widget_get_accessible (button_data->button);
1608 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1610 switch (button_data->type)
1613 button_data->image = gtk_image_new ();
1614 child = button_data->image;
1615 button_data->label = NULL;
1616 atk_object_set_name (atk_obj, _("File System Root"));
1619 case DESKTOP_BUTTON:
1620 button_data->image = gtk_image_new ();
1621 button_data->label = gtk_label_new (NULL);
1622 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1623 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1624 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
1628 button_data->label = gtk_label_new (NULL);
1629 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1630 child = button_data->label;
1631 button_data->image = NULL;
1634 button_data->dir_name = g_strdup (dir_name);
1635 button_data->file = g_object_ref (file);
1636 button_data->file_is_hidden = file_is_hidden;
1639 * The following function ensures that the alignment will always
1640 * request the same size whether the button's text is bold or not.
1642 if (button_data->label)
1643 set_label_size_request (button_data->label, button_data);
1645 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1646 gtk_widget_show_all (button_data->button);
1648 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1650 g_signal_connect (button_data->button, "clicked",
1651 G_CALLBACK (button_clicked_cb),
1653 g_object_weak_ref (G_OBJECT (button_data->button),
1654 (GWeakNotify) button_data_free, button_data);
1656 gtk_drag_source_set (button_data->button,
1660 gtk_drag_source_add_uri_targets (button_data->button);
1661 g_signal_connect (button_data->button, "drag-data-get",
1662 G_CALLBACK (button_drag_data_get_cb), button_data);
1668 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1670 GtkFileSystem *file_system)
1673 GList *current_path = NULL;
1674 gboolean need_new_fake_root = FALSE;
1676 for (list = path_bar->button_list; list; list = list->next)
1678 ButtonData *button_data;
1680 button_data = list->data;
1681 if (g_file_equal (file, button_data->file))
1683 current_path = list;
1686 if (list == path_bar->fake_root)
1687 need_new_fake_root = TRUE;
1692 if (need_new_fake_root)
1694 path_bar->fake_root = NULL;
1695 for (list = current_path; list; list = list->next)
1697 ButtonData *button_data;
1699 button_data = list->data;
1700 if (BUTTON_IS_FAKE_ROOT (button_data))
1702 path_bar->fake_root = list;
1708 for (list = path_bar->button_list; list; list = list->next)
1710 gtk_path_bar_update_button_appearance (path_bar,
1711 BUTTON_DATA (list->data),
1712 (list == current_path) ? TRUE : FALSE);
1715 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1717 path_bar->first_scrolled_button = current_path;
1718 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1731 GtkPathBar *path_bar;
1734 gboolean first_directory;
1738 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1745 gtk_path_bar_clear_buttons (info->path_bar);
1746 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1747 info->path_bar->fake_root = info->fake_root;
1749 for (l = info->path_bar->button_list; l; l = l->next)
1751 GtkWidget *button = BUTTON_DATA (l->data)->button;
1752 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1759 for (l = info->new_buttons; l; l = l->next)
1761 ButtonData *button_data;
1763 button_data = BUTTON_DATA (l->data);
1764 gtk_widget_destroy (button_data->button);
1767 g_list_free (info->new_buttons);
1771 g_object_unref (info->file);
1772 if (info->parent_file)
1773 g_object_unref (info->parent_file);
1775 child_ordering_changed (info->path_bar);
1781 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1783 const GError *error,
1786 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1787 struct SetFileInfo *file_info = data;
1788 ButtonData *button_data;
1789 const gchar *display_name;
1792 if (cancellable != file_info->path_bar->get_info_cancellable)
1794 gtk_path_bar_set_file_finish (file_info, FALSE);
1795 g_object_unref (cancellable);
1799 g_object_unref (cancellable);
1800 file_info->path_bar->get_info_cancellable = NULL;
1802 if (cancelled || !info)
1804 gtk_path_bar_set_file_finish (file_info, FALSE);
1808 display_name = g_file_info_get_display_name (info);
1809 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1811 gtk_widget_push_composite_child ();
1812 button_data = make_directory_button (file_info->path_bar, display_name,
1814 file_info->first_directory, is_hidden);
1815 gtk_widget_pop_composite_child ();
1816 g_object_unref (file_info->file);
1818 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1820 if (BUTTON_IS_FAKE_ROOT (button_data))
1821 file_info->fake_root = file_info->new_buttons;
1823 file_info->file = file_info->parent_file;
1824 file_info->first_directory = FALSE;
1826 if (!file_info->file)
1828 gtk_path_bar_set_file_finish (file_info, TRUE);
1832 file_info->parent_file = g_file_get_parent (file_info->file);
1834 file_info->path_bar->get_info_cancellable =
1835 _gtk_file_system_get_info (file_info->path_bar->file_system,
1837 "standard::display-name,standard::is-hidden,standard::is-backup",
1838 gtk_path_bar_get_info_callback,
1843 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1845 const gboolean keep_trail,
1848 struct SetFileInfo *info;
1850 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1851 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1853 /* Check whether the new path is already present in the pathbar as buttons.
1854 * This could be a parent directory or a previous selected subdirectory.
1857 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1860 info = g_new0 (struct SetFileInfo, 1);
1861 info->file = g_object_ref (file);
1862 info->path_bar = path_bar;
1863 info->first_directory = TRUE;
1864 info->parent_file = g_file_get_parent (info->file);
1866 if (path_bar->get_info_cancellable)
1867 g_cancellable_cancel (path_bar->get_info_cancellable);
1869 path_bar->get_info_cancellable =
1870 _gtk_file_system_get_info (path_bar->file_system,
1872 "standard::display-name,standard::is-hidden,standard::is-backup",
1873 gtk_path_bar_get_info_callback,
1879 /* FIXME: This should be a construct-only property */
1881 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1882 GtkFileSystem *file_system)
1886 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1888 g_assert (path_bar->file_system == NULL);
1890 path_bar->file_system = g_object_ref (file_system);
1892 home = g_get_home_dir ();
1895 const gchar *desktop;
1897 path_bar->home_file = g_file_new_for_path (home);
1898 /* FIXME: Need file system backend specific way of getting the
1901 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1902 if (desktop != NULL)
1903 path_bar->desktop_file = g_file_new_for_path (desktop);
1905 path_bar->desktop_file = NULL;
1909 path_bar->home_file = NULL;
1910 path_bar->desktop_file = NULL;
1912 path_bar->root_file = g_file_new_for_path ("/");
1917 * @path_bar: a #GtkPathBar
1919 * If the selected button in the pathbar is not the furthest button "up" (in the
1920 * root direction), act as if the user clicked on the next button up.
1923 _gtk_path_bar_up (GtkPathBar *path_bar)
1927 for (l = path_bar->button_list; l; l = l->next)
1929 GtkWidget *button = BUTTON_DATA (l->data)->button;
1930 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1934 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1935 button_clicked_cb (next_button, l->next->data);
1943 * _gtk_path_bar_down:
1944 * @path_bar: a #GtkPathBar
1946 * If the selected button in the pathbar is not the furthest button "down" (in the
1947 * leaf direction), act as if the user clicked on the next button down.
1950 _gtk_path_bar_down (GtkPathBar *path_bar)
1954 for (l = path_bar->button_list; l; l = l->next)
1956 GtkWidget *button = BUTTON_DATA (l->data)->button;
1957 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1961 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1962 button_clicked_cb (prev_button, l->prev->data);