[gtk+/wip/csoriano/pathbar-prototype: 44/46] Implement new GtkFilesPathBar and use it on GtkFileChooser



commit b63bd13071ea2410098c5f2cbc651d5b2d53291f
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Nov 19 00:38:54 2015 +0100

    Implement new GtkFilesPathBar and use it on GtkFileChooser

 gtk/Makefile.am                |    2 +
 gtk/gtk.h                      |    1 +
 gtk/gtkfilechooserwidget.c     |   32 ++--
 gtk/gtkfilespathbar.c          |  341 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkfilespathbar.h          |   83 ++++++++++
 gtk/ui/gtkfilechooserwidget.ui |    4 +-
 gtk/ui/gtkpathbar.ui           |    8 +-
 tests/testpathbar.c            |   69 +++++++-
 8 files changed, 513 insertions(+), 27 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 6054690..9bafddb 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -183,6 +183,7 @@ gtk_public_h_sources =              \
        gtkfilechoosernative.h  \
        gtkfilechooserwidget.h  \
        gtkfilefilter.h         \
+       gtkfilespathbar.h       \
        gtkfixed.h              \
        gtkflowbox.h            \
        gtkfontbutton.h         \
@@ -705,6 +706,7 @@ gtk_base_c_sources =                \
        gtkfilechooserutils.c   \
        gtkfilechooserwidget.c  \
        gtkfilefilter.c         \
+       gtkfilespathbar.c       \
        gtkfilesystem.c         \
        gtkfilesystemmodel.c    \
        gtkfixed.c              \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 029f640..3755c5c 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -100,6 +100,7 @@
 #include <gtk/gtkfilechoosernative.h>
 #include <gtk/gtkfilechooserwidget.h>
 #include <gtk/gtkfilefilter.h>
+#include <gtk/gtkfilespathbar.h>
 #include <gtk/gtkflowbox.h>
 #include <gtk/gtkfontbutton.h>
 #include <gtk/gtkfontchooser.h>
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index c852701..e31d0a4 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -48,7 +48,7 @@
 #include "gtkmessagedialog.h"
 #include "gtkmountoperation.h"
 #include "gtkpaned.h"
-#include "gtkpathbar.h"
+#include "gtkfilespathbar.h"
 #include "gtkplacessidebar.h"
 #include "gtkplacessidebarprivate.h"
 #include "gtkplacesviewprivate.h"
@@ -544,11 +544,9 @@ static void list_row_activated         (GtkTreeView           *tree_view,
 static void list_cursor_changed        (GtkTreeView           *treeview,
                                         GtkFileChooserWidget  *impl);
 
-static void path_bar_clicked (GtkPathBar            *path_bar,
-                              GFile                 *file,
-                              GFile                 *child,
-                              gboolean               child_is_hidden,
-                              GtkFileChooserWidget *impl);
+static void on_path_bar_file (GtkFilesPathBar            *path_bar,
+                              GParamSpec                 *pspec,
+                              GtkFileChooserWidget       *impl);
 
 static void update_cell_renderer_attributes (GtkFileChooserWidget *impl);
 
@@ -3018,7 +3016,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_files_path_bar_set_file (GTK_FILES_PATH_BAR (priv->browse_path_bar), file);
   g_object_unref (file);
 }
 
@@ -5466,7 +5464,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_files_path_bar_set_file (GTK_FILES_PATH_BAR (priv->browse_path_bar), data->file);
 
   if (priv->current_folder != data->file)
     {
@@ -7815,14 +7813,18 @@ list_row_activated (GtkTreeView          *tree_view,
 }
 
 static void
-path_bar_clicked (GtkPathBar           *path_bar,
-                  GFile                *file,
-                  GFile                *child_file,
-                  gboolean              child_is_hidden,
+on_path_bar_file (GtkFilesPathBar      *path_bar,
+                  GParamSpec           *pspec,
                   GtkFileChooserWidget *impl)
 {
+  GFile *file;
+
+  file = gtk_files_path_bar_get_file (path_bar);
+
+  /*
   if (child_file)
     pending_select_files_add (impl, child_file);
+   */
 
   if (!change_folder_and_display_error (impl, file, FALSE))
     return;
@@ -7831,8 +7833,10 @@ path_bar_clicked (GtkPathBar           *path_bar,
    * show hidden files so that ".baz" appears in the file list, as it will still
    * be shown in the path bar: "/foo/[bar]/.baz"
    */
+  /*
   if (child_is_hidden)
     g_object_set (impl, "show-hidden", TRUE, NULL);
+   */
 }
 
 static void
@@ -8468,7 +8472,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gtk_widget_class_bind_template_callback (widget_class, list_selection_changed);
   gtk_widget_class_bind_template_callback (widget_class, list_cursor_changed);
   gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed);
-  gtk_widget_class_bind_template_callback (widget_class, path_bar_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, on_path_bar_file);
   gtk_widget_class_bind_template_callback (widget_class, places_sidebar_open_location_cb);
   gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_error_message_cb);
   gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_other_locations_cb);
@@ -8602,7 +8606,7 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
   /* Ensure GTK+ private types used by the template
    * definition before calling gtk_widget_init_template()
    */
-  g_type_ensure (GTK_TYPE_PATH_BAR);
+  g_type_ensure (GTK_TYPE_FILES_PATH_BAR);
   g_type_ensure (GTK_TYPE_PLACES_VIEW);
 
   gtk_widget_init_template (GTK_WIDGET (impl));
diff --git a/gtk/gtkfilespathbar.c b/gtk/gtkfilespathbar.c
new file mode 100644
index 0000000..c496127
--- /dev/null
+++ b/gtk/gtkfilespathbar.c
@@ -0,0 +1,341 @@
+/* gtkfilespathbar.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 2 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 "gtkfilespathbar.h"
+#include "gtkpathbar.h"
+#include "gtkpopover.h"
+
+#include "gtkintl.h"
+#include "gtkmarshalers.h"
+#include "gtktypebuiltins.h"
+
+/**
+ * SECTION:gtkfilespathbar
+ * @Short_description: Widget that displays a path in UNIX format in a button-like manner
+ * @Title: GtkFilesPathBar
+ * @See_also: #GtkPathBar, #GtkFileChooser
+ *
+ * #GtkFilesPathBar is a stock widget that displays a path in UNIX format in a way that
+ * the user can interact with it, selecting part of it or providing menus for
+ * every part of the path.
+ *
+ * Given the usual big lenght of paths, it conveniently manages the overflow of it,
+ * hiding the parts of the path that doesn't have snouegh space to be displayed
+ * in a overflow popover
+ */
+
+struct _GtkFilesPathBarPrivate
+{
+  GtkWidget *path_bar;
+
+  GFile *file;
+  gboolean edit_mode_enabled;
+  GBinding *edit_mode_enabled_binding;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkFilesPathBar, gtk_files_path_bar, GTK_TYPE_BIN)
+
+enum {
+  POPULATE_POPUP,
+  LAST_SIGNAL
+};
+
+enum {
+  PROP_0,
+  PROP_FILE,
+  PROP_EDIT_MODE_ENABLED,
+  LAST_PROP
+};
+
+static GParamSpec *files_path_bar_properties[LAST_PROP] = { NULL, };
+static guint files_path_bar_signals[LAST_SIGNAL] = { 0 };
+
+static void
+on_path_bar_populate_popup (GtkPathBar      *path_bar,
+                            GtkWidget       *container,
+                            const gchar     *selected_path,
+                            GtkFilesPathBar *self)
+{
+  GFile *file;
+
+  file = g_file_new_for_path (selected_path);
+  g_signal_emit (self, files_path_bar_signals[POPULATE_POPUP], 0,
+                 container, file);
+}
+
+static void
+on_path_bar_selected_path (GtkPathBar      *path_bar,
+                           GParamSpec      *pspec,
+                           GtkFilesPathBar *self)
+{
+  GFile *file;
+
+  file = g_file_new_for_path (gtk_path_bar_get_selected_path (path_bar));
+
+  gtk_files_path_bar_set_file (self, file);
+
+  g_object_unref (file);
+}
+
+static void
+gtk_files_path_bar_finalize (GObject *object)
+{
+  GtkFilesPathBar *self = (GtkFilesPathBar *)object;
+  GtkFilesPathBarPrivate *priv = gtk_files_path_bar_get_instance_private (self);
+
+  g_clear_object (&priv->file);
+  g_clear_object (&priv->edit_mode_enabled_binding);
+
+  G_OBJECT_CLASS (gtk_files_path_bar_parent_class)->finalize (object);
+}
+
+static void
+gtk_files_path_bar_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GtkFilesPathBar *self = GTK_FILES_PATH_BAR (object);
+  GtkFilesPathBarPrivate *priv = gtk_files_path_bar_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      g_value_set_object (value, priv->file);
+      break;
+    case PROP_EDIT_MODE_ENABLED:
+      g_value_set_boolean (value, priv->edit_mode_enabled);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtk_files_path_bar_set_property (GObject      *object,
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
+{
+  GtkFilesPathBar *self = GTK_FILES_PATH_BAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_FILE:
+      gtk_files_path_bar_set_file (self, g_value_get_object (value));
+      break;
+    case PROP_EDIT_MODE_ENABLED:
+      gtk_files_path_bar_set_edit_mode_enabled (self, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gtk_files_path_bar_class_init (GtkFilesPathBarClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gtk_files_path_bar_finalize;
+  object_class->get_property = gtk_files_path_bar_get_property;
+  object_class->set_property = gtk_files_path_bar_set_property;
+
+  /**
+   * GtkFilesPathBar::populate-popup:
+   * @files_path_bar: the object which received the signal.
+   * @container: (type Gtk.Widget): a #GtkContainer
+   * @path: (type const gchar*): string of the path where the user performed a right click.
+   *
+   * The path bar 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.
+   *
+   * 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.
+   *
+   * Since: 3.20
+   */
+  files_path_bar_signals [POPULATE_POPUP] =
+          g_signal_new (I_("populate-popup"),
+                        G_OBJECT_CLASS_TYPE (object_class),
+                        G_SIGNAL_RUN_FIRST,
+                        G_STRUCT_OFFSET (GtkFilesPathBarClass, populate_popup),
+                        NULL, NULL,
+                        _gtk_marshal_VOID__OBJECT_STRING,
+                        G_TYPE_NONE, 2,
+                        GTK_TYPE_WIDGET,
+                        G_TYPE_STRING);
+
+  files_path_bar_properties[PROP_FILE] =
+          g_param_spec_object ("file",
+                               P_("File"),
+                               P_("The file set in the path bar."),
+                               G_TYPE_FILE,
+                               G_PARAM_READWRITE);
+
+  files_path_bar_properties[PROP_EDIT_MODE_ENABLED] =
+          g_param_spec_boolean ("edit-mode-enabled",
+                                P_("Edit mode enabled"),
+                                P_("Show an entry to edit the path in text mode"),
+                                FALSE,
+                                G_PARAM_READWRITE);
+
+  g_object_class_install_properties (object_class, LAST_PROP, files_path_bar_properties);
+
+  gtk_widget_class_set_css_name (widget_class, "files-path-bar");
+}
+
+static void
+gtk_files_path_bar_init (GtkFilesPathBar *self)
+{
+  GtkFilesPathBarPrivate *priv = gtk_files_path_bar_get_instance_private (self);
+
+  g_type_ensure (GTK_TYPE_FILES_PATH_BAR);
+
+  priv->path_bar = gtk_path_bar_new ();
+  gtk_widget_show (priv->path_bar);
+  g_signal_connect (GTK_PATH_BAR (priv->path_bar), "populate-popup",
+                    G_CALLBACK (on_path_bar_populate_popup), self);
+  g_signal_connect (GTK_PATH_BAR (priv->path_bar), "notify::selected-path",
+                    G_CALLBACK (on_path_bar_selected_path), self);
+  gtk_container_add (GTK_CONTAINER (self), priv->path_bar);
+
+  priv->edit_mode_enabled = FALSE;
+  g_object_bind_property (self, "edit-mode-enabled", priv->path_bar, "edit-mode-enabled", 
G_BINDING_SYNC_CREATE);
+}
+
+/**
+ * gtk_files_path_bar_get_file:
+ * @files_path_bar: a #GtkFilesPathBar
+ *
+ * Get the path represented by the files path bar
+ *
+ * Returns: (transfer none): The current #GFile.
+ *
+ * Since: 3.20
+ */
+GFile*
+gtk_files_path_bar_get_file (GtkFilesPathBar *self)
+{
+  GtkFilesPathBarPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_FILES_PATH_BAR (self), NULL);
+
+  priv = gtk_files_path_bar_get_instance_private (GTK_FILES_PATH_BAR (self));
+
+  return priv->file;
+}
+
+/**
+ * gtk_files_path_bar_set_file:
+ * @files_path_bar: a #GtkFilesPathBar
+ * @file: the #GFile.
+ *
+ * Set the #GFile represented by the path bar.
+ *
+ * Since: 3.20
+ */
+void
+gtk_files_path_bar_set_file (GtkFilesPathBar *self,
+                             GFile           *file)
+{
+  GtkFilesPathBarPrivate *priv;
+  gchar *uri;
+  gchar *path;
+
+  g_return_if_fail (GTK_IS_FILES_PATH_BAR (self));
+
+  priv = gtk_files_path_bar_get_instance_private (GTK_FILES_PATH_BAR (self));
+
+  if (priv->file && g_file_equal (priv->file, file))
+    return;
+
+  g_clear_object (&priv->file);
+  /* Use a new object to avoid complex debugging in applications */
+  uri = g_file_get_uri (file);
+  priv->file = g_file_new_for_uri (uri);
+  path = g_file_get_path (file);
+
+  gtk_path_bar_set_path (GTK_PATH_BAR (priv->path_bar), path);
+
+  g_object_notify_by_pspec (G_OBJECT (self), files_path_bar_properties[PROP_FILE]);
+
+  g_free (uri);
+  g_free (path);
+}
+
+/**
+ * gtk_files_path_bar_get_edit_mode_enabled:
+ * @files_path_bar: a #GtkFilesPathBar
+ *
+ * Returns %TRUE if the path bar is in edit mode.
+ *
+ * Since: 3.20
+ */
+gboolean
+gtk_files_path_bar_get_edit_mode_enabled (GtkFilesPathBar *self)
+{
+  GtkFilesPathBarPrivate *priv ;
+
+  g_return_val_if_fail (GTK_IS_FILES_PATH_BAR (self), FALSE);
+
+  priv = gtk_files_path_bar_get_instance_private (GTK_FILES_PATH_BAR (self));
+
+  return priv->edit_mode_enabled;
+}
+
+/**
+ * gtk_files_path_bar_set_edit_mode_enabled:
+ * @files_path_bar: a #GtkFilesPathBar
+ * @enable: %TRUE to enable the edit mode.
+ *
+ * Sets the files path bar in a text edit mode that allows to edit the path as text.
+ *
+ * Since: 3.20
+ */
+void
+gtk_files_path_bar_set_edit_mode_enabled (GtkFilesPathBar *self,
+                                    gboolean    enable)
+{
+  GtkFilesPathBarPrivate *priv ;
+
+  g_return_if_fail (GTK_IS_FILES_PATH_BAR (self));
+
+  priv = gtk_files_path_bar_get_instance_private (GTK_FILES_PATH_BAR (self));
+
+  if (priv->edit_mode_enabled != enable)
+    {
+      priv->edit_mode_enabled = enable;
+
+      g_object_notify (G_OBJECT (self), "edit-mode-enabled");
+    }
+}
+
+GtkWidget *
+gtk_files_path_bar_new (void)
+{
+  return g_object_new (GTK_TYPE_FILES_PATH_BAR, NULL);
+}
diff --git a/gtk/gtkfilespathbar.h b/gtk/gtkfilespathbar.h
new file mode 100644
index 0000000..498335f
--- /dev/null
+++ b/gtk/gtkfilespathbar.h
@@ -0,0 +1,83 @@
+/* gtkfilespathbar.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 2 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_FILES_PATH_BAR_H__
+#define __GTK_FILES_PATH_BAR_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkbin.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_FILES_PATH_BAR            (gtk_files_path_bar_get_type())
+#define GTK_FILES_PATH_BAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILES_PATH_BAR, 
GtkFilesPathBar))
+#define GTK_FILES_PATH_BAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILES_PATH_BAR, 
GtkFilesPathBarClass))
+#define GTK_IS_FILES_PATH_BAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILES_PATH_BAR))
+#define GTK_IS_FILES_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILES_PATH_BAR)
+#define GTK_FILES_PATH_BAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILES_PATH_BAR, 
GtkFilesPathBarClass))
+
+typedef struct _GtkFilesPathBar GtkFilesPathBar;
+typedef struct _GtkFilesPathBarClass GtkFilesPathBarClass;
+typedef struct _GtkFilesPathBarPrivate GtkFilesPathBarPrivate;
+
+struct _GtkFilesPathBarClass
+{
+  GtkBinClass parent;
+
+  /*< public >*/
+
+  void                (* populate_popup)              (GtkFilesPathBar       *files_path_bar,
+                                                       GFile                 *selected_file);
+  /*< private >*/
+
+  /* Padding for future expansion */
+  gpointer reserved[10];
+};
+
+struct _GtkFilesPathBar
+{
+  GtkBin parent_instance;
+};
+
+GDK_AVAILABLE_IN_3_20
+GType                 gtk_files_path_bar_get_type              (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_20
+GtkWidget*            gtk_files_path_bar_new                   (void);
+GDK_AVAILABLE_IN_3_20
+void                  gtk_files_path_bar_set_file              (GtkFilesPathBar       *files_path_bar,
+                                                                GFile                 *file);
+GDK_AVAILABLE_IN_3_20
+GFile*                gtk_files_path_bar_get_file              (GtkFilesPathBar       *files_path_bar);
+
+GDK_AVAILABLE_IN_3_20
+gboolean              gtk_files_path_bar_get_edit_mode_enabled (GtkFilesPathBar       *files_path_bar);
+
+GDK_AVAILABLE_IN_3_20
+void                  gtk_files_path_bar_set_edit_mode_enabled (GtkFilesPathBar       *files_path_bar,
+                                                                gboolean               enable);
+
+
+G_END_DECLS
+
+#endif /* __GTK_FILES_PATH_BAR_H__ */
diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui
index 0ddf34b..8fee0b9 100644
--- a/gtk/ui/gtkfilechooserwidget.ui
+++ b/gtk/ui/gtkfilechooserwidget.ui
@@ -55,9 +55,9 @@
                                 <property name="spacing">6</property>
                                 <property name="border_width">6</property>
                                 <child>
-                                  <object class="GtkPathBar" id="browse_path_bar">
+                                  <object class="GtkFilesPathBar" id="browse_path_bar">
                                     <property name="visible">True</property>
-                                    <signal name="path-clicked" handler="path_bar_clicked" after="yes" 
swapped="no"/>
+                                    <signal name="notify::file" handler="on_path_bar_file"/>
                                   </object>
                                   <packing>
                                     <property name="expand">1</property>
diff --git a/gtk/ui/gtkpathbar.ui b/gtk/ui/gtkpathbar.ui
index f4de916..bfd682b 100644
--- a/gtk/ui/gtkpathbar.ui
+++ b/gtk/ui/gtkpathbar.ui
@@ -28,7 +28,7 @@
     <child>
       <object class="GtkStack" id="main_stack">
         <property name="visible">true</property>
-        <property name="visible-child">path_bar_stack</property>
+        <property name="visible-child">path_bar_containers_stack</property>
         <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
         <child>
           <object class="GtkEntry" id="edit_entry">
@@ -38,14 +38,14 @@
           </object>
         </child>
         <child>
-          <object class="GtkStack" id="path_bar_stack">
+          <object class="GtkStack" id="path_bar_containers_stack">
             <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">
+              <object class="GtkPathBarContainer" id="path_bar_container_1">
                 <property name="visible">true</property>
                 <child internal-child="overflow_button">
                   <object class="GtkMenuButton" id="overflow_button_1">
@@ -72,7 +72,7 @@
               </object>
             </child>
             <child>
-              <object class="GtkPathBarContainer" id="path_bar_2">
+              <object class="GtkPathBarContainer" id="path_bar_container_2">
                 <property name="visible">true</property>
                 <child internal-child="overflow_button">
                   <object class="GtkMenuButton" id="overflow_button_2">
diff --git a/tests/testpathbar.c b/tests/testpathbar.c
index aa7b3a2..39a3a3f 100644
--- a/tests/testpathbar.c
+++ b/tests/testpathbar.c
@@ -4,7 +4,9 @@
 
 static GActionGroup *action_group;
 static GList *path_bars = NULL;
+static GList *files_path_bars = NULL;
 static const gchar* original_path = "/test/test 2/test 3/asda lkasdl//pppppppppppppppp/ alskd/";
+static const gchar* file_original_path = "/test/test 2/test 3/asda lkasdl/pppppppppppppppp/alskd/";
 
 static void
 action_menu_1 (GSimpleAction *action,
@@ -84,7 +86,7 @@ on_path_selected_set_path (GtkPathBar *path_bar,
 {
   gchar *selected_path;
 
-  selected_path = gtk_path_bar_get_selected_path (path_bar);
+  selected_path = g_strdup (gtk_path_bar_get_selected_path (path_bar));
   g_print ("Path selected: %s, setting path to GtkPathBar\n", selected_path);
   gtk_path_bar_set_path (path_bar, selected_path);
   g_free (selected_path);
@@ -94,19 +96,49 @@ static void
 on_reset_button_clicked (GtkButton *reset_button)
 {
   GList *l;
+  GFile *file;
+
+  file = g_file_new_for_path (file_original_path);
+
+  for (l = files_path_bars; l != NULL; l = l->next)
+    gtk_files_path_bar_set_file (l->data, file);
 
   for (l = path_bars; l != NULL; l = l->next)
     gtk_path_bar_set_path (l->data, original_path);
+
+  g_object_unref (file);
 }
 
 static void
-on_edit_mode_button_clicked (GtkButton  *reset_button,
-                             GtkPathBar *path_bar)
+on_path_bar_edit_mode_button_clicked (GtkButton  *reset_button,
+                                      GtkPathBar *path_bar)
 {
   gtk_path_bar_set_edit_mode_enabled (path_bar,
                                       !gtk_path_bar_get_edit_mode_enabled (path_bar));
 }
 
+static void
+on_files_path_bar_edit_mode_button_clicked (GtkButton  *reset_button,
+                                            GtkFilesPathBar *path_bar)
+{
+  gtk_files_path_bar_set_edit_mode_enabled (path_bar,
+                                            !gtk_files_path_bar_get_edit_mode_enabled (path_bar));
+}
+
+static void
+on_file_changed (GtkFilesPathBar *path_bar,
+                 GParamSpec      *pspec,
+                 gpointer        *user_data)
+{
+  GFile *file;
+  gchar *uri;
+
+  file = gtk_files_path_bar_get_file (path_bar);
+  uri = g_file_get_uri (file);
+  g_print ("File selected: %s in GtkFilesPathBar\n", uri);
+  g_free (uri);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -116,6 +148,7 @@ main (int argc, char *argv[])
   GtkWidget *reset_button;
   GtkWidget *edit_mode_button;
   GtkWidget *label;
+  GFile *file;
 
   gtk_init (&argc, &argv);
 
@@ -152,7 +185,7 @@ main (int argc, char *argv[])
   edit_mode_button = gtk_button_new_from_icon_name ("edit-symbolic", GTK_ICON_SIZE_MENU);
   gtk_widget_set_hexpand (edit_mode_button, FALSE);
   g_signal_connect (GTK_BUTTON (edit_mode_button), "clicked",
-                    G_CALLBACK (on_edit_mode_button_clicked), path_bar);
+                    G_CALLBACK (on_path_bar_edit_mode_button_clicked), path_bar);
   gtk_grid_attach (GTK_GRID (grid), edit_mode_button, 1, 1, 1, 1);
 
   path_bar = gtk_path_bar_new ();
@@ -168,7 +201,7 @@ main (int argc, char *argv[])
   edit_mode_button = gtk_button_new_from_icon_name ("edit-symbolic", GTK_ICON_SIZE_MENU);
   gtk_widget_set_hexpand (edit_mode_button, FALSE);
   g_signal_connect (GTK_BUTTON (edit_mode_button), "clicked",
-                    G_CALLBACK (on_edit_mode_button_clicked), path_bar);
+                    G_CALLBACK (on_path_bar_edit_mode_button_clicked), path_bar);
   gtk_grid_attach (GTK_GRID (grid), edit_mode_button, 1, 2, 1, 1);
 
   label = gtk_label_new ("File chooser use case test");
@@ -187,14 +220,36 @@ main (int argc, char *argv[])
   edit_mode_button = gtk_button_new_from_icon_name ("edit-symbolic", GTK_ICON_SIZE_MENU);
   gtk_widget_set_hexpand (edit_mode_button, FALSE);
   g_signal_connect (GTK_BUTTON (edit_mode_button), "clicked",
-                    G_CALLBACK (on_edit_mode_button_clicked), path_bar);
+                    G_CALLBACK (on_path_bar_edit_mode_button_clicked), path_bar);
   gtk_grid_attach (GTK_GRID (grid), edit_mode_button, 1, 4, 1, 1);
 
+  /* GtkFilesPathBar tests */
+  label = gtk_label_new ("GtkFilesPathBar tests");
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 2, 1);
+  path_bar = gtk_files_path_bar_new ();
+  file = g_file_new_for_path (file_original_path);
+  gtk_files_path_bar_set_file (GTK_FILES_PATH_BAR (path_bar), file);
+  g_signal_connect (GTK_FILES_PATH_BAR (path_bar), "populate-popup",
+                    G_CALLBACK (on_populate_popup), window);
+  g_signal_connect (GTK_FILES_PATH_BAR (path_bar), "notify::file",
+                    G_CALLBACK (on_file_changed), window);
+  files_path_bars = g_list_append (files_path_bars, path_bar);
+  gtk_grid_attach (GTK_GRID (grid), path_bar, 0, 6, 1, 1);
+
+  edit_mode_button = gtk_button_new_from_icon_name ("edit-symbolic", GTK_ICON_SIZE_MENU);
+  gtk_widget_set_hexpand (edit_mode_button, FALSE);
+  g_signal_connect (GTK_BUTTON (edit_mode_button), "clicked",
+                    G_CALLBACK (on_files_path_bar_edit_mode_button_clicked), path_bar);
+  gtk_grid_attach (GTK_GRID (grid), edit_mode_button, 1, 6, 1, 1);
+
+  g_clear_object (&file);
+
+  /* Reset button */
   reset_button = gtk_button_new_with_label ("Reset State");
   gtk_widget_set_hexpand (reset_button, TRUE);
   g_signal_connect (GTK_BUTTON (reset_button), "clicked",
                     G_CALLBACK (on_reset_button_clicked), window);
-  gtk_grid_attach (GTK_GRID (grid), reset_button, 0, 5, 2, 1);
+  gtk_grid_attach (GTK_GRID (grid), reset_button, 0, 7, 2, 1);
 
   gtk_container_add (GTK_CONTAINER (window), grid);
   gtk_widget_show_all (window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]