[polari/wip/actions] Move window actions to window



commit f8b1cde660f452e6c0ea7a4bcd9e5188d1a33072
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Thu Aug 8 18:09:40 2013 +0200

    Move window actions to window

 data/resources/main-window.ui |   12 +-
 src/application.js            |  255 ++++-----------------------------------
 src/joinDialog.js             |    6 +-
 src/mainWindow.js             |  266 +++++++++++++++++++++++++++++++++++++++--
 src/roomList.js               |   25 ++--
 5 files changed, 301 insertions(+), 263 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 5ff61db..3ff84b1 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -5,11 +5,11 @@
     <section>
       <item>
         <attribute name="label" translatable="yes">Join a Room</attribute>
-        <attribute name="action">app.show-join-dialog</attribute>
+        <attribute name="action">win.show-join-dialog</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">Message a User</attribute>
-        <attribute name="action">app.message-user</attribute>
+        <attribute name="action">win.message-user</attribute>
       </item>
     </section>
   </menu>
@@ -46,7 +46,7 @@
                 <property name="valign">center</property>
                 <property name="margin-left">6</property>
                 <property name="menu_model">join_menu</property>
-                <property name="action_name">app.room-menu</property>
+                <property name="action_name">win.room-menu</property>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -70,7 +70,7 @@
                 <property name="focus_on_click">False</property>
                 <property name="halign">center</property>
                 <property name="valign">center</property>
-                <property name="action_name">app.selection-mode</property>
+                <property name="action_name">win.selection-mode</property>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -133,7 +133,7 @@
                      it on the first and last button has the same effect,
                      and spares us from using a custom title widget -->
                 <property name="margin-left">24</property>
-                <property name="action_name">app.user-list</property>
+                <property name="action_name">win.user-list</property>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -228,7 +228,7 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
-                                    <property name="action_name">app.leave-selected-rooms</property>
+                                    <property name="action_name">win.leave-selected-rooms</property>
                                     <property name="use_underline">True</property>
                                   </object>
                                 </child>
diff --git a/src/application.js b/src/application.js
index c0a448b..fd893d1 100644
--- a/src/application.js
+++ b/src/application.js
@@ -54,8 +54,6 @@ const Application = new Lang.Class({
         this._chatroomManager = ChatroomManager.getDefault();
         this._accountsMonitor = AccountsMonitor.getDefault();
 
-        this._settings = new Gio.Settings({ schema: 'org.gnome.polari' });
-
         this.pasteManager = new PasteManager.PasteManager();
         this.notificationQueue = new AppNotifications.NotificationQueue();
         this.commandOutputQueue = new AppNotifications.CommandOutputQueue();
@@ -65,36 +63,6 @@ const Application = new Lang.Class({
         this.set_app_menu(builder.get_object('app-menu'));
 
         let actionEntries = [
-          { name: 'room-menu',
-            activate: Lang.bind(this, this._onToggleAction),
-            create_hook: Lang.bind(this, this._accountActionsCreateHook),
-            state: GLib.Variant.new('b', false) },
-          { name: 'show-join-dialog',
-            activate: Lang.bind(this, this._onShowJoinDialog),
-            create_hook: Lang.bind(this, this._accountActionsCreateHook),
-            accel: '<Primary>n' },
-          { name: 'message-user',
-            activate: Lang.bind(this, this._onMessageUser) },
-          { name: 'join-room',
-            activate: Lang.bind(this, this._onJoinRoom),
-            parameter_type: GLib.VariantType.new('(ssu)') },
-          { name: 'leave-room',
-            activate: Lang.bind(this, this._onLeaveRoom),
-            parameter_type: GLib.VariantType.new('s') },
-          { name: 'leave-current-room',
-            activate: Lang.bind(this, this._onLeaveCurrentRoom),
-            create_hook: Lang.bind(this, this._leaveRoomCreateHook),
-            accel: '<Primary>w' },
-          { name: 'leave-selected-rooms' },
-          { name: 'user-list',
-            activate: Lang.bind(this, this._onToggleAction),
-            create_hook: Lang.bind(this, this._userListCreateHook),
-            state: GLib.Variant.new('b', false),
-            accel: 'F9' },
-          { name: 'selection-mode',
-            activate: Lang.bind(this, this._onToggleAction),
-            create_hook: Lang.bind(this, this._selectionModeHook),
-            state: GLib.Variant.new('b', false) },
           { name: 'connections',
             activate: Lang.bind(this, this._onListConnections) },
           { name: 'preferences',
@@ -103,15 +71,7 @@ const Application = new Lang.Class({
             activate: Lang.bind(this, this._onShowAbout) },
           { name: 'quit',
             activate: Lang.bind(this, this._onQuit),
-            accel: '<Primary>q' },
-          { name: 'next-room',
-            accel: '<Primary>Page_Down' },
-          { name: 'previous-room',
-            accel: '<Primary>Page_Up' },
-          { name: 'first-room',
-            accel: '<Primary>Home' },
-          { name: 'last-room',
-            accel: '<Primary>End' }
+            accel: '<Primary>q' }
         ];
         actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
@@ -133,6 +93,28 @@ const Application = new Lang.Class({
                                          'app.' + actionEntry.name, null);
                 this.add_action(action);
         }));
+        let windowAccels = [
+          { name: 'show-join-dialog',
+            accel: '<Primary>n' },
+          { name: 'leave-current-room',
+            accel: '<Primary>w' },
+          { name: 'user-list',
+            accel: 'F9' },
+          { name: 'next-room',
+            accel: '<Primary>Page_Down' },
+          { name: 'previous-room',
+            accel: '<Primary>Page_Up' },
+          { name: 'first-room',
+            accel: '<Primary>Home' },
+          { name: 'last-room',
+            accel: '<Primary>End' }
+        ];
+        windowAccels.forEach(Lang.bind(this,
+            function(actionEntry) {
+                if (actionEntry.accel)
+                    this.add_accelerator(actionEntry.accel,
+                                         'win.' + actionEntry.name, null);
+        }));
 
         this._window = new MainWindow.MainWindow(this);
         this._window.window.connect('destroy', Lang.bind(this,
@@ -159,197 +141,6 @@ const Application = new Lang.Class({
             this._window.window.present();
     },
 
-    _updateAccountAction: function(action) {
-        action.enabled = this._accountsMonitor.dupAccounts().filter(
-            function(a) {
-                return a.enabled;
-            }).length > 0;
-    },
-
-    _accountActionsCreateHook: function(action) {
-        this._accountsMonitor.connect('accounts-changed', Lang.bind(this,
-            function() {
-                this._updateAccountAction(action);
-            }));
-        this._updateAccountAction(action);
-    },
-
-    _leaveRoomCreateHook: function(action) {
-        this._chatroomManager.connect('active-changed', Lang.bind(this,
-            function() {
-                action.enabled = this._chatroomManager.getActiveRoom() != null;
-            }));
-        action.enabled = this._chatroomManager.getActiveRoom() != null;
-    },
-
-    _updateUserListAction: function(action) {
-        let room = this._chatroomManager.getActiveRoom();
-        action.enabled = room && room.channel.handle_type == Tp.HandleType.ROOM;
-        if (!action.enabled)
-            action.change_state(GLib.Variant.new('b', false));
-    },
-
-    _userListCreateHook: function(action) {
-        this._chatroomManager.connect('active-changed', Lang.bind(this,
-            function() {
-                this._updateUserListAction(action);
-            }));
-        this._updateUserListAction(action);
-    },
-
-    _updateSelectionModeAction: function(action) {
-        action.enabled = this._chatroomManager.roomCount > 0;
-        if (!action.enabled)
-            action.change_state(GLib.Variant.new('b', false));
-    },
-
-    _selectionModeHook: function(action) {
-        this._chatroomManager.connect('active-changed', Lang.bind(this,
-            function() {
-                this._updateSelectionModeAction(action);
-            }));
-        this._updateSelectionModeAction(action);
-    },
-
-    _onShowJoinDialog: function() {
-        this._window.showJoinRoomDialog();
-    },
-
-    _onMessageUser: function() {
-        log('Activated action "Message user"');
-    },
-
-    _addSavedChannel: function(account, channel) {
-        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
-        let savedChannel = {
-            account: GLib.Variant.new('s', account.get_object_path()),
-            channel: GLib.Variant.new('s', channel)
-        };
-        for (let i = 0; i < savedChannels.length; i++)
-            if (savedChannels[i].account.equal(savedChannel.account) &&
-                savedChannels[i].channel.equal(savedChannel.channel))
-                return;
-        savedChannels.push(savedChannel);
-        this._settings.set_value('saved-channel-list',
-                                 GLib.Variant.new('aa{sv}', savedChannels));
-    },
-
-    _removeSavedChannel: function(account, channel) {
-        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
-        let savedChannel = {
-            account: GLib.Variant.new('s', account.get_object_path()),
-            channel: GLib.Variant.new('s', channel)
-        };
-        let i;
-        for (i = 0; i < savedChannels.length; i++)
-            if (savedChannels[i].account.equal(savedChannel.account) &&
-                savedChannels[i].channel.equal(savedChannel.channel))
-                break;
-        if (!savedChannels[i])
-            return;
-        savedChannels.splice(i, 1);
-        this._settings.set_value('saved-channel-list',
-                                 GLib.Variant.new('aa{sv}', savedChannels));
-    },
-
-    _updateAccountName: function(account, name, callback) {
-        let sv = { account: GLib.Variant.new('s', name) };
-        let asv = GLib.Variant.new('a{sv}', sv);
-        account.update_parameters_vardict_async(asv, [], callback);
-    },
-
-    _ensureChannel: function(requestData) {
-        let account = requestData.account;
-
-        let req = Tp.AccountChannelRequest.new_text(account, requestData.time);
-        req.set_target_id(Tp.HandleType.ROOM, requestData.target);
-        req.set_delegate_to_preferred_handler(true);
-        let preferredHandler = Tp.CLIENT_BUS_NAME_BASE + 'Polari';
-        req.ensure_channel_async(preferredHandler, null,
-                                 Lang.bind(this,
-                                           this._onEnsureChannel, requestData));
-    },
-
-    _onEnsureChannel: function(req, res, requestData) {
-        let account = req.account;
-
-        try {
-            req.ensure_channel_finish(res);
-        } catch (e if e.matches(Tp.Error, Tp.Error.DISCONNECTED)) {
-            let [error,] = account.dup_detailed_error_vardict();
-            if (error != TP_ERROR_ALREADY_CONNECTED)
-                throw(e);
-
-            if (++requestData.retry >= MAX_RETRIES) {
-                throw(e);
-                return;
-            }
-
-            // Try again with a different nick
-            let params = account.dup_parameters_vardict().deep_unpack();
-            let oldNick = params['account'].deep_unpack();
-            let nick = oldNick + '_';
-            this._updateAccountName(account, nick, Lang.bind(this,
-                function() {
-                    this._ensureChannel(requestData);
-                }));
-            return;
-        } catch (e) {
-            logError(e, 'Failed to ensure channel');
-        }
-
-        if (requestData.retry > 0)
-            this._updateAccountName(account, requestData.originalNick, null);
-        this._addSavedChannel(account, requestData.target);
-    },
-
-    _onJoinRoom: function(action, parameter) {
-        let [accountPath, channelName, time] = parameter.deep_unpack();
-        // have this in AccountMonitor?
-        let factory = Tp.AccountManager.dup().get_factory();
-        let account = factory.ensure_account(accountPath, []);
-
-        let requestData = {
-          account: account,
-          target: channelName,
-          time: time,
-          retry: 0,
-          originalNick: account.nickname };
-
-        this._ensureChannel(requestData);
-    },
-
-    _onLeaveRoom: function(action, parameter) {
-        let reason = Tp.ChannelGroupChangeReason.NONE;
-        let message = _("Good Bye"); // TODO - our first setting!
-        let room = this._chatroomManager.getRoomById(parameter.deep_unpack());
-        if (!room)
-            return;
-        room.channel.leave_async(reason, message, Lang.bind(this,
-            function(c, res) {
-                try {
-                    c.leave_finish(res);
-                } catch(e) {
-                    logError(e, 'Failed to leave channel');
-                }
-            }));
-        this._removeSavedChannel(room.channel.connection.get_account(),
-                                 room.channel.identifier);
-    },
-
-    _onLeaveCurrentRoom: function() {
-        let room = this._chatroomManager.getActiveRoom();
-        if (!room)
-            return;
-        let action = this.lookup_action('leave-room');
-        action.activate(GLib.Variant.new('s', room.id));
-    },
-
-    _onToggleAction: function(action) {
-        let state = action.get_state();
-        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
-    },
-
     _onListConnections: function() {
         let dialog = new Connections.ConnectionsDialog();
         dialog.widget.show();
diff --git a/src/joinDialog.js b/src/joinDialog.js
index 11ec146..8c13442 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -16,7 +16,8 @@ const TP_CURRENT_TIME = GLib.MAXUINT32;
 const JoinDialog = new Lang.Class({
     Name: 'JoinDialog',
 
-    _init: function() {
+    _init: function(window) {
+        this.window = window
         this._createWidget();
 
         this._accounts = {};
@@ -67,8 +68,7 @@ const JoinDialog = new Lang.Class({
         if (room[0] != '#')
             room = '#' + room;
 
-        let app = Gio.Application.get_default();
-        let action = app.lookup_action('join-room');
+        let action = this.window.lookup_action('join-room');
         action.activate(GLib.Variant.new('(ssu)',
                                          [ account.get_object_path(),
                                            room,
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 7dc44a4..d0acccd 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -28,12 +28,7 @@ const MainWindow = new Lang.Class({
         this.window = builder.get_object('main_window');
         this.window.application = app;
 
-        let overlay = builder.get_object('overlay');
-
-        overlay.add_overlay(app.notificationQueue.widget);
-        overlay.add_overlay(app.commandOutputQueue.widget);
-
-        this._ircParser = new IrcParser.IrcParser();
+        this._settings = new Gio.Settings({ schema: 'org.gnome.polari' });
 
         this._accountsMonitor = new AccountsMonitor.getDefault();
         this._accountsMonitor.connect('account-status-changed',
@@ -49,6 +44,68 @@ const MainWindow = new Lang.Class({
         this._roomManager.connect('active-changed',
                                   Lang.bind(this, this._activeRoomChanged));
 
+        let actionEntries = [
+          { name: 'room-menu',
+            activate: Lang.bind(this, this._onToggleAction),
+            create_hook: Lang.bind(this, this._accountActionsCreateHook),
+            state: GLib.Variant.new('b', false) },
+          { name: 'show-join-dialog',
+            activate: Lang.bind(this, this._onShowJoinDialog),
+            create_hook: Lang.bind(this, this._accountActionsCreateHook) },
+          { name: 'message-user',
+            activate: Lang.bind(this, this._onMessageUser) },
+          { name: 'join-room',
+            activate: Lang.bind(this, this._onJoinRoom),
+            parameter_type: GLib.VariantType.new('(ssu)') },
+          { name: 'leave-room',
+            activate: Lang.bind(this, this._onLeaveRoom),
+            parameter_type: GLib.VariantType.new('s') },
+          { name: 'leave-current-room',
+            activate: Lang.bind(this, this._onLeaveCurrentRoom),
+            create_hook: Lang.bind(this, this._leaveRoomCreateHook) },
+          { name: 'leave-selected-rooms' },
+          { name: 'user-list',
+            activate: Lang.bind(this, this._onToggleAction),
+            create_hook: Lang.bind(this, this._userListCreateHook),
+            state: GLib.Variant.new('b', false) },
+          { name: 'selection-mode',
+            activate: Lang.bind(this, this._onToggleAction),
+            create_hook: Lang.bind(this, this._selectionModeHook),
+            state: GLib.Variant.new('b', false) },
+          { name: 'next-room',
+            accel: '<Primary>Page_Down' },
+          { name: 'previous-room',
+            accel: '<Primary>Page_Up' },
+          { name: 'first-room',
+            accel: '<Primary>Home' },
+          { name: 'last-room',
+            accel: '<Primary>End' }
+        ];
+        actionEntries.forEach(Lang.bind(this,
+            function(actionEntry) {
+                let props = {};
+                ['name', 'state', 'parameter_type'].forEach(
+                    function(prop) {
+                        if (actionEntry[prop])
+                            props[prop] = actionEntry[prop];
+                    });
+                let action = new Gio.SimpleAction(props);
+                if (actionEntry.create_hook)
+                    actionEntry.create_hook(action);
+                if (actionEntry.activate)
+                    action.connect('activate', actionEntry.activate);
+                if (actionEntry.change_state)
+                    action.connect('change-state', actionEntry.change_state);
+                this.window.add_action(action);
+        }));
+
+        let overlay = builder.get_object('overlay');
+
+        overlay.add_overlay(app.notificationQueue.widget);
+        overlay.add_overlay(app.commandOutputQueue.widget);
+
+        this._ircParser = new IrcParser.IrcParser();
+
         this._rooms = {};
 
         this._room = null;
@@ -70,7 +127,7 @@ const MainWindow = new Lang.Class({
         this._nickEntry.width_chars = ChatView.MAX_NICK_CHARS
 
         let scroll = builder.get_object('room_list_scrollview');
-        this._roomList = new RoomList.RoomList();
+        this._roomList = new RoomList.RoomList(this.window);
         scroll.add(this._roomList.widget);
 
         this._userListStack = builder.get_object('user_list_stack');
@@ -81,7 +138,7 @@ const MainWindow = new Lang.Class({
                 revealer.reveal_child = value.get_boolean();
             }));
 
-        this._selectionModeAction = app.lookup_action('selection-mode');
+        this._selectionModeAction = this.window.lookup_action('selection-mode');
         this._selectionModeAction.connect('notify::state',
                     Lang.bind(this, this._onSelectionModeChanged));
 
@@ -123,6 +180,197 @@ const MainWindow = new Lang.Class({
         this.window.show_all();
     },
 
+    _onToggleAction: function(action) {
+        let state = action.get_state();
+        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
+    },
+
+    _updateAccountAction: function(action) {
+        action.enabled = this._accountsMonitor.dupAccounts().filter(
+            function(a) {
+                return a.enabled;
+            }).length > 0;
+    },
+
+    _accountActionsCreateHook: function(action) {
+        this._accountsMonitor.connect('accounts-changed', Lang.bind(this,
+            function() {
+                this._updateAccountAction(action);
+            }));
+        this._updateAccountAction(action);
+    },
+
+    _onShowJoinDialog: function() {
+        this.showJoinRoomDialog();
+    },
+
+    _onMessageUser: function() {
+        log('Activated action "Message user"');
+    },
+
+    _addSavedChannel: function(account, channel) {
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
+        let savedChannel = {
+            account: GLib.Variant.new('s', account.get_object_path()),
+            channel: GLib.Variant.new('s', channel)
+        };
+        for (let i = 0; i < savedChannels.length; i++)
+            if (savedChannels[i].account.equal(savedChannel.account) &&
+                savedChannels[i].channel.equal(savedChannel.channel))
+                return;
+        savedChannels.push(savedChannel);
+        this._settings.set_value('saved-channel-list',
+                                 GLib.Variant.new('aa{sv}', savedChannels));
+    },
+
+    _removeSavedChannel: function(account, channel) {
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
+        let savedChannel = {
+            account: GLib.Variant.new('s', account.get_object_path()),
+            channel: GLib.Variant.new('s', channel)
+        };
+        let i;
+        for (i = 0; i < savedChannels.length; i++)
+            if (savedChannels[i].account.equal(savedChannel.account) &&
+                savedChannels[i].channel.equal(savedChannel.channel))
+                break;
+        if (!savedChannels[i])
+            return;
+        savedChannels.splice(i, 1);
+        this._settings.set_value('saved-channel-list',
+                                 GLib.Variant.new('aa{sv}', savedChannels));
+    },
+
+    _updateAccountName: function(account, name, callback) {
+        let sv = { account: GLib.Variant.new('s', name) };
+        let asv = GLib.Variant.new('a{sv}', sv);
+        account.update_parameters_vardict_async(asv, [], callback);
+    },
+
+    _ensureChannel: function(requestData) {
+        let account = requestData.account;
+
+        let req = Tp.AccountChannelRequest.new_text(account, requestData.time);
+        req.set_target_id(Tp.HandleType.ROOM, requestData.target);
+        req.set_delegate_to_preferred_handler(true);
+        let preferredHandler = Tp.CLIENT_BUS_NAME_BASE + 'Polari';
+        req.ensure_channel_async(preferredHandler, null,
+                                 Lang.bind(this,
+                                           this._onEnsureChannel, requestData));
+    },
+
+    _onEnsureChannel: function(req, res, requestData) {
+        let account = req.account;
+
+        try {
+            req.ensure_channel_finish(res);
+        } catch (e if e.matches(Tp.Error, Tp.Error.DISCONNECTED)) {
+            let [error,] = account.dup_detailed_error_vardict();
+            if (error != TP_ERROR_ALREADY_CONNECTED)
+                throw(e);
+
+            if (++requestData.retry >= MAX_RETRIES) {
+                throw(e);
+                return;
+            }
+
+            // Try again with a different nick
+            let params = account.dup_parameters_vardict().deep_unpack();
+            let oldNick = params['account'].deep_unpack();
+            let nick = oldNick + '_';
+            this._updateAccountName(account, nick, Lang.bind(this,
+                function() {
+                    this._ensureChannel(requestData);
+                }));
+            return;
+        } catch (e) {
+            logError(e, 'Failed to ensure channel');
+        }
+
+        if (requestData.retry > 0)
+            this._updateAccountName(account, requestData.originalNick, null);
+        this._addSavedChannel(account, requestData.target);
+    },
+
+    _onJoinRoom: function(action, parameter) {
+        let [accountPath, channelName, time] = parameter.deep_unpack();
+        // have this in AccountMonitor?
+        let factory = Tp.AccountManager.dup().get_factory();
+        let account = factory.ensure_account(accountPath, []);
+
+        let requestData = {
+          account: account,
+          target: channelName,
+          time: time,
+          retry: 0,
+          originalNick: account.nickname };
+
+        this._ensureChannel(requestData);
+    },
+
+    _onLeaveRoom: function(action, parameter) {
+        let reason = Tp.ChannelGroupChangeReason.NONE;
+        let message = _("Good Bye"); // TODO - our first setting!
+        let room = this._roomManager.getRoomById(parameter.deep_unpack());
+        if (!room)
+            return;
+        room.channel.leave_async(reason, message, Lang.bind(this,
+            function(c, res) {
+                try {
+                    c.leave_finish(res);
+                } catch(e) {
+                    logError(e, 'Failed to leave channel');
+                }
+            }));
+        this._removeSavedChannel(room.channel.connection.get_account(),
+                                 room.channel.identifier);
+    },
+
+    _leaveRoomCreateHook: function(action) {
+        this._roomManager.connect('active-changed', Lang.bind(this,
+            function() {
+                action.enabled = this._roomManager.getActiveRoom() != null;
+            }));
+        action.enabled = this._roomManager.getActiveRoom() != null;
+    },
+
+    _onLeaveCurrentRoom: function() {
+        let room = this._roomManager.getActiveRoom();
+        if (!room)
+            return;
+        let action = this.lookup_action('leave-room');
+        action.activate(GLib.Variant.new('s', room.id));
+    },
+
+    _updateUserListAction: function(action) {
+        let room = this._roomManager.getActiveRoom();
+        action.enabled = room && room.channel.handle_type == Tp.HandleType.ROOM;
+        if (!action.enabled)
+            action.change_state(GLib.Variant.new('b', false));
+    },
+
+    _userListCreateHook: function(action) {
+        this._roomManager.connect('active-changed', Lang.bind(this,
+            function() {
+                this._updateUserListAction(action);
+            }));
+        this._updateUserListAction(action);
+    },
+
+    _updateSelectionModeAction: function(action) {
+        action.enabled = this._roomManager.roomCount > 0;
+        if (!action.enabled)
+            action.change_state(GLib.Variant.new('b', false));
+    },
+
+    _selectionModeHook: function(action) {
+        this._roomManager.connect('active-changed', Lang.bind(this,
+            function() {
+                this._updateSelectionModeAction(action);
+            }));
+        this._updateSelectionModeAction(action);
+    },
+
     _onSelectionModeChanged: function() {
         let enabled = this._selectionModeAction.state.get_boolean();
         this._selectionRevealer.reveal_child = enabled;
@@ -245,7 +493,7 @@ const MainWindow = new Lang.Class({
     },
 
     showJoinRoomDialog: function() {
-        let dialog = new JoinDialog.JoinDialog();
+        let dialog = new JoinDialog.JoinDialog(this.window);
         dialog.widget.transient_for = this.window;
         dialog.widget.show();
         dialog.widget.connect('response',
diff --git a/src/roomList.js b/src/roomList.js
index 44eaa0e..66076f1 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -12,16 +12,15 @@ const Lang = imports.lang;
 const RoomRow = new Lang.Class({
     Name: 'RoomRow',
 
-    _init: function(room) {
+    _init: function(window, room) {
         this._createWidget(room.icon);
 
-        let app = Gio.Application.get_default();
         this.widget.room = room;
 
         this._eventBox.connect('button-release-event',
                             Lang.bind(this, this._onButtonRelease));
 
-        this._selectionModeAction = app.lookup_action('selection-mode');
+        this._selectionModeAction = window.lookup_action('selection-mode');
         this._selectionModeAction.connect('notify::state',
                           Lang.bind(this, this._onSelectionModeChanged));
 
@@ -123,7 +122,8 @@ const RoomRow = new Lang.Class({
 const RoomList = new Lang.Class({
     Name: 'RoomList',
 
-    _init: function() {
+    _init: function(window) {
+        this.window = window
         this.widget = new Gtk.ListBox({ hexpand: false });
 
         this.widget.set_selection_mode(Gtk.SelectionMode.BROWSE);
@@ -147,36 +147,35 @@ const RoomList = new Lang.Class({
         this._roomManager.connect('active-changed',
                                   Lang.bind(this, this._activeRoomChanged));
 
-        let app = Gio.Application.get_default();
-        this._selectionModeAction = app.lookup_action('selection-mode');
+        this._selectionModeAction = window.lookup_action('selection-mode');
         this._selectionModeAction.connect('notify::state', Lang.bind(this,
                                           this._onSelectionModeChanged));
 
-        this._leaveSelectedAction = app.lookup_action('leave-selected-rooms');
+        this._leaveSelectedAction = window.lookup_action('leave-selected-rooms');
         this._leaveSelectedAction.connect('activate',
                                           Lang.bind(this, this._onLeaveSelectedActivated));
 
-        this._leaveAction = app.lookup_action('leave-room');
+        this._leaveAction = window.lookup_action('leave-room');
         this._leaveAction.connect('activate',
                                   Lang.bind(this, this._onLeaveActivated));
 
         let action;
-        action = app.lookup_action('next-room');
+        action = window.lookup_action('next-room');
         action.connect('activate', Lang.bind(this,
             function() {
                 this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, 1);
             }));
-        action = app.lookup_action('previous-room');
+        action = window.lookup_action('previous-room');
         action.connect('activate', Lang.bind(this,
             function() {
                 this._moveSelection(Gtk.MovementStep.DISPLAY_LINES, -1);
             }));
-        action = app.lookup_action('first-room');
+        action = window.lookup_action('first-room');
         action.connect('activate', Lang.bind(this,
             function() {
                 this._moveSelection(Gtk.MovementStep.BUFFER_ENDS, -1);
             }));
-        action = app.lookup_action('last-room');
+        action = window.lookup_action('last-room');
         action.connect('activate', Lang.bind(this,
             function() {
                 this._moveSelection(Gtk.MovementStep.BUFFER_ENDS, 1);
@@ -229,7 +228,7 @@ const RoomList = new Lang.Class({
     },
 
     _roomAdded: function(roomManager, room) {
-        let roomRow = new RoomRow(room);
+        let roomRow = new RoomRow(this.window, room);
         this.widget.add(roomRow.widget);
         this._roomRows[room.id] = roomRow;
 


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