[polari] roomList: Move selection when the active room is removed



commit d1f08c035e1139a93dc994d75aee1316faa97a56
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Feb 27 21:39:19 2014 +0100

    roomList: Move selection when the active room is removed
    
    Since commit 0827a395dc24d22, rooms may be removed without the user
    explicitly leaving them. If the currently active room is removed
    like that, we will need to make sure to move the selection to not
    end up with no active room and a hidden room list, just like we do
    when explicitly leaving a room.

 src/roomList.js |   48 +++++++++++++++++++++++++++---------------------
 1 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index c7d3988..c77bf2a 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -223,27 +223,7 @@ const RoomList = new Lang.Class({
         let [id, ] = param.deep_unpack();
         let row = this._roomRows[id].widget;
 
-        let activeRoom = this._roomManager.getActiveRoom();
-        let current = this._roomRows[activeRoom.id].widget;
-
-        if (current == row) {
-            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._roomManager.setActiveRoom(newActive);
-            if (selected != row)
-                this.widget.select_row(selected);
-        }
+        this._moveSelectionFromRow(row);
         row.hide();
     },
 
@@ -261,6 +241,31 @@ const RoomList = new Lang.Class({
             focus.emit('grab-focus');
     },
 
+    _moveSelectionFromRow: function(row) {
+        let activeRoom = this._roomManager.getActiveRoom();
+        let current = this._roomRows[activeRoom.id].widget;
+
+        if (current != row)
+            return;
+
+        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._roomManager.setActiveRoom(newActive);
+        if (selected != row)
+            this.widget.select_row(selected);
+    },
+
     _roomAdded: function(roomManager, room) {
         let roomRow = new RoomRow(room);
         this.widget.add(roomRow.widget);
@@ -288,6 +293,7 @@ const RoomList = new Lang.Class({
         if (!roomRow)
             return;
 
+        this._moveSelectionFromRow(roomRow.widget);
         this.widget.remove(roomRow.widget);
         delete this._roomRows[room.id];
     },


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