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"
39 #include "gtksizerequest.h"
54 #define BUTTON_DATA(x) ((ButtonData *)(x))
56 #define SCROLL_DELAY_FACTOR 5
58 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
60 /* Icon size for if we can't get it from the theme */
61 #define FALLBACK_ICON_SIZE 16
63 typedef struct _ButtonData ButtonData;
73 GCancellable *cancellable;
74 guint ignore_changes : 1;
75 guint file_is_hidden : 1;
77 /* This macro is used to check if a button can be used as a fake root.
78 * All buttons in front of a fake root are automatically hidden when in a
79 * directory below a fake root and replaced with the "<" arrow button.
81 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
83 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
85 static void gtk_path_bar_finalize (GObject *object);
86 static void gtk_path_bar_dispose (GObject *object);
87 static void gtk_path_bar_realize (GtkWidget *widget);
88 static void gtk_path_bar_unrealize (GtkWidget *widget);
89 static void gtk_path_bar_size_request (GtkWidget *widget,
90 GtkRequisition *requisition);
91 static void gtk_path_bar_map (GtkWidget *widget);
92 static void gtk_path_bar_unmap (GtkWidget *widget);
93 static void gtk_path_bar_size_allocate (GtkWidget *widget,
94 GtkAllocation *allocation);
95 static void gtk_path_bar_add (GtkContainer *container,
97 static void gtk_path_bar_remove (GtkContainer *container,
99 static void gtk_path_bar_forall (GtkContainer *container,
100 gboolean include_internals,
101 GtkCallback callback,
102 gpointer callback_data);
103 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
104 GdkEventScroll *event);
105 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
106 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
107 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
108 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
109 GdkEventButton *event,
110 GtkPathBar *path_bar);
111 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
112 GdkEventButton *event,
113 GtkPathBar *path_bar);
114 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
115 GdkEventButton *event,
116 GtkPathBar *path_bar);
117 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
118 GdkEventButton *event,
119 GtkPathBar *path_bar);
120 static void gtk_path_bar_grab_notify (GtkWidget *widget,
121 gboolean was_grabbed);
122 static void gtk_path_bar_state_changed (GtkWidget *widget,
123 GtkStateType previous_state);
124 static void gtk_path_bar_style_set (GtkWidget *widget,
125 GtkStyle *previous_style);
126 static void gtk_path_bar_screen_changed (GtkWidget *widget,
127 GdkScreen *previous_screen);
128 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
129 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
130 ButtonData *button_data,
131 gboolean current_dir);
134 on_slider_unmap (GtkWidget *widget,
135 GtkPathBar *path_bar)
137 if (path_bar->timer &&
138 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
139 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
140 gtk_path_bar_stop_scrolling (path_bar);
144 get_slider_button (GtkPathBar *path_bar,
145 GtkArrowType arrow_type)
150 gtk_widget_push_composite_child ();
152 button = gtk_button_new ();
153 atk_obj = gtk_widget_get_accessible (button);
154 if (arrow_type == GTK_ARROW_LEFT)
155 atk_object_set_name (atk_obj, _("Up Path"));
157 atk_object_set_name (atk_obj, _("Down Path"));
159 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
160 gtk_container_add (GTK_CONTAINER (button),
161 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
162 gtk_container_add (GTK_CONTAINER (path_bar), button);
163 gtk_widget_show_all (button);
165 g_signal_connect (G_OBJECT (button), "unmap",
166 G_CALLBACK (on_slider_unmap), path_bar);
168 gtk_widget_pop_composite_child ();
174 gtk_path_bar_init (GtkPathBar *path_bar)
176 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
177 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
179 path_bar->get_info_cancellable = NULL;
181 path_bar->spacing = 0;
182 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
183 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
184 path_bar->icon_size = FALLBACK_ICON_SIZE;
186 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
187 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
188 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
189 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
191 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
192 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
193 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
194 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
196 g_signal_connect (path_bar->up_slider_button, "button-press-event",
197 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
198 g_signal_connect (path_bar->up_slider_button, "button-release-event",
199 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
200 g_signal_connect (path_bar->down_slider_button, "button-press-event",
201 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
202 g_signal_connect (path_bar->down_slider_button, "button-release-event",
203 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
207 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
209 GObjectClass *gobject_class;
210 GtkObjectClass *object_class;
211 GtkWidgetClass *widget_class;
212 GtkContainerClass *container_class;
214 gobject_class = (GObjectClass *) path_bar_class;
215 object_class = (GtkObjectClass *) path_bar_class;
216 widget_class = (GtkWidgetClass *) path_bar_class;
217 container_class = (GtkContainerClass *) path_bar_class;
219 gobject_class->finalize = gtk_path_bar_finalize;
220 gobject_class->dispose = gtk_path_bar_dispose;
222 widget_class->size_request = gtk_path_bar_size_request;
223 widget_class->realize = gtk_path_bar_realize;
224 widget_class->unrealize = gtk_path_bar_unrealize;
225 widget_class->map = gtk_path_bar_map;
226 widget_class->unmap = gtk_path_bar_unmap;
227 widget_class->size_allocate = gtk_path_bar_size_allocate;
228 widget_class->style_set = gtk_path_bar_style_set;
229 widget_class->screen_changed = gtk_path_bar_screen_changed;
230 widget_class->grab_notify = gtk_path_bar_grab_notify;
231 widget_class->state_changed = gtk_path_bar_state_changed;
232 widget_class->scroll_event = gtk_path_bar_scroll;
234 container_class->add = gtk_path_bar_add;
235 container_class->forall = gtk_path_bar_forall;
236 container_class->remove = gtk_path_bar_remove;
238 /* container_class->child_type = gtk_path_bar_child_type;*/
240 path_bar_signals [PATH_CLICKED] =
241 g_signal_new (I_("path-clicked"),
242 G_OBJECT_CLASS_TYPE (object_class),
244 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
246 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
255 gtk_path_bar_finalize (GObject *object)
257 GtkPathBar *path_bar;
259 path_bar = GTK_PATH_BAR (object);
261 gtk_path_bar_stop_scrolling (path_bar);
263 g_list_free (path_bar->button_list);
264 if (path_bar->root_file)
265 g_object_unref (path_bar->root_file);
266 if (path_bar->home_file)
267 g_object_unref (path_bar->home_file);
268 if (path_bar->desktop_file)
269 g_object_unref (path_bar->desktop_file);
271 if (path_bar->root_icon)
272 g_object_unref (path_bar->root_icon);
273 if (path_bar->home_icon)
274 g_object_unref (path_bar->home_icon);
275 if (path_bar->desktop_icon)
276 g_object_unref (path_bar->desktop_icon);
278 if (path_bar->file_system)
279 g_object_unref (path_bar->file_system);
281 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
284 /* Removes the settings signal handler. It's safe to call multiple times */
286 remove_settings_signal (GtkPathBar *path_bar,
289 if (path_bar->settings_signal_id)
291 GtkSettings *settings;
293 settings = gtk_settings_get_for_screen (screen);
294 g_signal_handler_disconnect (settings,
295 path_bar->settings_signal_id);
296 path_bar->settings_signal_id = 0;
301 gtk_path_bar_dispose (GObject *object)
303 GtkPathBar *path_bar = GTK_PATH_BAR (object);
305 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
307 if (path_bar->get_info_cancellable)
308 g_cancellable_cancel (path_bar->get_info_cancellable);
309 path_bar->get_info_cancellable = NULL;
311 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
316 * Ideally, our size is determined by another widget, and we are just filling
320 gtk_path_bar_size_request (GtkWidget *widget,
321 GtkRequisition *requisition)
323 ButtonData *button_data;
324 GtkPathBar *path_bar;
325 GtkRequisition child_requisition;
329 path_bar = GTK_PATH_BAR (widget);
331 requisition->width = 0;
332 requisition->height = 0;
334 for (list = path_bar->button_list; list; list = list->next)
336 button_data = BUTTON_DATA (list->data);
337 gtk_size_request_get_size (GTK_SIZE_REQUEST (button_data->button),
338 &child_requisition, NULL);
340 if (button_data->type == NORMAL_BUTTON)
341 /* Use 2*Height as button width because of ellipsized label. */
342 requisition->width = MAX (child_requisition.height * 2, requisition->width);
344 requisition->width = MAX (child_requisition.width, requisition->width);
346 requisition->height = MAX (child_requisition.height, requisition->height);
349 /* Add space for slider, if we have more than one path */
350 /* Theoretically, the slider could be bigger than the other button. But we're
351 * not going to worry about that now.
353 path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
354 if (path_bar->button_list && path_bar->button_list->next != NULL)
355 requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
357 gtk_size_request_get_size (GTK_SIZE_REQUEST (path_bar->up_slider_button),
358 &child_requisition, NULL);
359 gtk_size_request_get_size (GTK_SIZE_REQUEST (path_bar->down_slider_button),
360 &child_requisition, NULL);
362 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
363 requisition->width += border_width * 2;
364 requisition->height += border_width * 2;
368 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
370 if (path_bar->button_list)
374 button = BUTTON_DATA (path_bar->button_list->data)->button;
375 if (gtk_widget_get_child_visible (button))
377 gtk_path_bar_stop_scrolling (path_bar);
378 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
381 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
383 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
384 if (gtk_widget_get_child_visible (button))
386 gtk_path_bar_stop_scrolling (path_bar);
387 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
390 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
395 gtk_path_bar_map (GtkWidget *widget)
397 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
399 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
403 gtk_path_bar_unmap (GtkWidget *widget)
405 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
406 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
408 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
412 gtk_path_bar_realize (GtkWidget *widget)
414 GtkPathBar *path_bar;
415 GtkAllocation allocation;
417 GdkWindowAttr attributes;
418 gint attributes_mask;
420 gtk_widget_set_realized (widget, TRUE);
422 path_bar = GTK_PATH_BAR (widget);
423 window = gtk_widget_get_parent_window (widget);
424 gtk_widget_set_window (widget, window);
425 g_object_ref (window);
427 gtk_widget_get_allocation (widget, &allocation);
429 attributes.window_type = GDK_WINDOW_CHILD;
430 attributes.x = allocation.x;
431 attributes.y = allocation.y;
432 attributes.width = allocation.width;
433 attributes.height = allocation.height;
434 attributes.wclass = GDK_INPUT_ONLY;
435 attributes.event_mask = gtk_widget_get_events (widget);
436 attributes.event_mask |= GDK_SCROLL_MASK;
437 attributes_mask = GDK_WA_X | GDK_WA_Y;
439 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
440 &attributes, attributes_mask);
441 gdk_window_set_user_data (path_bar->event_window, widget);
443 gtk_widget_style_attach (widget);
447 gtk_path_bar_unrealize (GtkWidget *widget)
449 GtkPathBar *path_bar;
451 path_bar = GTK_PATH_BAR (widget);
453 gdk_window_set_user_data (path_bar->event_window, NULL);
454 gdk_window_destroy (path_bar->event_window);
455 path_bar->event_window = NULL;
457 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
460 /* This is a tad complicated
463 gtk_path_bar_size_allocate (GtkWidget *widget,
464 GtkAllocation *allocation)
467 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
468 GtkTextDirection direction;
469 GtkAllocation child_allocation;
470 GList *list, *first_button;
472 gint allocation_width;
474 gboolean need_sliders = FALSE;
475 gint up_slider_offset = 0;
476 GtkRequisition child_requisition;
478 gtk_widget_set_allocation (widget, allocation);
480 if (gtk_widget_get_realized (widget))
481 gdk_window_move_resize (path_bar->event_window,
482 allocation->x, allocation->y,
483 allocation->width, allocation->height);
485 /* No path is set; we don't have to allocate anything. */
486 if (path_bar->button_list == NULL)
489 direction = gtk_widget_get_direction (widget);
490 border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar));
491 allocation_width = allocation->width - 2 * border_width;
493 /* First, we check to see if we need the scrollbars. */
494 if (path_bar->fake_root)
495 width = path_bar->spacing + path_bar->slider_width;
499 for (list = path_bar->button_list; list; list = list->next)
501 child = BUTTON_DATA (list->data)->button;
503 gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
504 &child_requisition, NULL);
506 width += child_requisition.width + path_bar->spacing;
507 if (list == path_bar->fake_root)
511 if (width <= allocation_width)
513 if (path_bar->fake_root)
514 first_button = path_bar->fake_root;
516 first_button = g_list_last (path_bar->button_list);
520 gboolean reached_end = FALSE;
521 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
523 if (path_bar->first_scrolled_button)
524 first_button = path_bar->first_scrolled_button;
526 first_button = path_bar->button_list;
529 /* To see how much space we have, and how many buttons we can display.
530 * We start at the first button, count forward until hit the new
531 * button, then count backwards.
533 /* Count down the path chain towards the end. */
534 gtk_size_request_get_size (GTK_SIZE_REQUEST (BUTTON_DATA (first_button->data)->button),
535 &child_requisition, NULL);
537 width = child_requisition.width;
538 list = first_button->prev;
539 while (list && !reached_end)
541 child = BUTTON_DATA (list->data)->button;
543 gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
544 &child_requisition, NULL);
546 if (width + child_requisition.width +
547 path_bar->spacing + slider_space > allocation_width)
549 else if (list == path_bar->fake_root)
552 width += child_requisition.width + path_bar->spacing;
557 /* Finally, we walk up, seeing how many of the previous buttons we can
559 while (first_button->next && !reached_end)
561 child = BUTTON_DATA (first_button->next->data)->button;
563 gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
564 &child_requisition, NULL);
566 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
572 width += child_requisition.width + path_bar->spacing;
573 if (first_button == path_bar->fake_root)
575 first_button = first_button->next;
580 /* Now, we allocate space to the buttons */
581 child_allocation.y = allocation->y + border_width;
582 child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
584 if (direction == GTK_TEXT_DIR_RTL)
586 child_allocation.x = allocation->x + allocation->width - border_width;
587 if (need_sliders || path_bar->fake_root)
589 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
590 up_slider_offset = allocation->width - border_width - path_bar->slider_width;
595 child_allocation.x = allocation->x + border_width;
596 if (need_sliders || path_bar->fake_root)
598 up_slider_offset = border_width;
599 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
603 for (list = first_button; list; list = list->prev)
605 GtkAllocation widget_allocation;
606 ButtonData *button_data;
608 button_data = BUTTON_DATA (list->data);
609 child = button_data->button;
611 gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
612 &child_requisition, NULL);
614 child_allocation.width = MIN (child_requisition.width,
615 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
617 if (direction == GTK_TEXT_DIR_RTL)
618 child_allocation.x -= child_allocation.width;
620 /* Check to see if we've don't have any more space to allocate buttons */
621 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
623 gtk_widget_get_allocation (widget, &widget_allocation);
624 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x + border_width)
627 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
629 gtk_widget_get_allocation (widget, &widget_allocation);
630 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
631 widget_allocation.x + border_width + allocation_width)
635 if (child_allocation.width < child_requisition.width)
637 if (!gtk_widget_get_has_tooltip (child))
638 gtk_widget_set_tooltip_text (child, button_data->dir_name);
640 else if (gtk_widget_get_has_tooltip (child))
641 gtk_widget_set_tooltip_text (child, NULL);
643 gtk_widget_set_child_visible (child, TRUE);
644 gtk_widget_size_allocate (child, &child_allocation);
646 if (direction == GTK_TEXT_DIR_RTL)
647 child_allocation.x -= path_bar->spacing;
649 child_allocation.x += child_allocation.width + path_bar->spacing;
651 /* Now we go hide all the widgets that don't fit */
654 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
657 for (list = first_button->next; list; list = list->next)
659 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
662 if (need_sliders || path_bar->fake_root)
664 child_allocation.width = path_bar->slider_width;
665 child_allocation.x = up_slider_offset + allocation->x;
666 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
668 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
669 gtk_widget_show_all (path_bar->up_slider_button);
672 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
676 child_allocation.width = path_bar->slider_width;
678 if (direction == GTK_TEXT_DIR_RTL)
679 child_allocation.x = border_width;
681 child_allocation.x = allocation->width - border_width - path_bar->slider_width;
683 child_allocation.x += allocation->x;
685 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
687 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
688 gtk_widget_show_all (path_bar->down_slider_button);
689 gtk_path_bar_update_slider_buttons (path_bar);
692 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
696 gtk_path_bar_style_set (GtkWidget *widget,
697 GtkStyle *previous_style)
699 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
701 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
705 gtk_path_bar_screen_changed (GtkWidget *widget,
706 GdkScreen *previous_screen)
708 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
709 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
711 /* We might nave a new settings, so we remove the old one */
713 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
715 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
719 gtk_path_bar_scroll (GtkWidget *widget,
720 GdkEventScroll *event)
722 switch (event->direction)
724 case GDK_SCROLL_RIGHT:
725 case GDK_SCROLL_DOWN:
726 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
728 case GDK_SCROLL_LEFT:
730 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
738 gtk_path_bar_add (GtkContainer *container,
741 gtk_widget_set_parent (widget, GTK_WIDGET (container));
745 gtk_path_bar_remove_1 (GtkContainer *container,
748 gboolean was_visible = gtk_widget_get_visible (widget);
749 gtk_widget_unparent (widget);
751 gtk_widget_queue_resize (GTK_WIDGET (container));
755 gtk_path_bar_remove (GtkContainer *container,
758 GtkPathBar *path_bar;
761 path_bar = GTK_PATH_BAR (container);
763 if (widget == path_bar->up_slider_button)
765 gtk_path_bar_remove_1 (container, widget);
766 path_bar->up_slider_button = NULL;
770 if (widget == path_bar->down_slider_button)
772 gtk_path_bar_remove_1 (container, widget);
773 path_bar->down_slider_button = NULL;
777 children = path_bar->button_list;
780 if (widget == BUTTON_DATA (children->data)->button)
782 gtk_path_bar_remove_1 (container, widget);
783 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
784 g_list_free (children);
788 children = children->next;
793 gtk_path_bar_forall (GtkContainer *container,
794 gboolean include_internals,
795 GtkCallback callback,
796 gpointer callback_data)
798 GtkPathBar *path_bar;
801 g_return_if_fail (callback != NULL);
802 path_bar = GTK_PATH_BAR (container);
804 children = path_bar->button_list;
808 child = BUTTON_DATA (children->data)->button;
809 children = children->next;
811 (* callback) (child, callback_data);
814 if (path_bar->up_slider_button)
815 (* callback) (path_bar->up_slider_button, callback_data);
817 if (path_bar->down_slider_button)
818 (* callback) (path_bar->down_slider_button, callback_data);
822 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
824 GtkAllocation allocation, button_allocation;
826 GList *down_button = NULL;
827 gint space_available;
829 if (path_bar->ignore_click)
831 path_bar->ignore_click = FALSE;
835 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
837 /* Return if the last button is already visible */
841 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
843 /* We find the button at the 'down' end that we have to make
845 for (list = path_bar->button_list; list; list = list->next)
847 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
854 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
855 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
857 space_available = (allocation.width
858 - 2 * gtk_container_get_border_width (GTK_CONTAINER (path_bar))
859 - 2 * path_bar->spacing - 2 * path_bar->slider_width
860 - button_allocation.width);
861 path_bar->first_scrolled_button = down_button;
863 /* We have space_available free space that's not being used.
864 * So we walk down from the end, adding buttons until we use all free space.
866 while (space_available > 0)
868 path_bar->first_scrolled_button = down_button;
869 down_button = down_button->next;
872 space_available -= (button_allocation.width
873 + path_bar->spacing);
878 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
882 if (path_bar->ignore_click)
884 path_bar->ignore_click = FALSE;
888 list = g_list_last (path_bar->button_list);
890 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
892 /* Return if the first button is already visible */
896 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
898 for ( ; list; list = list->prev)
900 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
902 if (list->prev == path_bar->fake_root)
903 path_bar->fake_root = NULL;
904 path_bar->first_scrolled_button = list;
911 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
913 gboolean retval = FALSE;
917 if (path_bar->scrolling_up)
918 gtk_path_bar_scroll_up (path_bar);
919 else if (path_bar->scrolling_down)
920 gtk_path_bar_scroll_down (path_bar);
922 if (path_bar->need_timer)
924 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
927 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
929 path_bar->need_timer = FALSE;
931 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
932 (GSourceFunc)gtk_path_bar_scroll_timeout,
943 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
947 g_source_remove (path_bar->timer);
949 path_bar->need_timer = FALSE;
954 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
955 GdkEventButton *event,
956 GtkPathBar *path_bar)
959 GList *up_button = NULL;
961 if (event->type != GDK_FOCUS_CHANGE)
964 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
966 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
973 /* don't let the focus vanish */
974 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
975 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
976 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
982 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
983 GdkEventButton *event,
984 GtkPathBar *path_bar)
987 GList *down_button = NULL;
989 if (event->type != GDK_FOCUS_CHANGE)
992 for (list = path_bar->button_list; list; list = list->next)
994 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1001 /* don't let the focus vanish */
1002 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1003 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1004 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1010 gtk_path_bar_slider_button_press (GtkWidget *widget,
1011 GdkEventButton *event,
1012 GtkPathBar *path_bar)
1014 if (event->type != GDK_BUTTON_PRESS || event->button != 1)
1017 path_bar->ignore_click = FALSE;
1019 if (widget == path_bar->up_slider_button)
1021 path_bar->scrolling_down = FALSE;
1022 path_bar->scrolling_up = TRUE;
1023 gtk_path_bar_scroll_up (path_bar);
1025 else if (widget == path_bar->down_slider_button)
1027 path_bar->scrolling_up = FALSE;
1028 path_bar->scrolling_down = TRUE;
1029 gtk_path_bar_scroll_down (path_bar);
1032 if (!path_bar->timer)
1034 GtkSettings *settings = gtk_widget_get_settings (widget);
1037 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1039 path_bar->need_timer = TRUE;
1040 path_bar->timer = gdk_threads_add_timeout (timeout,
1041 (GSourceFunc)gtk_path_bar_scroll_timeout,
1049 gtk_path_bar_slider_button_release (GtkWidget *widget,
1050 GdkEventButton *event,
1051 GtkPathBar *path_bar)
1053 if (event->type != GDK_BUTTON_RELEASE)
1056 path_bar->ignore_click = TRUE;
1057 gtk_path_bar_stop_scrolling (path_bar);
1063 gtk_path_bar_grab_notify (GtkWidget *widget,
1064 gboolean was_grabbed)
1067 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1071 gtk_path_bar_state_changed (GtkWidget *widget,
1072 GtkStateType previous_state)
1074 if (!gtk_widget_is_sensitive (widget))
1075 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1079 /* Changes the icons wherever it is needed */
1081 reload_icons (GtkPathBar *path_bar)
1085 if (path_bar->root_icon)
1087 g_object_unref (path_bar->root_icon);
1088 path_bar->root_icon = NULL;
1090 if (path_bar->home_icon)
1092 g_object_unref (path_bar->home_icon);
1093 path_bar->home_icon = NULL;
1095 if (path_bar->desktop_icon)
1097 g_object_unref (path_bar->desktop_icon);
1098 path_bar->desktop_icon = NULL;
1101 for (list = path_bar->button_list; list; list = list->next)
1103 ButtonData *button_data;
1104 gboolean current_dir;
1106 button_data = BUTTON_DATA (list->data);
1107 if (button_data->type != NORMAL_BUTTON)
1109 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1110 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1117 change_icon_theme (GtkPathBar *path_bar)
1119 GtkSettings *settings;
1122 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1124 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1125 path_bar->icon_size = MAX (width, height);
1127 path_bar->icon_size = FALLBACK_ICON_SIZE;
1129 reload_icons (path_bar);
1131 /* Callback used when a GtkSettings value changes */
1133 settings_notify_cb (GObject *object,
1135 GtkPathBar *path_bar)
1139 name = g_param_spec_get_name (pspec);
1141 if (! strcmp (name, "gtk-icon-theme-name") ||
1142 ! strcmp (name, "gtk-icon-sizes"))
1143 change_icon_theme (path_bar);
1147 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1149 GtkSettings *settings;
1151 if (path_bar->settings_signal_id)
1154 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1155 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1157 change_icon_theme (path_bar);
1160 /* Public functions and their helpers */
1162 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1164 while (path_bar->button_list != NULL)
1166 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1168 path_bar->first_scrolled_button = NULL;
1169 path_bar->fake_root = NULL;
1173 button_clicked_cb (GtkWidget *button,
1176 ButtonData *button_data;
1177 GtkPathBar *path_bar;
1179 gboolean child_is_hidden;
1182 button_data = BUTTON_DATA (data);
1183 if (button_data->ignore_changes)
1186 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1188 button_list = g_list_find (path_bar->button_list, button_data);
1189 g_assert (button_list != NULL);
1191 g_signal_handlers_block_by_func (button,
1192 G_CALLBACK (button_clicked_cb), data);
1193 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1194 g_signal_handlers_unblock_by_func (button,
1195 G_CALLBACK (button_clicked_cb), data);
1197 if (button_list->prev)
1199 ButtonData *child_data;
1201 child_data = BUTTON_DATA (button_list->prev->data);
1202 child_file = child_data->file;
1203 child_is_hidden = child_data->file_is_hidden;
1208 child_is_hidden = FALSE;
1211 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1212 button_data->file, child_file, child_is_hidden);
1215 struct SetButtonImageData
1217 GtkPathBar *path_bar;
1218 ButtonData *button_data;
1222 set_button_image_get_info_cb (GCancellable *cancellable,
1224 const GError *error,
1227 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1229 struct SetButtonImageData *data = user_data;
1231 if (cancellable != data->button_data->cancellable)
1234 data->button_data->cancellable = NULL;
1236 if (!data->button_data->button)
1238 g_free (data->button_data);
1242 if (cancelled || error)
1245 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1246 data->path_bar->icon_size);
1247 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1249 switch (data->button_data->type)
1252 if (data->path_bar->home_icon)
1253 g_object_unref (pixbuf);
1255 data->path_bar->home_icon = pixbuf;
1258 case DESKTOP_BUTTON:
1259 if (data->path_bar->desktop_icon)
1260 g_object_unref (pixbuf);
1262 data->path_bar->desktop_icon = pixbuf;
1271 g_object_unref (cancellable);
1275 set_button_image (GtkPathBar *path_bar,
1276 ButtonData *button_data)
1278 GtkFileSystemVolume *volume;
1279 struct SetButtonImageData *data;
1281 switch (button_data->type)
1285 if (path_bar->root_icon != NULL)
1287 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1291 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1295 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1296 GTK_WIDGET (path_bar),
1297 path_bar->icon_size,
1299 _gtk_file_system_volume_unref (volume);
1301 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1305 if (path_bar->home_icon != NULL)
1307 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1311 data = g_new0 (struct SetButtonImageData, 1);
1312 data->path_bar = path_bar;
1313 data->button_data = button_data;
1315 if (button_data->cancellable)
1316 g_cancellable_cancel (button_data->cancellable);
1318 button_data->cancellable =
1319 _gtk_file_system_get_info (path_bar->file_system,
1320 path_bar->home_file,
1322 set_button_image_get_info_cb,
1326 case DESKTOP_BUTTON:
1327 if (path_bar->desktop_icon != NULL)
1329 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1333 data = g_new0 (struct SetButtonImageData, 1);
1334 data->path_bar = path_bar;
1335 data->button_data = button_data;
1337 if (button_data->cancellable)
1338 g_cancellable_cancel (button_data->cancellable);
1340 button_data->cancellable =
1341 _gtk_file_system_get_info (path_bar->file_system,
1342 path_bar->desktop_file,
1344 set_button_image_get_info_cb,
1353 button_data_free (ButtonData *button_data)
1355 if (button_data->file)
1356 g_object_unref (button_data->file);
1357 button_data->file = NULL;
1359 g_free (button_data->dir_name);
1360 button_data->dir_name = NULL;
1362 button_data->button = NULL;
1364 if (button_data->cancellable)
1365 g_cancellable_cancel (button_data->cancellable);
1367 g_free (button_data);
1371 get_dir_name (ButtonData *button_data)
1373 return button_data->dir_name;
1376 /* We always want to request the same size for the label, whether
1377 * or not the contents are bold
1380 label_size_request_cb (GtkWidget *widget,
1381 GtkRequisition *requisition,
1382 ButtonData *button_data)
1384 const gchar *dir_name = get_dir_name (button_data);
1385 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1386 gint bold_width, bold_height;
1389 pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
1391 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1392 pango_layout_set_markup (layout, markup, -1);
1395 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1396 requisition->width = MAX (requisition->width, bold_width);
1397 requisition->height = MAX (requisition->height, bold_height);
1399 g_object_unref (layout);
1403 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1404 ButtonData *button_data,
1405 gboolean current_dir)
1407 const gchar *dir_name = get_dir_name (button_data);
1409 if (button_data->label != NULL)
1415 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1416 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1421 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1425 if (button_data->image != NULL)
1427 set_button_image (path_bar, button_data);
1430 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1432 button_data->ignore_changes = TRUE;
1433 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1434 button_data->ignore_changes = FALSE;
1439 find_button_type (GtkPathBar *path_bar,
1442 if (path_bar->root_file != NULL &&
1443 g_file_equal (file, path_bar->root_file))
1445 if (path_bar->home_file != NULL &&
1446 g_file_equal (file, path_bar->home_file))
1448 if (path_bar->desktop_file != NULL &&
1449 g_file_equal (file, path_bar->desktop_file))
1450 return DESKTOP_BUTTON;
1452 return NORMAL_BUTTON;
1456 button_drag_data_get_cb (GtkWidget *widget,
1457 GdkDragContext *context,
1458 GtkSelectionData *selection_data,
1463 ButtonData *button_data;
1464 GtkPathBar *path_bar;
1468 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
1470 uris[0] = g_file_get_uri (button_data->file);
1473 gtk_selection_data_set_uris (selection_data, uris);
1478 make_directory_button (GtkPathBar *path_bar,
1479 const char *dir_name,
1481 gboolean current_dir,
1482 gboolean file_is_hidden)
1485 GtkWidget *child = NULL;
1486 GtkWidget *label_alignment = NULL;
1487 ButtonData *button_data;
1489 file_is_hidden = !! file_is_hidden;
1490 /* Is it a special button? */
1491 button_data = g_new0 (ButtonData, 1);
1493 button_data->type = find_button_type (path_bar, file);
1494 button_data->button = gtk_toggle_button_new ();
1495 atk_obj = gtk_widget_get_accessible (button_data->button);
1496 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1498 switch (button_data->type)
1501 button_data->image = gtk_image_new ();
1502 child = button_data->image;
1503 button_data->label = NULL;
1504 atk_object_set_name (atk_obj, _("File System Root"));
1507 case DESKTOP_BUTTON:
1508 button_data->image = gtk_image_new ();
1509 button_data->label = gtk_label_new (NULL);
1510 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1511 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1512 child = gtk_hbox_new (FALSE, 2);
1513 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1514 gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
1518 button_data->label = gtk_label_new (NULL);
1519 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1520 label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
1521 gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
1522 child = label_alignment;
1523 button_data->image = NULL;
1526 /* label_alignment is created because we can't override size-request
1527 * on label itself and still have the contents of the label centered
1528 * properly in the label's requisition
1530 if (label_alignment)
1531 g_signal_connect (label_alignment, "size-request",
1532 G_CALLBACK (label_size_request_cb), button_data);
1534 button_data->dir_name = g_strdup (dir_name);
1535 button_data->file = g_object_ref (file);
1536 button_data->file_is_hidden = file_is_hidden;
1538 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1539 gtk_widget_show_all (button_data->button);
1541 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1543 g_signal_connect (button_data->button, "clicked",
1544 G_CALLBACK (button_clicked_cb),
1546 g_object_weak_ref (G_OBJECT (button_data->button),
1547 (GWeakNotify) button_data_free, button_data);
1549 gtk_drag_source_set (button_data->button,
1553 gtk_drag_source_add_uri_targets (button_data->button);
1554 g_signal_connect (button_data->button, "drag-data-get",
1555 G_CALLBACK (button_drag_data_get_cb), button_data);
1561 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1563 GtkFileSystem *file_system)
1566 GList *current_path = NULL;
1567 gboolean need_new_fake_root = FALSE;
1569 for (list = path_bar->button_list; list; list = list->next)
1571 ButtonData *button_data;
1573 button_data = list->data;
1574 if (g_file_equal (file, button_data->file))
1576 current_path = list;
1579 if (list == path_bar->fake_root)
1580 need_new_fake_root = TRUE;
1585 if (need_new_fake_root)
1587 path_bar->fake_root = NULL;
1588 for (list = current_path; list; list = list->next)
1590 ButtonData *button_data;
1592 button_data = list->data;
1593 if (BUTTON_IS_FAKE_ROOT (button_data))
1595 path_bar->fake_root = list;
1601 for (list = path_bar->button_list; list; list = list->next)
1603 gtk_path_bar_update_button_appearance (path_bar,
1604 BUTTON_DATA (list->data),
1605 (list == current_path) ? TRUE : FALSE);
1608 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1610 path_bar->first_scrolled_button = current_path;
1611 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1624 GtkPathBar *path_bar;
1627 gboolean first_directory;
1631 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1638 gtk_path_bar_clear_buttons (info->path_bar);
1639 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1640 info->path_bar->fake_root = info->fake_root;
1642 for (l = info->path_bar->button_list; l; l = l->next)
1644 GtkWidget *button = BUTTON_DATA (l->data)->button;
1645 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1652 for (l = info->new_buttons; l; l = l->next)
1654 ButtonData *button_data;
1656 button_data = BUTTON_DATA (l->data);
1657 gtk_widget_destroy (button_data->button);
1660 g_list_free (info->new_buttons);
1664 g_object_unref (info->file);
1665 if (info->parent_file)
1666 g_object_unref (info->parent_file);
1671 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1673 const GError *error,
1676 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1677 struct SetFileInfo *file_info = data;
1678 ButtonData *button_data;
1679 const gchar *display_name;
1682 if (cancellable != file_info->path_bar->get_info_cancellable)
1684 gtk_path_bar_set_file_finish (file_info, FALSE);
1685 g_object_unref (cancellable);
1689 g_object_unref (cancellable);
1690 file_info->path_bar->get_info_cancellable = NULL;
1692 if (cancelled || !info)
1694 gtk_path_bar_set_file_finish (file_info, FALSE);
1698 display_name = g_file_info_get_display_name (info);
1699 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1701 gtk_widget_push_composite_child ();
1702 button_data = make_directory_button (file_info->path_bar, display_name,
1704 file_info->first_directory, is_hidden);
1705 gtk_widget_pop_composite_child ();
1706 g_object_unref (file_info->file);
1708 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1710 if (BUTTON_IS_FAKE_ROOT (button_data))
1711 file_info->fake_root = file_info->new_buttons;
1713 file_info->file = file_info->parent_file;
1714 file_info->first_directory = FALSE;
1716 if (!file_info->file)
1718 gtk_path_bar_set_file_finish (file_info, TRUE);
1722 file_info->parent_file = g_file_get_parent (file_info->file);
1724 file_info->path_bar->get_info_cancellable =
1725 _gtk_file_system_get_info (file_info->path_bar->file_system,
1727 "standard::display-name,standard::is-hidden,standard::is-backup",
1728 gtk_path_bar_get_info_callback,
1733 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1735 const gboolean keep_trail,
1738 struct SetFileInfo *info;
1741 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
1742 g_return_val_if_fail (G_IS_FILE (file), FALSE);
1746 /* Check whether the new path is already present in the pathbar as buttons.
1747 * This could be a parent directory or a previous selected subdirectory.
1750 gtk_path_bar_check_parent_path (path_bar, file, path_bar->file_system))
1753 info = g_new0 (struct SetFileInfo, 1);
1754 info->file = g_object_ref (file);
1755 info->path_bar = path_bar;
1756 info->first_directory = TRUE;
1757 info->parent_file = g_file_get_parent (info->file);
1759 if (path_bar->get_info_cancellable)
1760 g_cancellable_cancel (path_bar->get_info_cancellable);
1762 path_bar->get_info_cancellable =
1763 _gtk_file_system_get_info (path_bar->file_system,
1765 "standard::display-name,standard::is-hidden,standard::is-backup",
1766 gtk_path_bar_get_info_callback,
1772 /* FIXME: This should be a construct-only property */
1774 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1775 GtkFileSystem *file_system)
1779 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1781 g_assert (path_bar->file_system == NULL);
1783 path_bar->file_system = g_object_ref (file_system);
1785 home = g_get_home_dir ();
1788 const gchar *desktop;
1790 path_bar->home_file = g_file_new_for_path (home);
1791 /* FIXME: Need file system backend specific way of getting the
1794 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1795 if (desktop != NULL)
1796 path_bar->desktop_file = g_file_new_for_path (desktop);
1798 path_bar->desktop_file = NULL;
1802 path_bar->home_file = NULL;
1803 path_bar->desktop_file = NULL;
1805 path_bar->root_file = g_file_new_for_path ("/");
1810 * @path_bar: a #GtkPathBar
1812 * If the selected button in the pathbar is not the furthest button "up" (in the
1813 * root direction), act as if the user clicked on the next button up.
1816 _gtk_path_bar_up (GtkPathBar *path_bar)
1820 for (l = path_bar->button_list; l; l = l->next)
1822 GtkWidget *button = BUTTON_DATA (l->data)->button;
1823 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1827 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1828 button_clicked_cb (next_button, l->next->data);
1836 * _gtk_path_bar_down:
1837 * @path_bar: a #GtkPathBar
1839 * If the selected button in the pathbar is not the furthest button "down" (in the
1840 * leaf direction), act as if the user clicked on the next button down.
1843 _gtk_path_bar_down (GtkPathBar *path_bar)
1847 for (l = path_bar->button_list; l; l = l->next)
1849 GtkWidget *button = BUTTON_DATA (l->data)->button;
1850 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1854 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1855 button_clicked_cb (prev_button, l->prev->data);