2 * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gtkpathbar.h"
23 #include "gtktogglebutton.h"
27 #include "gtkicontheme.h"
28 #include "gtkiconfactory.h"
32 #include "gtkmarshalers.h"
46 #define BUTTON_DATA(x) ((ButtonData *)(x))
48 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
50 /* Icon size for if we can't get it from the theme */
51 #define FALLBACK_ICON_SIZE 20
53 typedef struct _ButtonData ButtonData;
63 gboolean ignore_changes;
66 G_DEFINE_TYPE (GtkPathBar,
70 static void gtk_path_bar_finalize (GObject *object);
71 static void gtk_path_bar_dispose (GObject *object);
72 static void gtk_path_bar_size_request (GtkWidget *widget,
73 GtkRequisition *requisition);
74 static void gtk_path_bar_size_allocate (GtkWidget *widget,
75 GtkAllocation *allocation);
76 static void gtk_path_bar_add (GtkContainer *container,
78 static void gtk_path_bar_remove (GtkContainer *container,
80 static void gtk_path_bar_forall (GtkContainer *container,
81 gboolean include_internals,
83 gpointer callback_data);
84 static void gtk_path_bar_scroll_up (GtkWidget *button,
85 GtkPathBar *path_bar);
86 static void gtk_path_bar_scroll_down (GtkWidget *button,
87 GtkPathBar *path_bar);
88 static void gtk_path_bar_style_set (GtkWidget *widget,
89 GtkStyle *previous_style);
90 static void gtk_path_bar_screen_changed (GtkWidget *widget,
91 GdkScreen *previous_screen);
92 static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
93 static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
94 ButtonData *button_data,
95 gboolean current_dir);
98 get_slider_button (GtkPathBar *path_bar,
99 GtkArrowType arrow_type)
103 gtk_widget_push_composite_child ();
105 button = gtk_button_new ();
106 gtk_container_add (GTK_CONTAINER (button), gtk_arrow_new (arrow_type, GTK_SHADOW_OUT));
107 gtk_container_add (GTK_CONTAINER (path_bar), button);
108 gtk_widget_show_all (button);
110 gtk_widget_pop_composite_child ();
116 gtk_path_bar_init (GtkPathBar *path_bar)
118 GTK_WIDGET_SET_FLAGS (path_bar, GTK_NO_WINDOW);
119 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
121 path_bar->spacing = 3;
122 path_bar->up_slider_button = get_slider_button (path_bar, GTK_ARROW_LEFT);
123 path_bar->down_slider_button = get_slider_button (path_bar, GTK_ARROW_RIGHT);
124 path_bar->icon_size = FALLBACK_ICON_SIZE;
126 g_signal_connect (path_bar->up_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
127 g_signal_connect (path_bar->down_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
131 gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
133 GObjectClass *gobject_class;
134 GtkObjectClass *object_class;
135 GtkWidgetClass *widget_class;
136 GtkContainerClass *container_class;
138 gobject_class = (GObjectClass *) path_bar_class;
139 object_class = (GtkObjectClass *) path_bar_class;
140 widget_class = (GtkWidgetClass *) path_bar_class;
141 container_class = (GtkContainerClass *) path_bar_class;
143 gobject_class->finalize = gtk_path_bar_finalize;
144 gobject_class->dispose = gtk_path_bar_dispose;
146 widget_class->size_request = gtk_path_bar_size_request;
147 widget_class->size_allocate = gtk_path_bar_size_allocate;
148 widget_class->style_set = gtk_path_bar_style_set;
149 widget_class->screen_changed = gtk_path_bar_screen_changed;
151 container_class->add = gtk_path_bar_add;
152 container_class->forall = gtk_path_bar_forall;
153 container_class->remove = gtk_path_bar_remove;
155 /* container_class->child_type = gtk_path_bar_child_type;*/
157 path_bar_signals [PATH_CLICKED] =
158 g_signal_new ("path_clicked",
159 G_OBJECT_CLASS_TYPE (object_class),
161 G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
163 _gtk_marshal_VOID__POINTER,
170 gtk_path_bar_finalize (GObject *object)
172 GtkPathBar *path_bar;
174 path_bar = GTK_PATH_BAR (object);
175 g_list_free (path_bar->button_list);
176 if (path_bar->root_path)
177 gtk_file_path_free (path_bar->root_path);
178 if (path_bar->home_path)
179 gtk_file_path_free (path_bar->home_path);
180 if (path_bar->desktop_path)
181 gtk_file_path_free (path_bar->desktop_path);
183 if (path_bar->root_icon)
184 g_object_unref (path_bar->root_icon);
185 if (path_bar->home_icon)
186 g_object_unref (path_bar->home_icon);
187 if (path_bar->desktop_icon)
188 g_object_unref (path_bar->desktop_icon);
190 if (path_bar->file_system)
191 g_object_unref (path_bar->file_system);
193 G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
196 /* Removes the settings signal handler. It's safe to call multiple times */
198 remove_settings_signal (GtkPathBar *path_bar,
201 if (path_bar->settings_signal_id)
203 GtkSettings *settings;
205 settings = gtk_settings_get_for_screen (screen);
206 g_signal_handler_disconnect (settings,
207 path_bar->settings_signal_id);
208 path_bar->settings_signal_id = 0;
213 gtk_path_bar_dispose (GObject *object)
215 remove_settings_signal (GTK_PATH_BAR (object),
216 gtk_widget_get_screen (GTK_WIDGET (object)));
218 G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
223 * Ideally, our size is determined by another widget, and we are just filling
227 gtk_path_bar_size_request (GtkWidget *widget,
228 GtkRequisition *requisition)
230 ButtonData *button_data;
231 GtkPathBar *path_bar;
232 GtkRequisition child_requisition;
235 path_bar = GTK_PATH_BAR (widget);
237 requisition->width = 0;
238 requisition->height = 0;
240 for (list = path_bar->button_list; list; list = list->next)
242 button_data = BUTTON_DATA (list->data);
243 gtk_widget_size_request (button_data->button, &child_requisition);
244 requisition->width = MAX (child_requisition.width, requisition->width);
245 requisition->height = MAX (child_requisition.height, requisition->height);
248 /* Add space for slider, if we have more than one path */
249 /* Theoretically, the slider could be bigger than the other button. But we're
250 * not going to worry about that now.
252 path_bar->slider_width = requisition->height / 2 + 5;
253 if (path_bar->button_list && path_bar->button_list->next != NULL)
254 requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
256 gtk_widget_size_request (path_bar->up_slider_button, &child_requisition);
257 gtk_widget_size_request (path_bar->down_slider_button, &child_requisition);
259 requisition->width += GTK_CONTAINER (widget)->border_width * 2;
260 requisition->height += GTK_CONTAINER (widget)->border_width * 2;
262 widget->requisition = *requisition;
266 gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
268 if (path_bar->button_list)
272 button = BUTTON_DATA (path_bar->button_list->data)->button;
273 if (gtk_widget_get_child_visible (button))
274 gtk_widget_set_sensitive (path_bar->down_slider_button, FALSE);
276 gtk_widget_set_sensitive (path_bar->down_slider_button, TRUE);
278 button = BUTTON_DATA (g_list_last (path_bar->button_list)->data)->button;
279 if (gtk_widget_get_child_visible (button))
280 gtk_widget_set_sensitive (path_bar->up_slider_button, FALSE);
282 gtk_widget_set_sensitive (path_bar->up_slider_button, TRUE);
286 /* This is a tad complicated
289 gtk_path_bar_size_allocate (GtkWidget *widget,
290 GtkAllocation *allocation)
293 GtkPathBar *path_bar = GTK_PATH_BAR (widget);
294 GtkTextDirection direction;
295 GtkAllocation child_allocation;
296 GList *list, *first_button;
298 gint allocation_width;
300 gboolean need_sliders = FALSE;
301 gint up_slider_offset = 0;
302 gint down_slider_offset = 0;
304 widget->allocation = *allocation;
306 /* No path is set; we don't have to allocate anything. */
307 if (path_bar->button_list == NULL)
310 direction = gtk_widget_get_direction (widget);
311 border_width = (gint) GTK_CONTAINER (path_bar)->border_width;
312 allocation_width = allocation->width - 2 * border_width;
314 /* First, we check to see if we need the scrollbars. */
315 width = BUTTON_DATA (path_bar->button_list->data)->button->requisition.width;
316 for (list = path_bar->button_list->next; list; list = list->next)
318 child = BUTTON_DATA (list->data)->button;
320 width += child->requisition.width + path_bar->spacing;
323 if (width <= allocation_width)
325 first_button = g_list_last (path_bar->button_list);
329 gboolean reached_end = FALSE;
330 gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width);
332 if (path_bar->first_scrolled_button)
333 first_button = path_bar->first_scrolled_button;
335 first_button = path_bar->button_list;
338 /* To see how much space we have, and how many buttons we can display.
339 * We start at the first button, count forward until hit the new
340 * button, then count backwards.
342 /* Count down the path chain towards the end. */
343 width = BUTTON_DATA (first_button->data)->button->requisition.width;
344 list = first_button->prev;
345 while (list && !reached_end)
347 child = BUTTON_DATA (list->data)->button;
349 if (width + child->requisition.width +
350 path_bar->spacing + slider_space > allocation_width)
353 width += child->requisition.width + path_bar->spacing;
358 /* Finally, we walk up, seeing how many of the previous buttons we can
360 while (first_button->next && ! reached_end)
362 child = BUTTON_DATA (first_button->next->data)->button;
364 if (width + child->requisition.width + path_bar->spacing + slider_space > allocation_width)
370 width += child->requisition.width + path_bar->spacing;
371 first_button = first_button->next;
376 /* Now, we allocate space to the buttons */
377 child_allocation.y = allocation->y + border_width;
378 child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
380 if (direction == GTK_TEXT_DIR_RTL)
382 child_allocation.x = allocation->x + allocation->width - border_width;
385 child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
386 up_slider_offset = allocation->width - border_width - path_bar->slider_width;
391 child_allocation.x = allocation->x + border_width;
394 up_slider_offset = border_width;
395 child_allocation.x += (path_bar->spacing + path_bar->slider_width);
399 for (list = first_button; list; list = list->prev)
401 child = BUTTON_DATA (list->data)->button;
403 child_allocation.width = child->requisition.width;
404 if (direction == GTK_TEXT_DIR_RTL)
405 child_allocation.x -= child_allocation.width;
407 /* Check to see if we've don't have any more space to allocate buttons */
408 if (need_sliders && direction == GTK_TEXT_DIR_RTL)
410 if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width)
413 else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
415 if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
416 widget->allocation.x + border_width + allocation_width)
420 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, TRUE);
421 gtk_widget_size_allocate (child, &child_allocation);
423 if (direction == GTK_TEXT_DIR_RTL)
425 child_allocation.x -= path_bar->spacing;
426 down_slider_offset = child_allocation.x - widget->allocation.x - path_bar->slider_width;
430 child_allocation.x += child_allocation.width + path_bar->spacing;
431 down_slider_offset = child_allocation.x - widget->allocation.x;
434 /* Now we go hide all the widgets that don't fit */
437 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
440 for (list = first_button->next; list; list = list->next)
442 gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, FALSE);
447 child_allocation.width = path_bar->slider_width;
449 child_allocation.x = up_slider_offset + allocation->x;
450 gtk_widget_size_allocate (path_bar->up_slider_button, &child_allocation);
452 child_allocation.x = down_slider_offset + allocation->x;
453 gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
455 gtk_widget_set_child_visible (path_bar->up_slider_button, TRUE);
456 gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
457 gtk_widget_show_all (path_bar->up_slider_button);
458 gtk_widget_show_all (path_bar->down_slider_button);
459 gtk_path_bar_update_slider_buttons (path_bar);
463 gtk_widget_set_child_visible (path_bar->up_slider_button, FALSE);
464 gtk_widget_set_child_visible (path_bar->down_slider_button, FALSE);
469 gtk_path_bar_style_set (GtkWidget *widget,
470 GtkStyle *previous_style)
472 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set)
473 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_set (widget, previous_style);
475 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
479 gtk_path_bar_screen_changed (GtkWidget *widget,
480 GdkScreen *previous_screen)
482 if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
483 GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
485 /* We might nave a new settings, so we remove the old one */
487 remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
489 gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
493 gtk_path_bar_add (GtkContainer *container,
496 gtk_widget_set_parent (widget, GTK_WIDGET (container));
500 gtk_path_bar_remove (GtkContainer *container,
503 GtkPathBar *path_bar;
506 path_bar = GTK_PATH_BAR (container);
508 children = path_bar->button_list;
512 if (widget == BUTTON_DATA (children->data)->button)
514 gboolean was_visible;
516 was_visible = GTK_WIDGET_VISIBLE (widget);
517 gtk_widget_unparent (widget);
519 path_bar->button_list = g_list_remove_link (path_bar->button_list, children);
520 g_list_free (children);
523 gtk_widget_queue_resize (GTK_WIDGET (container));
527 children = children->next;
532 gtk_path_bar_forall (GtkContainer *container,
533 gboolean include_internals,
534 GtkCallback callback,
535 gpointer callback_data)
537 GtkPathBar *path_bar;
540 g_return_if_fail (callback != NULL);
541 path_bar = GTK_PATH_BAR (container);
543 children = path_bar->button_list;
547 child = BUTTON_DATA (children->data)->button;
548 children = children->next;
550 (* callback) (child, callback_data);
553 (* callback) (path_bar->up_slider_button, callback_data);
554 (* callback) (path_bar->down_slider_button, callback_data);
558 gtk_path_bar_scroll_down (GtkWidget *button, GtkPathBar *path_bar)
561 GList *down_button = NULL;
562 GList *up_button = NULL;
563 gint space_available;
566 GtkTextDirection direction;
568 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
570 border_width = GTK_CONTAINER (path_bar)->border_width;
571 direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
573 /* We find the button at the 'down' end that we have to make
575 for (list = path_bar->button_list; list; list = list->next)
577 if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
584 /* Find the last visible button on the 'up' end
586 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
588 if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
595 space_needed = BUTTON_DATA (down_button->data)->button->allocation.width + path_bar->spacing;
596 if (direction == GTK_TEXT_DIR_RTL)
597 space_available = path_bar->down_slider_button->allocation.x - GTK_WIDGET (path_bar)->allocation.x;
599 space_available = (GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width - border_width) -
600 (path_bar->down_slider_button->allocation.x + path_bar->down_slider_button->allocation.width);
602 /* We have space_available extra space that's not being used. We
603 * need space_needed space to make the button fit. So we walk down
604 * from the end, removing buttons until we get all the space we
606 while (space_available < space_needed)
608 space_available += BUTTON_DATA (up_button->data)->button->allocation.width + path_bar->spacing;
609 up_button = up_button->prev;
610 path_bar->first_scrolled_button = up_button;
615 gtk_path_bar_scroll_up (GtkWidget *button, GtkPathBar *path_bar)
619 gtk_widget_queue_resize (GTK_WIDGET (path_bar));
621 for (list = g_list_last (path_bar->button_list); list; list = list->prev)
623 if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
625 path_bar->first_scrolled_button = list;
631 /* Changes the icons wherever it is needed */
633 reload_icons (GtkPathBar *path_bar)
637 if (path_bar->root_icon)
639 g_object_unref (path_bar->root_icon);
640 path_bar->root_icon = NULL;
642 if (path_bar->home_icon)
644 g_object_unref (path_bar->home_icon);
645 path_bar->home_icon = NULL;
647 if (path_bar->desktop_icon)
649 g_object_unref (path_bar->desktop_icon);
650 path_bar->desktop_icon = NULL;
653 for (list = path_bar->button_list; list; list = list->next)
655 ButtonData *button_data;
656 gboolean current_dir;
658 button_data = BUTTON_DATA (list->data);
659 if (button_data->type != NORMAL_BUTTON)
661 current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
662 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
669 change_icon_theme (GtkPathBar *path_bar)
671 GtkSettings *settings;
674 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
676 if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_BUTTON, &width, &height))
677 path_bar->icon_size = MAX (width, height);
679 path_bar->icon_size = FALLBACK_ICON_SIZE;
681 reload_icons (path_bar);
683 /* Callback used when a GtkSettings value changes */
685 settings_notify_cb (GObject *object,
687 GtkPathBar *path_bar)
691 name = g_param_spec_get_name (pspec);
693 if (! strcmp (name, "gtk-icon-theme-name") ||
694 ! strcmp (name, "gtk-icon-sizes"))
695 change_icon_theme (path_bar);
699 gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
701 GtkSettings *settings;
703 if (path_bar->settings_signal_id)
706 settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
707 path_bar->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
709 change_icon_theme (path_bar);
712 /* Public functions and their helpers */
714 gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
716 while (path_bar->button_list != NULL)
718 gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->button_list->data)->button);
720 path_bar->first_scrolled_button = NULL;
724 button_clicked_cb (GtkWidget *button,
727 ButtonData *button_data;
730 button_data = BUTTON_DATA (data);
731 if (button_data->ignore_changes)
734 path_bar = button->parent;
735 g_assert (GTK_IS_PATH_BAR (path_bar));
736 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
738 g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0, button_data->path);
742 get_button_image (GtkPathBar *path_bar,
743 ButtonType button_type)
745 GtkFileSystemVolume *volume;
751 if (path_bar->root_icon != NULL)
752 return path_bar->root_icon;
754 volume = gtk_file_system_get_volume_for_path (path_bar->file_system, path_bar->root_path);
758 path_bar->root_icon = gtk_file_system_volume_render_icon (path_bar->file_system,
760 GTK_WIDGET (path_bar),
763 gtk_file_system_volume_free (path_bar->file_system, volume);
765 return path_bar->root_icon;
767 if (path_bar->home_icon != NULL)
768 return path_bar->home_icon;
770 path_bar->home_icon = gtk_file_system_render_icon (path_bar->file_system,
772 GTK_WIDGET (path_bar),
775 return path_bar->home_icon;
777 if (path_bar->desktop_icon != NULL)
778 return path_bar->desktop_icon;
780 path_bar->desktop_icon = gtk_file_system_render_icon (path_bar->file_system,
781 path_bar->desktop_path,
782 GTK_WIDGET (path_bar),
785 return path_bar->desktop_icon;
794 button_data_free (ButtonData *button_data)
796 gtk_file_path_free (button_data->path);
797 g_free (button_data->dir_name);
798 g_free (button_data);
802 gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
803 ButtonData *button_data,
804 gboolean current_dir)
806 const gchar *dir_name;
808 if (button_data->type == HOME_BUTTON)
809 dir_name = _("Home");
810 else if (button_data->type == DESKTOP_BUTTON)
811 dir_name = _("Desktop");
813 dir_name = button_data->dir_name;
815 if (button_data->label != NULL)
821 markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
822 gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
827 gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
831 if (button_data->image != NULL)
834 pixbuf = get_button_image (path_bar, button_data->type);
835 gtk_image_set_from_pixbuf (GTK_IMAGE (button_data->image), pixbuf);
838 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
840 button_data->ignore_changes = TRUE;
841 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
842 button_data->ignore_changes = FALSE;
847 find_button_type (GtkPathBar *path_bar,
850 if (! gtk_file_path_compare (path, path_bar->root_path))
852 if (! gtk_file_path_compare (path, path_bar->home_path))
854 if (! gtk_file_path_compare (path, path_bar->desktop_path))
855 return DESKTOP_BUTTON;
857 return NORMAL_BUTTON;
861 make_directory_button (GtkPathBar *path_bar,
862 const char *dir_name,
864 gboolean current_dir)
866 GtkWidget *child = NULL;
867 ButtonData *button_data;
869 /* Is it a special button? */
870 button_data = g_new0 (ButtonData, 1);
872 button_data->type = find_button_type (path_bar, path);
873 button_data->button = gtk_toggle_button_new ();
875 switch (button_data->type)
878 button_data->image = gtk_image_new ();
879 child = button_data->image;
880 button_data->label = NULL;
884 button_data->image = gtk_image_new ();
885 button_data->label = gtk_label_new (NULL);
886 child = gtk_hbox_new (FALSE, 2);
887 gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
888 gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
892 button_data->label = gtk_label_new (NULL);
893 child = button_data->label;
894 button_data->image = NULL;
897 button_data->dir_name = g_strdup (dir_name);
898 button_data->path = gtk_file_path_new_dup (gtk_file_path_get_string (path));
900 gtk_container_add (GTK_CONTAINER (button_data->button), child);
901 gtk_widget_show_all (button_data->button);
903 gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
905 g_signal_connect (button_data->button, "clicked",
906 G_CALLBACK (button_clicked_cb),
908 g_object_weak_ref (G_OBJECT (button_data->button),
909 (GWeakNotify) button_data_free, button_data);
915 gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
916 const GtkFilePath *file_path,
917 GtkFileSystem *file_system)
920 GList *current_path = NULL;
922 for (list = path_bar->button_list; list; list = list->next)
924 ButtonData *button_data;
926 button_data = list->data;
927 if (! gtk_file_path_compare (file_path, button_data->path))
936 for (list = path_bar->button_list; list; list = list->next)
938 gtk_path_bar_update_button_appearance (path_bar,
939 BUTTON_DATA (list->data),
940 (list == current_path) ? TRUE : FALSE);
948 _gtk_path_bar_set_path (GtkPathBar *path_bar,
949 const GtkFilePath *file_path,
953 gboolean first_directory = TRUE;
955 GList *new_buttons = NULL;
957 g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), FALSE);
958 g_return_val_if_fail (file_path != NULL, FALSE);
962 /* Check whether the new path is already present in the pathbar as buttons.
963 * This could be a parent directory or a previous selected subdirectory.
965 if (gtk_path_bar_check_parent_path (path_bar, file_path, path_bar->file_system))
968 path = gtk_file_path_copy (file_path);
970 gtk_widget_push_composite_child ();
974 GtkFilePath *parent_path = NULL;
975 ButtonData *button_data;
976 const gchar *display_name;
977 GtkFileFolder *file_folder;
978 GtkFileInfo *file_info;
981 valid = gtk_file_system_get_parent (path_bar->file_system,
988 gtk_file_path_free (path);
992 file_folder = gtk_file_system_get_folder (path_bar->file_system,
993 parent_path ? parent_path : path,
994 GTK_FILE_INFO_DISPLAY_NAME,
999 gtk_file_path_free (parent_path);
1000 gtk_file_path_free (path);
1004 file_info = gtk_file_folder_get_info (file_folder, parent_path ? path : NULL, error);
1005 g_object_unref (file_folder);
1010 gtk_file_path_free (parent_path);
1011 gtk_file_path_free (path);
1015 display_name = gtk_file_info_get_display_name (file_info);
1017 button_data = make_directory_button (path_bar, display_name, path, first_directory);
1018 gtk_file_info_free (file_info);
1019 gtk_file_path_free (path);
1021 new_buttons = g_list_prepend (new_buttons, button_data);
1023 if (button_data->type != NORMAL_BUTTON)
1025 gtk_file_path_free (parent_path);
1030 first_directory = FALSE;
1037 gtk_path_bar_clear_buttons (path_bar);
1038 path_bar->button_list = g_list_reverse (new_buttons);
1040 for (l = path_bar->button_list; l; l = l->next)
1042 GtkWidget *button = BUTTON_DATA (l->data)->button;
1043 gtk_container_add (GTK_CONTAINER (path_bar), button);
1050 for (l = new_buttons; l; l = l->next)
1052 GtkWidget *button = BUTTON_DATA (l->data)->button;
1053 gtk_widget_destroy (button);
1054 gtk_widget_unref (button);
1057 g_list_free (new_buttons);
1060 gtk_widget_pop_composite_child ();
1066 /* FIXME: This should be a construct-only property */
1068 _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
1069 GtkFileSystem *file_system)
1074 g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
1076 g_assert (path_bar->file_system == NULL);
1078 path_bar->file_system = g_object_ref (file_system);
1080 home = g_get_home_dir ();
1081 desktop = g_build_filename (home, "Desktop", NULL);
1082 path_bar->home_path = gtk_file_system_filename_to_path (path_bar->file_system, home);
1083 path_bar->desktop_path = gtk_file_system_filename_to_path (path_bar->file_system, desktop);
1084 path_bar->root_path = gtk_file_system_filename_to_path (path_bar->file_system, "/");
1090 * @path_bar: a #GtkPathBar
1092 * If the selected button in the pathbar is not the furthest button "up" (in the
1093 * root direction), act as if the user clicked on the next button up.
1096 _gtk_path_bar_up (GtkPathBar *path_bar)
1100 for (l = path_bar->button_list; l; l = l->next)
1102 GtkWidget *button = BUTTON_DATA (l->data)->button;
1103 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1107 GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
1108 button_clicked_cb (next_button, l->next->data);
1116 * _gtk_path_bar_down:
1117 * @path_bar: a #GtkPathBar
1119 * If the selected button in the pathbar is not the furthest button "down" (in the
1120 * leaf direction), act as if the user clicked on the next button down.
1123 _gtk_path_bar_down (GtkPathBar *path_bar)
1127 for (l = path_bar->button_list; l; l = l->next)
1129 GtkWidget *button = BUTTON_DATA (l->data)->button;
1130 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
1134 GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
1135 button_clicked_cb (prev_button, l->prev->data);