[polari/wip/fmuellner/nickserv: 2/21] mainWindow: Focus the first added room



commit 4cf310d5ed4b739b8e969520b949260f529aaa5b
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Aug 2 01:18:03 2016 +0200

    mainWindow: Focus the first added room
    
    Now that the active room is a property of the window, it makes sense
    to move initialization there as well rather than leaving it in the
    chatroom manager.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769655

 src/chatroomManager.js |   12 +++---------
 src/mainWindow.js      |   11 +++++++++++
 2 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index c59c0cb..c0151a5 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -413,8 +413,6 @@ const _ChatroomManager = new Lang.Class({
                 }
 
                 let room = this._ensureRoomForChannel(channel);
-                if (this.roomCount == 1)
-                    this._setActiveRoom(room);
             }));
     },
 
@@ -434,11 +432,10 @@ const _ChatroomManager = new Lang.Class({
                 let room = this._ensureRoomForChannel(channel);
                 //channel.join_async('', null);
 
-                if (present || this.roomCount == 1)
-                    this._setActiveRoom(room);
-
-                if (present)
+                if (present) {
                     this._app.activate();
+                    this._setActiveRoom(room);
+                }
             }));
     },
 
@@ -448,9 +445,6 @@ const _ChatroomManager = new Lang.Class({
 
         this._rooms[room.id] = room;
         this.emit('room-added', room);
-
-        if (this.roomCount == 1)
-            this._setActiveRoom(room);
     },
 
     _removeRoom: function(room) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 4c491ab..4db610e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -8,6 +8,7 @@ const Tp = imports.gi.TelepathyGLib;
 
 const AccountsMonitor = imports.accountsMonitor;
 const AppNotifications = imports.appNotifications;
+const ChatroomManager = imports.chatroomManager;
 const JoinDialog = imports.joinDialog;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
@@ -166,6 +167,10 @@ const MainWindow = new Lang.Class({
                                       Lang.bind(this, this._onAccountsChanged));
         this._onAccountsChanged(this._accountsMonitor);
 
+        this._roomManager = ChatroomManager.getDefault();
+        this._roomManager.connect('room-added',
+                                  Lang.bind(this, this._onRoomAdded));
+
         this._updateUserListLabel();
 
         this._userListAction = app.lookup_action('user-list');
@@ -307,6 +312,12 @@ const MainWindow = new Lang.Class({
         );
     },
 
+    _onRoomAdded: function(mgr, room) {
+        if (this.active_room)
+            return;
+        this.active_room = room;
+    },
+
     showJoinRoomDialog: function() {
         let dialog = new JoinDialog.JoinDialog({ transient_for: this });
         dialog.show();


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