1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
3 * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 #include "gtkpathbar.h"
25 #include "gtktogglebutton.h"
30 #include "gtkicontheme.h"
31 #include "gtkiconfactory.h"
35 #include "gtkmarshalers.h"
50 #define BUTTON_DATA(x) ((ButtonData *)(x))
52 #define SCROLL_DELAY_FACTOR 5
54 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
56 /* Icon size for if we can't get it from the theme */
57 #define FALLBACK_ICON_SIZE 16
59 typedef struct _ButtonData ButtonData;
69 GCancellable *cancellable;
70 guint ignore_changes : 1;
71 guint file_is_hidden : 1;
73 /* This macro is used to check if a button can be used as a fake root.
74 * All buttons in front of a fake root are automatically hidden when in a
75 * directory below a fake root and replaced with the "<" arrow button.
77 #define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
79 G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
81 static void gtk_path_bar_finalize (GObject *object);
82 static void gtk_path_bar_dispose (GObject *object);
83 static void gtk_path_bar_realize (GtkWidget *widget);
84 static void gtk_path_bar_unrealize (GtkWidget *widget);
85 static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
88 static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
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 GtkWidgetPath *gtk_path_bar_get_path_for_child (GtkContainer *container,
105 static gboolean gtk_path_bar_scroll (GtkWidget *widget,
106 GdkEventScroll *event);
107 static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
108 static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
109 static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
110 static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
111 GdkEventButton *event,
112 GtkPathBar *path_bar);
113 static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
114 GdkEventButton *event,
115 GtkPathBar *path_bar);
116 static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
117 GdkEventButton *event,
118 GtkPathBar *path_bar);
119 static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
120 GdkEventButton *event,
121 GtkPathBar *path_bar);
122 static void gtk_path_bar_grab_notify (GtkWidget *widget,
123 gboolean was_grabbed);
124 static void gtk_path_bar_state_changed (GtkWidget *widget,
125 GtkStateType previous_state);
126 static void gtk_path_bar_style_updated (GtkWidget *widget);
127 static void gtk_path_bar_screen_changed (GtkWidget *widget,
128 GdkScreen *previous_screen);
129 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
130 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
131 ButtonData *button_data,
132 gboolean current_dir);
135 on_slider_unmap (GtkWidget *widget,
136 GtkPathBar *path_bar)
138 if (path_bar->timer &&
139 ((widget == path_bar->up_slider_button && path_bar->scrolling_up) ||
140 (widget == path_bar->down_slider_button && path_bar->scrolling_down)))
141 gtk_path_bar_stop_scrolling (path_bar);
145 get_slider_button (GtkPathBar *path_bar,
146 GtkArrowType arrow_type)
151 gtk_widget_push_composite_child ();
153 button = gtk_button_new ();
154 atk_obj = gtk_widget_get_accessible (button);
155 if (arrow_type == GTK_ARROW_LEFT)
156 atk_object_set_name (atk_obj, _("Up Path"));
158 atk_object_set_name (atk_obj, _("Down Path"));
160 gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
161 gtk_widget_add_events (button, GDK_SCROLL_MASK);
162 gtk_container_add (GTK_CONTAINER (button),
163 gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
164 gtk_container_add (GTK_CONTAINER (path_bar), button);
165 gtk_widget_show_all (button);
167 g_signal_connect (G_OBJECT (button), "unmap",
168 G_CALLBACK (on_slider_unmap), path_bar);
170 gtk_widget_pop_composite_child ();
176 gtk_path_bar_init (GtkPathBar *path_bar)
178 GtkStyleContext *context;
180 gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
181 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
183 path_bar->get_info_cancellable = NULL;
185 path_bar->spacing = 0;
186 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
187 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
188 path_bar->icon_size = FALLBACK_ICON_SIZE;
190 g_signal_connect_swapped (path_bar->up_slider_button, "clicked",
191 G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
192 g_signal_connect_swapped (path_bar->down_slider_button, "clicked",
193 G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
195 g_signal_connect (path_bar->up_slider_button, "focus-out-event",
196 G_CALLBACK (gtk_path_bar_slider_up_defocus), path_bar);
197 g_signal_connect (path_bar->down_slider_button, "focus-out-event",
198 G_CALLBACK (gtk_path_bar_slider_down_defocus), path_bar);
200 g_signal_connect (path_bar->up_slider_button, "button-press-event",
201 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
202 g_signal_connect (path_bar->up_slider_button, "button-release-event",
203 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
204 g_signal_connect (path_bar->down_slider_button, "button-press-event",
205 G_CALLBACK (gtk_path_bar_slider_button_press), path_bar);
206 g_signal_connect (path_bar->down_slider_button, "button-release-event",
207 G_CALLBACK (gtk_path_bar_slider_button_release), path_bar);
209 context = gtk_widget_get_style_context (GTK_WIDGET (path_bar));
210 gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
214 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
216 GObjectClass *gobject_class;
217 GtkWidgetClass *widget_class;
218 GtkContainerClass *container_class;
220 gobject_class = (GObjectClass *) path_bar_class;
221 widget_class = (GtkWidgetClass *) path_bar_class;
222 container_class = (GtkContainerClass *) path_bar_class;
224 gobject_class->finalize = gtk_path_bar_finalize;
225 gobject_class->dispose = gtk_path_bar_dispose;
227 widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
228 widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
229 widget_class->realize = gtk_path_bar_realize;
230 widget_class->unrealize = gtk_path_bar_unrealize;
231 widget_class->map = gtk_path_bar_map;
232 widget_class->unmap = gtk_path_bar_unmap;
233 widget_class->size_allocate = gtk_path_bar_size_allocate;
234 widget_class->style_updated = gtk_path_bar_style_updated;
235 widget_class->screen_changed = gtk_path_bar_screen_changed;
236 widget_class->grab_notify = gtk_path_bar_grab_notify;
237 widget_class->state_changed = gtk_path_bar_state_changed;
238 widget_class->scroll_event = gtk_path_bar_scroll;
240 container_class->add = gtk_path_bar_add;
241 container_class->forall = gtk_path_bar_forall;
242 container_class->remove = gtk_path_bar_remove;
243 container_class->get_path_for_child = gtk_path_bar_get_path_for_child;
244 gtk_container_class_handle_border_width (container_class);
246 /* container_class->child_type = gtk_path_bar_child_type;*/
248 path_bar_signals [PATH_CLICKED] =
249 g_signal_new (I_("path-clicked"),
250 G_OBJECT_CLASS_TYPE (gobject_class),
252 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
254 _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
263 gtk_path_bar_finalize (GObject *object)
265 GtkPathBar *path_bar;
267 path_bar = GTK_PATH_BAR (object);
269 gtk_path_bar_stop_scrolling (path_bar);
271 g_list_free (path_bar->button_list);
272 if (path_bar->root_file)
273 g_object_unref (path_bar->root_file);
274 if (path_bar->home_file)
275 g_object_unref (path_bar->home_file);
276 if (path_bar->desktop_file)
277 g_object_unref (path_bar->desktop_file);
279 if (path_bar->root_icon)
280 g_object_unref (path_bar->root_icon);
281 if (path_bar->home_icon)
282 g_object_unref (path_bar->home_icon);
283 if (path_bar->desktop_icon)
284 g_object_unref (path_bar->desktop_icon);
286 if (path_bar->file_system)
287 g_object_unref (path_bar->file_system);
289 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
292 /* Removes the settings signal handler. It's safe to call multiple times */
294 remove_settings_signal (GtkPathBar *path_bar,
297 if (path_bar->settings_signal_id)
299 GtkSettings *settings;
301 settings = gtk_settings_get_for_screen (screen);
302 g_signal_handler_disconnect (settings,
303 path_bar->settings_signal_id);
304 path_bar->settings_signal_id = 0;
309 gtk_path_bar_dispose (GObject *object)
311 GtkPathBar *path_bar = GTK_PATH_BAR (object);
313 remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
315 if (path_bar->get_info_cancellable)
316 g_cancellable_cancel (path_bar->get_info_cancellable);
317 path_bar->get_info_cancellable = NULL;
319 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
324 * Ideally, our size is determined by another widget, and we are just filling
328 gtk_path_bar_get_preferred_width (GtkWidget *widget,
332 ButtonData *button_data;
333 GtkPathBar *path_bar;
337 gint child_min, child_nat;
339 path_bar = GTK_PATH_BAR (widget);
341 *minimum = *natural = 0;
344 for (list = path_bar->button_list; list; list = list->next)
346 button_data = BUTTON_DATA (list->data);
347 gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
348 gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
349 height = MAX (height, child_height);
351 if (button_data->type == NORMAL_BUTTON)
353 /* Use 2*Height as button width because of ellipsized label. */
354 child_min = MAX (child_min, child_height * 2);
355 child_nat = MAX (child_min, child_height * 2);
358 *minimum = MAX (*minimum, child_min);
359 *natural = MAX (*natural, child_nat);
362 /* Add space for slider, if we have more than one path */
363 /* Theoretically, the slider could be bigger than the other button. But we're
364 * not going to worry about that now.
366 path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
367 if (path_bar->button_list && path_bar->button_list->next != NULL)
369 *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
370 *natural += (path_bar->spacing + path_bar->slider_width) * 2;
375 gtk_path_bar_get_preferred_height (GtkWidget *widget,
379 ButtonData *button_data;
380 GtkPathBar *path_bar;
382 gint child_min, child_nat;
384 path_bar = GTK_PATH_BAR (widget);
386 *minimum = *natural = 0;
388 for (list = path_bar->button_list; list; list = list->next)
390 button_data = BUTTON_DATA (list->data);
391 gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
393 *minimum = MAX (*minimum, child_min);
394 *natural = MAX (*natural, child_nat);
399 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
401 if (path_bar->button_list)
405 button = BUTTON_DATA (path_bar->button_list->data)->button;
406 if (gtk_widget_get_child_visible (button))
408 gtk_path_bar_stop_scrolling (path_bar);
409 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
412 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
414 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
415 if (gtk_widget_get_child_visible (button))
417 gtk_path_bar_stop_scrolling (path_bar);
418 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
421 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
426 gtk_path_bar_map (GtkWidget *widget)
428 gdk_window_show (GTK_PATH_BAR (widget)->event_window);
430 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
434 gtk_path_bar_unmap (GtkWidget *widget)
436 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
437 gdk_window_hide (GTK_PATH_BAR (widget)->event_window);
439 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
443 gtk_path_bar_realize (GtkWidget *widget)
445 GtkPathBar *path_bar;
446 GtkAllocation allocation;
448 GdkWindowAttr attributes;
449 gint attributes_mask;
451 gtk_widget_set_realized (widget, TRUE);
453 path_bar = GTK_PATH_BAR (widget);
454 window = gtk_widget_get_parent_window (widget);
455 gtk_widget_set_window (widget, window);
456 g_object_ref (window);
458 gtk_widget_get_allocation (widget, &allocation);
460 attributes.window_type = GDK_WINDOW_CHILD;
461 attributes.x = allocation.x;
462 attributes.y = allocation.y;
463 attributes.width = allocation.width;
464 attributes.height = allocation.height;
465 attributes.wclass = GDK_INPUT_ONLY;
466 attributes.event_mask = gtk_widget_get_events (widget);
467 attributes.event_mask |= GDK_SCROLL_MASK;
468 attributes_mask = GDK_WA_X | GDK_WA_Y;
470 path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
471 &attributes, attributes_mask);
472 gdk_window_set_user_data (path_bar->event_window, widget);
476 gtk_path_bar_unrealize (GtkWidget *widget)
478 GtkPathBar *path_bar;
480 path_bar = GTK_PATH_BAR (widget);
482 gdk_window_set_user_data (path_bar->event_window, NULL);
483 gdk_window_destroy (path_bar->event_window);
484 path_bar->event_window = NULL;
486 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
490 child_ordering_changed (GtkPathBar *path_bar)
494 if (path_bar->up_slider_button)
495 gtk_widget_reset_style (path_bar->up_slider_button);
496 if (path_bar->down_slider_button)
497 gtk_widget_reset_style (path_bar->down_slider_button);
499 for (l = path_bar->button_list; l; l = l->next)
501 ButtonData *data = l->data;
503 gtk_widget_reset_style (data->button);
507 /* This is a tad complicated
510 gtk_path_bar_size_allocate (GtkWidget *widget,
511 GtkAllocation *allocation)
514 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
515 GtkTextDirection direction;
516 GtkAllocation child_allocation;
517 GList *list, *first_button;
519 gint allocation_width;
520 gboolean need_sliders = FALSE;
521 gint up_slider_offset = 0;
522 GtkRequisition child_requisition;
524 gtk_widget_set_allocation (widget, allocation);
526 if (gtk_widget_get_realized (widget))
527 gdk_window_move_resize (path_bar->event_window,
528 allocation->x, allocation->y,
529 allocation->width, allocation->height);
531 /* No path is set; we don't have to allocate anything. */
532 if (path_bar->button_list == NULL)
535 direction = gtk_widget_get_direction (widget);
536 allocation_width = allocation->width;
538 /* First, we check to see if we need the scrollbars. */
539 if (path_bar->fake_root)
540 width = path_bar->spacing + path_bar->slider_width;
544 for (list = path_bar->button_list; list; list = list->next)
546 child = BUTTON_DATA (list->data)->button;
548 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
550 width += child_requisition.width + path_bar->spacing;
551 if (list == path_bar->fake_root)
555 if (width <= allocation_width)
557 if (path_bar->fake_root)
558 first_button = path_bar->fake_root;
560 first_button = g_list_last (path_bar->button_list);
564 gboolean reached_end = FALSE;
565 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
567 if (path_bar->first_scrolled_button)
568 first_button = path_bar->first_scrolled_button;
570 first_button = path_bar->button_list;
573 /* To see how much space we have, and how many buttons we can display.
574 * We start at the first button, count forward until hit the new
575 * button, then count backwards.
577 /* Count down the path chain towards the end. */
578 gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
579 &child_requisition, NULL);
581 width = child_requisition.width;
582 list = first_button->prev;
583 while (list && !reached_end)
585 child = BUTTON_DATA (list->data)->button;
587 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
589 if (width + child_requisition.width +
590 path_bar->spacing + slider_space > allocation_width)
592 else if (list == path_bar->fake_root)
595 width += child_requisition.width + path_bar->spacing;
600 /* Finally, we walk up, seeing how many of the previous buttons we can
602 while (first_button->next && !reached_end)
604 child = BUTTON_DATA (first_button->next->data)->button;
606 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
608 if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
614 width += child_requisition.width + path_bar->spacing;
615 if (first_button == path_bar->fake_root)
617 first_button = first_button->next;
622 /* Now, we allocate space to the buttons */
623 child_allocation.y = allocation->y;
624 child_allocation.height = allocation->height;
626 if (direction == GTK_TEXT_DIR_RTL)
628 child_allocation.x = allocation->x + allocation->width;
629 if (need_sliders || path_bar->fake_root)
631 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
632 up_slider_offset = allocation->width - path_bar->slider_width;
637 child_allocation.x = allocation->x;
638 if (need_sliders || path_bar->fake_root)
640 up_slider_offset = 0;
641 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
645 for (list = first_button; list; list = list->prev)
647 GtkAllocation widget_allocation;
648 ButtonData *button_data;
650 button_data = BUTTON_DATA (list->data);
651 child = button_data->button;
653 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
655 child_allocation.width = MIN (child_requisition.width,
656 allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
658 if (direction == GTK_TEXT_DIR_RTL)
659 child_allocation.x -= child_allocation.width;
661 /* Check to see if we've don't have any more space to allocate buttons */
662 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
664 gtk_widget_get_allocation (widget, &widget_allocation);
665 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
668 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
670 gtk_widget_get_allocation (widget, &widget_allocation);
671 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
672 widget_allocation.x + allocation_width)
676 if (child_allocation.width < child_requisition.width)
678 if (!gtk_widget_get_has_tooltip (child))
679 gtk_widget_set_tooltip_text (child, button_data->dir_name);
681 else if (gtk_widget_get_has_tooltip (child))
682 gtk_widget_set_tooltip_text (child, NULL);
684 gtk_widget_set_child_visible (child, TRUE);
685 gtk_widget_size_allocate (child, &child_allocation);
687 if (direction == GTK_TEXT_DIR_RTL)
688 child_allocation.x -= path_bar->spacing;
690 child_allocation.x += child_allocation.width + path_bar->spacing;
692 /* Now we go hide all the widgets that don't fit */
695 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
698 for (list = first_button->next; list; list = list->next)
700 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
703 if (need_sliders || path_bar->fake_root)
705 child_allocation.width = path_bar->slider_width;
706 child_allocation.x = up_slider_offset + allocation->x;
707 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
709 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
710 gtk_widget_show_all (path_bar->up_slider_button);
713 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
717 child_allocation.width = path_bar->slider_width;
719 if (direction == GTK_TEXT_DIR_RTL)
720 child_allocation.x = 0;
722 child_allocation.x = allocation->width - path_bar->slider_width;
724 child_allocation.x += allocation->x;
726 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
728 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
729 gtk_widget_show_all (path_bar->down_slider_button);
730 gtk_path_bar_update_slider_buttons (path_bar);
733 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
735 child_ordering_changed (path_bar);
739 gtk_path_bar_style_updated (GtkWidget *widget)
741 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
743 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
747 gtk_path_bar_screen_changed (GtkWidget *widget,
748 GdkScreen *previous_screen)
750 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
751 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
753 /* We might nave a new settings, so we remove the old one */
755 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
757 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
761 gtk_path_bar_scroll (GtkWidget *widget,
762 GdkEventScroll *event)
764 switch (event->direction)
766 case GDK_SCROLL_RIGHT:
767 case GDK_SCROLL_DOWN:
768 gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
770 case GDK_SCROLL_LEFT:
772 gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
774 case GDK_SCROLL_SMOOTH:
782 gtk_path_bar_add (GtkContainer *container,
786 gtk_widget_set_parent (widget, GTK_WIDGET (container));
790 gtk_path_bar_remove_1 (GtkContainer *container,
793 gboolean was_visible = gtk_widget_get_visible (widget);
794 gtk_widget_unparent (widget);
796 gtk_widget_queue_resize (GTK_WIDGET (container));
800 gtk_path_bar_remove (GtkContainer *container,
803 GtkPathBar *path_bar;
806 path_bar = GTK_PATH_BAR (container);
808 if (widget == path_bar->up_slider_button)
810 gtk_path_bar_remove_1 (container, widget);
811 path_bar->up_slider_button = NULL;
815 if (widget == path_bar->down_slider_button)
817 gtk_path_bar_remove_1 (container, widget);
818 path_bar->down_slider_button = NULL;
822 children = path_bar->button_list;
825 if (widget == BUTTON_DATA (children->data)->button)
827 gtk_path_bar_remove_1 (container, widget);
828 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
829 g_list_free (children);
833 children = children->next;
838 gtk_path_bar_forall (GtkContainer *container,
839 gboolean include_internals,
840 GtkCallback callback,
841 gpointer callback_data)
843 GtkPathBar *path_bar;
846 g_return_if_fail (callback != NULL);
847 path_bar = GTK_PATH_BAR (container);
849 children = path_bar->button_list;
853 child = BUTTON_DATA (children->data)->button;
854 children = children->next;
856 (* callback) (child, callback_data);
859 if (path_bar->up_slider_button)
860 (* callback) (path_bar->up_slider_button, callback_data);
862 if (path_bar->down_slider_button)
863 (* callback) (path_bar->down_slider_button, callback_data);
866 static GtkWidgetPath *
867 gtk_path_bar_get_path_for_child (GtkContainer *container,
870 GtkPathBar *path_bar = GTK_PATH_BAR (container);
873 path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
875 if (gtk_widget_get_visible (child) &&
876 gtk_widget_get_child_visible (child))
878 GtkWidgetPath *sibling_path;
879 GList *visible_children;
883 /* 1. Build the list of visible children, in visually left-to-right order
884 * (i.e. independently of the widget's direction). Note that our
885 * button_list is stored in innermost-to-outermost path order!
888 visible_children = NULL;
890 if (gtk_widget_get_visible (path_bar->down_slider_button) &&
891 gtk_widget_get_child_visible (path_bar->down_slider_button))
892 visible_children = g_list_prepend (visible_children, path_bar->down_slider_button);
894 for (l = path_bar->button_list; l; l = l->next)
896 ButtonData *data = l->data;
898 if (gtk_widget_get_visible (data->button) &&
899 gtk_widget_get_child_visible (data->button))
900 visible_children = g_list_prepend (visible_children, data->button);
903 if (gtk_widget_get_visible (path_bar->up_slider_button) &&
904 gtk_widget_get_child_visible (path_bar->up_slider_button))
905 visible_children = g_list_prepend (visible_children, path_bar->up_slider_button);
907 if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
908 visible_children = g_list_reverse (visible_children);
910 /* 2. Find the index of the child within that list */
914 for (l = visible_children; l; l = l->next)
916 GtkWidget *button = l->data;
924 /* 3. Build the path */
926 sibling_path = gtk_widget_path_new ();
928 for (l = visible_children; l; l = l->next)
929 gtk_widget_path_append_for_widget (sibling_path, l->data);
931 gtk_widget_path_append_with_siblings (path, sibling_path, pos);
933 g_list_free (visible_children);
934 gtk_widget_path_unref (sibling_path);
937 gtk_widget_path_append_for_widget (path, child);
943 gtk_path_bar_scroll_down (GtkPathBar *path_bar)
945 GtkAllocation allocation, button_allocation;
947 GList *down_button = NULL;
948 gint space_available;
950 if (path_bar->ignore_click)
952 path_bar->ignore_click = FALSE;
956 if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->button_list->data)->button))
958 /* Return if the last button is already visible */
962 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
964 /* We find the button at the 'down' end that we have to make
966 for (list = path_bar->button_list; list; list = list->next)
968 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
975 gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
976 gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
978 space_available = (allocation.width
979 - 2 * path_bar->spacing - 2 * path_bar->slider_width
980 - button_allocation.width);
981 path_bar->first_scrolled_button = down_button;
983 /* We have space_available free space that's not being used.
984 * So we walk down from the end, adding buttons until we use all free space.
986 while (space_available > 0)
988 path_bar->first_scrolled_button = down_button;
989 down_button = down_button->next;
992 space_available -= (button_allocation.width
993 + path_bar->spacing);
998 gtk_path_bar_scroll_up (GtkPathBar *path_bar)
1002 if (path_bar->ignore_click)
1004 path_bar->ignore_click = FALSE;
1008 list = g_list_last (path_bar->button_list);
1010 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1012 /* Return if the first button is already visible */
1016 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1018 for ( ; list; list = list->prev)
1020 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
1022 if (list->prev == path_bar->fake_root)
1023 path_bar->fake_root = NULL;
1024 path_bar->first_scrolled_button = list;
1031 gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
1033 gboolean retval = FALSE;
1035 if (path_bar->timer)
1037 if (path_bar->scrolling_up)
1038 gtk_path_bar_scroll_up (path_bar);
1039 else if (path_bar->scrolling_down)
1040 gtk_path_bar_scroll_down (path_bar);
1042 if (path_bar->need_timer)
1044 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (path_bar));
1047 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
1049 path_bar->need_timer = FALSE;
1051 path_bar->timer = gdk_threads_add_timeout (timeout * SCROLL_DELAY_FACTOR,
1052 (GSourceFunc)gtk_path_bar_scroll_timeout,
1063 gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
1065 if (path_bar->timer)
1067 g_source_remove (path_bar->timer);
1068 path_bar->timer = 0;
1069 path_bar->need_timer = FALSE;
1074 gtk_path_bar_slider_up_defocus (GtkWidget *widget,
1075 GdkEventButton *event,
1076 GtkPathBar *path_bar)
1079 GList *up_button = NULL;
1081 if (event->type != GDK_FOCUS_CHANGE)
1084 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
1086 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1093 /* don't let the focus vanish */
1094 if ((!gtk_widget_is_sensitive (path_bar->up_slider_button)) ||
1095 (!gtk_widget_get_child_visible (path_bar->up_slider_button)))
1096 gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
1102 gtk_path_bar_slider_down_defocus (GtkWidget *widget,
1103 GdkEventButton *event,
1104 GtkPathBar *path_bar)
1107 GList *down_button = NULL;
1109 if (event->type != GDK_FOCUS_CHANGE)
1112 for (list = path_bar->button_list; list; list = list->next)
1114 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
1121 /* don't let the focus vanish */
1122 if ((!gtk_widget_is_sensitive (path_bar->down_slider_button)) ||
1123 (!gtk_widget_get_child_visible (path_bar->down_slider_button)))
1124 gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
1130 gtk_path_bar_slider_button_press (GtkWidget *widget,
1131 GdkEventButton *event,
1132 GtkPathBar *path_bar)
1134 if (event->type != GDK_BUTTON_PRESS || event->button != GDK_BUTTON_PRIMARY)
1137 path_bar->ignore_click = FALSE;
1139 if (widget == path_bar->up_slider_button)
1141 path_bar->scrolling_down = FALSE;
1142 path_bar->scrolling_up = TRUE;
1143 gtk_path_bar_scroll_up (path_bar);
1145 else if (widget == path_bar->down_slider_button)
1147 path_bar->scrolling_up = FALSE;
1148 path_bar->scrolling_down = TRUE;
1149 gtk_path_bar_scroll_down (path_bar);
1152 if (!path_bar->timer)
1154 GtkSettings *settings = gtk_widget_get_settings (widget);
1157 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
1159 path_bar->need_timer = TRUE;
1160 path_bar->timer = gdk_threads_add_timeout (timeout,
1161 (GSourceFunc)gtk_path_bar_scroll_timeout,
1169 gtk_path_bar_slider_button_release (GtkWidget *widget,
1170 GdkEventButton *event,
1171 GtkPathBar *path_bar)
1173 if (event->type != GDK_BUTTON_RELEASE)
1176 path_bar->ignore_click = TRUE;
1177 gtk_path_bar_stop_scrolling (path_bar);
1183 gtk_path_bar_grab_notify (GtkWidget *widget,
1184 gboolean was_grabbed)
1187 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1191 gtk_path_bar_state_changed (GtkWidget *widget,
1192 GtkStateType previous_state)
1194 if (!gtk_widget_is_sensitive (widget))
1195 gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
1199 /* Changes the icons wherever it is needed */
1201 reload_icons (GtkPathBar *path_bar)
1205 if (path_bar->root_icon)
1207 g_object_unref (path_bar->root_icon);
1208 path_bar->root_icon = NULL;
1210 if (path_bar->home_icon)
1212 g_object_unref (path_bar->home_icon);
1213 path_bar->home_icon = NULL;
1215 if (path_bar->desktop_icon)
1217 g_object_unref (path_bar->desktop_icon);
1218 path_bar->desktop_icon = NULL;
1221 for (list = path_bar->button_list; list; list = list->next)
1223 ButtonData *button_data;
1224 gboolean current_dir;
1226 button_data = BUTTON_DATA (list->data);
1227 if (button_data->type != NORMAL_BUTTON)
1229 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
1230 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1237 change_icon_theme (GtkPathBar *path_bar)
1239 GtkSettings *settings;
1242 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1244 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
1245 path_bar->icon_size = MAX (width, height);
1247 path_bar->icon_size = FALLBACK_ICON_SIZE;
1249 reload_icons (path_bar);
1251 /* Callback used when a GtkSettings value changes */
1253 settings_notify_cb (GObject *object,
1255 GtkPathBar *path_bar)
1259 name = g_param_spec_get_name (pspec);
1261 if (! strcmp (name, "gtk-icon-theme-name") ||
1262 ! strcmp (name, "gtk-icon-sizes"))
1263 change_icon_theme (path_bar);
1267 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
1269 GtkSettings *settings;
1271 if (path_bar->settings_signal_id)
1274 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
1275 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
1277 change_icon_theme (path_bar);
1280 /* Public functions and their helpers */
1282 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
1284 while (path_bar->button_list != NULL)
1286 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
1288 path_bar->first_scrolled_button = NULL;
1289 path_bar->fake_root = NULL;
1293 button_clicked_cb (GtkWidget *button,
1296 ButtonData *button_data;
1297 GtkPathBar *path_bar;
1299 gboolean child_is_hidden;
1302 button_data = BUTTON_DATA (data);
1303 if (button_data->ignore_changes)
1306 path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
1308 button_list = g_list_find (path_bar->button_list, button_data);
1309 g_assert (button_list != NULL);
1311 g_signal_handlers_block_by_func (button,
1312 G_CALLBACK (button_clicked_cb), data);
1313 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
1314 g_signal_handlers_unblock_by_func (button,
1315 G_CALLBACK (button_clicked_cb), data);
1317 if (button_list->prev)
1319 ButtonData *child_data;
1321 child_data = BUTTON_DATA (button_list->prev->data);
1322 child_file = child_data->file;
1323 child_is_hidden = child_data->file_is_hidden;
1328 child_is_hidden = FALSE;
1331 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
1332 button_data->file, child_file, child_is_hidden);
1335 struct SetButtonImageData
1337 GtkPathBar *path_bar;
1338 ButtonData *button_data;
1342 set_button_image_get_info_cb (GCancellable *cancellable,
1344 const GError *error,
1347 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1349 struct SetButtonImageData *data = user_data;
1351 if (cancellable != data->button_data->cancellable)
1354 data->button_data->cancellable = NULL;
1356 if (!data->button_data->button)
1358 g_free (data->button_data);
1362 if (cancelled || error)
1365 pixbuf = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
1366 data->path_bar->icon_size);
1367 gtk_image_set_from_pixbuf (GTK_IMAGE (data->button_data->image), pixbuf);
1369 switch (data->button_data->type)
1372 if (data->path_bar->home_icon)
1373 g_object_unref (pixbuf);
1375 data->path_bar->home_icon = pixbuf;
1378 case DESKTOP_BUTTON:
1379 if (data->path_bar->desktop_icon)
1380 g_object_unref (pixbuf);
1382 data->path_bar->desktop_icon = pixbuf;
1391 g_object_unref (cancellable);
1395 set_button_image (GtkPathBar *path_bar,
1396 ButtonData *button_data)
1398 GtkFileSystemVolume *volume;
1399 struct SetButtonImageData *data;
1401 switch (button_data->type)
1405 if (path_bar->root_icon != NULL)
1407 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1411 volume = _gtk_file_system_get_volume_for_file (path_bar->file_system, path_bar->root_file);
1415 path_bar->root_icon = _gtk_file_system_volume_render_icon (volume,
1416 GTK_WIDGET (path_bar),
1417 path_bar->icon_size,
1419 _gtk_file_system_volume_unref (volume);
1421 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->root_icon);
1425 if (path_bar->home_icon != NULL)
1427 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->home_icon);
1431 data = g_new0 (struct SetButtonImageData, 1);
1432 data->path_bar = path_bar;
1433 data->button_data = button_data;
1435 if (button_data->cancellable)
1436 g_cancellable_cancel (button_data->cancellable);
1438 button_data->cancellable =
1439 _gtk_file_system_get_info (path_bar->file_system,
1440 path_bar->home_file,
1442 set_button_image_get_info_cb,
1446 case DESKTOP_BUTTON:
1447 if (path_bar->desktop_icon != NULL)
1449 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
1453 data = g_new0 (struct SetButtonImageData, 1);
1454 data->path_bar = path_bar;
1455 data->button_data = button_data;
1457 if (button_data->cancellable)
1458 g_cancellable_cancel (button_data->cancellable);
1460 button_data->cancellable =
1461 _gtk_file_system_get_info (path_bar->file_system,
1462 path_bar->desktop_file,
1464 set_button_image_get_info_cb,
1473 button_data_free (ButtonData *button_data)
1475 if (button_data->file)
1476 g_object_unref (button_data->file);
1477 button_data->file = NULL;
1479 g_free (button_data->dir_name);
1480 button_data->dir_name = NULL;
1482 button_data->button = NULL;
1484 if (button_data->cancellable)
1485 g_cancellable_cancel (button_data->cancellable);
1487 g_free (button_data);
1491 get_dir_name (ButtonData *button_data)
1493 return button_data->dir_name;
1496 /* We always want to request the same size for the label, whether
1497 * or not the contents are bold
1500 set_label_size_request (GtkWidget *widget,
1501 ButtonData *button_data)
1503 const gchar *dir_name = get_dir_name (button_data);
1504 PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
1505 gint width, height, bold_width, bold_height;
1508 pango_layout_get_pixel_size (layout, &width, &height);
1510 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1511 pango_layout_set_markup (layout, markup, -1);
1514 pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
1516 gtk_widget_set_size_request (widget,
1517 MAX (width, bold_width),
1518 MAX (height, bold_height));
1519 g_object_unref (layout);
1523 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
1524 ButtonData *button_data,
1525 gboolean current_dir)
1527 const gchar *dir_name = get_dir_name (button_data);
1529 if (button_data->label != NULL)
1535 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
1536 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
1541 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
1545 if (button_data->image != NULL)
1547 set_button_image (path_bar, button_data);
1550 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
1552 button_data->ignore_changes = TRUE;
1553 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
1554 button_data->ignore_changes = FALSE;
1559 find_button_type (GtkPathBar *path_bar,
1562 if (path_bar->root_file != NULL &&
1563 g_file_equal (file, path_bar->root_file))
1565 if (path_bar->home_file != NULL &&
1566 g_file_equal (file, path_bar->home_file))
1568 if (path_bar->desktop_file != NULL &&
1569 g_file_equal (file, path_bar->desktop_file))
1570 return DESKTOP_BUTTON;
1572 return NORMAL_BUTTON;
1576 button_drag_data_get_cb (GtkWidget *widget,
1577 GdkDragContext *context,
1578 GtkSelectionData *selection_data,
1583 ButtonData *button_data;
1588 uris[0] = g_file_get_uri (button_data->file);
1591 gtk_selection_data_set_uris (selection_data, uris);
1597 make_directory_button (GtkPathBar *path_bar,
1598 const char *dir_name,
1600 gboolean current_dir,
1601 gboolean file_is_hidden)
1604 GtkWidget *child = NULL;
1605 ButtonData *button_data;
1607 file_is_hidden = !! file_is_hidden;
1608 /* Is it a special button? */
1609 button_data = g_new0 (ButtonData, 1);
1611 button_data->type = find_button_type (path_bar, file);
1612 button_data->button = gtk_toggle_button_new ();
1613 atk_obj = gtk_widget_get_accessible (button_data->button);
1614 gtk_button_set_focus_on_click (GTK_BUTTON (button_data->button), FALSE);
1615 gtk_widget_add_events (button_data->button, GDK_SCROLL_MASK);
1617 switch (button_data->type)
1620 button_data->image = gtk_image_new ();
1621 child = button_data->image;
1622 button_data->label = NULL;
1623 atk_object_set_name (atk_obj, _("File System Root"));
1626 case DESKTOP_BUTTON:
1627 button_data->image = gtk_image_new ();
1628 button_data->label = gtk_label_new (NULL);
1629 child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
1630 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
1631 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
1635 button_data->label = gtk_label_new (NULL);
1636 gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
1637 child = button_data->label;
1638 button_data->image = NULL;
1641 button_data->dir_name = g_strdup (dir_name);
1642 button_data->file = g_object_ref (file);
1643 button_data->file_is_hidden = file_is_hidden;
1646 * The following function ensures that the alignment will always
1647 * request the same size whether the button's text is bold or not.
1649 if (button_data->label)
1650 set_label_size_request (button_data->label, button_data);
1652 gtk_container_add (GTK_CONTAINER (button_data->button), child);
1653 gtk_widget_show_all (button_data->button);
1655 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
1657 g_signal_connect (button_data->button, "clicked",
1658 G_CALLBACK (button_clicked_cb),
1660 g_object_weak_ref (G_OBJECT (button_data->button),
1661 (GWeakNotify) button_data_free, button_data);
1663 gtk_drag_source_set (button_data->button,
1667 gtk_drag_source_add_uri_targets (button_data->button);
1668 g_signal_connect (button_data->button, "drag-data-get",
1669 G_CALLBACK (button_drag_data_get_cb), button_data);
1675 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
1679 GList *current_path = NULL;
1680 gboolean need_new_fake_root = FALSE;
1682 for (list = path_bar->button_list; list; list = list->next)
1684 ButtonData *button_data;
1686 button_data = list->data;
1687 if (g_file_equal (file, button_data->file))
1689 current_path = list;
1692 if (list == path_bar->fake_root)
1693 need_new_fake_root = TRUE;
1698 if (need_new_fake_root)
1700 path_bar->fake_root = NULL;
1701 for (list = current_path; list; list = list->next)
1703 ButtonData *button_data;
1705 button_data = list->data;
1706 if (BUTTON_IS_FAKE_ROOT (button_data))
1708 path_bar->fake_root = list;
1714 for (list = path_bar->button_list; list; list = list->next)
1716 gtk_path_bar_update_button_appearance (path_bar,
1717 BUTTON_DATA (list->data),
1718 (list == current_path) ? TRUE : FALSE);
1721 if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
1723 path_bar->first_scrolled_button = current_path;
1724 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
1737 GtkPathBar *path_bar;
1740 gboolean first_directory;
1744 gtk_path_bar_set_file_finish (struct SetFileInfo *info,
1751 gtk_path_bar_clear_buttons (info->path_bar);
1752 info->path_bar->button_list = g_list_reverse (info->new_buttons);
1753 info->path_bar->fake_root = info->fake_root;
1755 for (l = info->path_bar->button_list; l; l = l->next)
1757 GtkWidget *button = BUTTON_DATA (l->data)->button;
1758 gtk_container_add (GTK_CONTAINER (info->path_bar), button);
1761 child_ordering_changed (info->path_bar);
1767 for (l = info->new_buttons; l; l = l->next)
1769 ButtonData *button_data;
1771 button_data = BUTTON_DATA (l->data);
1772 gtk_widget_destroy (button_data->button);
1775 g_list_free (info->new_buttons);
1779 g_object_unref (info->file);
1780 if (info->parent_file)
1781 g_object_unref (info->parent_file);
1787 gtk_path_bar_get_info_callback (GCancellable *cancellable,
1789 const GError *error,
1792 gboolean cancelled = g_cancellable_is_cancelled (cancellable);
1793 struct SetFileInfo *file_info = data;
1794 ButtonData *button_data;
1795 const gchar *display_name;
1798 if (cancellable != file_info->path_bar->get_info_cancellable)
1800 gtk_path_bar_set_file_finish (file_info, FALSE);
1801 g_object_unref (cancellable);
1805 g_object_unref (cancellable);
1806 file_info->path_bar->get_info_cancellable = NULL;
1808 if (cancelled || !info)
1810 gtk_path_bar_set_file_finish (file_info, FALSE);
1814 display_name = g_file_info_get_display_name (info);
1815 is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
1817 gtk_widget_push_composite_child ();
1818 button_data = make_directory_button (file_info->path_bar, display_name,
1820 file_info->first_directory, is_hidden);
1821 gtk_widget_pop_composite_child ();
1822 g_object_unref (file_info->file);
1824 file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
1826 if (BUTTON_IS_FAKE_ROOT (button_data))
1827 file_info->fake_root = file_info->new_buttons;
1829 /* We have assigned the info for the innermost button, i.e. the deepest directory.
1830 * Now, go on to fetch the info for this directory's parent.
1833 file_info->file = file_info->parent_file;
1834 file_info->first_directory = FALSE;
1836 if (!file_info->file)
1838 /* No parent? Okay, we are done. */
1839 gtk_path_bar_set_file_finish (file_info, TRUE);
1843 file_info->parent_file = g_file_get_parent (file_info->file);
1845 /* Recurse asynchronously */
1846 file_info->path_bar->get_info_cancellable =
1847 _gtk_file_system_get_info (file_info->path_bar->file_system,
1849 "standard::display-name,standard::is-hidden,standard::is-backup",
1850 gtk_path_bar_get_info_callback,
1855 _gtk_path_bar_set_file (GtkPathBar *path_bar,
1857 const gboolean keep_trail)
1859 struct SetFileInfo *info;
1861 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1862 g_return_if_fail (G_IS_FILE (file));
1864 /* Check whether the new path is already present in the pathbar as buttons.
1865 * This could be a parent directory or a previous selected subdirectory.
1867 if (keep_trail && gtk_path_bar_check_parent_path (path_bar, file))
1870 info = g_new0 (struct SetFileInfo, 1);
1871 info->file = g_object_ref (file);
1872 info->path_bar = path_bar;
1873 info->first_directory = TRUE;
1874 info->parent_file = g_file_get_parent (info->file);
1876 if (path_bar->get_info_cancellable)
1877 g_cancellable_cancel (path_bar->get_info_cancellable);
1879 path_bar->get_info_cancellable =
1880 _gtk_file_system_get_info (path_bar->file_system,
1882 "standard::display-name,standard::is-hidden,standard::is-backup",
1883 gtk_path_bar_get_info_callback,
1887 /* FIXME: This should be a construct-only property */
1889 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1890 GtkFileSystem *file_system)
1894 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1896 g_assert (path_bar->file_system == NULL);
1898 path_bar->file_system = g_object_ref (file_system);
1900 home = g_get_home_dir ();
1903 const gchar *desktop;
1905 path_bar->home_file = g_file_new_for_path (home);
1906 /* FIXME: Need file system backend specific way of getting the
1909 desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
1910 if (desktop != NULL)
1911 path_bar->desktop_file = g_file_new_for_path (desktop);
1913 path_bar->desktop_file = NULL;
1917 path_bar->home_file = NULL;
1918 path_bar->desktop_file = NULL;
1920 path_bar->root_file = g_file_new_for_path ("/");
1925 * @path_bar: a #GtkPathBar
1927 * If the selected button in the pathbar is not the furthest button "up" (in the
1928 * root direction), act as if the user clicked on the next button up.
1931 _gtk_path_bar_up (GtkPathBar *path_bar)
1935 for (l = path_bar->button_list; l; l = l->next)
1937 GtkWidget *button = BUTTON_DATA (l->data)->button;
1938 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1942 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1943 button_clicked_cb (next_button, l->next->data);
1951 * _gtk_path_bar_down:
1952 * @path_bar: a #GtkPathBar
1954 * If the selected button in the pathbar is not the furthest button "down" (in the
1955 * leaf direction), act as if the user clicked on the next button down.
1958 _gtk_path_bar_down (GtkPathBar *path_bar)
1962 for (l = path_bar->button_list; l; l = l->next)
1964 GtkWidget *button = BUTTON_DATA (l->data)->button;
1965 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1969 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1970 button_clicked_cb (prev_button, l->prev->data);