[polari/wip/fmuellner/window-experiments: 351/356] mainWindow: Add a convenience :active-room-id property



commit cdeb879845be9989765dfd5b32db4f19483ae447
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jul 16 01:46:42 2016 +0200

    mainWindow: Add a convenience :active-room-id property
    
    Often we are only interested in the active room's ID, not the actual
    room; maybe not worth the code though ...

 src/mainWindow.js |   12 +++++++++++-
 src/roomList.js   |   15 ++++++---------
 src/roomStack.js  |   12 ++++++------
 3 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index fd56d16..b2460f7 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -116,7 +116,12 @@ const MainWindow = new Lang.Class({
                                                 'active-room',
                                                 'active-room',
                                                 GObject.ParamFlags.READWRITE,
-                                                Polari.Room.$gtype)
+                                                Polari.Room.$gtype),
+        'active-room-id': GObject.ParamSpec.string('active-room-id',
+                                                   'active-room-id',
+                                                   'active-room-id',
+                                                   GObject.ParamFlags.READABLE,
+                                                   '')
     },
     Signals: { 'active-room-state-changed': {} },
 
@@ -357,6 +362,7 @@ const MainWindow = new Lang.Class({
         this._updateTitlebar();
 
         this.notify('active-room');
+        this.notify('active-room-id');
         this.emit('active-room-state-changed');
 
         if (!this._room)
@@ -378,6 +384,10 @@ const MainWindow = new Lang.Class({
             });
     },
 
+    get active_room_id() {
+        return this._room ? this._room.id : '';
+    },
+
     _onRoomsLoaded: function(mgr) {
         if (this.active_room)
             return;
diff --git a/src/roomList.js b/src/roomList.js
index eeae5c3..2bfa617 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -424,9 +424,9 @@ const RoomList = new Lang.Class({
         this.parent();
 
         let toplevel = this.get_toplevel();
-        toplevel.connect('notify::active-room',
-                         Lang.bind(this, this._activeRoomChanged));
-        this._activeRoomChanged();
+        toplevel.connect('notify::active-room-id',
+                         Lang.bind(this, this._activeRoomIdChanged));
+        this._activeRoomIdChanged();
     },
 
     _rowToRoomIndex: function(index) {
@@ -481,7 +481,7 @@ const RoomList = new Lang.Class({
             return;
 
         let toplevel = this.get_toplevel();
-        let current = this._roomRows.get(toplevel.active_room.id);
+        let current = this._roomRows.get(toplevel.active_room_id);
 
         if (current != row)
             return;
@@ -567,11 +567,8 @@ const RoomList = new Lang.Class({
         this._placeholders.get(account).visible = !hasRooms;
     },
 
-    _activeRoomChanged: function() {
-        let room = this.get_toplevel().active_room;
-        if (!room)
-            return;
-        let row = this._roomRows.get(room.id);
+    _activeRoomIdChanged: function() {
+        let row = this._roomRows.get(this.get_toplevel().active_room_id);
         if (!row)
             return;
 
diff --git a/src/roomStack.js b/src/roomStack.js
index 2870796..042c4ea 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -51,11 +51,11 @@ const RoomStack = new Lang.Class({
 
         let toplevel = this.get_toplevel();
 
-        toplevel.connect('notify::active-room',
-                         Lang.bind(this, this._activeRoomChanged));
+        toplevel.connect('notify::active-room-id',
+                         Lang.bind(this, this._activeRoomIdChanged));
         toplevel.connect('active-room-state-changed',
                          Lang.bind(this, this._updateSensitivity));
-        this._activeRoomChanged();
+        this._activeRoomIdChanged();
         this._updateSensitivity();
     },
 
@@ -77,9 +77,9 @@ const RoomStack = new Lang.Class({
         this._rooms.delete(room.id);
     },
 
-    _activeRoomChanged: function() {
-        let room = this.get_toplevel().active_room;
-        this.set_visible_child_name(room ? room.id : 'placeholder');
+    _activeRoomIdChanged: function() {
+        let toplevel = this.get_toplevel();
+        this.set_visible_child_name(toplevel.active_room_id || 'placeholder');
     },
 
     _updateSensitivity: function() {


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