[gtk+/wip/csoriano/pathbar-prototype: 167/167] Implement new GtkPathBar
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/csoriano/pathbar-prototype: 167/167] Implement new GtkPathBar
- Date: Wed, 11 Nov 2015 13:55:57 +0000 (UTC)
commit 31edfc65a46163b9c03818e3045c7378ceb389b9
Author: Carlos Soriano <csoriano gnome org>
Date: Thu Oct 22 20:15:34 2015 +0200
Implement new GtkPathBar
Following mockups and rewritting it completly to be able
to be used by other projects like gnome-builder and dconf-editor
and sanitize its code.
This GtkPathBar will be only "visual", so no file management is done,
and instead a subclass GtkFilesPathBar in a following patch will
implement file management for the use case of GtkFileChooser and Nautilus.
gtk/Makefile.am | 4 +-
gtk/glade/gtk-private-widgets.xml | 2 -
gtk/gtk.h | 1 +
gtk/gtkcontainer.c | 2 +-
gtk/gtkfilechooserwidget.c | 12 +-
gtk/gtkpathbar.c | 2166 ++++++------------------------
gtk/gtkpathbar.h | 101 +-
gtk/gtkpathbarcontainer.c | 231 ++++
gtk/gtkpathbarcontainerprivate.h | 66 +
gtk/makefile.msc.in | 1 +
gtk/theme/Adwaita/_common.scss | 29 +-
gtk/theme/Adwaita/gtk-contained-dark.css | 47 +-
gtk/theme/Adwaita/gtk-contained.css | 47 +-
gtk/ui/gtkpathbar.ui | 107 +-
tests/Makefile.am | 5 +
tests/testpathbar.c | 166 +++
16 files changed, 1096 insertions(+), 1891 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index fc2a0c1..3bb8492 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -238,6 +238,7 @@ gtk_public_h_sources = \
gtkpagesetup.h \
gtkpaned.h \
gtkpapersize.h \
+ gtkpathbar.h \
gtkplacessidebar.h \
gtkplug.h \
gtkpopover.h \
@@ -488,8 +489,8 @@ gtk_private_h_sources = \
gtkmountoperationprivate.h \
gtknativedialogprivate.h \
gtkorientableprivate.h \
+ gtkpathbarcontainerprivate.h \
gtkpango.h \
- gtkpathbar.h \
gtkplacessidebarprivate.h \
gtkplacesviewprivate.h \
gtkplacesviewrowprivate.h \
@@ -775,6 +776,7 @@ gtk_base_c_sources = \
gtkorientable.c \
gtkoverlay.c \
gtkpagesetup.c \
+ gtkpathbarcontainer.c \
gtkpaned.c \
gtkpango.c \
gtkpapersize.c \
diff --git a/gtk/glade/gtk-private-widgets.xml b/gtk/glade/gtk-private-widgets.xml
index d15a568..91758e4 100644
--- a/gtk/glade/gtk-private-widgets.xml
+++ b/gtk/glade/gtk-private-widgets.xml
@@ -6,7 +6,6 @@
<glade-widget-classes>
<!-- base GTK+ private widgets -->
- <glade-widget-class name="GtkPathBar" generic-name="pathbar" title="Path Bar"
icon-name="widget-gtk-toolbar"/>
<glade-widget-class name="GtkColorEditor" generic-name="coloreditor" title="Color Editor"
icon-name="widget-gtk-colorselection"/>
<glade-widget-class name="GtkColorSwatch" generic-name="colorswatch" title="Color Swatch"
icon-name="widget-gtk-colorselection"/>
<glade-widget-class name="GtkColorPlane" generic-name="colorplane" title="Color Plane"
icon-name="widget-gtk-colorselection"/>
@@ -23,7 +22,6 @@
</glade-widget-classes>
<glade-widget-group name="gtk-private" title="Private GTK+ Classes">
- <glade-widget-class-ref name="GtkPathBar"/>
<glade-widget-class-ref name="GtkColorEditor"/>
<glade-widget-class-ref name="GtkColorSwatch"/>
<glade-widget-class-ref name="GtkColorPlane"/>
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 2c0fc21..029f640 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -152,6 +152,7 @@
#include <gtk/gtkoverlay.h>
#include <gtk/gtkpagesetup.h>
#include <gtk/gtkpapersize.h>
+#include <gtk/gtkpathbar.h>
#include <gtk/gtkpaned.h>
#include <gtk/gtkplacessidebar.h>
#include <gtk/gtkpopover.h>
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 45480fe..1f8ae8c 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -81,7 +81,7 @@
* in a two-dimensional grid.
*
* For implementations of GtkContainer only the virtual method gtk_container_forall
- * is required, since it's used for painting and realizing children.
+ * is required, since it's used for drawing the children.
*
* # Height for width geometry management
*
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 387f618..76ae085 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -3017,7 +3017,7 @@ put_recent_folder_in_pathbar (GtkFileChooserWidget *impl, GtkTreeIter *iter)
gtk_tree_model_get (GTK_TREE_MODEL (priv->recent_model), iter,
MODEL_COL_FILE, &file,
-1);
- _gtk_path_bar_set_file (GTK_PATH_BAR (priv->browse_path_bar), file, FALSE);
+ //_gtk_path_bar_set_file (GTK_PATH_BAR (priv->browse_path_bar), file, FALSE);
g_object_unref (file);
}
@@ -5465,7 +5465,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
if (! _gtk_file_info_consider_as_directory (info))
goto out;
- _gtk_path_bar_set_file (GTK_PATH_BAR (priv->browse_path_bar), data->file, data->keep_trail);
+ //_gtk_path_bar_set_file (GTK_PATH_BAR (priv->browse_path_bar), data->file, data->keep_trail);
if (priv->current_folder != data->file)
{
@@ -7929,7 +7929,7 @@ up_folder_handler (GtkFileChooserWidget *impl)
{
GtkFileChooserWidgetPrivate *priv = impl->priv;
- _gtk_path_bar_up (GTK_PATH_BAR (priv->browse_path_bar));
+ //_gtk_path_bar_up (GTK_PATH_BAR (priv->browse_path_bar));
}
/* Handler for the "down-folder" keybinding signal */
@@ -7938,7 +7938,7 @@ down_folder_handler (GtkFileChooserWidget *impl)
{
GtkFileChooserWidgetPrivate *priv = impl->priv;
- _gtk_path_bar_down (GTK_PATH_BAR (priv->browse_path_bar));
+ //_gtk_path_bar_down (GTK_PATH_BAR (priv->browse_path_bar));
}
/* Handler for the "home-folder" keybinding signal */
@@ -8532,9 +8532,9 @@ post_process_ui (GtkFileChooserWidget *impl)
g_list_free (cells);
/* Set the GtkPathBar file system backend */
- _gtk_path_bar_set_file_system (GTK_PATH_BAR (impl->priv->browse_path_bar), impl->priv->file_system);
+ //_gtk_path_bar_set_file_system (GTK_PATH_BAR (impl->priv->browse_path_bar), impl->priv->file_system);
file = g_file_new_for_path ("/");
- _gtk_path_bar_set_file (GTK_PATH_BAR (impl->priv->browse_path_bar), file, FALSE);
+ //_gtk_path_bar_set_file (GTK_PATH_BAR (impl->priv->browse_path_bar), file, FALSE);
g_object_unref (file);
/* Set the fixed size icon renderer, this requires
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 51b4fc1..80ef207 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -1,1933 +1,613 @@
-/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* gtkpathbar.c
- * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb gnome org>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Copyright (C) 2015 Red Hat
*
- * This library is distributed in the hope that it will be useful,
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ * Authors: Carlos Soriano <csoriano gnome org>
*/
#include "config.h"
+#include "gtkmain.h"
#include "gtkpathbar.h"
-
-#include <string.h>
-
+#include "gtkbutton.h"
+#include "gtktogglebutton.h"
+#include "gtklabel.h"
#include "gtkbox.h"
-#include "gtkdnd.h"
-#include "gtkicontheme.h"
-#include "gtkimage.h"
+#include "gtkpopover.h"
+#include "gtkbuilder.h"
+#include "gtkstylecontext.h"
+#include "gtkpathbarcontainerprivate.h"
+
#include "gtkintl.h"
-#include "gtklabel.h"
-#include "gtkmain.h"
#include "gtkmarshalers.h"
-#include "gtksettings.h"
-#include "gtktogglebutton.h"
-#include "gtkwidgetpath.h"
-#include "gtkwidgetprivate.h"
+#include "gtktypebuiltins.h"
+#include "gtkhidingboxprivate.h"
struct _GtkPathBarPrivate
{
- GtkFileSystem *file_system;
- GFile *root_file;
- GFile *home_file;
- GFile *desktop_file;
-
- GCancellable *get_info_cancellable;
-
- GIcon *root_icon;
- GIcon *home_icon;
- GIcon *desktop_icon;
-
- GdkWindow *event_window;
-
- GList *button_list;
- GList *first_scrolled_button;
- GList *fake_root;
- GtkWidget *up_slider_button;
- GtkWidget *down_slider_button;
- guint settings_signal_id;
- gint16 slider_width;
- gint16 button_offset;
- guint timer;
- guint slider_visible : 1;
- guint need_timer : 1;
- guint ignore_click : 1;
- guint scrolling_up : 1;
- guint scrolling_down : 1;
+ GtkWidget *path_bar_1;
+ GtkWidget *path_bar_2;
+ GtkWidget *path_box_1;
+ GtkWidget *path_box_2;
+ GtkWidget *overflow_button_1;
+ GtkWidget *overflow_button_2;
+ GtkWidget *overflow_popover;
+ GtkWidget *overflow_container;
+ GtkWidget *path_chunk_popover_container;
+
+ gchar *path;
+ gboolean hide_direction;
+
+ gboolean selecting_path;
};
+G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBar, gtk_path_bar, GTK_TYPE_STACK)
+
enum {
- PATH_CLICKED,
+ POPULATE_POPUP,
+ PATH_SELECTED,
LAST_SIGNAL
};
-typedef enum {
- NORMAL_BUTTON,
- ROOT_BUTTON,
- HOME_BUTTON,
- DESKTOP_BUTTON
-} ButtonType;
-
-#define BUTTON_DATA(x) ((ButtonData *)(x))
-
-#define SCROLL_DELAY_FACTOR 5
-#define TIMEOUT_INITIAL 500
-#define TIMEOUT_REPEAT 50
-
-static guint path_bar_signals [LAST_SIGNAL] = { 0 };
-
-/* Icon size for if we can't get it from the theme */
-#define FALLBACK_ICON_SIZE 16
-
-typedef struct _ButtonData ButtonData;
-
-struct _ButtonData
-{
- GtkWidget *button;
- ButtonType type;
- char *dir_name;
- GFile *file;
- GtkWidget *image;
- GtkWidget *label;
- GCancellable *cancellable;
- guint ignore_changes : 1;
- guint file_is_hidden : 1;
+enum {
+ PROP_0,
+ PROP_PATH,
+ PROP_HIDE_DIRECTION,
+ LAST_PROP
};
-/* This macro is used to check if a button can be used as a fake root.
- * All buttons in front of a fake root are automatically hidden when in a
- * directory below a fake root and replaced with the "<" arrow button.
- */
-#define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON)
-
-G_DEFINE_TYPE_WITH_PRIVATE (GtkPathBar, gtk_path_bar, GTK_TYPE_CONTAINER)
-
-static void gtk_path_bar_finalize (GObject *object);
-static void gtk_path_bar_dispose (GObject *object);
-static void gtk_path_bar_realize (GtkWidget *widget);
-static void gtk_path_bar_unrealize (GtkWidget *widget);
-static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
- gint *minimum,
- gint *natural);
-static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
- gint *minimum,
- gint *natural);
-static void gtk_path_bar_map (GtkWidget *widget);
-static void gtk_path_bar_unmap (GtkWidget *widget);
-static void gtk_path_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static void gtk_path_bar_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_path_bar_remove (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_path_bar_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data);
-static GtkWidgetPath *gtk_path_bar_get_path_for_child (GtkContainer *container,
- GtkWidget *child);
-static gboolean gtk_path_bar_scroll (GtkWidget *widget,
- GdkEventScroll *event);
-static void gtk_path_bar_scroll_up (GtkPathBar *path_bar);
-static void gtk_path_bar_scroll_down (GtkPathBar *path_bar);
-static void gtk_path_bar_stop_scrolling (GtkPathBar *path_bar);
-static gboolean gtk_path_bar_slider_up_defocus (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar);
-static gboolean gtk_path_bar_slider_down_defocus (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar);
-static gboolean gtk_path_bar_slider_button_press (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar);
-static gboolean gtk_path_bar_slider_button_release(GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar);
-static void gtk_path_bar_grab_notify (GtkWidget *widget,
- gboolean was_grabbed);
-static void gtk_path_bar_state_changed (GtkWidget *widget,
- GtkStateType previous_state);
-static void gtk_path_bar_style_updated (GtkWidget *widget);
-static void gtk_path_bar_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen);
-static void gtk_path_bar_check_icon_theme (GtkPathBar *path_bar);
-static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
- ButtonData *button_data,
- gboolean current_dir);
-
-static void
-on_slider_unmap (GtkWidget *widget,
- GtkPathBar *path_bar)
-{
- if (path_bar->priv->timer &&
- ((widget == path_bar->priv->up_slider_button && path_bar->priv->scrolling_up) ||
- (widget == path_bar->priv->down_slider_button && path_bar->priv->scrolling_down)))
- gtk_path_bar_stop_scrolling (path_bar);
-}
-
-static void
-gtk_path_bar_init (GtkPathBar *path_bar)
-{
- GtkStyleContext *context;
-
- path_bar->priv = gtk_path_bar_get_instance_private (path_bar);
-
- gtk_widget_init_template (GTK_WIDGET (path_bar));
-
- /* Add the children manually because GtkPathBar derives from an abstract class,
- * Glade cannot edit a <template> in gtkpathbar.ui if it's only a GtkContainer.
- */
- gtk_container_add (GTK_CONTAINER (path_bar), path_bar->priv->down_slider_button);
- gtk_container_add (GTK_CONTAINER (path_bar), path_bar->priv->up_slider_button);
-
- /* GtkBuilder wont let us connect 'swapped' without specifying the signal's
- * user data in the .ui file
- */
- g_signal_connect_swapped (path_bar->priv->up_slider_button, "clicked",
- G_CALLBACK (gtk_path_bar_scroll_up), path_bar);
- g_signal_connect_swapped (path_bar->priv->down_slider_button, "clicked",
- G_CALLBACK (gtk_path_bar_scroll_down), path_bar);
-
- gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
- gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
-
- context = gtk_widget_get_style_context (GTK_WIDGET (path_bar));
- gtk_style_context_add_class (context, "path-bar");
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
-
- path_bar->priv->get_info_cancellable = NULL;
-}
-
-static void
-gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
-{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
-
- gobject_class = (GObjectClass *) path_bar_class;
- widget_class = (GtkWidgetClass *) path_bar_class;
- container_class = (GtkContainerClass *) path_bar_class;
-
- gobject_class->finalize = gtk_path_bar_finalize;
- gobject_class->dispose = gtk_path_bar_dispose;
-
- widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
- widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
- widget_class->realize = gtk_path_bar_realize;
- widget_class->unrealize = gtk_path_bar_unrealize;
- widget_class->map = gtk_path_bar_map;
- widget_class->unmap = gtk_path_bar_unmap;
- widget_class->size_allocate = gtk_path_bar_size_allocate;
- widget_class->style_updated = gtk_path_bar_style_updated;
- widget_class->screen_changed = gtk_path_bar_screen_changed;
- widget_class->grab_notify = gtk_path_bar_grab_notify;
- widget_class->state_changed = gtk_path_bar_state_changed;
- widget_class->scroll_event = gtk_path_bar_scroll;
-
- container_class->add = gtk_path_bar_add;
- container_class->forall = gtk_path_bar_forall;
- container_class->remove = gtk_path_bar_remove;
- container_class->get_path_for_child = gtk_path_bar_get_path_for_child;
- gtk_container_class_handle_border_width (container_class);
- /* FIXME: */
- /* container_class->child_type = gtk_path_bar_child_type;*/
-
- path_bar_signals [PATH_CLICKED] =
- g_signal_new (I_("path-clicked"),
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
- NULL, NULL,
- _gtk_marshal_VOID__POINTER_POINTER_BOOLEAN,
- G_TYPE_NONE, 3,
- G_TYPE_POINTER,
- G_TYPE_POINTER,
- G_TYPE_BOOLEAN);
-
- /* Bind class to template
- */
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gtk/libgtk/ui/gtkpathbar.ui");
-
- gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, up_slider_button);
- gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, down_slider_button);
-
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_slider_button_press);
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_slider_button_release);
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_slider_up_defocus);
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_slider_down_defocus);
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_scroll_up);
- gtk_widget_class_bind_template_callback (widget_class, gtk_path_bar_scroll_down);
- gtk_widget_class_bind_template_callback (widget_class, on_slider_unmap);
-}
-
-
-static void
-gtk_path_bar_finalize (GObject *object)
-{
- GtkPathBar *path_bar;
-
- path_bar = GTK_PATH_BAR (object);
-
- gtk_path_bar_stop_scrolling (path_bar);
-
- g_list_free (path_bar->priv->button_list);
- g_clear_object (&path_bar->priv->root_file);
- g_clear_object (&path_bar->priv->home_file);
- g_clear_object (&path_bar->priv->desktop_file);
-
- g_clear_object (&path_bar->priv->root_icon);
- g_clear_object (&path_bar->priv->home_icon);
- g_clear_object (&path_bar->priv->desktop_icon);
-
- g_clear_object (&path_bar->priv->file_system);
-
- G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
-}
-
-/* Removes the settings signal handler. It's safe to call multiple times */
-static void
-remove_settings_signal (GtkPathBar *path_bar,
- GdkScreen *screen)
-{
- if (path_bar->priv->settings_signal_id)
- {
- GtkSettings *settings;
-
- settings = gtk_settings_get_for_screen (screen);
- g_signal_handler_disconnect (settings,
- path_bar->priv->settings_signal_id);
- path_bar->priv->settings_signal_id = 0;
- }
-}
-
-static void
-gtk_path_bar_dispose (GObject *object)
-{
- GtkPathBar *path_bar = GTK_PATH_BAR (object);
- remove_settings_signal (path_bar, gtk_widget_get_screen (GTK_WIDGET (object)));
-
- if (path_bar->priv->get_info_cancellable)
- g_cancellable_cancel (path_bar->priv->get_info_cancellable);
- path_bar->priv->get_info_cancellable = NULL;
-
- G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
-}
-
-/* Size requisition:
- *
- * Ideally, our size is determined by another widget, and we are just filling
- * available space.
- */
-static void
-gtk_path_bar_get_preferred_width (GtkWidget *widget,
- gint *minimum,
- gint *natural)
-{
- ButtonData *button_data;
- GtkPathBar *path_bar;
- GList *list;
- gint child_height;
- gint height;
- gint child_min, child_nat;
+static GParamSpec *path_bar_properties[LAST_PROP] = { NULL, };
+static guint path_bar_signals[LAST_SIGNAL] = { 0 };
- path_bar = GTK_PATH_BAR (widget);
-
- *minimum = *natural = 0;
- height = 0;
-
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- button_data = BUTTON_DATA (list->data);
- gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
- gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
- height = MAX (height, child_height);
-
- if (button_data->type == NORMAL_BUTTON)
- {
- /* Use 2*Height as button width because of ellipsized label. */
- child_min = MAX (child_min, child_height * 2);
- child_nat = MAX (child_min, child_height * 2);
- }
-
- *minimum = MAX (*minimum, child_min);
- *natural = *natural + child_nat;
- }
-
- /* Add space for slider, if we have more than one path */
- /* Theoretically, the slider could be bigger than the other button. But we're
- * not going to worry about that now.
- */
- path_bar->priv->slider_width = MIN (height * 2 / 3 + 5, height);
- if (path_bar->priv->button_list && path_bar->priv->button_list->next != NULL)
- {
- *minimum += path_bar->priv->slider_width * 2;
- *natural += path_bar->priv->slider_width * 2;
- }
-}
-
-static void
-gtk_path_bar_get_preferred_height (GtkWidget *widget,
- gint *minimum,
- gint *natural)
-{
- ButtonData *button_data;
+typedef struct {
+ GtkWidget *button;
+ gchar *label;
+ GString *path;
GtkPathBar *path_bar;
- GList *list;
- gint child_min, child_nat;
-
- path_bar = GTK_PATH_BAR (widget);
-
- *minimum = *natural = 0;
-
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- button_data = BUTTON_DATA (list->data);
- gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
-
- *minimum = MAX (*minimum, child_min);
- *natural = MAX (*natural, child_nat);
- }
-}
-
-static void
-gtk_path_bar_update_slider_buttons (GtkPathBar *path_bar)
-{
- if (path_bar->priv->button_list)
- {
- GtkWidget *button;
-
- button = BUTTON_DATA (path_bar->priv->button_list->data)->button;
- if (gtk_widget_get_child_visible (button))
- {
- gtk_path_bar_stop_scrolling (path_bar);
- gtk_widget_set_sensitive (path_bar->priv->down_slider_button, FALSE);
- }
- else
- gtk_widget_set_sensitive (path_bar->priv->down_slider_button, TRUE);
-
- button = BUTTON_DATA (g_list_last (path_bar->priv->button_list)->data)->button;
- if (gtk_widget_get_child_visible (button))
- {
- gtk_path_bar_stop_scrolling (path_bar);
- gtk_widget_set_sensitive (path_bar->priv->up_slider_button, FALSE);
- }
- else
- gtk_widget_set_sensitive (path_bar->priv->up_slider_button, TRUE);
- }
-}
+} PathChunkData;
static void
-gtk_path_bar_map (GtkWidget *widget)
+emit_path_selected (GtkPathBar *self,
+ const gchar *path)
{
- gdk_window_show (GTK_PATH_BAR (widget)->priv->event_window);
+ g_signal_emit (self, path_bar_signals[PATH_SELECTED], 0, path);
- GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->map (widget);
}
static void
-gtk_path_bar_unmap (GtkWidget *widget)
+emit_populate_popup (GtkPathBar *self,
+ const gchar *path)
{
- gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
- gdk_window_hide (GTK_PATH_BAR (widget)->priv->event_window);
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unmap (widget);
+ g_signal_emit (self, path_bar_signals[POPULATE_POPUP], 0,
+ priv->path_chunk_popover_container, path);
}
static void
-gtk_path_bar_realize (GtkWidget *widget)
+get_path_bar_widgets (GtkPathBar *self,
+ GtkWidget **path_bar,
+ GtkWidget **overflow_button,
+ GtkWidget **path_box,
+ gboolean current)
{
- GtkPathBar *path_bar;
- GtkAllocation allocation;
- GdkWindow *window;
- GdkWindowAttr attributes;
- gint attributes_mask;
-
- gtk_widget_set_realized (widget, TRUE);
-
- path_bar = GTK_PATH_BAR (widget);
- window = gtk_widget_get_parent_window (widget);
- gtk_widget_set_window (widget, window);
- g_object_ref (window);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = allocation.x;
- attributes.y = allocation.y;
- attributes.width = allocation.width;
- attributes.height = allocation.height;
- attributes.wclass = GDK_INPUT_ONLY;
- attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= GDK_SCROLL_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y;
-
- path_bar->priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gtk_widget_register_window (widget, path_bar->priv->event_window);
-}
-
-static void
-gtk_path_bar_unrealize (GtkWidget *widget)
-{
- GtkPathBar *path_bar;
-
- path_bar = GTK_PATH_BAR (widget);
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+ GtkWidget *current_path_bar;
- gtk_widget_unregister_window (widget, path_bar->priv->event_window);
- gdk_window_destroy (path_bar->priv->event_window);
- path_bar->priv->event_window = NULL;
-
- GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->unrealize (widget);
-}
-
-static void
-child_ordering_changed (GtkPathBar *path_bar)
-{
- GList *l;
-
- if (path_bar->priv->up_slider_button)
- _gtk_widget_invalidate_style_context (path_bar->priv->up_slider_button,
- GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
- if (path_bar->priv->down_slider_button)
- _gtk_widget_invalidate_style_context (path_bar->priv->down_slider_button,
- GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
-
- for (l = path_bar->priv->button_list; l; l = l->next)
+ current_path_bar = gtk_stack_get_visible_child (GTK_STACK (self));
+ if (current_path_bar == NULL ||
+ (current_path_bar == priv->path_bar_1 && current) ||
+ (current_path_bar == priv->path_bar_2 && !current))
{
- ButtonData *data = l->data;
-
- _gtk_widget_invalidate_style_context (data->button,
- GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
- }
-}
-
-/* This is a tad complicated
- */
-static void
-gtk_path_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkWidget *child;
- GtkPathBar *path_bar = GTK_PATH_BAR (widget);
- GtkTextDirection direction;
- GtkAllocation child_allocation;
- GList *list, *first_button;
- gint width;
- gint allocation_width;
- gboolean need_sliders = FALSE;
- gint up_slider_offset = 0;
- gint down_slider_offset = 0;
- GtkRequisition child_requisition;
- gboolean needs_reorder = FALSE;
-
- gtk_widget_set_allocation (widget, allocation);
-
- if (gtk_widget_get_realized (widget))
- gdk_window_move_resize (path_bar->priv->event_window,
- allocation->x, allocation->y,
- allocation->width, allocation->height);
-
- /* No path is set; we don't have to allocate anything. */
- if (path_bar->priv->button_list == NULL)
- {
- _gtk_widget_set_simple_clip (widget, NULL);
-
- return;
- }
-
- direction = gtk_widget_get_direction (widget);
- allocation_width = allocation->width;
-
- /* First, we check to see if we need the scrollbars. */
- if (path_bar->priv->fake_root)
- width = path_bar->priv->slider_width;
- else
- width = 0;
-
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- child = BUTTON_DATA (list->data)->button;
-
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- width += child_requisition.width;
- if (list == path_bar->priv->fake_root)
- break;
- }
-
- if (width <= allocation_width)
- {
- if (path_bar->priv->fake_root)
- first_button = path_bar->priv->fake_root;
- else
- first_button = g_list_last (path_bar->priv->button_list);
- }
- else
- {
- gboolean reached_end = FALSE;
- gint slider_space = 2 * path_bar->priv->slider_width;
-
- if (path_bar->priv->first_scrolled_button)
- first_button = path_bar->priv->first_scrolled_button;
- else
- first_button = path_bar->priv->button_list;
- need_sliders = TRUE;
-
- /* To see how much space we have, and how many buttons we can display.
- * We start at the first button, count forward until hit the new
- * button, then count backwards.
- */
- /* Count down the path chain towards the end. */
- gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
- &child_requisition, NULL);
-
- width = child_requisition.width;
- list = first_button->prev;
- while (list && !reached_end)
- {
- child = BUTTON_DATA (list->data)->button;
-
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- if (width + child_requisition.width + slider_space > allocation_width)
- reached_end = TRUE;
- else if (list == path_bar->priv->fake_root)
- break;
- else
- width += child_requisition.width;
-
- list = list->prev;
- }
-
- /* Finally, we walk up, seeing how many of the previous buttons we can
- * add */
- while (first_button->next && !reached_end)
- {
- child = BUTTON_DATA (first_button->next->data)->button;
-
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- if (width + child_requisition.width + slider_space > allocation_width)
- {
- reached_end = TRUE;
- }
- else
- {
- width += child_requisition.width;
- if (first_button == path_bar->priv->fake_root)
- break;
- first_button = first_button->next;
- }
- }
- }
-
- /* Now, we allocate space to the buttons */
- child_allocation.y = allocation->y;
- child_allocation.height = allocation->height;
-
- if (direction == GTK_TEXT_DIR_RTL)
- {
- child_allocation.x = allocation->x + allocation->width;
- if (need_sliders || path_bar->priv->fake_root)
- {
- child_allocation.x -= path_bar->priv->slider_width;
- up_slider_offset = allocation->width - path_bar->priv->slider_width;
- }
- }
- else
- {
- child_allocation.x = allocation->x;
- if (need_sliders || path_bar->priv->fake_root)
- {
- up_slider_offset = 0;
- child_allocation.x += path_bar->priv->slider_width;
- }
- }
-
- for (list = first_button; list; list = list->prev)
- {
- GtkAllocation widget_allocation;
- ButtonData *button_data;
-
- button_data = BUTTON_DATA (list->data);
- child = button_data->button;
-
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- child_allocation.width = MIN (child_requisition.width,
- allocation_width - 2 * path_bar->priv->slider_width);
-
- if (direction == GTK_TEXT_DIR_RTL)
- child_allocation.x -= child_allocation.width;
-
- /* Check to see if we've don't have any more space to allocate buttons */
- if (need_sliders && direction == GTK_TEXT_DIR_RTL)
- {
- gtk_widget_get_allocation (widget, &widget_allocation);
- if (child_allocation.x - path_bar->priv->slider_width < widget_allocation.x)
- break;
- }
- else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
- {
- gtk_widget_get_allocation (widget, &widget_allocation);
- if (child_allocation.x + child_allocation.width + path_bar->priv->slider_width >
- widget_allocation.x + allocation_width)
- break;
- }
-
- if (child_allocation.width < child_requisition.width)
- {
- if (!gtk_widget_get_has_tooltip (child))
- gtk_widget_set_tooltip_text (child, button_data->dir_name);
- }
- else if (gtk_widget_get_has_tooltip (child))
- gtk_widget_set_tooltip_text (child, NULL);
-
- needs_reorder |= gtk_widget_get_child_visible (child) == FALSE;
- gtk_widget_set_child_visible (child, TRUE);
- gtk_widget_size_allocate (child, &child_allocation);
-
- if (direction == GTK_TEXT_DIR_RTL)
- {
- down_slider_offset = child_allocation.x - allocation->x - path_bar->priv->slider_width;
- }
- else
- {
- down_slider_offset += child_allocation.width;
- child_allocation.x += child_allocation.width;
- }
- }
- /* Now we go hide all the widgets that don't fit */
- while (list)
- {
- child = BUTTON_DATA (list->data)->button;
- needs_reorder |= gtk_widget_get_child_visible (child) == TRUE;
- gtk_widget_set_child_visible (child, FALSE);
- list = list->prev;
- }
- for (list = first_button->next; list; list = list->next)
- {
- child = BUTTON_DATA (list->data)->button;
- needs_reorder |= gtk_widget_get_child_visible (child) == TRUE;
- gtk_widget_set_child_visible (child, FALSE);
- }
-
- if (need_sliders || path_bar->priv->fake_root)
- {
- child_allocation.width = path_bar->priv->slider_width;
- child_allocation.x = up_slider_offset + allocation->x;
- gtk_widget_size_allocate (path_bar->priv->up_slider_button, &child_allocation);
-
- needs_reorder |= gtk_widget_get_child_visible (path_bar->priv->up_slider_button) == FALSE;
- gtk_widget_set_child_visible (path_bar->priv->up_slider_button, TRUE);
- gtk_widget_show_all (path_bar->priv->up_slider_button);
-
- if (direction == GTK_TEXT_DIR_LTR)
- down_slider_offset += path_bar->priv->slider_width;
+ if (path_bar)
+ *path_bar = priv->path_bar_1;
+ if (overflow_button)
+ *overflow_button = priv->overflow_button_1;
+ if (path_box)
+ *path_box = priv->path_box_1;
}
else
{
- needs_reorder |= gtk_widget_get_child_visible (path_bar->priv->up_slider_button) == TRUE;
- gtk_widget_set_child_visible (path_bar->priv->up_slider_button, FALSE);
- }
-
- if (need_sliders)
- {
- child_allocation.width = path_bar->priv->slider_width;
- child_allocation.x = down_slider_offset + allocation->x;
-
- gtk_widget_size_allocate (path_bar->priv->down_slider_button, &child_allocation);
-
- needs_reorder |= gtk_widget_get_child_visible (path_bar->priv->down_slider_button) == FALSE;
- gtk_widget_set_child_visible (path_bar->priv->down_slider_button, TRUE);
- gtk_widget_show_all (path_bar->priv->down_slider_button);
- gtk_path_bar_update_slider_buttons (path_bar);
- }
- else
- {
- needs_reorder |= gtk_widget_get_child_visible (path_bar->priv->down_slider_button) == TRUE;
- gtk_widget_set_child_visible (path_bar->priv->down_slider_button, FALSE);
- }
-
- if (needs_reorder)
- child_ordering_changed (path_bar);
-
- _gtk_widget_set_simple_clip (widget, NULL);
-}
-
-static void
-gtk_path_bar_style_updated (GtkWidget *widget)
-{
- GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->style_updated (widget);
-
- gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
-}
-
-static void
-gtk_path_bar_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen)
-{
- if (GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed)
- GTK_WIDGET_CLASS (gtk_path_bar_parent_class)->screen_changed (widget, previous_screen);
-
- /* We might nave a new settings, so we remove the old one */
- if (previous_screen)
- remove_settings_signal (GTK_PATH_BAR (widget), previous_screen);
-
- gtk_path_bar_check_icon_theme (GTK_PATH_BAR (widget));
-}
-
-static gboolean
-gtk_path_bar_scroll (GtkWidget *widget,
- GdkEventScroll *event)
-{
- switch (event->direction)
- {
- case GDK_SCROLL_RIGHT:
- case GDK_SCROLL_DOWN:
- gtk_path_bar_scroll_down (GTK_PATH_BAR (widget));
- break;
- case GDK_SCROLL_LEFT:
- case GDK_SCROLL_UP:
- gtk_path_bar_scroll_up (GTK_PATH_BAR (widget));
- break;
- case GDK_SCROLL_SMOOTH:
- break;
- }
-
- return TRUE;
-}
-
-static void
-gtk_path_bar_add (GtkContainer *container,
- GtkWidget *widget)
-
-{
- gtk_widget_set_parent (widget, GTK_WIDGET (container));
-}
-
-static void
-gtk_path_bar_remove_1 (GtkContainer *container,
- GtkWidget *widget)
-{
- gboolean was_visible = gtk_widget_get_visible (widget);
- gtk_widget_unparent (widget);
- if (was_visible)
- gtk_widget_queue_resize (GTK_WIDGET (container));
-}
-
-static void
-gtk_path_bar_remove (GtkContainer *container,
- GtkWidget *widget)
-{
- GtkPathBar *path_bar;
- GList *children;
-
- path_bar = GTK_PATH_BAR (container);
-
- if (widget == path_bar->priv->up_slider_button)
- {
- gtk_path_bar_remove_1 (container, widget);
- path_bar->priv->up_slider_button = NULL;
- return;
- }
-
- if (widget == path_bar->priv->down_slider_button)
- {
- gtk_path_bar_remove_1 (container, widget);
- path_bar->priv->down_slider_button = NULL;
- return;
- }
-
- children = path_bar->priv->button_list;
- while (children)
- {
- if (widget == BUTTON_DATA (children->data)->button)
- {
- gtk_path_bar_remove_1 (container, widget);
- path_bar->priv->button_list = g_list_remove_link (path_bar->priv->button_list, children);
- g_list_free (children);
- return;
- }
-
- children = children->next;
- }
-}
-
-static void
-gtk_path_bar_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data)
-{
- GtkPathBar *path_bar;
- GList *children;
-
- g_return_if_fail (callback != NULL);
- path_bar = GTK_PATH_BAR (container);
-
- children = path_bar->priv->button_list;
- while (children)
- {
- GtkWidget *child;
- child = BUTTON_DATA (children->data)->button;
- children = children->next;
-
- (* callback) (child, callback_data);
- }
-
- if (path_bar->priv->up_slider_button)
- (* callback) (path_bar->priv->up_slider_button, callback_data);
-
- if (path_bar->priv->down_slider_button)
- (* callback) (path_bar->priv->down_slider_button, callback_data);
-}
-
-static GtkWidgetPath *
-gtk_path_bar_get_path_for_child (GtkContainer *container,
- GtkWidget *child)
-{
- GtkPathBar *path_bar = GTK_PATH_BAR (container);
- GtkWidgetPath *path;
-
- path = _gtk_widget_create_path (GTK_WIDGET (path_bar));
-
- if (gtk_widget_get_visible (child) &&
- gtk_widget_get_child_visible (child))
- {
- GtkWidgetPath *sibling_path;
- GList *visible_children;
- GList *l;
- int pos;
-
- /* 1. Build the list of visible children, in visually left-to-right order
- * (i.e. independently of the widget's direction). Note that our
- * button_list is stored in innermost-to-outermost path order!
- */
-
- visible_children = NULL;
-
- if (gtk_widget_get_visible (path_bar->priv->down_slider_button) &&
- gtk_widget_get_child_visible (path_bar->priv->down_slider_button))
- visible_children = g_list_prepend (visible_children, path_bar->priv->down_slider_button);
-
- for (l = path_bar->priv->button_list; l; l = l->next)
- {
- ButtonData *data = l->data;
-
- if (gtk_widget_get_visible (data->button) &&
- gtk_widget_get_child_visible (data->button))
- visible_children = g_list_prepend (visible_children, data->button);
- }
-
- if (gtk_widget_get_visible (path_bar->priv->up_slider_button) &&
- gtk_widget_get_child_visible (path_bar->priv->up_slider_button))
- visible_children = g_list_prepend (visible_children, path_bar->priv->up_slider_button);
-
- if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
- visible_children = g_list_reverse (visible_children);
-
- /* 2. Find the index of the child within that list */
-
- pos = 0;
-
- for (l = visible_children; l; l = l->next)
- {
- GtkWidget *button = l->data;
-
- if (button == child)
- break;
-
- pos++;
- }
-
- /* 3. Build the path */
-
- sibling_path = gtk_widget_path_new ();
-
- for (l = visible_children; l; l = l->next)
- gtk_widget_path_append_for_widget (sibling_path, l->data);
-
- gtk_widget_path_append_with_siblings (path, sibling_path, pos);
-
- g_list_free (visible_children);
- gtk_widget_path_unref (sibling_path);
+ if (path_bar)
+ *path_bar = priv->path_bar_2;
+ if (overflow_button)
+ *overflow_button = priv->overflow_button_2;
+ if (path_box)
+ *path_box = priv->path_box_2;
}
- else
- gtk_widget_path_append_for_widget (path, child);
-
- return path;
}
static void
-gtk_path_bar_scroll_down (GtkPathBar *path_bar)
+on_path_chunk_popover_destroyed (GtkPathBar *self)
{
- GtkAllocation allocation, button_allocation;
- GList *list;
- GList *down_button = NULL;
- gint space_available;
-
- if (path_bar->priv->ignore_click)
- {
- path_bar->priv->ignore_click = FALSE;
- return;
- }
+ GtkPathBarPrivate *priv;
- if (gtk_widget_get_child_visible (BUTTON_DATA (path_bar->priv->button_list->data)->button))
- {
- /* Return if the last button is already visible */
- return;
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
-
- /* We find the button at the 'down' end that we have to make
- * visible */
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
- {
- down_button = list;
- break;
- }
- }
-
- gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
- gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
+ if (self == NULL)
+ return;
- space_available = (allocation.width
- - 2 * path_bar->priv->slider_width
- - button_allocation.width);
- path_bar->priv->first_scrolled_button = down_button;
-
- /* We have space_available free space that's not being used.
- * So we walk down from the end, adding buttons until we use all free space.
- */
- while (space_available > 0)
- {
- path_bar->priv->first_scrolled_button = down_button;
- down_button = down_button->next;
- if (!down_button)
- break;
- space_available -= button_allocation.width;
- }
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+ priv->path_chunk_popover_container = NULL;
}
static void
-gtk_path_bar_scroll_up (GtkPathBar *path_bar)
+show_path_chunk_popover (GtkPathBar *self,
+ GtkWidget *path_chunk)
{
- GList *list;
-
- if (path_bar->priv->ignore_click)
- {
- path_bar->priv->ignore_click = FALSE;
- return;
- }
-
- list = g_list_last (path_bar->priv->button_list);
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+ GtkWidget *popover;
- if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
+ if (priv->path_chunk_popover_container != NULL)
{
- /* Return if the first button is already visible */
- return;
+ popover = gtk_widget_get_ancestor (priv->path_chunk_popover_container,
+ GTK_TYPE_POPOVER);
+ gtk_widget_destroy (popover);
}
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
+ popover = gtk_popover_new (path_chunk);
+ priv->path_chunk_popover_container = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_container_add (GTK_CONTAINER (popover), priv->path_chunk_popover_container);
+ /* Clean private pointer when its destroyed, most of the times due to its
+ * relative_to associated widget being destroyed */
+ g_signal_connect_swapped (popover, "destroy",
+ G_CALLBACK (on_path_chunk_popover_destroyed), self);
- for ( ; list; list = list->prev)
- {
- if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
- {
- if (list->prev == path_bar->priv->fake_root)
- path_bar->priv->fake_root = NULL;
- path_bar->priv->first_scrolled_button = list;
- return;
- }
- }
+ gtk_widget_show (popover);
}
static gboolean
-gtk_path_bar_scroll_timeout (GtkPathBar *path_bar)
+on_path_chunk_button_release_event (GtkWidget *path_chunk,
+ GdkEventButton *event)
{
- gboolean retval = FALSE;
+ PathChunkData *data;
+ GtkPathBarPrivate *priv;
- if (path_bar->priv->timer)
- {
- if (path_bar->priv->scrolling_up)
- gtk_path_bar_scroll_up (path_bar);
- else if (path_bar->priv->scrolling_down)
- gtk_path_bar_scroll_down (path_bar);
-
- if (path_bar->priv->need_timer)
- {
- path_bar->priv->need_timer = FALSE;
-
- path_bar->priv->timer = gdk_threads_add_timeout (TIMEOUT_REPEAT * SCROLL_DELAY_FACTOR,
- (GSourceFunc)gtk_path_bar_scroll_timeout,
- path_bar);
- g_source_set_name_by_id (path_bar->priv->timer, "[gtk+] gtk_path_bar_scroll_timeout");
- }
- else
- retval = TRUE;
- }
+ data = g_object_get_data (G_OBJECT (path_chunk), "data");
+ g_assert (data != NULL);
- return retval;
-}
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (data->path_bar));
-static void
-gtk_path_bar_stop_scrolling (GtkPathBar *path_bar)
-{
- if (path_bar->priv->timer)
+ if (event->type == GDK_BUTTON_RELEASE)
{
- g_source_remove (path_bar->priv->timer);
- path_bar->priv->timer = 0;
- path_bar->priv->need_timer = FALSE;
- }
-}
-
-static gboolean
-gtk_path_bar_slider_up_defocus (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar)
-{
- GList *list;
- GList *up_button = NULL;
-
- if (event->type != GDK_FOCUS_CHANGE)
- return FALSE;
-
- for (list = g_list_last (path_bar->priv->button_list); list; list = list->prev)
- {
- if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
+ switch (event->button)
{
- up_button = list;
- break;
- }
- }
+ case GDK_BUTTON_PRIMARY:
+ if (priv->selecting_path)
+ return TRUE;
- /* don't let the focus vanish */
- if ((!gtk_widget_is_sensitive (path_bar->priv->up_slider_button)) ||
- (!gtk_widget_get_child_visible (path_bar->priv->up_slider_button)))
- gtk_widget_grab_focus (BUTTON_DATA (up_button->data)->button);
+ priv->selecting_path = TRUE;
+ gtk_path_bar_select_path (data->path_bar, (const gchar*) data->path->str);
+ priv->selecting_path = FALSE;
+ emit_path_selected (data->path_bar, data->path->str);
- return FALSE;
-}
+ return TRUE;
-static gboolean
-gtk_path_bar_slider_down_defocus (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar)
-{
- GList *list;
- GList *down_button = NULL;
+ case GDK_BUTTON_SECONDARY:
+ show_path_chunk_popover (data->path_bar, path_chunk);
+ emit_populate_popup (data->path_bar, data->path->str);
- if (event->type != GDK_FOCUS_CHANGE)
- return FALSE;
+ return TRUE;
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
- {
- down_button = list;
+ default:
break;
}
}
- /* don't let the focus vanish */
- if ((!gtk_widget_is_sensitive (path_bar->priv->down_slider_button)) ||
- (!gtk_widget_get_child_visible (path_bar->priv->down_slider_button)))
- gtk_widget_grab_focus (BUTTON_DATA (down_button->data)->button);
-
- return FALSE;
-}
-
-static gboolean
-gtk_path_bar_slider_button_press (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar)
-{
- if (event->type != GDK_BUTTON_PRESS || event->button != GDK_BUTTON_PRIMARY)
- return FALSE;
-
- path_bar->priv->ignore_click = FALSE;
-
- if (widget == path_bar->priv->up_slider_button)
- {
- path_bar->priv->scrolling_down = FALSE;
- path_bar->priv->scrolling_up = TRUE;
- gtk_path_bar_scroll_up (path_bar);
- }
- else if (widget == path_bar->priv->down_slider_button)
- {
- path_bar->priv->scrolling_up = FALSE;
- path_bar->priv->scrolling_down = TRUE;
- gtk_path_bar_scroll_down (path_bar);
- }
-
- if (!path_bar->priv->timer)
- {
- path_bar->priv->need_timer = TRUE;
- path_bar->priv->timer = gdk_threads_add_timeout (TIMEOUT_INITIAL,
- (GSourceFunc)gtk_path_bar_scroll_timeout,
- path_bar);
- g_source_set_name_by_id (path_bar->priv->timer, "[gtk+] gtk_path_bar_scroll_timeout");
- }
-
- return FALSE;
-}
-
-static gboolean
-gtk_path_bar_slider_button_release (GtkWidget *widget,
- GdkEventButton *event,
- GtkPathBar *path_bar)
-{
- if (event->type != GDK_BUTTON_RELEASE)
- return FALSE;
-
- path_bar->priv->ignore_click = TRUE;
- gtk_path_bar_stop_scrolling (path_bar);
-
return FALSE;
}
static void
-gtk_path_bar_grab_notify (GtkWidget *widget,
- gboolean was_grabbed)
+free_path_chunk_data (PathChunkData *data)
{
- if (!was_grabbed)
- gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
+ g_free (data->label);
+ g_string_free (data->path, TRUE);
+ g_slice_free (PathChunkData, data);
}
-static void
-gtk_path_bar_state_changed (GtkWidget *widget,
- GtkStateType previous_state)
+static GtkWidget *
+create_path_chunk (GtkPathBar *self,
+ const GString *path,
+ const gchar *label,
+ gboolean add_separator)
{
- if (!gtk_widget_is_sensitive (widget))
- gtk_path_bar_stop_scrolling (GTK_PATH_BAR (widget));
-}
+ GtkWidget *button;
+ GtkWidget *separator;
+ GtkWidget *path_chunk;
+ GtkWidget *button_label;
+ GtkStyleContext *style;
+ PathChunkData *path_chunk_data;
+ GtkTextDirection direction;
+ direction = gtk_widget_get_direction (GTK_WIDGET (self));
-/* Changes the icons wherever it is needed */
-static void
-reload_icons (GtkPathBar *path_bar)
-{
- GList *list;
+ path_chunk = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ button = gtk_toggle_button_new ();
+ button_label = gtk_label_new (label);
+ gtk_label_set_ellipsize (GTK_LABEL (button_label), PANGO_ELLIPSIZE_MIDDLE);
+ // FIXME: the GtkLabel requests more than the number of chars set here.
+ // For visual testing for now substract 2 chars.
+ gtk_label_set_width_chars (GTK_LABEL (button_label),
+ MIN (g_utf8_strlen (label, -1), 10));
+ gtk_container_add (GTK_CONTAINER (button), button_label);
- g_clear_object (&path_bar->priv->root_icon);
- g_clear_object (&path_bar->priv->home_icon);
- g_clear_object (&path_bar->priv->desktop_icon);
+ g_signal_connect_swapped (button, "button-release-event",
+ G_CALLBACK (on_path_chunk_button_release_event), path_chunk);
+ style = gtk_widget_get_style_context (button);
+ gtk_style_context_add_class (style, "flat");
- for (list = path_bar->priv->button_list; list; list = list->next)
+ if (add_separator)
{
- ButtonData *button_data;
- gboolean current_dir;
-
- button_data = BUTTON_DATA (list->data);
- if (button_data->type != NORMAL_BUTTON)
- {
- current_dir = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button));
- gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
- }
+ separator = gtk_label_new ("/");
+ gtk_widget_set_sensitive (separator, FALSE);
}
-}
-
-static void
-change_icon_theme (GtkPathBar *path_bar)
-{
- reload_icons (path_bar);
-}
-
-/* Callback used when a GtkSettings value changes */
-static void
-settings_notify_cb (GObject *object,
- GParamSpec *pspec,
- GtkPathBar *path_bar)
-{
- const char *name;
-
- name = g_param_spec_get_name (pspec);
-
- if (strcmp (name, "gtk-icon-theme-name") == 0)
- change_icon_theme (path_bar);
-}
-static void
-gtk_path_bar_check_icon_theme (GtkPathBar *path_bar)
-{
- if (path_bar->priv->settings_signal_id == 0)
+ if (direction == GTK_TEXT_DIR_LTR)
{
- GtkSettings *settings;
-
- settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
- path_bar->priv->settings_signal_id = g_signal_connect (settings, "notify",
- G_CALLBACK (settings_notify_cb), path_bar);
+ gtk_container_add (GTK_CONTAINER (path_chunk), button);
+ if (add_separator)
+ gtk_container_add (GTK_CONTAINER (path_chunk), separator);
+ } else {
+ if (add_separator)
+ gtk_container_add (GTK_CONTAINER (path_chunk), separator);
+ gtk_container_add (GTK_CONTAINER (path_chunk), button);
}
- change_icon_theme (path_bar);
-}
+ path_chunk_data = g_slice_new (PathChunkData);
+ path_chunk_data->label = g_strdup (label);
+ path_chunk_data->path = g_string_new (path->str);
+ path_chunk_data->path_bar = self;
+ path_chunk_data->button = button;
+ g_object_set_data_full (G_OBJECT (path_chunk), "data",
+ path_chunk_data, (GDestroyNotify) free_path_chunk_data);
-/* Public functions and their helpers */
-static void
-gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
-{
- while (path_bar->priv->button_list != NULL)
- {
- gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA
(path_bar->priv->button_list->data)->button);
- }
- path_bar->priv->first_scrolled_button = NULL;
- path_bar->priv->fake_root = NULL;
+ gtk_widget_show_all (path_chunk);
+
+ return path_chunk;
}
static void
-button_clicked_cb (GtkWidget *button,
- gpointer data)
+populate_overflow_popover (GtkPathBar *self)
{
- ButtonData *button_data;
- GtkPathBar *path_bar;
- GList *button_list;
- gboolean child_is_hidden;
- GFile *child_file;
-
- button_data = BUTTON_DATA (data);
- if (button_data->ignore_changes)
- return;
-
- path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
-
- button_list = g_list_find (path_bar->priv->button_list, button_data);
- g_assert (button_list != NULL);
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+ GList *overflow_children;
+ GList *l;
+ PathChunkData *data;
+ GtkWidget *path_chunk;
+ GtkWidget *path_box;
- g_signal_handlers_block_by_func (button,
- G_CALLBACK (button_clicked_cb), data);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_signal_handlers_unblock_by_func (button,
- G_CALLBACK (button_clicked_cb), data);
+ gtk_container_foreach (GTK_CONTAINER (priv->overflow_container),
+ (GtkCallback) gtk_widget_destroy, NULL);
- if (button_list->prev)
+ get_path_bar_widgets (self, NULL, NULL, &path_box, TRUE);
+ overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (path_box));
+ for (l = overflow_children; l != NULL; l = l->next)
{
- ButtonData *child_data;
-
- child_data = BUTTON_DATA (button_list->prev->data);
- child_file = child_data->file;
- child_is_hidden = child_data->file_is_hidden;
- }
- else
- {
- child_file = NULL;
- child_is_hidden = FALSE;
+ data = g_object_get_data (l->data, "data");
+ path_chunk = create_path_chunk (self, (const GString*) data->path,
+ (const gchar*) data->label, FALSE);
+ gtk_container_add (GTK_CONTAINER (priv->overflow_container), path_chunk);
}
- g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
- button_data->file, child_file, child_is_hidden);
+ g_list_free (overflow_children);
}
-struct SetButtonImageData
-{
- GtkPathBar *path_bar;
- ButtonData *button_data;
-};
-
static void
-set_button_image_get_info_cb (GCancellable *cancellable,
- GFileInfo *info,
- const GError *error,
- gpointer user_data)
+gtk_path_bar_finalize (GObject *object)
{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- GIcon *icon;
- struct SetButtonImageData *data = user_data;
-
- if (cancellable != data->button_data->cancellable)
- goto out;
-
- data->button_data->cancellable = NULL;
-
- if (!data->button_data->button)
- {
- g_free (data->button_data);
- goto out;
- }
-
- if (cancelled || error)
- goto out;
-
- icon = g_file_info_get_symbolic_icon (info);
- gtk_image_set_from_gicon (GTK_IMAGE (data->button_data->image), icon, GTK_ICON_SIZE_BUTTON);
+ GtkPathBar *self = (GtkPathBar *)object;
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (self);
- switch (data->button_data->type)
- {
- case HOME_BUTTON:
- g_set_object (&data->path_bar->priv->home_icon, icon);
- break;
-
- case DESKTOP_BUTTON:
- g_set_object (&data->path_bar->priv->desktop_icon, icon);
- break;
+ g_free (priv->path);
- default:
- break;
- };
-
-out:
- g_free (data);
- g_object_unref (cancellable);
+ G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
}
static void
-set_button_image (GtkPathBar *path_bar,
- ButtonData *button_data)
+gtk_path_bar_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GtkFileSystemVolume *volume;
- struct SetButtonImageData *data;
+ GtkPathBar *self = GTK_PATH_BAR (object);
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (self);
- switch (button_data->type)
+ switch (prop_id)
{
- case ROOT_BUTTON:
-
- if (path_bar->priv->root_icon != NULL)
- {
- gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->priv->root_icon,
GTK_ICON_SIZE_BUTTON);
- break;
- }
-
- volume = _gtk_file_system_get_volume_for_file (path_bar->priv->file_system, path_bar->priv->root_file);
- if (volume == NULL)
- return;
-
- path_bar->priv->root_icon = _gtk_file_system_volume_get_symbolic_icon (volume);
- _gtk_file_system_volume_unref (volume);
- gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->priv->root_icon,
GTK_ICON_SIZE_BUTTON);
-
- break;
-
- case HOME_BUTTON:
- if (path_bar->priv->home_icon != NULL)
- {
- gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->priv->home_icon,
GTK_ICON_SIZE_BUTTON);
- break;
- }
-
- data = g_new0 (struct SetButtonImageData, 1);
- data->path_bar = path_bar;
- data->button_data = button_data;
-
- if (button_data->cancellable)
- g_cancellable_cancel (button_data->cancellable);
-
- button_data->cancellable =
- _gtk_file_system_get_info (path_bar->priv->file_system,
- path_bar->priv->home_file,
- "standard::symbolic-icon",
- set_button_image_get_info_cb,
- data);
+ case PROP_PATH:
+ g_value_set_string (value, priv->path);
break;
-
- case DESKTOP_BUTTON:
- if (path_bar->priv->desktop_icon != NULL)
- {
- gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->priv->desktop_icon,
GTK_ICON_SIZE_BUTTON);
- break;
- }
-
- data = g_new0 (struct SetButtonImageData, 1);
- data->path_bar = path_bar;
- data->button_data = button_data;
-
- if (button_data->cancellable)
- g_cancellable_cancel (button_data->cancellable);
-
- button_data->cancellable =
- _gtk_file_system_get_info (path_bar->priv->file_system,
- path_bar->priv->desktop_file,
- "standard::symbolic-icon",
- set_button_image_get_info_cb,
- data);
+ case PROP_HIDE_DIRECTION:
+ g_value_set_int (value, priv->hide_direction);
break;
default:
- break;
- }
-}
-
-static void
-button_data_free (ButtonData *button_data)
-{
- if (button_data->file)
- g_object_unref (button_data->file);
- button_data->file = NULL;
-
- g_free (button_data->dir_name);
- button_data->dir_name = NULL;
-
- button_data->button = NULL;
-
- if (button_data->cancellable)
- g_cancellable_cancel (button_data->cancellable);
- else
- g_free (button_data);
-}
-
-static const char *
-get_dir_name (ButtonData *button_data)
-{
- return button_data->dir_name;
-}
-
-static void
-gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
- ButtonData *button_data,
- gboolean current_dir)
-{
- const gchar *dir_name = get_dir_name (button_data);
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (button_data->button);
-
- gtk_style_context_remove_class (context, "text-button");
- gtk_style_context_remove_class (context, "image-button");
-
- if (button_data->label != NULL)
- {
- gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
- if (button_data->image == NULL)
- gtk_style_context_add_class (context, "text-button");
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
-
- if (button_data->image != NULL)
- {
- set_button_image (path_bar, button_data);
- if (button_data->label == NULL)
- gtk_style_context_add_class (context, "image-button");
- }
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
- {
- button_data->ignore_changes = TRUE;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
- button_data->ignore_changes = FALSE;
- }
-}
-
-static ButtonType
-find_button_type (GtkPathBar *path_bar,
- GFile *file)
-{
- if (path_bar->priv->root_file != NULL &&
- g_file_equal (file, path_bar->priv->root_file))
- return ROOT_BUTTON;
- if (path_bar->priv->home_file != NULL &&
- g_file_equal (file, path_bar->priv->home_file))
- return HOME_BUTTON;
- if (path_bar->priv->desktop_file != NULL &&
- g_file_equal (file, path_bar->priv->desktop_file))
- return DESKTOP_BUTTON;
-
- return NORMAL_BUTTON;
}
static void
-button_drag_data_get_cb (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint time_,
- gpointer data)
+gtk_path_bar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- ButtonData *button_data;
- char *uris[2];
-
- button_data = data;
-
- uris[0] = g_file_get_uri (button_data->file);
- uris[1] = NULL;
-
- gtk_selection_data_set_uris (selection_data, uris);
+ GtkPathBar *self = GTK_PATH_BAR (object);
- g_free (uris[0]);
-}
-
-static ButtonData *
-make_directory_button (GtkPathBar *path_bar,
- const char *dir_name,
- GFile *file,
- gboolean current_dir,
- gboolean file_is_hidden)
-{
- AtkObject *atk_obj;
- GtkWidget *child = NULL;
- ButtonData *button_data;
-
- file_is_hidden = !! file_is_hidden;
- /* Is it a special button? */
- button_data = g_new0 (ButtonData, 1);
-
- button_data->type = find_button_type (path_bar, file);
- button_data->button = gtk_toggle_button_new ();
- atk_obj = gtk_widget_get_accessible (button_data->button);
- gtk_widget_set_focus_on_click (button_data->button, FALSE);
- gtk_widget_add_events (button_data->button, GDK_SCROLL_MASK);
-
- switch (button_data->type)
+ switch (prop_id)
{
- case ROOT_BUTTON:
- button_data->image = gtk_image_new ();
- child = button_data->image;
- button_data->label = NULL;
- atk_object_set_name (atk_obj, _("File System Root"));
+ case PROP_PATH:
+ gtk_path_bar_set_path (self, g_value_get_string (value));
break;
- case HOME_BUTTON:
- case DESKTOP_BUTTON:
- button_data->image = gtk_image_new ();
- button_data->label = gtk_label_new (NULL);
- child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
+ case PROP_HIDE_DIRECTION:
+ gtk_path_bar_set_hide_direction (self, g_value_get_int (value));
break;
- case NORMAL_BUTTON:
default:
- button_data->label = gtk_label_new (NULL);
- child = button_data->label;
- button_data->image = NULL;
- }
-
- button_data->dir_name = g_strdup (dir_name);
- button_data->file = g_object_ref (file);
- button_data->file_is_hidden = file_is_hidden;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static GtkSizeRequestMode
+get_request_mode (GtkWidget *self)
+{
+ return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
+static void
+gtk_path_bar_class_init (GtkPathBarClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = gtk_path_bar_finalize;
+ object_class->get_property = gtk_path_bar_get_property;
+ object_class->set_property = gtk_path_bar_set_property;
+
+ widget_class->get_request_mode = get_request_mode;
+
+ /**
+ * GtkPlacesSidebar::populate-popup:
+ * @sidebar: the object which received the signal.
+ * @container: (type Gtk.Widget): a #GtkMenu or another #GtkContainer
+ * @selected_item: (type Gio.File) (nullable): #GFile with the item to which the popup should refer, or
#NULL in the case of a @selected_volume.
+ * @selected_volume: (type Gio.Volume) (nullable): #GVolume if the selected item is a volume, or #NULL if
it is a file.
+ *
+ * The places sidebar emits this signal when the user invokes a contextual
+ * popup on one of its items. In the signal handler, the application may
+ * add extra items to the menu as appropriate. For example, a file manager
+ * may want to add a "Properties" command to the menu.
+ *
+ * It is not necessary to store the @selected_item for each menu item;
+ * during their callbacks, the application can use gtk_places_sidebar_get_location()
+ * to get the file to which the item refers.
+ *
+ * The @selected_item argument may be %NULL in case the selection refers to
+ * a volume. In this case, @selected_volume will be non-%NULL. In this case,
+ * the calling application will have to g_object_ref() the @selected_volume and
+ * keep it around to use it in the callback.
+ *
+ * The @container and all its contents are destroyed after the user
+ * dismisses the popup. The popup is re-created (and thus, this signal is
+ * emitted) every time the user activates the contextual menu.
+ *
+ * Before 3.18, the @container always was a #GtkMenu, and you were expected
+ * to add your items as #GtkMenuItems. Since 3.18, the popup may be implemented
+ * as a #GtkPopover, in which case @container will be something else, e.g. a
+ * #GtkBox, to which you may add #GtkModelButtons or other widgets, such as
+ * #GtkEntries, #GtkSpinButtons, etc. If your application can deal with this
+ * situation, you can set #GtkPlacesSidebar::populate-all to %TRUE to request
+ * that this signal is emitted for populating popovers as well.
+ *
+ * Since: 3.10
+ */
+ path_bar_signals [POPULATE_POPUP] =
+ g_signal_new (I_("populate-popup"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkPathBarClass, populate_popup),
+ NULL, NULL,
+ _gtk_marshal_VOID__OBJECT_STRING,
+ G_TYPE_NONE, 2,
+ GTK_TYPE_WIDGET,
+ G_TYPE_STRING);
- gtk_container_add (GTK_CONTAINER (button_data->button), child);
- gtk_widget_show_all (button_data->button);
+ path_bar_signals [PATH_SELECTED] =
+ g_signal_new (I_("path-selected"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkPathBarClass, path_selected),
+ NULL, NULL,
+ _gtk_marshal_VOID__OBJECT_STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
- gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
+ path_bar_properties[PROP_PATH] =
+ g_param_spec_string ("path",
+ P_("Path"),
+ P_("The path managed by the path bar. Should use UNIX path specs"),
+ NULL,
+ G_PARAM_READWRITE);
- g_signal_connect (button_data->button, "clicked",
- G_CALLBACK (button_clicked_cb),
- button_data);
- g_object_weak_ref (G_OBJECT (button_data->button),
- (GWeakNotify) button_data_free, button_data);
+ path_bar_properties[PROP_HIDE_DIRECTION] =
+ g_param_spec_int ("hide-direction",
+ P_("Hide direction"),
+ P_("From where the container will start hiding widgets when there is not enough
space"),
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE);
- gtk_drag_source_set (button_data->button,
- GDK_BUTTON1_MASK,
- NULL, 0,
- GDK_ACTION_COPY);
- gtk_drag_source_add_uri_targets (button_data->button);
- g_signal_connect (button_data->button, "drag-data-get",
- G_CALLBACK (button_drag_data_get_cb), button_data);
+ g_object_class_install_properties (object_class, LAST_PROP, path_bar_properties);
- return button_data;
-}
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkpathbar.ui");
-static gboolean
-gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
- GFile *file)
-{
- GList *list;
- GList *current_path = NULL;
- gboolean need_new_fake_root = FALSE;
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_bar_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_bar_2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_button_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_button_2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_box_1);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, path_box_2);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_popover);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkPathBar, overflow_container);
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- ButtonData *button_data;
-
- button_data = list->data;
- if (g_file_equal (file, button_data->file))
- {
- current_path = list;
- break;
- }
- if (list == path_bar->priv->fake_root)
- need_new_fake_root = TRUE;
- }
+ gtk_widget_class_bind_template_callback (widget_class, populate_overflow_popover);
- if (current_path)
- {
- if (need_new_fake_root)
- {
- path_bar->priv->fake_root = NULL;
- for (list = current_path; list; list = list->next)
- {
- ButtonData *button_data;
-
- button_data = list->data;
- if (BUTTON_IS_FAKE_ROOT (button_data))
- {
- path_bar->priv->fake_root = list;
- break;
- }
- }
- }
-
- for (list = path_bar->priv->button_list; list; list = list->next)
- {
- gtk_path_bar_update_button_appearance (path_bar,
- BUTTON_DATA (list->data),
- (list == current_path) ? TRUE : FALSE);
- }
-
- if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
- {
- path_bar->priv->first_scrolled_button = current_path;
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
- }
-
- return TRUE;
- }
- return FALSE;
+ gtk_widget_class_set_css_name (widget_class, "path-bar");
}
-
-struct SetFileInfo
-{
- GFile *file;
- GFile *parent_file;
- GtkPathBar *path_bar;
- GList *new_buttons;
- GList *fake_root;
- gboolean first_directory;
-};
-
static void
-gtk_path_bar_set_file_finish (struct SetFileInfo *info,
- gboolean result)
+gtk_path_bar_init (GtkPathBar *self)
{
- if (result)
- {
- GList *l;
+ GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (self);
- gtk_path_bar_clear_buttons (info->path_bar);
- info->path_bar->priv->button_list = g_list_reverse (info->new_buttons);
- info->path_bar->priv->fake_root = info->fake_root;
+ g_type_ensure (GTK_TYPE_PATH_BAR_CONTAINER);
+ gtk_widget_init_template (GTK_WIDGET (self));
- for (l = info->path_bar->priv->button_list; l; l = l->next)
- {
- GtkWidget *button = BUTTON_DATA (l->data)->button;
- gtk_container_add (GTK_CONTAINER (info->path_bar), button);
- }
-
- child_ordering_changed (info->path_bar);
- }
- else
- {
- GList *l;
+ priv->selecting_path = FALSE;
+ priv->hide_direction = GTK_DIR_RIGHT;
+}
- for (l = info->new_buttons; l; l = l->next)
- {
- ButtonData *button_data;
+void
+gtk_path_bar_set_path (GtkPathBar *self,
+ const gchar *path)
+{
+ GtkPathBarPrivate *priv;
+ gchar ** splitted_path;
+ GString *current_path = NULL;
+ GtkWidget *path_chunk;
+ PathChunkData *data;
+ GList *children;
+ GtkWidget *path_box;
+ GtkWidget *overflow_button;
+ GtkWidget *path_bar;
- button_data = BUTTON_DATA (l->data);
- gtk_widget_destroy (button_data->button);
- }
+ g_return_if_fail (GTK_IS_PATH_BAR (self));
- g_list_free (info->new_buttons);
- }
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- if (info->file)
- g_object_unref (info->file);
- if (info->parent_file)
- g_object_unref (info->parent_file);
+ if (g_strcmp0 (priv->path, path) == 0)
+ return;
- g_free (info);
-}
+ get_path_bar_widgets (GTK_PATH_BAR (self), &path_bar, &overflow_button, &path_box, FALSE);
-static void
-gtk_path_bar_get_info_callback (GCancellable *cancellable,
- GFileInfo *info,
- const GError *error,
- gpointer data)
-{
- gboolean cancelled = g_cancellable_is_cancelled (cancellable);
- struct SetFileInfo *file_info = data;
- ButtonData *button_data;
- const gchar *display_name;
- gboolean is_hidden;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->overflow_button_1), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->overflow_button_2), FALSE);
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- return;
+ gtk_container_foreach (GTK_CONTAINER (path_box), (GtkCallback) gtk_widget_destroy, NULL);
- if (cancellable != file_info->path_bar->priv->get_info_cancellable)
+ if (priv->path)
{
- gtk_path_bar_set_file_finish (file_info, FALSE);
- g_object_unref (cancellable);
- return;
+ g_free (priv->path);
+ priv->path = NULL;
}
- g_object_unref (cancellable);
- file_info->path_bar->priv->get_info_cancellable = NULL;
+ splitted_path = g_strsplit (path, "/", -1);
+ current_path = g_string_new ("");
- if (cancelled || !info)
+ for (guint i = 0; i < g_strv_length (splitted_path); i++)
{
- gtk_path_bar_set_file_finish (file_info, FALSE);
- return;
- }
-
- display_name = g_file_info_get_display_name (info);
- is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+ if (g_strcmp0 (splitted_path[i], "") == 0)
+ continue;
- button_data = make_directory_button (file_info->path_bar, display_name,
- file_info->file,
- file_info->first_directory, is_hidden);
- g_object_unref (file_info->file);
-
- file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
-
- if (BUTTON_IS_FAKE_ROOT (button_data))
- file_info->fake_root = file_info->new_buttons;
-
- /* We have assigned the info for the innermost button, i.e. the deepest directory.
- * Now, go on to fetch the info for this directory's parent.
- */
-
- file_info->file = file_info->parent_file;
- file_info->first_directory = FALSE;
+ g_string_append (current_path, "/");
+ g_string_append (current_path, splitted_path[i]);
+ path_chunk = create_path_chunk (self, current_path, splitted_path[i], TRUE);
+ gtk_container_add (GTK_CONTAINER (path_box), path_chunk);
+ data = g_object_get_data (G_OBJECT (path_chunk), "data");
+ }
- if (!file_info->file)
+ children = gtk_container_get_children (GTK_CONTAINER (path_box));
+ if (children != NULL)
{
- /* No parent? Okay, we are done. */
- gtk_path_bar_set_file_finish (file_info, TRUE);
- return;
+ path_chunk = GTK_WIDGET (g_list_last (children)->data);
+ data = g_object_get_data (G_OBJECT (path_chunk), "data");
+ priv->selecting_path = TRUE;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->button), TRUE);
+ priv->selecting_path = FALSE;
+ priv->path = g_strdup (data->path->str);
}
- file_info->parent_file = g_file_get_parent (file_info->file);
+ gtk_stack_set_visible_child (GTK_STACK (self), path_bar);
+ g_object_notify_by_pspec (G_OBJECT (self), path_bar_properties[PROP_PATH]);
- /* Recurse asynchronously */
- file_info->path_bar->priv->get_info_cancellable =
- _gtk_file_system_get_info (file_info->path_bar->priv->file_system,
- file_info->file,
- "standard::display-name,standard::is-hidden,standard::is-backup",
- gtk_path_bar_get_info_callback,
- file_info);
+ g_strfreev (splitted_path);
+ g_string_free (current_path, TRUE);
+ g_list_free (children);
}
void
-_gtk_path_bar_set_file (GtkPathBar *path_bar,
- GFile *file,
- gboolean keep_trail)
+gtk_path_bar_select_path (GtkPathBar *self,
+ const gchar *path)
{
- struct SetFileInfo *info;
-
- g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
- g_return_if_fail (G_IS_FILE (file));
+ GtkPathBarPrivate *priv;
+ PathChunkData *data;
+ GList *children;
+ GList *l;
+ GtkWidget *path_box;
- /* Check whether the new path is already present in the pathbar as buttons.
- * This could be a parent directory or a previous selected subdirectory.
- */
- if (keep_trail && gtk_path_bar_check_parent_path (path_bar, file))
- return;
+ g_return_if_fail (GTK_IS_PATH_BAR (self));
- info = g_new0 (struct SetFileInfo, 1);
- info->file = g_object_ref (file);
- info->path_bar = path_bar;
- info->first_directory = TRUE;
- info->parent_file = g_file_get_parent (info->file);
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- if (path_bar->priv->get_info_cancellable)
- g_cancellable_cancel (path_bar->priv->get_info_cancellable);
+ g_return_if_fail (g_str_has_prefix (priv->path, path));
- path_bar->priv->get_info_cancellable =
- _gtk_file_system_get_info (path_bar->priv->file_system,
- info->file,
- "standard::display-name,standard::is-hidden,standard::is-backup",
- gtk_path_bar_get_info_callback,
- info);
+ get_path_bar_widgets (GTK_PATH_BAR (self), NULL, NULL, &path_box, TRUE);
+ children = gtk_container_get_children (GTK_CONTAINER (path_box));
+ for (l = children; l != NULL; l = l->next)
+ {
+ data = g_object_get_data (G_OBJECT (l->data), "data");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->button),
+ g_strcmp0 (data->path->str, path) == 0);
+ }
+ g_list_free (children);
}
-/* FIXME: This should be a construct-only property */
void
-_gtk_path_bar_set_file_system (GtkPathBar *path_bar,
- GtkFileSystem *file_system)
+gtk_path_bar_set_hide_direction (GtkPathBar *self,
+ GtkDirectionType hide_direction)
{
- const char *home;
-
- g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
+ GtkPathBarPrivate *priv ;
- g_assert (path_bar->priv->file_system == NULL);
+ g_return_if_fail (GTK_IS_PATH_BAR (self));
+ g_return_if_fail (hide_direction == GTK_DIR_LEFT || hide_direction == GTK_DIR_RIGHT);
- path_bar->priv->file_system = g_object_ref (file_system);
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
- home = g_get_home_dir ();
- if (home != NULL)
- {
- const gchar *desktop;
-
- path_bar->priv->home_file = g_file_new_for_path (home);
- /* FIXME: Need file system backend specific way of getting the
- * Desktop path.
- */
- desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
- if (desktop != NULL)
- path_bar->priv->desktop_file = g_file_new_for_path (desktop);
- else
- path_bar->priv->desktop_file = NULL;
- }
- else
+ if (gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box_1)) != hide_direction)
{
- path_bar->priv->home_file = NULL;
- path_bar->priv->desktop_file = NULL;
+ gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box_1), hide_direction);
+ gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box_2), hide_direction);
+
+ g_object_notify (G_OBJECT (self), "hide-direction");
+
+ gtk_widget_queue_resize (GTK_WIDGET (self));
}
- path_bar->priv->root_file = g_file_new_for_path ("/");
}
-/**
- * _gtk_path_bar_up:
- * @path_bar: a #GtkPathBar
- *
- * If the selected button in the pathbar is not the furthest button “up” (in the
- * root direction), act as if the user clicked on the next button up.
- **/
-void
-_gtk_path_bar_up (GtkPathBar *path_bar)
+GtkDirectionType
+gtk_path_bar_get_hide_direction (GtkPathBar *self)
{
- GList *l;
+ GtkPathBarPrivate *priv ;
- for (l = path_bar->priv->button_list; l; l = l->next)
- {
- GtkWidget *button = BUTTON_DATA (l->data)->button;
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- {
- if (l->next)
- {
- GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
- button_clicked_cb (next_button, l->next->data);
- }
- break;
- }
- }
+ g_return_val_if_fail (GTK_IS_PATH_BAR (self), 0);
+
+ priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+
+ return gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box_1));
}
-/**
- * _gtk_path_bar_down:
- * @path_bar: a #GtkPathBar
- *
- * If the selected button in the pathbar is not the furthest button “down” (in the
- * leaf direction), act as if the user clicked on the next button down.
- **/
-void
-_gtk_path_bar_down (GtkPathBar *path_bar)
+GtkWidget *
+gtk_path_bar_new (void)
{
- GList *l;
-
- for (l = path_bar->priv->button_list; l; l = l->next)
- {
- GtkWidget *button = BUTTON_DATA (l->data)->button;
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- {
- if (l->prev)
- {
- GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
- button_clicked_cb (prev_button, l->prev->data);
- }
- break;
- }
- }
+ return g_object_new (GTK_TYPE_PATH_BAR, NULL);
}
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index 7fdd7b3..73a2777 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -1,67 +1,88 @@
/* gtkpathbar.h
- * Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb gnome org>
*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Copyright (C) 2015 Red Hat
*
- * This library is distributed in the hope that it will be useful,
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ * Authors: Carlos Soriano <csoriano gnome org>
*/
#ifndef __GTK_PATH_BAR_H__
#define __GTK_PATH_BAR_H__
-#include "gtkcontainer.h"
-#include "gtkfilesystem.h"
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkstack.h>
G_BEGIN_DECLS
-typedef struct _GtkPathBar GtkPathBar;
-typedef struct _GtkPathBarClass GtkPathBarClass;
+#define GTK_TYPE_PATH_BAR (gtk_path_bar_get_type())
+#define GTK_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PATH_BAR, GtkPathBar))
+#define GTK_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PATH_BAR, GtkPathBarClass))
+#define GTK_IS_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PATH_BAR))
+#define GTK_IS_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PATH_BAR)
+#define GTK_PATH_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PATH_BAR, GtkPathBarClass))
+
+typedef struct _GtkPathBar GtkPathBar;
+typedef struct _GtkPathBarClass GtkPathBarClass;
typedef struct _GtkPathBarPrivate GtkPathBarPrivate;
+struct _GtkPathBarClass
+{
+ GtkStackClass parent;
-#define GTK_TYPE_PATH_BAR (gtk_path_bar_get_type ())
-#define GTK_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PATH_BAR, GtkPathBar))
-#define GTK_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PATH_BAR,
GtkPathBarClass))
-#define GTK_IS_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PATH_BAR))
-#define GTK_IS_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PATH_BAR))
-#define GTK_PATH_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PATH_BAR,
GtkPathBarClass))
+ /*< public >*/
-struct _GtkPathBar
-{
- GtkContainer parent;
+ void (* populate_popup) (GtkPathBar *path_bar,
+ const gchar *selected_path);
+ void (* path_selected) (GtkPathBar *path_bar,
+ const gchar *selected_path);
- GtkPathBarPrivate *priv;
+ /*< private >*/
+
+ /* Padding for future expansion */
+ gpointer reserved[10];
};
-struct _GtkPathBarClass
+struct _GtkPathBar
{
- GtkContainerClass parent_class;
-
- void (* path_clicked) (GtkPathBar *path_bar,
- GFile *file,
- GFile *child_file,
- gboolean child_is_hidden);
+ GtkStack parent_instance;
};
-GDK_AVAILABLE_IN_ALL
-GType gtk_path_bar_get_type (void) G_GNUC_CONST;
-void _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
- GtkFileSystem *file_system);
-void _gtk_path_bar_set_file (GtkPathBar *path_bar,
- GFile *file,
- gboolean keep_trail);
-void _gtk_path_bar_up (GtkPathBar *path_bar);
-void _gtk_path_bar_down (GtkPathBar *path_bar);
+GDK_AVAILABLE_IN_3_20
+GType gtk_path_bar_get_type (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_20
+GtkWidget* gtk_path_bar_new (void);
+GDK_AVAILABLE_IN_3_20
+void gtk_path_bar_set_path (GtkPathBar *path_bar,
+ const gchar *path);
+GDK_AVAILABLE_IN_3_20
+void gtk_path_bar_select_path (GtkPathBar *path_bar,
+ const gchar *path);
+GDK_AVAILABLE_IN_3_20
+const gchar* gtk_path_bar_get_path (GtkPathBar *path_bar);
+GDK_AVAILABLE_IN_3_20
+void gtk_path_bar_set_hide_direction (GtkPathBar *path_bar,
+ GtkDirectionType hide_direction);
+GDK_AVAILABLE_IN_3_20
+GtkDirectionType gtk_path_bar_get_hide_direction (GtkPathBar *path_bar);
+
+
G_END_DECLS
#endif /* __GTK_PATH_BAR_H__ */
+
diff --git a/gtk/gtkpathbarcontainer.c b/gtk/gtkpathbarcontainer.c
new file mode 100644
index 0000000..a7ab9a6
--- /dev/null
+++ b/gtk/gtkpathbarcontainer.c
@@ -0,0 +1,231 @@
+/* gtkpathbarcontainer.c
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Carlos Soriano <csoriano gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkpathbarcontainerprivate.h"
+#include "gtkbuildable.h"
+#include "gtkwidget.h"
+#include "gtkmenubutton.h"
+#include "gtksizerequest.h"
+#include "gtkhidingboxprivate.h"
+#include "gtkwidgetprivate.h"
+
+struct _GtkPathBarContainerPrivate
+{
+ GtkWidget *overflow_button;
+ GtkWidget *path_box;
+};
+
+static GtkBuildableIface *parent_buildable_iface;
+
+static GObject *
+buildable_get_internal_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const gchar *childname)
+{
+ if (g_strcmp0 (childname, "overflow_button") == 0)
+ return G_OBJECT (gtk_path_bar_container_get_overflow_button (GTK_PATH_BAR_CONTAINER (buildable)));
+ if (g_strcmp0 (childname, "path_box") == 0)
+ return G_OBJECT (gtk_path_bar_container_get_path_box (GTK_PATH_BAR_CONTAINER (buildable)));
+
+ return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
+
+static void
+buildable_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+ iface->get_internal_child = buildable_get_internal_child;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GtkPathBarContainer, gtk_path_bar_container, GTK_TYPE_CONTAINER,
+ G_ADD_PRIVATE (GtkPathBarContainer)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_init))
+static void
+container_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (GTK_PATH_BAR_CONTAINER
(container));
+
+ (* callback) (priv->overflow_button, callback_data);
+ (* callback) (priv->path_box, callback_data);
+}
+
+static GtkSizeRequestMode
+get_request_mode (GtkWidget *self)
+{
+ return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
+}
+
+static void
+size_allocate (GtkWidget *self,
+ GtkAllocation *allocation)
+{
+ GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (GTK_PATH_BAR_CONTAINER
(self));
+ gint path_min_width;
+ gint path_nat_width;
+ gint overflow_button_min_width;
+ GtkAllocation path_container_allocation;
+ GtkAllocation overflow_button_allocation;
+ GtkTextDirection direction;
+ gboolean overflow;
+ GList *overflow_children;
+ GList *children;
+
+ gtk_widget_set_allocation (self, allocation);
+
+ children = gtk_container_get_children (GTK_CONTAINER (priv->path_box));
+ gtk_widget_set_child_visible (priv->overflow_button, FALSE);
+
+ if (g_list_length (children) == 0)
+ return;
+
+ gtk_widget_get_preferred_width (priv->path_box, &path_min_width, &path_nat_width);
+ gtk_widget_get_preferred_width (priv->overflow_button, &overflow_button_min_width, NULL);
+
+ /* Try to allocate all children with our allocation so we can request if there
+ * is some overflow children */
+ path_container_allocation.x = allocation->x;
+ path_container_allocation.width = allocation->width;
+ path_container_allocation.y = allocation->y;
+ path_container_allocation.height = allocation->height;
+ gtk_widget_size_allocate (priv->path_box, &path_container_allocation);
+ overflow_children = gtk_hiding_box_get_overflow_children (GTK_HIDING_BOX (priv->path_box));
+ overflow = overflow_children != NULL;
+ g_list_free (overflow_children);
+
+ direction = gtk_widget_get_direction (self);
+
+ if (overflow && direction == GTK_TEXT_DIR_LTR)
+ {
+ overflow_button_allocation.y = allocation->y;
+ overflow_button_allocation.height = allocation->height;
+ overflow_button_allocation.width = overflow_button_min_width;
+ overflow_button_allocation.x = allocation->x;
+ gtk_widget_set_child_visible (priv->overflow_button, TRUE);
+ gtk_widget_size_allocate (priv->overflow_button, &overflow_button_allocation);
+ }
+
+ path_container_allocation.x = overflow ? allocation->x + overflow_button_min_width
+ : allocation->x;
+ path_container_allocation.width = overflow ? allocation->width - overflow_button_min_width
+ : allocation->width;
+ path_container_allocation.y = allocation->y;
+ path_container_allocation.height = allocation->height;
+ gtk_widget_size_allocate (priv->path_box, &path_container_allocation);
+
+ if (overflow && direction == GTK_TEXT_DIR_RTL)
+ {
+ overflow_button_allocation.y = allocation->y;
+ overflow_button_allocation.height = allocation->height;
+ overflow_button_allocation.width = overflow_button_min_width;
+ overflow_button_allocation.x = path_container_allocation.x +
+ path_container_allocation.width -
+ overflow_button_min_width;
+ gtk_widget_set_child_visible (priv->overflow_button, TRUE);
+ gtk_widget_size_allocate (priv->overflow_button, &overflow_button_allocation);
+ }
+
+ _gtk_widget_set_simple_clip (self, NULL);
+
+ g_list_free (children);
+}
+
+static void
+get_preferred_width (GtkWidget *self,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (GTK_PATH_BAR_CONTAINER
(self));
+
+ gtk_widget_get_preferred_width (priv->path_box, minimum_width, natural_width);
+}
+
+static void
+get_preferred_height (GtkWidget *self,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (GTK_PATH_BAR_CONTAINER
(self));
+
+ gtk_widget_get_preferred_height (priv->path_box, minimum_height, natural_height);
+}
+
+static void
+gtk_path_bar_container_class_init (GtkPathBarContainerClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+ widget_class->get_request_mode = get_request_mode;
+ widget_class->get_preferred_width = get_preferred_width;
+ widget_class->get_preferred_height = get_preferred_height;
+ widget_class->size_allocate = size_allocate;
+
+ // Neccesary to draw and realize children
+ container_class->forall = container_forall;
+}
+
+static void
+gtk_path_bar_container_init (GtkPathBarContainer *self)
+{
+ GtkPathBarContainerPrivate *priv = gtk_path_bar_container_get_instance_private (self);
+
+ gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+
+ priv->overflow_button = gtk_menu_button_new ();
+ priv->path_box = gtk_hiding_box_new ();
+
+ gtk_widget_set_parent (priv->overflow_button, GTK_WIDGET (self));
+ gtk_widget_set_parent (priv->path_box, GTK_WIDGET (self));
+}
+
+GtkWidget *
+gtk_path_bar_container_new (void)
+{
+ return g_object_new (GTK_TYPE_PATH_BAR_CONTAINER, NULL);
+}
+
+GtkWidget *
+gtk_path_bar_container_get_overflow_button (GtkPathBarContainer *self)
+{
+ GtkPathBarContainerPrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_PATH_BAR_CONTAINER (self), NULL);
+
+ priv = gtk_path_bar_container_get_instance_private (self);
+
+ return priv->overflow_button;
+}
+
+GtkWidget *
+gtk_path_bar_container_get_path_box (GtkPathBarContainer *self)
+{
+ GtkPathBarContainerPrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_PATH_BAR_CONTAINER (self), NULL);
+
+ priv = gtk_path_bar_container_get_instance_private (self);
+
+ return priv->path_box;
+}
diff --git a/gtk/gtkpathbarcontainerprivate.h b/gtk/gtkpathbarcontainerprivate.h
new file mode 100644
index 0000000..4042a04
--- /dev/null
+++ b/gtk/gtkpathbarcontainerprivate.h
@@ -0,0 +1,66 @@
+/* gtkpathbarcontainerprivate.h
+ *
+ * Copyright (C) 2015 Red Hat
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Carlos Soriano <csoriano gnome org>
+ */
+
+#ifndef __GTK_PATH_BAR_CONTAINER_PRIVATE_H__
+#define __GTK_PATH_BAR_CONTAINER_PRIVATE_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkcontainer.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_PATH_BAR_CONTAINER (gtk_path_bar_container_get_type())
+#define GTK_PATH_BAR_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_TYPE_PATH_BAR_CONTAINER, GtkPathBarContainer))
+#define GTK_PATH_BAR_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_TYPE_PATH_BAR_CONTAINER, GtkPathBarContainerClass))
+#define GTK_IS_PATH_BAR_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_TYPE_PATH_BAR_CONTAINER))
+#define GTK_IS_PATH_BAR_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_TYPE_PATH_BAR_CONTAINER)
+#define GTK_PATH_BAR_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_TYPE_PATH_BAR_CONTAINER, GtkPathBarContainerClass))
+
+typedef struct _GtkPathBarContainer GtkPathBarContainer;
+typedef struct _GtkPathBarContainerClass GtkPathBarContainerClass;
+typedef struct _GtkPathBarContainerPrivate GtkPathBarContainerPrivate;
+
+struct _GtkPathBarContainerClass
+{
+ GtkContainerClass parent;
+
+ /* Padding for future expansion */
+ gpointer reserved[10];
+};
+
+struct _GtkPathBarContainer
+{
+ GtkContainer parent_instance;
+};
+
+GType gtk_path_bar_container_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gtk_path_bar_container_new (void);
+
+GtkWidget *gtk_path_bar_container_get_path_box (GtkPathBarContainer
*path_bar_container);
+
+GtkWidget *gtk_path_bar_container_get_overflow_button (GtkPathBarContainer
*path_bar_container);
+
+G_END_DECLS
+
+#endif /* GTK_PATH_BAR_CONTAINER_PRIVATE_H_ */
diff --git a/gtk/makefile.msc.in b/gtk/makefile.msc.in
index 78a5244..fcce86b 100644
--- a/gtk/makefile.msc.in
+++ b/gtk/makefile.msc.in
@@ -446,6 +446,7 @@ gtk_public_h_sources = \
gtkpagesetup.h \
gtkpaned.h \
gtkpapersize.h \
+ gtkpathbar.h \
gtkplug.h \
gtkprintcontext.h \
gtkprintoperation.h \
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index ee3e978..9736117 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -1245,20 +1245,23 @@ headerbar {
* Pathbars *
************/
-.path-bar button {
- padding: 5px 6px 6px;
- &:first-child { padding-left: 8px; }
- &:last-child { padding-right: 8px; }
- &:only-child {
- padding-left: 12px;
- padding-right: 12px;
- }
+path-bar button.flat, .path-bar-overflow-popover button.flat {
+ background-image: none;
+ border-radius: 0px;
+ border-top-color: transparent;
+ border-width: 2px 0px 2px 0px;
+ box-shadow: 0px 0px 0px;
+ margin: 0px;
+ opacity: 0.55;
+ padding: 3px 8px 4px;
- // the following is for spacing the icon and the label inside the home button
- & label:last-child { padding-left: 2px; }
- & label:first-child { padding-right: 2px; }
- & label:only-child { padding-right: 0; padding-left: 0; }
- image { padding-top: 1px; }
+ &:hover {
+ border-bottom-color: mix($selected_bg_color, $selected_fg_color, 75%);
+ }
+
+ &:checked {
+ border-bottom-color: $selected_bg_color;
+ }
}
/**************
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 4bd1214..2575749 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -1865,28 +1865,31 @@ headerbar {
/************
* Pathbars *
************/
-.path-bar button, .path-bar headerbar button.titlebutton, headerbar .path-bar button.titlebutton,
-.path-bar .titlebar button.titlebutton,
-.titlebar .path-bar button.titlebutton {
- padding: 5px 6px 6px; }
- .path-bar button:first-child {
- padding-left: 8px; }
- .path-bar button:last-child {
- padding-right: 8px; }
- .path-bar button:only-child {
- padding-left: 12px;
- padding-right: 12px; }
- .path-bar button label:last-child {
- padding-left: 2px; }
- .path-bar button label:first-child {
- padding-right: 2px; }
- .path-bar button label:only-child {
- padding-right: 0;
- padding-left: 0; }
- .path-bar button image,
- .path-bar .titlebar button.titlebutton image,
- .titlebar .path-bar button.titlebutton image {
- padding-top: 1px; }
+path-bar button.flat, path-bar .sidebar-button.button, path-bar headerbar button.titlebutton, headerbar
path-bar button.titlebutton,
+path-bar .titlebar button.titlebutton,
+.titlebar path-bar button.titlebutton, .path-bar-overflow-popover button.flat, .path-bar-overflow-popover
.sidebar-button.button, .path-bar-overflow-popover headerbar button.titlebutton, headerbar
.path-bar-overflow-popover button.titlebutton,
+.path-bar-overflow-popover .titlebar button.titlebutton,
+.titlebar .path-bar-overflow-popover button.titlebutton {
+ background-image: none;
+ border-radius: 0px;
+ border-top-color: transparent;
+ border-width: 2px 0px 2px 0px;
+ box-shadow: 0px 0px 0px;
+ margin: 0px;
+ opacity: 0.55;
+ padding: 3px 8px 4px; }
+ path-bar button.flat:hover, path-bar .sidebar-button.button:hover, path-bar headerbar
button.titlebutton:hover, headerbar path-bar button.titlebutton:hover,
+ path-bar .titlebar button.titlebutton:hover,
+ .titlebar path-bar button.titlebutton:hover, .path-bar-overflow-popover button.flat:hover,
.path-bar-overflow-popover .sidebar-button.button:hover, .path-bar-overflow-popover headerbar
button.titlebutton:hover, headerbar .path-bar-overflow-popover button.titlebutton:hover,
+ .path-bar-overflow-popover .titlebar button.titlebutton:hover,
+ .titlebar .path-bar-overflow-popover button.titlebutton:hover {
+ border-bottom-color: #5986b5; }
+ path-bar button.flat:checked, path-bar .sidebar-button.button:checked, path-bar headerbar
button.titlebutton:checked, headerbar path-bar button.titlebutton:checked,
+ path-bar .titlebar button.titlebutton:checked,
+ .titlebar path-bar button.titlebutton:checked, .path-bar-overflow-popover button.flat:checked,
.path-bar-overflow-popover .sidebar-button.button:checked, .path-bar-overflow-popover headerbar
button.titlebutton:checked, headerbar .path-bar-overflow-popover button.titlebutton:checked,
+ .path-bar-overflow-popover .titlebar button.titlebutton:checked,
+ .titlebar .path-bar-overflow-popover button.titlebutton:checked {
+ border-bottom-color: #215d9c; }
/**************
* Tree Views *
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 9724733..a50f929 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -1865,28 +1865,31 @@ headerbar {
/************
* Pathbars *
************/
-.path-bar button, .path-bar headerbar button.titlebutton, headerbar .path-bar button.titlebutton,
-.path-bar .titlebar button.titlebutton,
-.titlebar .path-bar button.titlebutton {
- padding: 5px 6px 6px; }
- .path-bar button:first-child {
- padding-left: 8px; }
- .path-bar button:last-child {
- padding-right: 8px; }
- .path-bar button:only-child {
- padding-left: 12px;
- padding-right: 12px; }
- .path-bar button label:last-child {
- padding-left: 2px; }
- .path-bar button label:first-child {
- padding-right: 2px; }
- .path-bar button label:only-child {
- padding-right: 0;
- padding-left: 0; }
- .path-bar button image,
- .path-bar .titlebar button.titlebutton image,
- .titlebar .path-bar button.titlebutton image {
- padding-top: 1px; }
+path-bar button.flat, path-bar .sidebar-button.button, path-bar headerbar button.titlebutton, headerbar
path-bar button.titlebutton,
+path-bar .titlebar button.titlebutton,
+.titlebar path-bar button.titlebutton, .path-bar-overflow-popover button.flat, .path-bar-overflow-popover
.sidebar-button.button, .path-bar-overflow-popover headerbar button.titlebutton, headerbar
.path-bar-overflow-popover button.titlebutton,
+.path-bar-overflow-popover .titlebar button.titlebutton,
+.titlebar .path-bar-overflow-popover button.titlebutton {
+ background-image: none;
+ border-radius: 0px;
+ border-top-color: transparent;
+ border-width: 2px 0px 2px 0px;
+ box-shadow: 0px 0px 0px;
+ margin: 0px;
+ opacity: 0.55;
+ padding: 3px 8px 4px; }
+ path-bar button.flat:hover, path-bar .sidebar-button.button:hover, path-bar headerbar
button.titlebutton:hover, headerbar path-bar button.titlebutton:hover,
+ path-bar .titlebar button.titlebutton:hover,
+ .titlebar path-bar button.titlebutton:hover, .path-bar-overflow-popover button.flat:hover,
.path-bar-overflow-popover .sidebar-button.button:hover, .path-bar-overflow-popover headerbar
button.titlebutton:hover, headerbar .path-bar-overflow-popover button.titlebutton:hover,
+ .path-bar-overflow-popover .titlebar button.titlebutton:hover,
+ .titlebar .path-bar-overflow-popover button.titlebutton:hover {
+ border-bottom-color: #77ace3; }
+ path-bar button.flat:checked, path-bar .sidebar-button.button:checked, path-bar headerbar
button.titlebutton:checked, headerbar path-bar button.titlebutton:checked,
+ path-bar .titlebar button.titlebutton:checked,
+ .titlebar path-bar button.titlebutton:checked, .path-bar-overflow-popover button.flat:checked,
.path-bar-overflow-popover .sidebar-button.button:checked, .path-bar-overflow-popover headerbar
button.titlebutton:checked, headerbar .path-bar-overflow-popover button.titlebutton:checked,
+ .path-bar-overflow-popover .titlebar button.titlebutton:checked,
+ .titlebar .path-bar-overflow-popover button.titlebutton:checked {
+ border-bottom-color: #4a90d9; }
/**************
* Tree Views *
diff --git a/gtk/ui/gtkpathbar.ui b/gtk/ui/gtkpathbar.ui
index d9a433d..c73bf59 100644
--- a/gtk/ui/gtkpathbar.ui
+++ b/gtk/ui/gtkpathbar.ui
@@ -1,54 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
- <!-- interface-requires gtk+ 3.10 -->
- <object class="GtkButton" id="down_slider_button">
- <property name="visible">1</property>
- <property name="can_focus">1</property>
- <property name="receives_default">1</property>
- <property name="focus_on_click">0</property>
- <child internal-child="accessible">
- <object class="AtkObject" id="down_slider_button-atkobject">
- <property name="AtkObject::accessible-name" translatable="yes">Down Path</property>
- </object>
- </child>
- <signal name="button-press-event" handler="gtk_path_bar_slider_button_press" swapped="no"/>
- <signal name="button-release-event" handler="gtk_path_bar_slider_button_release" swapped="no"/>
- <signal name="focus-out-event" handler="gtk_path_bar_slider_down_defocus" swapped="no"/>
- <signal name="unmap" handler="on_slider_unmap" swapped="no"/>
- <child>
- <object class="GtkImage">
- <property name="visible">1</property>
- <property name="icon-name">pan-end-symbolic</property>
- <property name="icon-size">1</property>
- </object>
- </child>
+ <object class="GtkPopover" id="overflow_popover">
+ <property name="width-request">200</property>
+ <child>
+ <object class="GtkBox" id="overflow_container">
+ <property name="visible">true</property>
+ <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+ </object>
+ </child>
<style>
- <class name="image-button"/>
+ <class name="path-bar-overflow-popover"/>
</style>
</object>
- <object class="GtkButton" id="up_slider_button">
- <property name="visible">1</property>
- <property name="can_focus">1</property>
- <property name="receives_default">1</property>
- <property name="focus_on_click">0</property>
- <child internal-child="accessible">
- <object class="AtkObject" id="up_slider_button-atkobject">
- <property name="AtkObject::accessible-name" translatable="yes">Up Path</property>
+ <template class="GtkPathBar" parent="GtkStack">
+ <property name="visible">true</property>
+ <property name="valign">GTK_ALIGN_START</property>
+ <property name="vexpand">false</property>
+ <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
+ <property name="transition-duration">150</property>
+ <child>
+ <object class="GtkPathBarContainer" id="path_bar_1">
+ <property name="visible">true</property>
+ <child internal-child="overflow_button">
+ <object class="GtkMenuButton" id="overflow_button_1">
+ <property name="visible">true</property>
+ <property name="popover">overflow_popover</property>
+ <signal name="clicked" handler="populate_overflow_popover" object="GtkPathBar" swapped="yes"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon_name">image-loading-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="flat"/>
+ </style>
+ </object>
+ </child>
+ <child internal-child="path_box">
+ <object class="GtkHidingBox" id="path_box_1">
+ <property name="visible">true</property>
+ </object>
+ </child>
</object>
</child>
- <signal name="button-press-event" handler="gtk_path_bar_slider_button_press" swapped="no"/>
- <signal name="button-release-event" handler="gtk_path_bar_slider_button_release" swapped="no"/>
- <signal name="focus-out-event" handler="gtk_path_bar_slider_up_defocus" swapped="no"/>
- <signal name="unmap" handler="on_slider_unmap" swapped="no"/>
<child>
- <object class="GtkImage">
- <property name="visible">1</property>
- <property name="icon-name">pan-start-symbolic</property>
- <property name="icon-size">1</property>
+ <object class="GtkPathBarContainer" id="path_bar_2">
+ <property name="visible">true</property>
+ <child internal-child="overflow_button">
+ <object class="GtkMenuButton" id="overflow_button_2">
+ <property name="visible">true</property>
+ <property name="popover">overflow_popover</property>
+ <signal name="clicked" handler="populate_overflow_popover" object="GtkPathBar" swapped="yes"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon_name">image-loading-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="flat"/>
+ </style>
+ </object>
+ </child>
+ <child internal-child="path_box">
+ <object class="GtkHidingBox" id="path_box_2">
+ <property name="visible">true</property>
+ </object>
+ </child>
</object>
</child>
<style>
- <class name="image-button"/>
+ <class name="path-bar"/>
</style>
- </object>
+ </template>
</interface>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 50f2986..447a1f8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -106,6 +106,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testorientable \
testoverlay \
testoverlaystyleclass \
+ testpathbar \
testprint \
testrecentchooser \
testrecentchoosermenu \
@@ -301,6 +302,7 @@ testanimation_DEPENDENCIES = $(TEST_DEPS)
testpixbuf_save_DEPENDENCIES = $(TEST_DEPS)
testpixbuf_color_DEPENDENCIES = $(TEST_DEPS)
testpixbuf_scale_DEPENDENCIES = $(TEST_DEPS)
+testpathbar_DEPENDENCIES = $(TEST_DEPS)
testgmenu_DEPENDENCIES = $(TEST_DEPS)
testlogout_DEPENDENCIES = $(TEST_DEPS)
teststack_DEPENDENCIES = $(TEST_DEPS)
@@ -399,6 +401,9 @@ testtoolbar_SOURCES = \
testmenubutton_SOURCES = \
testmenubutton.c
+testpathbar_SOURCES = \
+ testpathbar.c
+
testprint_SOURCES = \
testprint.c \
testprintfileoperation.h \
diff --git a/tests/testpathbar.c b/tests/testpathbar.c
new file mode 100644
index 0000000..4ddc3c2
--- /dev/null
+++ b/tests/testpathbar.c
@@ -0,0 +1,166 @@
+#include "config.h"
+#include "glib.h"
+#include <gtk/gtk.h>
+
+static GActionGroup *action_group;
+static GList *path_bars = NULL;
+static const gchar* original_path = "/test/test 2/test 3/asda lkasdl//pppppppppppppppp/ alskd/";
+
+static void
+action_menu_1 (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_print ("Menu 1 action\n");
+}
+
+static void
+action_menu_2 (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_print ("Menu 2 action\n");
+}
+
+static void
+action_special (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_print ("Special action\n");
+}
+
+const GActionEntry entries[] = {
+ { "menu_1", action_menu_1 },
+ { "menu_2", action_menu_2 },
+ { "special", action_special },
+};
+
+static void
+on_populate_popup (GtkPathBar *path_bar,
+ GtkWidget *container,
+ const gchar *selected_path)
+{
+ GtkWidget *menu_item;
+
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "action_group.menu_1");
+ g_object_set (menu_item, "text", "Menu 1", NULL);
+ g_print ("container %s\n", G_OBJECT_TYPE_NAME (container));
+ gtk_container_add (GTK_CONTAINER (container), menu_item);
+
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "action_group.menu_2");
+ g_object_set (menu_item, "text", "Menu 2", NULL);
+ gtk_container_add (GTK_CONTAINER (container), menu_item);
+
+ if (g_strcmp0 (selected_path, "/test/test 2/test 3") == 0)
+ {
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "action_group.special");
+ g_object_set (menu_item, "text", "Special", NULL);
+ gtk_container_add (GTK_CONTAINER (container), menu_item);
+ }
+
+ gtk_widget_show_all (container);
+
+ g_print ("Populate popup\n");
+}
+
+static void
+on_path_selected (GtkPathBar *path_bar,
+ const gchar *path)
+{
+ g_print ("Path selected: %s\n", path);
+}
+
+static void
+on_path_selected_set_path (GtkPathBar *path_bar,
+ const gchar *path)
+{
+ g_print ("Path selected: %s, setting path to GtkPathBar\n", path);
+ gtk_path_bar_set_path (path_bar, path);
+}
+
+static void
+on_reset_button_clicked (GtkButton *reset_button)
+{
+ GList *l;
+
+ for (l = path_bars; l != NULL; l = l->next)
+ gtk_path_bar_set_path (l->data, original_path);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window;
+ GtkWidget *path_bar;
+ GtkWidget *box;
+ GtkWidget *reset_button;
+
+ gtk_init (&argc, &argv);
+
+ window = g_object_connect (g_object_new (gtk_window_get_type (),
+ "type", GTK_WINDOW_TOPLEVEL,
+ "title", "Test path bar",
+ "resizable", TRUE,
+ "default-height", 200,
+ NULL),
+ "signal::destroy", gtk_main_quit, NULL,
+ NULL);
+
+ action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+ g_action_map_add_action_entries (G_ACTION_MAP (action_group), entries,
+ G_N_ELEMENTS (entries), window);
+
+ gtk_widget_insert_action_group (window, "action_group", action_group);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
+ g_type_ensure (GTK_TYPE_PATH_BAR);
+ path_bar = gtk_path_bar_new ();
+ gtk_container_add (GTK_CONTAINER (box), path_bar);
+ gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), original_path);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "populate-popup",
+ G_CALLBACK (on_populate_popup), window);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "path-selected",
+ G_CALLBACK (on_path_selected), window);
+ path_bars = g_list_append (path_bars, path_bar);
+
+ path_bar = gtk_path_bar_new ();
+ gtk_container_add (GTK_CONTAINER (box), path_bar);
+ gtk_path_bar_set_hide_direction (GTK_PATH_BAR (path_bar), GTK_DIR_LEFT);
+ gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), original_path);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "populate-popup",
+ G_CALLBACK (on_populate_popup), window);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "path-selected",
+ G_CALLBACK (on_path_selected), window);
+ path_bars = g_list_append (path_bars, path_bar);
+
+ path_bar = gtk_path_bar_new ();
+ gtk_container_add (GTK_CONTAINER (box), path_bar);
+ gtk_path_bar_set_hide_direction (GTK_PATH_BAR (path_bar), GTK_DIR_LEFT);
+ gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), original_path);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "populate-popup",
+ G_CALLBACK (on_populate_popup), window);
+ g_signal_connect (GTK_PATH_BAR (path_bar), "path-selected",
+ G_CALLBACK (on_path_selected_set_path), window);
+ path_bars = g_list_append (path_bars, path_bar);
+
+ reset_button = gtk_button_new_with_label ("Reset State");
+ gtk_widget_set_hexpand (reset_button, TRUE);
+ gtk_container_add (GTK_CONTAINER (box), reset_button);
+ g_signal_connect (GTK_BUTTON (reset_button), "clicked",
+ G_CALLBACK (on_reset_button_clicked), window);
+
+ gtk_container_add (GTK_CONTAINER (window), box);
+ gtk_widget_show_all (window);
+
+
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]