1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
3 * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkpathbar.h"
27 #include "gtktogglebutton.h"
28 #include "gtkalignment.h"
33 #include "gtkicontheme.h"
34 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
53 #define BUTTON_DATA(x) ((ButtonData *)(x))
55 #define SCROLL_DELAY_FACTOR 5
57 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
59 /* Icon size for if we can't get it from the theme */
60 #define FALLBACK_ICON_SIZE 16
62 typedef struct _ButtonData ButtonData;
72 GCancellable *cancellable;
73 guint ignore_changes : 1;
74 guint file_is_hidden : 1;
76 /* This macro is used to check if a button can be used as a fake root.
77 * All buttons in front of a fake root are automatically hidden when in a
78 * directory below a fake root and replaced with the "<" arrow button.
80 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
82 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
84 static void gtk_path_bar_finalize (GObject *object);
85 static void gtk_path_bar_dispose (GObject *object);
86 static void gtk_path_bar_realize (GtkWidget *widget);
87 static void gtk_path_bar_unrealize (GtkWidget *widget);
88 static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
91 static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
94 static void gtk_path_bar_map (GtkWidget *widget);
95 static void gtk_path_bar_unmap (GtkWidget *widget);
96 static void gtk_path_bar_size_allocate (GtkWidget *widget,
97 GtkAllocation *allocation);
98 static void gtk_path_bar_add (GtkContainer *container,
100 static void gtk_path_bar_remove (GtkContainer *container,
102 static void gtk_path_bar_forall (GtkContainer *container,
103 gboolean include_internals,
104 GtkCallback callback,
105 gpointer callback_data);
106 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
107 GdkEventScroll *event);
108 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
109 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
110 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
111 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
112 GdkEventButton *event,
113 GtkPathBar *path_bar);
114 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
115 GdkEventButton *event,
116 GtkPathBar *path_bar);
117 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
118 GdkEventButton *event,
119 GtkPathBar *path_bar);
120 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
121 GdkEventButton *event,
122 GtkPathBar *path_bar);
123 static void gtk_path_bar_grab_notify (GtkWidget *widget,
124 gboolean was_grabbed);
125 static void gtk_path_bar_state_changed (GtkWidget *widget,
126 GtkStateType previous_state);
127 static void gtk_path_bar_style_set (GtkWidget *widget,
128 GtkStyle *previous_style);
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_set = gtk_path_bar_style_set;
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 gtk_container_class_handle_border_width (container_class);
241 /* container_class->child_type = gtk_path_bar_child_type;*/
243 path_bar_signals [PATH_CLICKED] =
244 g_signal_new (I_("path-clicked"),
245 G_OBJECT_CLASS_TYPE (gobject_class),
247 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
249 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
258 gtk_path_bar_finalize (GObject *object)
260 GtkPathBar *path_bar;
262 path_bar = GTK_PATH_BAR (object);
264 gtk_path_bar_stop_scrolling (path_bar);
266 g_list_free (path_bar->button_list);
267 if (path_bar->root_file)
268 g_object_unref (path_bar->root_file);
269 if (path_bar->home_file)
270 g_object_unref (path_bar->home_file);
271 if (path_bar->desktop_file)
272 g_object_unref (path_bar->desktop_file);
274 if (path_bar->root_icon)
275 g_object_unref (path_bar->root_icon);
276 if (path_bar->home_icon)
277 g_object_unref (path_bar->home_icon);
278 if (path_bar->desktop_icon)
279 g_object_unref (path_bar->desktop_icon);
281 if (path_bar->file_system)
282 g_object_unref (path_bar->file_system);
284 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
287 /* Removes the settings signal handler. It's safe to call multiple times */
289 remove_settings_signal (GtkPathBar *path_bar,
292 if (path_bar->settings_signal_id)
294 GtkSettings *settings;
296 settings = gtk_settings_get_for_screen (screen);
297 g_signal_handler_disconnect (settings,
298 path_bar->settings_signal_id);
299 path_bar->settings_signal_id = 0;
304 gtk_path_bar_dispose (GObject *object)
306 GtkPathBar *path_bar = GTK_PATH_BAR (object);
308 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
310 if (path_bar->get_info_cancellable)
311 g_cancellable_cancel (path_bar->get_info_cancellable);
312 path_bar->get_info_cancellable = NULL;
314 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
319 * Ideally, our size is determined by another widget, and we are just filling
323 gtk_path_bar_get_preferred_width (GtkWidget *widget,
327 ButtonData *button_data;
328 GtkPathBar *path_bar;
332 gint child_min, child_nat;
334 path_bar = GTK_PATH_BAR (widget);
336 *minimum = *natural = 0;
339 for (list = path_bar->button_list; list; list = list->next)
341 button_data = BUTTON_DATA (list->data);
342 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
343 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
344 height = MAX (height, child_height);
346 if (button_data->type == NORMAL_BUTTON)
348 /* Use 2*Height as button width because of ellipsized label. */
349 child_min = MAX (child_min, child_height * 2);
350 child_nat = MAX (child_min, child_height * 2);
353 *minimum = MAX (*minimum, child_min);
354 *natural = MAX (*natural, child_nat);
357 /* Add space for slider, if we have more than one path */
358 /* Theoretically, the slider could be bigger than the other button. But we're
359 * not going to worry about that now.
361 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
362 if (path_bar->button_list && path_bar->button_list->next != NULL)
364 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
365 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
370 gtk_path_bar_get_preferred_height (GtkWidget *widget,
374 ButtonData *button_data;
375 GtkPathBar *path_bar;
377 gint child_min, child_nat;
379 path_bar = GTK_PATH_BAR (widget);
381 *minimum = *natural = 0;
383 for (list = path_bar->button_list; list; list = list->next)
385 button_data = BUTTON_DATA (list->data);
386 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
388 *minimum = MAX (*minimum, child_min);
389 *natural = MAX (*natural, child_nat);
394 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
396 if (path_bar->button_list)
400 button = BUTTON_DATA (path_bar->button_list->data)->button;
401 if (gtk_widget_get_child_visible (button))
403 gtk_path_bar_stop_scrolling (path_bar);
404 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
407 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
409 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
410 if (gtk_widget_get_child_visible (button))
412 gtk_path_bar_stop_scrolling (path_bar);
413 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
416 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
421 gtk_path_bar_map (GtkWidget *widget)
423 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
425 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
429 gtk_path_bar_unmap (GtkWidget *widget)
431 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
432 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
434 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
438 gtk_path_bar_realize (GtkWidget *widget)
440 GtkPathBar *path_bar;
441 GtkAllocation allocation;
443 GdkWindowAttr attributes;
444 gint attributes_mask;
446 gtk_widget_set_realized (widget, TRUE);
448 path_bar = GTK_PATH_BAR (widget);
449 window = gtk_widget_get_parent_window (widget);
450 gtk_widget_set_window (widget, window);
451 g_object_ref (window);
453 gtk_widget_get_allocation (widget, &allocation);
455 attributes.window_type = GDK_WINDOW_CHILD;
456 attributes.x = allocation.x;
457 attributes.y = allocation.y;
458 attributes.width = allocation.width;
459 attributes.height = allocation.height;
460 attributes.wclass = GDK_INPUT_ONLY;
461 attributes.event_mask = gtk_widget_get_events (widget);
462 attributes.event_mask |= GDK_SCROLL_MASK;
463 attributes_mask = GDK_WA_X | GDK_WA_Y;
465 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
466 &attributes, attributes_mask);
467 gdk_window_set_user_data (path_bar->event_window, widget);
469 gtk_widget_style_attach (widget);
473 gtk_path_bar_unrealize (GtkWidget *widget)
475 GtkPathBar *path_bar;
477 path_bar = GTK_PATH_BAR (widget);
479 gdk_window_set_user_data (path_bar->event_window, NULL);
480 gdk_window_destroy (path_bar->event_window);
481 path_bar->event_window = NULL;
483 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
486 /* This is a tad complicated
489 gtk_path_bar_size_allocate (GtkWidget *widget,
490 GtkAllocation *allocation)
493 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
494 GtkTextDirection direction;
495 GtkAllocation child_allocation;
496 GList *list, *first_button;
498 gint allocation_width;
499 gboolean need_sliders = FALSE;
500 gint up_slider_offset = 0;
501 GtkRequisition child_requisition;
503 gtk_widget_set_allocation (widget, allocation);
505 if (gtk_widget_get_realized (widget))
506 gdk_window_move_resize (path_bar->event_window,
507 allocation->x, allocation->y,
508 allocation->width, allocation->height);
510 /* No path is set; we don't have to allocate anything. */
511 if (path_bar->button_list == NULL)
514 direction = gtk_widget_get_direction (widget);
515 allocation_width = allocation->width;
517 /* First, we check to see if we need the scrollbars. */
518 if (path_bar->fake_root)
519 width = path_bar->spacing + path_bar->slider_width;
523 for (list = path_bar->button_list; list; list = list->next)
525 child = BUTTON_DATA (list->data)->button;
527 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
529 width += child_requisition.width + path_bar->spacing;
530 if (list == path_bar->fake_root)
534 if (width <= allocation_width)
536 if (path_bar->fake_root)
537 first_button = path_bar->fake_root;
539 first_button = g_list_last (path_bar->button_list);
543 gboolean reached_end = FALSE;
544 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
546 if (path_bar->first_scrolled_button)
547 first_button = path_bar->first_scrolled_button;
549 first_button = path_bar->button_list;
552 /* To see how much space we have, and how many buttons we can display.
553 * We start at the first button, count forward until hit the new
554 * button, then count backwards.
556 /* Count down the path chain towards the end. */
557 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
558 &child_requisition, NULL);
560 width = child_requisition.width;
561 list = first_button->prev;
562 while (list && !reached_end)
564 child = BUTTON_DATA (list->data)->button;
566 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
568 if (width + child_requisition.width +
569 path_bar->spacing + slider_space > allocation_width)
571 else if (list == path_bar->fake_root)
574 width += child_requisition.width + path_bar->spacing;
579 /* Finally, we walk up, seeing how many of the previous buttons we can
581 while (first_button->next && !reached_end)
583 child = BUTTON_DATA (first_button->next->data)->button;
585 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
587 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
593 width += child_requisition.width + path_bar->spacing;
594 if (first_button == path_bar->fake_root)
596 first_button = first_button->next;
601 /* Now, we allocate space to the buttons */
602 child_allocation.y = allocation->y;
603 child_allocation.height = allocation->height;
605 if (direction == GTK_TEXT_DIR_RTL)
607 child_allocation.x = allocation->x + allocation->width;
608 if (need_sliders || path_bar->fake_root)
610 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
611 up_slider_offset = allocation->width - path_bar->slider_width;
616 child_allocation.x = allocation->x;
617 if (need_sliders || path_bar->fake_root)
619 up_slider_offset = 0;
620 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
624 for (list = first_button; list; list = list->prev)
626 GtkAllocation widget_allocation;
627 ButtonData *button_data;
629 button_data = BUTTON_DATA (list->data);
630 child = button_data->button;
632 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
634 child_allocation.width = MIN (child_requisition.width,
635 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
637 if (direction == GTK_TEXT_DIR_RTL)
638 child_allocation.x -= child_allocation.width;
640 /* Check to see if we've don't have any more space to allocate buttons */
641 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
643 gtk_widget_get_allocation (widget, &widget_allocation);
644 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
647 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
649 gtk_widget_get_allocation (widget, &widget_allocation);
650 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
651 widget_allocation.x + allocation_width)
655 if (child_allocation.width < child_requisition.width)
657 if (!gtk_widget_get_has_tooltip (child))
658 gtk_widget_set_tooltip_text (child, button_data->dir_name);
660 else if (gtk_widget_get_has_tooltip (child))
661 gtk_widget_set_tooltip_text (child, NULL);
663 gtk_widget_set_child_visible (child, TRUE);
664 gtk_widget_size_allocate (child, &child_allocation);
666 if (direction == GTK_TEXT_DIR_RTL)
667 child_allocation.x -= path_bar->spacing;
669 child_allocation.x += child_allocation.width + path_bar->spacing;
671 /* Now we go hide all the widgets that don't fit */
674 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
677 for (list = first_button->next; list; list = list->next)
679 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
682 if (need_sliders || path_bar->fake_root)
684 child_allocation.width = path_bar->slider_width;
685 child_allocation.x = up_slider_offset + allocation->x;
686 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
688 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
689 gtk_widget_show_all (path_bar->up_slider_button);
692 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
696 child_allocation.width = path_bar->slider_width;
698 if (direction == GTK_TEXT_DIR_RTL)
699 child_allocation.x = 0;
701 child_allocation.x = allocation->width - path_bar->slider_width;
703 child_allocation.x += allocation->x;
705 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
707 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
708 gtk_widget_show_all (path_bar->down_slider_button);
709 gtk_path_bar_update_slider_buttons (path_bar);
712 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
716 gtk_path_bar_style_set (GtkWidget *widget,
717 GtkStyle *previous_style)
719 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
721 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
725 gtk_path_bar_screen_changed (GtkWidget *widget,
726 GdkScreen *previous_screen)
728 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
729 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
731 /* We might nave a new settings, so we remove the old one */
733 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
735 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
739 gtk_path_bar_scroll (GtkWidget *widget,
740 GdkEventScroll *event)
742 switch (event->direction)
744 case GDK_SCROLL_RIGHT:
745 case GDK_SCROLL_DOWN:
746 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
748 case GDK_SCROLL_LEFT:
750 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
758 gtk_path_bar_add (GtkContainer *container,
761 gtk_widget_set_parent (widget, GTK_WIDGET (container));
765 gtk_path_bar_remove_1 (GtkContainer *container,
768 gboolean was_visible = gtk_widget_get_visible (widget);
769 gtk_widget_unparent (widget);
771 gtk_widget_queue_resize (GTK_WIDGET (container));
775 gtk_path_bar_remove (GtkContainer *container,
778 GtkPathBar *path_bar;
781 path_bar = GTK_PATH_BAR (container);
783 if (widget == path_bar->up_slider_button)
785 gtk_path_bar_remove_1 (container, widget);
786 path_bar->up_slider_button = NULL;
790 if (widget == path_bar->down_slider_button)
792 gtk_path_bar_remove_1 (container, widget);
793 path_bar->down_slider_button = NULL;
797 children = path_bar->button_list;
800 if (widget == BUTTON_DATA (children->data)->button)
802 gtk_path_bar_remove_1 (container, widget);
803 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
804 g_list_free (children);
808 children = children->next;
813 gtk_path_bar_forall (GtkContainer *container,
814 gboolean include_internals,
815 GtkCallback callback,
816 gpointer callback_data)
818 GtkPathBar *path_bar;
821 g_return_if_fail (callback != NULL);
822 path_bar = GTK_PATH_BAR (container);
824 children = path_bar->button_list;
828 child = BUTTON_DATA (children->data)->button;
829 children = children->next;
831 (* callback) (child, callback_data);
834 if (path_bar->up_slider_button)
835 (* callback) (path_bar->up_slider_button, callback_data);
837 if (path_bar->down_slider_button)
838 (* callback) (path_bar->down_slider_button, callback_data);
842 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
844 GtkAllocation allocation, button_allocation;
846 GList *down_button = NULL;
847 gint space_available;
849 if (path_bar->ignore_click)
851 path_bar->ignore_click = FALSE;
855 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
857 /* Return if the last button is already visible */
861 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
863 /* We find the button at the 'down' end that we have to make
865 for (list = path_bar->button_list; list; list = list->next)
867 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
874 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
875 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
877 space_available = (allocation.width
878 - 2 * path_bar->spacing - 2 * path_bar->slider_width
879 - button_allocation.width);
880 path_bar->first_scrolled_button = down_button;
882 /* We have space_available free space that's not being used.
883 * So we walk down from the end, adding buttons until we use all free space.
885 while (space_available > 0)
887 path_bar->first_scrolled_button = down_button;
888 down_button = down_button->next;
891 space_available -= (button_allocation.width
892 + path_bar->spacing);
897 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
901 if (path_bar->ignore_click)
903 path_bar->ignore_click = FALSE;
907 list = g_list_last (path_bar->button_list);
909 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
911 /* Return if the first button is already visible */
915 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
917 for ( ; list; list = list->prev)
919 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
921 if (list->prev == path_bar->fake_root)
922 path_bar->fake_root = NULL;
923 path_bar->first_scrolled_button = list;
930 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
932 gboolean retval = FALSE;
936 if (path_bar->scrolling_up)
937 gtk_path_bar_scroll_up (path_bar);
938 else if (path_bar->scrolling_down)
939 gtk_path_bar_scroll_down (path_bar);
941 if (path_bar->need_timer)
943 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
946 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
948 path_bar->need_timer = FALSE;
950 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
951 (GSourceFunc)gtk_path_bar_scroll_timeout,
962 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
966 g_source_remove (path_bar->timer);
968 path_bar->need_timer = FALSE;
973 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
974 GdkEventButton *event,
975 GtkPathBar *path_bar)
978 GList *up_button = NULL;
980 if (event->type != GDK_FOCUS_CHANGE)
983 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
985 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
992 /* don't let the focus vanish */
993 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
994 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
995 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
1001 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
1002 GdkEventButton *event,
1003 GtkPathBar *path_bar)
1006 GList *down_button = NULL;
1008 if (event->type != GDK_FOCUS_CHANGE)
1011 for (list = path_bar->button_list; list; list = list->next)
1013 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1020 /* don't let the focus vanish */
1021 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1022 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1023 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1029 gtk_path_bar_slider_button_press (GtkWidget *widget,
1030 GdkEventButton *event,
1031 GtkPathBar *path_bar)
1033 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1036 path_bar->ignore_click = FALSE;
1038 if (widget == path_bar->up_slider_button)
1040 path_bar->scrolling_down = FALSE;
1041 path_bar->scrolling_up = TRUE;
1042 gtk_path_bar_scroll_up (path_bar);
1044 else if (widget == path_bar->down_slider_button)
1046 path_bar->scrolling_up = FALSE;
1047 path_bar->scrolling_down = TRUE;
1048 gtk_path_bar_scroll_down (path_bar);
1051 if (!path_bar->timer)
1053 GtkSettings *settings = gtk_widget_get_settings (widget);
1056 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1058 path_bar->need_timer = TRUE;
1059 path_bar->timer = gdk_threads_add_timeout (timeout,
1060 (GSourceFunc)gtk_path_bar_scroll_timeout,
1068 gtk_path_bar_slider_button_release (GtkWidget *widget,
1069 GdkEventButton *event,
1070 GtkPathBar *path_bar)
1072 if (event->type != GDK_BUTTON_RELEASE)
1075 path_bar->ignore_click = TRUE;
1076 gtk_path_bar_stop_scrolling (path_bar);
1082 gtk_path_bar_grab_notify (GtkWidget *widget,
1083 gboolean was_grabbed)
1086 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1090 gtk_path_bar_state_changed (GtkWidget *widget,
1091 GtkStateType previous_state)
1093 if (!gtk_widget_is_sensitive (widget))
1094 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1098 /* Changes the icons wherever it is needed */
1100 reload_icons (GtkPathBar *path_bar)
1104 if (path_bar->root_icon)
1106 g_object_unref (path_bar->root_icon);
1107 path_bar->root_icon = NULL;
1109 if (path_bar->home_icon)
1111 g_object_unref (path_bar->home_icon);
1112 path_bar->home_icon = NULL;
1114 if (path_bar->desktop_icon)
1116 g_object_unref (path_bar->desktop_icon);
1117 path_bar->desktop_icon = NULL;
1120 for (list = path_bar->button_list; list; list = list->next)
1122 ButtonData *button_data;
1123 gboolean current_dir;
1125 button_data = BUTTON_DATA (list->data);
1126 if (button_data->type != NORMAL_BUTTON)
1128 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1129 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1136 change_icon_theme (GtkPathBar *path_bar)
1138 GtkSettings *settings;
1141 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1143 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1144 path_bar->icon_size = MAX (width, height);
1146 path_bar->icon_size = FALLBACK_ICON_SIZE;
1148 reload_icons (path_bar);
1150 /* Callback used when a GtkSettings value changes */
1152 settings_notify_cb (GObject *object,
1154 GtkPathBar *path_bar)
1158 name = g_param_spec_get_name (pspec);
1160 if (! strcmp (name, "gtk-icon-theme-name") ||
1161 ! strcmp (name, "gtk-icon-sizes"))
1162 change_icon_theme (path_bar);
1166 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1168 GtkSettings *settings;
1170 if (path_bar->settings_signal_id)
1173 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1174 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1176 change_icon_theme (path_bar);
1179 /* Public functions and their helpers */
1181 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1183 while (path_bar->button_list != NULL)
1185 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1187 path_bar->first_scrolled_button = NULL;
1188 path_bar->fake_root = NULL;
1192 button_clicked_cb (GtkWidget *button,
1195 ButtonData *button_data;
1196 GtkPathBar *path_bar;
1198 gboolean child_is_hidden;
1201 button_data = BUTTON_DATA (data);
1202 if (button_data->ignore_changes)
1205 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1207 button_list = g_list_find (path_bar->button_list, button_data);
1208 g_assert (button_list != NULL);
1210 g_signal_handlers_block_by_func (button,
1211 G_CALLBACK (button_clicked_cb), data);
1212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1213 g_signal_handlers_unblock_by_func (button,
1214 G_CALLBACK (button_clicked_cb), data);
1216 if (button_list->prev)
1218 ButtonData *child_data;
1220 child_data = BUTTON_DATA (button_list->prev->data);
1221 child_file = child_data->file;
1222 child_is_hidden = child_data->file_is_hidden;
1227 child_is_hidden = FALSE;
1230 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1231 button_data->file, child_file, child_is_hidden);
1234 struct SetButtonImageData
1236 GtkPathBar *path_bar;
1237 ButtonData *button_data;
1241 set_button_image_get_info_cb (GCancellable *cancellable,
1243 const GError *error,
1246 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1248 struct SetButtonImageData *data = user_data;
1250 if (cancellable != data->button_data->cancellable)
1253 data->button_data->cancellable = NULL;
1255 if (!data->button_data->button)
1257 g_free (data->button_data);
1261 if (cancelled || error)
1264 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1265 data->path_bar->icon_size);
1266 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1268 switch (data->button_data->type)
1271 if (data->path_bar->home_icon)
1272 g_object_unref (pixbuf);
1274 data->path_bar->home_icon = pixbuf;
1277 case DESKTOP_BUTTON:
1278 if (data->path_bar->desktop_icon)
1279 g_object_unref (pixbuf);
1281 data->path_bar->desktop_icon = pixbuf;
1290 g_object_unref (cancellable);
1294 set_button_image (GtkPathBar *path_bar,
1295 ButtonData *button_data)
1297 GtkFileSystemVolume *volume;
1298 struct SetButtonImageData *data;
1300 switch (button_data->type)
1304 if (path_bar->root_icon != NULL)
1306 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1310 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1314 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1315 GTK_WIDGET (path_bar),
1316 path_bar->icon_size,
1318 _gtk_file_system_volume_unref (volume);
1320 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1324 if (path_bar->home_icon != NULL)
1326 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1330 data = g_new0 (struct SetButtonImageData, 1);
1331 data->path_bar = path_bar;
1332 data->button_data = button_data;
1334 if (button_data->cancellable)
1335 g_cancellable_cancel (button_data->cancellable);
1337 button_data->cancellable =
1338 _gtk_file_system_get_info (path_bar->file_system,
1339 path_bar->home_file,
1341 set_button_image_get_info_cb,
1345 case DESKTOP_BUTTON:
1346 if (path_bar->desktop_icon != NULL)
1348 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1352 data = g_new0 (struct SetButtonImageData, 1);
1353 data->path_bar = path_bar;
1354 data->button_data = button_data;
1356 if (button_data->cancellable)
1357 g_cancellable_cancel (button_data->cancellable);
1359 button_data->cancellable =
1360 _gtk_file_system_get_info (path_bar->file_system,
1361 path_bar->desktop_file,
1363 set_button_image_get_info_cb,
1372 button_data_free (ButtonData *button_data)
1374 if (button_data->file)
1375 g_object_unref (button_data->file);
1376 button_data->file = NULL;
1378 g_free (button_data->dir_name);
1379 button_data->dir_name = NULL;
1381 button_data->button = NULL;
1383 if (button_data->cancellable)
1384 g_cancellable_cancel (button_data->cancellable);
1386 g_free (button_data);
1390 get_dir_name (ButtonData *button_data)
1392 return button_data->dir_name;
1395 /* We always want to request the same size for the label, whether
1396 * or not the contents are bold
1399 set_label_size_request (GtkWidget *alignment,
1400 ButtonData *button_data)
1402 const gchar *dir_name = get_dir_name (button_data);
1403 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1404 gint width, height, bold_width, bold_height;
1407 pango_layout_get_pixel_size (layout, &width, &height);
1409 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1410 pango_layout_set_markup (layout, markup, -1);
1413 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1415 gtk_widget_set_size_request (alignment,
1416 MAX (width, bold_width),
1417 MAX (height, bold_height));
1418 g_object_unref (layout);
1422 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1423 ButtonData *button_data,
1424 gboolean current_dir)
1426 const gchar *dir_name = get_dir_name (button_data);
1428 if (button_data->label != NULL)
1434 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1435 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1440 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1444 if (button_data->image != NULL)
1446 set_button_image (path_bar, button_data);
1449 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1451 button_data->ignore_changes = TRUE;
1452 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1453 button_data->ignore_changes = FALSE;
1458 find_button_type (GtkPathBar *path_bar,
1461 if (path_bar->root_file != NULL &&
1462 g_file_equal (file, path_bar->root_file))
1464 if (path_bar->home_file != NULL &&
1465 g_file_equal (file, path_bar->home_file))
1467 if (path_bar->desktop_file != NULL &&
1468 g_file_equal (file, path_bar->desktop_file))
1469 return DESKTOP_BUTTON;
1471 return NORMAL_BUTTON;
1475 button_drag_data_get_cb (GtkWidget *widget,
1476 GdkDragContext *context,
1477 GtkSelectionData *selection_data,
1482 ButtonData *button_data;
1483 GtkPathBar *path_bar;
1487 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
1489 uris[0] = g_file_get_uri (button_data->file);
1492 gtk_selection_data_set_uris (selection_data, uris);
1497 make_directory_button (GtkPathBar *path_bar,
1498 const char *dir_name,
1500 gboolean current_dir,
1501 gboolean file_is_hidden)
1504 GtkWidget *child = NULL;
1505 GtkWidget *label_alignment = NULL;
1506 ButtonData *button_data;
1508 file_is_hidden = !! file_is_hidden;
1509 /* Is it a special button? */
1510 button_data = g_new0 (ButtonData, 1);
1512 button_data->type = find_button_type (path_bar, file);
1513 button_data->button = gtk_toggle_button_new ();
1514 atk_obj = gtk_widget_get_accessible (button_data->button);
1515 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1517 switch (button_data->type)
1520 button_data->image = gtk_image_new ();
1521 child = button_data->image;
1522 button_data->label = NULL;
1523 atk_object_set_name (atk_obj, _("File System Root"));
1526 case DESKTOP_BUTTON:
1527 button_data->image = gtk_image_new ();
1528 button_data->label = gtk_label_new (NULL);
1529 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1530 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1531 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 2);
1532 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1533 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1537 button_data->label = gtk_label_new (NULL);
1538 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1539 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1540 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1541 child = label_alignment;
1542 button_data->image = NULL;
1545 button_data->dir_name = g_strdup (dir_name);
1546 button_data->file = g_object_ref (file);
1547 button_data->file_is_hidden = file_is_hidden;
1549 /* FIXME: Maybe we dont need this alignment at all and we can
1550 * use GtkMisc aligments or even GtkWidget:halign/valign center.
1552 * The following function ensures that the alignment will always
1553 * request the same size whether the button's text is bold or not.
1555 if (label_alignment)
1556 set_label_size_request (label_alignment, button_data);
1558 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1559 gtk_widget_show_all (button_data->button);
1561 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1563 g_signal_connect (button_data->button, "clicked",
1564 G_CALLBACK (button_clicked_cb),
1566 g_object_weak_ref (G_OBJECT (button_data->button),
1567 (GWeakNotify) button_data_free, button_data);
1569 gtk_drag_source_set (button_data->button,
1573 gtk_drag_source_add_uri_targets (button_data->button);
1574 g_signal_connect (button_data->button, "drag-data-get",
1575 G_CALLBACK (button_drag_data_get_cb), button_data);
1581 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1583 GtkFileSystem *file_system)
1586 GList *current_path = NULL;
1587 gboolean need_new_fake_root = FALSE;
1589 for (list = path_bar->button_list; list; list = list->next)
1591 ButtonData *button_data;
1593 button_data = list->data;
1594 if (g_file_equal (file, button_data->file))
1596 current_path = list;
1599 if (list == path_bar->fake_root)
1600 need_new_fake_root = TRUE;
1605 if (need_new_fake_root)
1607 path_bar->fake_root = NULL;
1608 for (list = current_path; list; list = list->next)
1610 ButtonData *button_data;
1612 button_data = list->data;
1613 if (BUTTON_IS_FAKE_ROOT (button_data))
1615 path_bar->fake_root = list;
1621 for (list = path_bar->button_list; list; list = list->next)
1623 gtk_path_bar_update_button_appearance (path_bar,
1624 BUTTON_DATA (list->data),
1625 (list == current_path) ? TRUE : FALSE);
1628 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1630 path_bar->first_scrolled_button = current_path;
1631 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1644 GtkPathBar *path_bar;
1647 gboolean first_directory;
1651 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1658 gtk_path_bar_clear_buttons (info->path_bar);
1659 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1660 info->path_bar->fake_root = info->fake_root;
1662 for (l = info->path_bar->button_list; l; l = l->next)
1664 GtkWidget *button = BUTTON_DATA (l->data)->button;
1665 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1672 for (l = info->new_buttons; l; l = l->next)
1674 ButtonData *button_data;
1676 button_data = BUTTON_DATA (l->data);
1677 gtk_widget_destroy (button_data->button);
1680 g_list_free (info->new_buttons);
1684 g_object_unref (info->file);
1685 if (info->parent_file)
1686 g_object_unref (info->parent_file);
1691 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1693 const GError *error,
1696 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1697 struct SetFileInfo *file_info = data;
1698 ButtonData *button_data;
1699 const gchar *display_name;
1702 if (cancellable != file_info->path_bar->get_info_cancellable)
1704 gtk_path_bar_set_file_finish (file_info, FALSE);
1705 g_object_unref (cancellable);
1709 g_object_unref (cancellable);
1710 file_info->path_bar->get_info_cancellable = NULL;
1712 if (cancelled || !info)
1714 gtk_path_bar_set_file_finish (file_info, FALSE);
1718 display_name = g_file_info_get_display_name (info);
1719 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1721 gtk_widget_push_composite_child ();
1722 button_data = make_directory_button (file_info->path_bar, display_name,
1724 file_info->first_directory, is_hidden);
1725 gtk_widget_pop_composite_child ();
1726 g_object_unref (file_info->file);
1728 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1730 if (BUTTON_IS_FAKE_ROOT (button_data))
1731 file_info->fake_root = file_info->new_buttons;
1733 file_info->file = file_info->parent_file;
1734 file_info->first_directory = FALSE;
1736 if (!file_info->file)
1738 gtk_path_bar_set_file_finish (file_info, TRUE);
1742 file_info->parent_file = g_file_get_parent (file_info->file);
1744 file_info->path_bar->get_info_cancellable =
1745 _gtk_file_system_get_info (file_info->path_bar->file_system,
1747 "standard::display-name,standard::is-hidden,standard::is-backup",
1748 gtk_path_bar_get_info_callback,
1753 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1755 const gboolean keep_trail,
1758 struct SetFileInfo *info;
1761 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1762 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1766 /* Check whether the new path is already present in the pathbar as buttons.
1767 * This could be a parent directory or a previous selected subdirectory.
1770 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1773 info = g_new0 (struct SetFileInfo, 1);
1774 info->file = g_object_ref (file);
1775 info->path_bar = path_bar;
1776 info->first_directory = TRUE;
1777 info->parent_file = g_file_get_parent (info->file);
1779 if (path_bar->get_info_cancellable)
1780 g_cancellable_cancel (path_bar->get_info_cancellable);
1782 path_bar->get_info_cancellable =
1783 _gtk_file_system_get_info (path_bar->file_system,
1785 "standard::display-name,standard::is-hidden,standard::is-backup",
1786 gtk_path_bar_get_info_callback,
1792 /* FIXME: This should be a construct-only property */
1794 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1795 GtkFileSystem *file_system)
1799 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1801 g_assert (path_bar->file_system == NULL);
1803 path_bar->file_system = g_object_ref (file_system);
1805 home = g_get_home_dir ();
1808 const gchar *desktop;
1810 path_bar->home_file = g_file_new_for_path (home);
1811 /* FIXME: Need file system backend specific way of getting the
1814 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1815 if (desktop != NULL)
1816 path_bar->desktop_file = g_file_new_for_path (desktop);
1818 path_bar->desktop_file = NULL;
1822 path_bar->home_file = NULL;
1823 path_bar->desktop_file = NULL;
1825 path_bar->root_file = g_file_new_for_path ("/");
1830 * @path_bar: a #GtkPathBar
1832 * If the selected button in the pathbar is not the furthest button "up" (in the
1833 * root direction), act as if the user clicked on the next button up.
1836 _gtk_path_bar_up (GtkPathBar *path_bar)
1840 for (l = path_bar->button_list; l; l = l->next)
1842 GtkWidget *button = BUTTON_DATA (l->data)->button;
1843 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1847 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1848 button_clicked_cb (next_button, l->next->data);
1856 * _gtk_path_bar_down:
1857 * @path_bar: a #GtkPathBar
1859 * If the selected button in the pathbar is not the furthest button "down" (in the
1860 * leaf direction), act as if the user clicked on the next button down.
1863 _gtk_path_bar_down (GtkPathBar *path_bar)
1867 for (l = path_bar->button_list; l; l = l->next)
1869 GtkWidget *button = BUTTON_DATA (l->data)->button;
1870 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1874 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1875 button_clicked_cb (prev_button, l->prev->data);