[baobab: 1/2] Add arrow key navigation to the treeview



commit bc5ae53115fbda68465a2d1620e8688627914d8f
Author: Harry Mallon <hjmallon gmail com>
Date:   Sun Oct 14 20:25:25 2018 +0100

    Add arrow key navigation to the treeview

 src/baobab-window.vala | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
---
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index c91bf46..656e4b3 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -421,6 +421,37 @@ namespace Baobab {
                 return false;
             });
 
+            treeview.key_press_event.connect ((event) => {
+                Gtk.TreeIter iter;
+                if (treeview.get_selection().get_selected (null, out iter)) {
+                    Gtk.TreePath path = treeview.model.get_path(iter);
+                    if (event.keyval == Gdk.Key.Right) {
+                        if (treeview.expand_row(path, false)) {
+                            return true;
+                        }
+                    }
+                    else if (event.keyval == Gdk.Key.Left) {
+                        if (treeview.collapse_row(path)) {
+                            return true;
+                        }
+                        else if (path.up()) {
+                            treeview.set_cursor(path, null, false);
+                            return true;
+                        }
+                    }
+                    else if (event.keyval == Gdk.Key.space) {
+                        if (treeview.expand_row(path, false)) {
+                            return true;
+                        }
+                        else if (treeview.collapse_row(path)) {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            });
+
             treeview.popup_menu.connect (() => {
                 return show_treeview_popup (treeview_popup_menu, null);
             });


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