[gtk+/places-sidebar] New public function to get the selected location from menu item callbacks



commit 8dd233dfaca63616b12b0711ac8b2b534d782654
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Dec 17 20:05:23 2012 -0600

    New public function to get the selected location from menu item callbacks
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkplacessidebar.c |   38 ++++++++++++++++++++++++++++++++++++++
 gtk/gtkplacessidebar.h |    2 ++
 2 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 1133958..7ede59b 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -3807,6 +3807,44 @@ gtk_places_sidebar_set_current_location (GtkPlacesSidebar *sidebar, GFile *locat
 }
 
 /**
+ * gtk_places_sidebar_get_selected_location:
+ * @sidebar: a places sidebar
+ *
+ * When you connect to the populate-popup signal for the @sidebar, the callback functions
+ * for your menu items will need to know the file to which the contextual menu refers.  Use
+ * this function to obtain that file's location.
+ *
+ * Returns: a GFile with the selected location, or #NULL if nothing is visually selected.
+ * It may be the case that the sidebar doesn't have anything visually selected because
+ * the location being shown in the sidebar's surrounding widgets is not actually
+ * in the list of places that the sidebar shows.  In that case, use
+ * gtk_places_sidebar_get_current_location().
+ */
+GFile *
+gtk_places_sidebar_get_selected_location (GtkPlacesSidebar *sidebar)
+{
+	GtkTreeIter iter;
+	GFile *file;
+
+	g_return_val_if_fail (sidebar != NULL, NULL);
+
+	file = NULL;
+
+	if (get_selected_iter (sidebar, &iter)) {
+		char *uri;
+
+		gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
+				    PLACES_SIDEBAR_COLUMN_URI, &uri,
+				    -1);
+
+		file = g_file_new_for_uri (uri);
+		g_free (uri);
+	}
+
+	return file;
+}
+
+/**
  * gtk_places_sidebar_set_show_desktop:
  * @sidebar: a places sidebar
  * @show_desktop: whether to show an item for the Desktop folder
diff --git a/gtk/gtkplacessidebar.h b/gtk/gtkplacessidebar.h
index 15f70a4..8d1fef3 100644
--- a/gtk/gtkplacessidebar.h
+++ b/gtk/gtkplacessidebar.h
@@ -57,6 +57,8 @@ GtkWidget *gtk_places_sidebar_new (void);
 
 void gtk_places_sidebar_set_current_location (GtkPlacesSidebar *sidebar, GFile *location);
 
+GFile *gtk_places_sidebar_get_selected_location (GtkPlacesSidebar *sidebar);
+
 void gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_desktop);
 
 void gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash);



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