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



commit 6d207941c4a8f518970609584aa98692b22df95a
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 07cb620..7117530 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -114,7 +114,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': {} },
 
@@ -301,6 +306,7 @@ const MainWindow = new Lang.Class({
         this._updateUserListLabel();
 
         this.notify('active-room');
+        this.notify('active-room-id');
         this.emit('active-room-state-changed');
 
         if (!this._room)
@@ -322,6 +328,10 @@ const MainWindow = new Lang.Class({
             });
     },
 
+    get active_room_id() {
+        return this._room ? this._room.id : '';
+    },
+
     _addApplicationStyle: function() {
         let provider = new Gtk.CssProvider();
         let uri = 'resource:///org/gnome/Polari/css/application.css';
diff --git a/src/roomList.js b/src/roomList.js
index 24cf111..72994c0 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -384,9 +384,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();
 
         let actions = [
             { name: 'next-room',
@@ -476,7 +476,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;
@@ -561,11 +561,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 2321d82..a519625 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -52,11 +52,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();
     },
 
@@ -78,9 +78,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]