[d-spy] treeview: handle right/left arrows



commit b71e480e9f7402bb30debf74d32c8b7b5e652e5f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 5 13:52:18 2021 -0700

    treeview: handle right/left arrows
    
    This is a bit more graceful in how left/right arrows are handled.

 lib/dspy-tree-view.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
---
diff --git a/lib/dspy-tree-view.c b/lib/dspy-tree-view.c
index 6ebd732..d8071ac 100644
--- a/lib/dspy-tree-view.c
+++ b/lib/dspy-tree-view.c
@@ -282,6 +282,36 @@ dspy_tree_view_row_expanded (GtkTreeView *view,
     }
 }
 
+static gboolean
+dspy_tree_view_move_cursor (GtkTreeView     *tree_view,
+                            GtkMovementStep  step,
+                            int              count,
+                            gboolean         extend,
+                            gboolean         modify)
+{
+  g_assert (GTK_IS_TREE_VIEW (tree_view));
+
+  if (step == GTK_MOVEMENT_VISUAL_POSITIONS)
+    {
+      g_autoptr(GtkTreePath) path = NULL;
+
+      gtk_tree_view_get_cursor (tree_view, &path, NULL);
+
+      if (count == 1)
+        {
+          gtk_tree_view_expand_row (tree_view, path, FALSE);
+          return TRUE;
+        }
+      else if (count == -1)
+        {
+          gtk_tree_view_collapse_row (tree_view, path);
+          return TRUE;
+        }
+    }
+
+  return GTK_TREE_VIEW_CLASS (dspy_tree_view_parent_class)->move_cursor (tree_view, step, count, extend, 
modify);
+}
+
 static void
 dspy_tree_view_class_init (DspyTreeViewClass *klass)
 {
@@ -289,6 +319,7 @@ dspy_tree_view_class_init (DspyTreeViewClass *klass)
 
   tree_view_class->row_activated = dspy_tree_view_row_activated;
   tree_view_class->row_expanded = dspy_tree_view_row_expanded;
+  tree_view_class->move_cursor = dspy_tree_view_move_cursor;
 
   signals [METHOD_ACTIVATED] =
     g_signal_new ("method-activated",


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