[polari] roomList: Don't use action signals to move selection



commit 2a09b6b01531e8d8abf938809061bf61ba346d20
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Sep 16 22:31:25 2014 +0200

    roomList: Don't use action signals to move selection
    
    Deferring to built-in keynav has proved rather fragile, as evidenced
    by changes to GtkListBox internals breaking it when key focus was
    not already on the selected row. Just move the selection explicitly
    by index.

 src/roomList.js |   57 ++++++++++++++++++++++++++----------------------------
 1 files changed, 27 insertions(+), 30 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index c46f42f..dfe2b68 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -179,22 +179,27 @@ const RoomList = new Lang.Class({
         action = app.lookup_action('next-room');
         action.connect('activate', Lang.bind(this,
             function() {
-                this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, 1);
+                this._moveSelection(Gtk.DirectionType.DOWN);
             }));
         action = app.lookup_action('previous-room');
         action.connect('activate', Lang.bind(this,
             function() {
-                this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, -1);
+                this._moveSelection(Gtk.DirectionType.UP);
             }));
         action = app.lookup_action('first-room');
         action.connect('activate', Lang.bind(this,
             function() {
-                this._moveSelection(Gtk.MovementStep.BUFFER_ENDS, -1);
+                let row = this.widget.get_row_at_index(0);
+                if (row)
+                    this.widget.select_row(row);
             }));
         action = app.lookup_action('last-room');
         action.connect('activate', Lang.bind(this,
             function() {
-                this._moveSelection(Gtk.MovementStep.BUFFER_ENDS, 1);
+                let nRows = this._roomManager.roomCount;
+                let row = this.widget.get_row_at_index(nRows - 1);
+                if (row)
+                    this.widget.select_row(row);
             }));
         action = app.lookup_action('nth-room');
         action.connect('activate', Lang.bind(this,
@@ -202,9 +207,7 @@ const RoomList = new Lang.Class({
                 let n = param.get_int32();
                 if (n > this._roomManager.roomCount)
                     return;
-                this._moveSelection(Gtk.MovementStep.BUFFER_ENDS, -1);
-                if (n > 1)
-                    this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, n - 1);
+                this.widget.select_row(this.widget.get_row_at_index(n - 1));
             }));
     },
 
@@ -237,18 +240,14 @@ const RoomList = new Lang.Class({
         row.hide();
     },
 
-    _moveSelection: function(movement, count) {
-        let toplevel = this.widget.get_toplevel();
-        let focus = toplevel.get_focus();
-
-        this.widget.emit('move-cursor', movement, count);
-
-        let newFocus = this.widget.get_focus_child();
-        if (newFocus)
-            this.widget.select_row(newFocus);
-
-        if (focus && focus.get_parent() != this.widget)
-            focus.emit('grab-focus');
+    _moveSelection: function(direction) {
+        let current = this.widget.get_selected_row();
+        if (!current)
+            return;
+        let inc = direction == Gtk.DirectionType.UP ? -1 : 1;
+        let row = this.widget.get_row_at_index(current.get_index() + inc);
+        if (row)
+            this.widget.select_row(row);
     },
 
     _moveSelectionFromRow: function(row) {
@@ -260,18 +259,16 @@ const RoomList = new Lang.Class({
 
         let selected = this.widget.get_selected_row();
         let newActive = null;
-        let visibleChildren = this.widget.get_children().filter(function(c) {
-            return c.visible;
-        });
-        if (visibleChildren.length > 1) {
-            row.can_focus = false;
-            this.widget.select_row(row);
-            row.can_focus = true;
-            let count = row.get_index() == 0 ? 1 : -1;
-            this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, count);
-            newActive = this.widget.get_selected_row().room;
-        }
+
+        this.widget.select_row(row);
+        this._moveSelection(row.get_index() == 0 ? Gtk.DirectionType.DOWN
+                                                 : Gtk.DirectionType.UP);
+
+        let newSelected = this.widget.get_selected_row();
+        if (newSelected != row)
+            newActive = newSelected.room;
         this._roomManager.setActiveRoom(newActive);
+
         if (selected != row)
             this.widget.select_row(selected);
     },


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