Make the gtkut_tree_view_get_selected_pointer() more versatile.
authorAndrej Kacian <ticho@claws-mail.org>
Tue, 27 Feb 2018 19:19:37 +0000 (20:19 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 27 Feb 2018 19:19:37 +0000 (20:19 +0100)
It can now be used also for non-trivial use cases, where
the caller needs to further work with the model and/or
selection, or if a string value needs to be read from the
model.

src/gtk/gtkutils.c
src/gtk/gtkutils.h

index 689af37..47b76df 100644 (file)
@@ -1991,12 +1991,14 @@ gboolean auto_configure_service_sync(const gchar *service, const gchar *domain,
 #endif
 
 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
-               gint column)
+               gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
+               GtkTreeIter *_iter)
 {
        GtkTreeIter iter;
        GtkTreeModel *model;
        GtkTreeSelection *sel;
        gpointer ptr;
+       GType type;
 
        cm_return_val_if_fail(view != NULL, NULL);
        cm_return_val_if_fail(column >= 0, NULL);
@@ -2013,11 +2015,20 @@ gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
        cm_return_val_if_fail(
                        gtk_tree_model_get_n_columns(model) > column,
                        NULL);
+
+       type = gtk_tree_model_get_column_type(model, column);
        cm_return_val_if_fail(
-                       gtk_tree_model_get_column_type(model, column) == G_TYPE_POINTER,
+                       type == G_TYPE_POINTER || type == G_TYPE_STRING,
                        NULL);
 
        gtk_tree_model_get(model, &iter, column, &ptr, -1);
 
+       if (_model != NULL)
+               *_model = model;
+       if (_selection != NULL)
+               *_selection = sel;
+       if (_iter != NULL)
+               *_iter = iter;
+
        return ptr;
 }
index eaf0fb0..592e575 100644 (file)
@@ -233,9 +233,15 @@ gboolean auto_configure_service_sync(const gchar *service, const gchar *domain,
 #endif
 
 /* Returns pointer stored in selected row of a tree view's model
- * in a given column. The column has to be of type G_TYPE_POINTER. */
+ * in a given column. The column has to be of type G_TYPE_POINTER
+ * or G_TYPE_STRING (in this case, the returned value has to be
+ * freed by the caller.
+ * _model, _selection and _iter parameters are optional, and if
+ * not NULL, they will be set to point to corresponding GtkTreeModel,
+ * GtkTreeSelection, and GtkTreeIter of the selected row. */
 gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
-               gint column);
+               gint column, GtkTreeModel **_model, GtkTreeSelection **_selection,
+               GtkTreeIter *_iter);
 
 #if GTK_CHECK_VERSION (3, 2, 0)
 #define GTK_TYPE_VBOX GTK_TYPE_BOX