[Xfce4-commits] <xfce4-settings:master> Don't permit selection on non-app rows in chooser.

Nick Schermer noreply at xfce.org
Sat Jan 21 22:16:14 CET 2012


Updating branch refs/heads/master
         to c16d1710c0ce6a73a884d4f172d1f7f467200415 (commit)
       from 1f2c8879d68446bc2543e0fbceb00fc437029fc3 (commit)

commit c16d1710c0ce6a73a884d4f172d1f7f467200415
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Jan 21 21:59:46 2012 +0100

    Don't permit selection on non-app rows in chooser.

 dialogs/mime-settings/xfce-mime-chooser.c |   33 +++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/dialogs/mime-settings/xfce-mime-chooser.c b/dialogs/mime-settings/xfce-mime-chooser.c
index a2d5fb1..07e24d9 100644
--- a/dialogs/mime-settings/xfce-mime-chooser.c
+++ b/dialogs/mime-settings/xfce-mime-chooser.c
@@ -43,6 +43,11 @@ static void     xfce_mime_chooser_row_activated     (GtkTreeView       *tree_vie
                                                      GtkTreePath       *path,
                                                      GtkTreeViewColumn *column,
                                                      XfceMimeChooser   *chooser);
+static gboolean xfce_mime_chooser_row_can_select    (GtkTreeSelection  *selection,
+                                                     GtkTreeModel      *model,
+                                                     GtkTreePath       *path,
+                                                     gboolean           path_currently_selected,
+                                                     gpointer           data);
 static void     xfce_mime_chooser_update_accept     (XfceMimeChooser   *chooser);
 static void     xfce_mime_chooser_notify_expanded   (GtkExpander       *expander,
                                                      GParamSpec        *pspec,
@@ -172,6 +177,8 @@ xfce_mime_chooser_init (XfceMimeChooser *chooser)
     chooser->treeview = treeview;
 
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+    gtk_tree_selection_set_select_function (selection,
+        xfce_mime_chooser_row_can_select, NULL, NULL);
     g_signal_connect_swapped (G_OBJECT (selection), "changed",
         G_CALLBACK (xfce_mime_chooser_update_accept), chooser);
 
@@ -268,6 +275,32 @@ xfce_mime_chooser_row_activated (GtkTreeView       *tree_view,
 
 
 
+static gboolean
+xfce_mime_chooser_row_can_select (GtkTreeSelection  *selection,
+                                  GtkTreeModel      *model,
+                                  GtkTreePath       *path,
+                                  gboolean           path_currently_selected,
+                                  gpointer           data)
+{
+    gboolean    permitted = TRUE;
+    GtkTreeIter iter;
+    GValue      value = { 0, };
+
+    /* we can always change the selection if the path is already selected */
+    if (G_UNLIKELY (!path_currently_selected))
+    {
+        /* check if there's an application for the path */
+        gtk_tree_model_get_iter (model, &iter, path);
+        gtk_tree_model_get_value (model, &iter, CHOOSER_COLUMN_APP_INFO, &value);
+        permitted = (g_value_get_object (&value) != NULL);
+        g_value_unset (&value);
+    }
+
+    return permitted;
+}
+
+
+
 static void
 xfce_mime_chooser_update_accept (XfceMimeChooser *chooser)
 {


More information about the Xfce4-commits mailing list