[polari] window: Move all actions into application



commit 6afcd2a032b0b87d57145dda52d2672f8d2b08f7
Author: Florian Müllner <florian muellner gmail com>
Date:   Sun Jul 21 16:07:41 2013 +0200

    window: Move all actions into application
    
    For single-window applications, there is not really a good reason
    to differentiate between "app" and "win" actions.

 data/resources/main-window.ui |    8 ++--
 src/application.js            |   73 ++++++++++++++++++++++++++++++++++-------
 src/mainWindow.js             |   44 ++-----------------------
 3 files changed, 68 insertions(+), 57 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index d7cb047..844a6df 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">win.join-room</attribute>
+        <attribute name="action">app.join-room</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">Message a User</attribute>
-        <attribute name="action">win.message-user</attribute>
+        <attribute name="action">app.message-user</attribute>
       </item>
     </section>
   </menu>
@@ -57,7 +57,7 @@
             <property name="receives_default">True</property>
             <property name="halign">center</property>
             <property name="valign">center</property>
-            <property name="action_name">win.leave-room</property>
+            <property name="action_name">app.leave-room</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -81,7 +81,7 @@
             <property name="receives_default">True</property>
             <property name="halign">center</property>
             <property name="valign">center</property>
-            <property name="action_name">win.user-list</property>
+            <property name="action_name">app.user-list</property>
             <style>
               <class name="image-button"/>
             </style>
diff --git a/src/application.js b/src/application.js
index 74f8528..e098c4b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -39,20 +39,48 @@ const Application = new Lang.Class({
         this.set_app_menu(builder.get_object('app-menu'));
 
         let actionEntries = [
+          { name: 'join-room',
+            activate: Lang.bind(this, this._onJoinRoom) },
+          { name: 'message-user',
+            activate: Lang.bind(this, this._onMessageUser) },
+          { name: 'leave-room',
+            activate: Lang.bind(this, this._onLeaveRoom) },
+          { name: 'user-list',
+            activate: Lang.bind(this, this._onToggleAction),
+            state: GLib.Variant.new('b', false) },
           { name: 'connections',
-            activate: Lang.bind(this, this._listConnections) },
+            activate: Lang.bind(this, this._onListConnections) },
           { name: 'preferences',
-            activate: Lang.bind(this, this._showPreferences) },
+            activate: Lang.bind(this, this._onShowPreferences) },
           { name: 'about',
-            activate: Lang.bind(this, this._showAbout) },
+            activate: Lang.bind(this, this._onShowAbout) },
           { name: 'quit',
-            activate: Lang.bind(this, this.release) }
+            activate: Lang.bind(this, this._onQuit) }
         ];
-        Utils.createActions(actionEntries).forEach(Lang.bind(this,
-            function(a) {
-                this.add_action(a);
-            }));
-        this.add_accelerator('<Primary>q', 'app.quit', null);
+        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.activate)
+                    action.connect('activate', actionEntry.activate);
+                if (actionEntry.change_state)
+                    action.connect('change-state', actionEntry.change_state);
+                this.add_action(action);
+        }));
+        let accels = [
+          { accel: '<Primary>q', action: 'app.quit', parameter: null },
+          { accel: '<Primary>n', action: 'app.join-room', parameter: null },
+          { accel: '<Primary>w', action: 'app.leave-room', parameter: null },
+          { accel: 'F9', action: 'app.user-list', parameter: null }
+        ];
+        accels.forEach(Lang.bind(this, function(a) {
+            this.add_accelerator(a.accel, a.action, a.parameter);
+        }));
 
         this._window = new MainWindow.MainWindow(this);
 
@@ -75,7 +103,24 @@ const Application = new Lang.Class({
             this._window.window.present();
     },
 
-    _listConnections: function() {
+    _onJoinRoom: function() {
+        this._window.showJoinRoomDialog();
+    },
+
+    _onMessageUser: function() {
+        log('Activated action "Message user"');
+    },
+
+    _onLeaveRoom: function() {
+        this._window._room.leave();
+    },
+
+    _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();
         dialog.widget.connect('response',
@@ -84,10 +129,10 @@ const Application = new Lang.Class({
             });
     },
 
-    _showPreferences: function() {
+    _onShowPreferences: function() {
     },
 
-    _showAbout: function() {
+    _onShowAbout: function() {
         let aboutParams = {
             authors: [
                 'Florian M' + String.fromCharCode(0x00FC) // ü
@@ -110,5 +155,9 @@ const Application = new Lang.Class({
         dialog.connect('response', function() {
             dialog.destroy();
         });
+    },
+
+    _onQuit: function() {
+        this._window.window.destroy();
     }
 });
diff --git a/src/mainWindow.js b/src/mainWindow.js
index fd66f3d..9a10216 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -42,33 +42,8 @@ const MainWindow = new Lang.Class({
         this._nicknameChangedId = 0;
         this._channelChangedId = 0;
 
-        let actionEntries = [
-          { name: 'join-room',
-            activate: Lang.bind(this, this._joinRoom) },
-          { name: 'message-user',
-            activate: Lang.bind(this, this._messageUser) },
-          { name: 'leave-room',
-            activate: Lang.bind(this, this._leaveRoom) },
-          { name: 'user-list',
-            activate: Lang.bind(this, this._toggleAction),
-            state: GLib.Variant.new('b', false) }
-        ];
-        Utils.createActions(actionEntries).forEach(Lang.bind(this,
-            function(a) {
-                this.window.add_action(a);
-            }));
         this._updateActionStates();
 
-        let accels = [
-          { accel: '<Primary>n', action: 'win.join-room', parameter: null },
-          { accel: '<Primary>w', action: 'win.leave-room', parameter: null },
-          { accel: 'F9', action: 'win.user-list', parameter: null }
-        ];
-        accels.forEach(Lang.bind(this, function(a) {
-            app.add_accelerator(a.accel, a.action, a.parameter);
-        }));
-
-
         this._titlebar = builder.get_object('titlebar');
         this._revealer = builder.get_object('room_list_revealer');
         this._chatStack = builder.get_object('chat_stack');
@@ -88,7 +63,7 @@ const MainWindow = new Lang.Class({
         scroll.add(this._userListStack);
 
         let revealer = builder.get_object('user_list_revealer');
-        this.window.connect('action-state-changed::user-list', Lang.bind(this,
+        app.connect('action-state-changed::user-list', Lang.bind(this,
             function(group, actionName, value) {
                 revealer.reveal_child = value.get_boolean();
             }));
@@ -201,7 +176,7 @@ const MainWindow = new Lang.Class({
             }));
     },
 
-    _joinRoom: function() {
+    showJoinRoomDialog: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/polari/join-room-dialog.ui');
 
@@ -240,19 +215,6 @@ const MainWindow = new Lang.Class({
         }));
     },
 
-    _messageUser: function() {
-        log('Activated action "Message user"');
-    },
-
-    _leaveRoom: function() {
-        this._room.leave();
-    },
-
-    _toggleAction: function(action) {
-        let state = action.get_state();
-        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
-    },
-
     _updateTitlebar: function() {
         this._titlebar.title = this._room ? this._room.display_name : null;
     },
@@ -295,7 +257,7 @@ const MainWindow = new Lang.Class({
         let actionNames = ['leave-room', 'user-list'];
         actionNames.forEach(Lang.bind(this,
             function(actionName) {
-                let action = this.window.lookup_action(actionName);
+                let action = this.window.application.lookup_action(actionName);
                 action.enabled = this._room != null;
                 if (action.state && !action.enabled)
                     action.change_state(GLib.Variant.new('b', false));


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