[polari/wip/fmuellner/window-experiments: 21/30] app: Split actions between app and window



commit 00857c7b4f0dfc8f015aed5a4e6943c74691308d
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 14 16:04:43 2016 +0200

    app: Split actions between app and window

 data/resources/main-window.ui |    4 +-
 src/application.js            |   72 +--------------------------------
 src/mainWindow.js             |   89 +++++++++++++++++++++++++++++++++++------
 src/roomList.js               |   13 ++++--
 4 files changed, 89 insertions(+), 89 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 9a6fbdf..9c2f69c 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -25,7 +25,7 @@
                 <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
-                <property name="action_name">app.show-join-dialog</property>
+                <property name="action_name">win.show-join-dialog</property>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -140,7 +140,7 @@
               <object class="GtkToggleButton" id="showUserListButton">
                 <property name="visible">True</property>
                 <property name="focus-on-click">False</property>
-                <property name="action-name">app.user-list</property>
+                <property name="action-name">win.user-list</property>
                 <style>
                   <class name="polari-user-list-button"/>
                   <class name="text-button"/>
diff --git a/src/application.js b/src/application.js
index 41221af..66e7d46 100644
--- a/src/application.js
+++ b/src/application.js
@@ -59,9 +59,6 @@ const Application = new Lang.Class({
         this.pasteManager = new PasteManager.PasteManager();
 
         let actionEntries = [
-          { name: 'show-join-dialog',
-            activate: Lang.bind(this, this._onShowJoinDialog),
-            accels: ['<Primary>n'] },
           { name: 'join-room',
             activate: Lang.bind(this, this._onJoinRoom),
             parameter_type: GLib.VariantType.new('(ssu)') },
@@ -71,19 +68,10 @@ const Application = new Lang.Class({
           { name: 'leave-room',
             activate: Lang.bind(this, this._onLeaveRoom),
             parameter_type: GLib.VariantType.new('(ss)') },
-          { name: 'leave-current-room',
-            activate: Lang.bind(this, this._onLeaveCurrentRoom),
-            create_hook: Lang.bind(this, this._leaveRoomCreateHook),
-            accels: ['<Primary>w'] },
           { name: 'authenticate-account',
             parameter_type: GLib.VariantType.new('(os)') },
           { name: 'reconnect-account',
             parameter_type: GLib.VariantType.new('o') },
-          { name: 'user-list',
-            activate: Lang.bind(this, this._onToggleAction),
-            create_hook: Lang.bind(this, this._userListCreateHook),
-            state: GLib.Variant.new('b', false),
-            accels: ['F9', '<Primary>u'] },
           { name: 'remove-connection',
             activate: Lang.bind(this, this._onRemoveConnection),
             parameter_type: GLib.VariantType.new('o') },
@@ -99,26 +87,12 @@ const Application = new Lang.Class({
             activate: Lang.bind(this, this._onShowAbout) },
           { name: 'quit',
             activate: Lang.bind(this, this._onQuit),
-            accels: ['<Primary>q'] },
-          { name: 'next-room',
-            accels: ['<Primary>Page_Down', '<Alt>Down'] },
-          { name: 'previous-room',
-            accels: ['<Primary>Page_Up', '<Alt>Up'] },
-          { name: 'first-room',
-            accels: ['<Primary>Home'] },
-          { name: 'last-room',
-            accels: ['<Primary>End'] },
-          { name: 'nth-room',
-            parameter_type: GLib.VariantType.new('i') },
-          { name: 'next-pending-room',
-            accels: ['<Alt><Shift>Down', '<Primary><Shift>Page_Down']},
-          { name: 'previous-pending-room',
-            accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']}
+            accels: ['<Primary>q'] }
         ];
         Utils.addActionEntries(this, 'app', actionEntries);
 
         for (let i = 1; i < 10; i++)
-            this.set_accels_for_action('app.nth-room(%d)'.format(i), ['<Alt>' + i]);
+            this.set_accels_for_action('win.nth-room(%d)'.format(i), ['<Alt>' + i]);
     },
 
     vfunc_activate: function() {
@@ -264,35 +238,6 @@ const Application = new Lang.Class({
             }).length > 0;
     },
 
-    _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.type == Tp.HandleType.ROOM && room.channel;
-    },
-
-    _userListCreateHook: function(action) {
-        this._chatroomManager.connect('active-state-changed', Lang.bind(this,
-            function() {
-                this._updateUserListAction(action);
-            }));
-        action.connect('notify::enabled', function() {
-            if (!action.enabled)
-                action.change_state(GLib.Variant.new('b', false));
-        });
-        this._updateUserListAction(action);
-    },
-
-    _onShowJoinDialog: function() {
-        this.active_window.showJoinRoomDialog();
-    },
-
     _savedChannelIndex: function(savedChannels, account, channel) {
         let accountPath = account.get_object_path();
         let matchChannel = channel.toLowerCase();
@@ -536,19 +481,6 @@ const Application = new Lang.Class({
         this._removeSavedChannel(room.account, room.channel_name);
     },
 
-    _onLeaveCurrentRoom: function() {
-        let room = this._chatroomManager.getActiveRoom();
-        if (!room)
-            return;
-        let action = this.lookup_action('leave-room');
-        action.activate(GLib.Variant.new('(ss)', [room.id, '']));
-    },
-
-    _onToggleAction: function(action) {
-        let state = action.get_state();
-        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
-    },
-
     _onRemoveConnection: function(action, parameter){
         let accountPath = parameter.deep_unpack();
         let factory = Tp.AccountManager.dup().get_factory();
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 530214f..abc243e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -171,18 +171,44 @@ const MainWindow = new Lang.Class({
 
         this._updateUserListLabel();
 
-        let app = this.application;
-        this._userListAction = app.lookup_action('user-list');
-
-        app.connect('action-state-changed::user-list', Lang.bind(this,
-            function(group, actionName, value) {
-                this._userListPopover.visible = value.get_boolean();
-            }));
-        this._userListPopover.connect('notify::visible', Lang.bind(this,
-            function() {
-                if (!this._userListPopover.visible)
-                    this._userListAction.change_state(GLib.Variant.new('b', false));
-            }));
+        let actionEntries = [
+          { name: 'show-join-dialog',
+            activate: Lang.bind(this, this._onShowJoinDialog),
+            accels: ['<Primary>n'] },
+          { name: 'leave-current-room',
+            activate: Lang.bind(this, this._onLeaveCurrentRoom),
+            create_hook: Lang.bind(this, this._leaveRoomCreateHook),
+            accels: ['<Primary>w'] },
+          { name: 'user-list',
+            activate: Lang.bind(this, this._onToggleAction),
+            create_hook: Lang.bind(this, this._userListCreateHook),
+            state: GLib.Variant.new('b', false),
+            accels: ['F9', '<Primary>u'] },
+          { name: 'next-room',
+            accels: ['<Primary>Page_Down', '<Alt>Down'] },
+          { name: 'previous-room',
+            accels: ['<Primary>Page_Up', '<Alt>Up'] },
+          { name: 'first-room',
+            accels: ['<Primary>Home'] },
+          { name: 'last-room',
+            accels: ['<Primary>End'] },
+          { name: 'nth-room',
+            parameter_type: GLib.VariantType.new('i') },
+          { name: 'next-pending-room',
+            accels: ['<Alt><Shift>Down', '<Primary><Shift>Page_Down']},
+          { name: 'previous-pending-room',
+            accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']}
+        ];
+        Utils.addActionEntries(this, 'win', actionEntries);
+
+        let action = this.lookup_action('user-list');
+        this.connect('action-state-changed::user-list', (w, name, value) => {
+            this._userListPopover.visible = value.get_boolean();
+        });
+        this._userListPopover.connect('notify::visible', () => {
+            if (!this._userListPopover.visible)
+                action.change_state(GLib.Variant.new('b', false));
+        });
 
         this._gtkSettings.connect('notify::gtk-decoration-layout',
                                   Lang.bind(this, this._updateDecorations));
@@ -294,11 +320,48 @@ const MainWindow = new Lang.Class({
         );
     },
 
-    showJoinRoomDialog: function() {
+    _onShowJoinDialog: function() {
         let dialog = new JoinDialog.JoinDialog({ transient_for: this });
         dialog.show();
     },
 
+    _onLeaveCurrentRoom: function() {
+        if (!this._room)
+            return;
+        let action = this.application.lookup_action('leave-room');
+        action.activate(GLib.Variant.new('(ss)', [this._room.id, '']));
+    },
+
+    _leaveRoomCreateHook: function(action) {
+        this._roomManager.connect('active-changed', () => {
+            action.enabled = this._roomManager.getActiveRoom() != null;
+        });
+        action.enabled = this._roomManager.getActiveRoom() != null;
+    },
+
+    _onToggleAction: function(action) {
+        let state = action.get_state();
+        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
+    },
+
+
+    _updateUserListAction: function(action) {
+        action.enabled = this._room &&
+                         this._room.type == Tp.HandleType.ROOM &&
+                         this._room.channel;
+    },
+
+    _userListCreateHook: function(action) {
+        this._roomManager.connect('active-state-changed', () => {
+            this._updateUserListAction(action);
+        });
+        action.connect('notify::enabled', () => {
+            if (!action.enabled)
+                action.change_state(GLib.Variant.new('b', false));
+        });
+        this._updateUserListAction(action);
+    },
+
     _updateUserListLabel: function() {
         let numMembers = 0;
 
diff --git a/src/roomList.js b/src/roomList.js
index 80df45a..03a25d7 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -367,10 +367,15 @@ const RoomList = new Lang.Class({
         this._roomManager.connect('active-changed',
                                   Lang.bind(this, this._activeRoomChanged));
 
-        let app = Gio.Application.get_default();
+        let action = Gio.Application.get_default().lookup_action('leave-room');
+        action.connect('activate', Lang.bind(this, this._onLeaveActivated));
+    },
+
+    vfunc_realize: function() {
+        this.parent();
+
+        let toplevel = this.get_toplevel();
         let actions = [
-            { name: 'leave-room',
-              handler: Lang.bind(this, this._onLeaveActivated) },
             { name: 'next-room',
               handler: () => { this._moveSelection(Gtk.DirectionType.DOWN); } },
             { name: 'previous-room',
@@ -394,7 +399,7 @@ const RoomList = new Lang.Class({
                                                        row => row.hasPending); } }
         ];
         actions.forEach(a => {
-            app.lookup_action(a.name).connect('activate', a.handler);
+            toplevel.lookup_action(a.name).connect('activate', a.handler);
         });
     },
 


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