[gtk+/pathbar: 7/8] Add gtk_path_bar_get_location()



commit 82612ba291f82fa39ace57dde774766194e04133
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Apr 29 14:46:14 2013 -0500

    Add gtk_path_bar_get_location()
    
    The old state was stored implicitly in the path bar's buttons.  Now we keep
    an additional field in the object's structure that actually contains
    the currently-shown location.
    
    Also, with this commit the path bar acquires the capability of showing a NULL path,
    i.e. with no buttons at all.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkpathbar.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkpathbar.h |    1 +
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index faeb4a9..0e6fb4f 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -43,6 +43,7 @@ struct _GtkPathBarPrivate
   GtkPlacesOpenFlags open_flags;
 
   GtkFileSystem *file_system;
+  GFile *current_location;
   GFile *root_file;
   GFile *home_file;
   GFile *desktop_file;
@@ -375,6 +376,8 @@ gtk_path_bar_finalize (GObject *object)
   gtk_path_bar_stop_scrolling (path_bar);
 
   g_list_free (path_bar->priv->button_list);
+  if (path_bar->priv->current_location)
+    g_object_unref (path_bar->priv->current_location);
   if (path_bar->priv->root_file)
     g_object_unref (path_bar->priv->root_file);
   if (path_bar->priv->home_file)
@@ -1987,11 +1990,26 @@ gtk_path_bar_set_location (GtkPathBar *path_bar,
                           GFile      *location,
                           gboolean    keep_trail)
 {
+  GtkPathBarPrivate *priv;
   struct SetFileInfo *info;
 
   g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
   g_return_if_fail (G_IS_FILE (location));
 
+  priv = path_bar->priv;
+
+  if (priv->current_location)
+    g_object_unref (priv->current_location);
+
+  if (location)
+    priv->current_location = g_object_ref (location);
+  else
+    {
+      priv->current_location = NULL;
+      gtk_path_bar_clear_buttons (path_bar);
+      return;
+    }
+
   /* Check whether the new path is already present in the pathbar as buttons.
    * This could be a parent directory or a previous selected subdirectory.
    */
@@ -2015,6 +2033,30 @@ gtk_path_bar_set_location (GtkPathBar *path_bar,
                                info);
 }
 
+/**
+ * gtk_path_bar_get_location:
+ * @path_bar: a #GtkPathBar
+ *
+ * Return value: (transfer full): a #GFile with the location that the @path_bar
+ * is showing currently, or #NULL if no path is being shown at all.
+ *
+ * Since: 3.10
+ */
+GFile *
+gtk_path_bar_get_location (GtkPathBar *path_bar)
+{
+  GtkPathBarPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_PATH_BAR (path_bar), NULL);
+
+  priv = path_bar->priv;
+
+  if (priv->current_location)
+    return g_object_ref (priv->current_location);
+  else
+    return NULL;
+}
+
 /* FIXME: This should be a construct-only property */
 void
 _gtk_path_bar_set_file_system (GtkPathBar    *path_bar,
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index 6ca93a2..480b191 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -67,6 +67,7 @@ void gtk_path_bar_set_open_flags (GtkPathBar *path_bar, GtkPlacesOpenFlags flags
 void gtk_path_bar_set_location (GtkPathBar *path_bar,
                                GFile      *location,
                                gboolean    keep_trail);
+GFile *gtk_path_bar_get_location (GtkPathBar *path_bar);
 
 void     _gtk_path_bar_set_file_system (GtkPathBar         *path_bar,
                                        GtkFileSystem      *file_system);


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