[gnome-maps/wip/fix-geoloc: 5/8] MainWindow: make _init smaller



commit 0bf7237341ce9f6ef7550ecc3c4517d362caf710
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Thu Jul 11 04:02:02 2013 +0200

    MainWindow: make _init smaller
    
    Split out initialization of actions and restoration of window geometry
    from _init making it a bit more manageable.

 src/mainWindow.js |   88 ++++++++++++++++++++++++++++------------------------
 1 files changed, 47 insertions(+), 41 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index fad496a..1bf7366 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -56,47 +56,8 @@ const MainWindow = new Lang.Class({
         this.window = ui.appWindow;
         this.window.application = app;
 
-        Utils.initActions(this.window, [
-            { 
-                properties: { name: 'about' }, 
-                signalHandlers: { activate: this._onAboutActivate }
-            }, {
-                properties: {
-                    name: 'map-type-menu', 
-                    state: GLib.Variant.new('b', false)
-                },
-                signalHandlers: { activate: this._onMapTypeMenuActivate }
-            }, {
-                properties: {
-                    name: 'map-type',
-                    parameter_type: GLib.VariantType.new('s'),
-                    state: GLib.Variant.new('s', 'STREET')
-                },
-                signalHandlers: { activate: this._onMapTypeActivate }
-            }
-        ], this);
-
-        // apply the last saved window size and position
-        let size = Application.settings.get_value('window-size');
-        if (size.n_children() == 2) {
-            let width = size.get_child_value(0);
-            let height = size.get_child_value(1);
-
-            this.window.set_default_size(width.get_int32(),
-                                         height.get_int32());
-        }
-
-        let position = Application.settings.get_value('window-position');
-        if (position.n_children() == 2) {
-            let x = position.get_child_value(0);
-            let y = position.get_child_value(1);
-
-            this.window.move(x.get_int32(),
-                             y.get_int32());
-        }
-
-        if (Application.settings.get_boolean('window-maximized'))
-            this.window.maximize();
+        this._initActions();
+        this._restoreWindowGeometry();
 
         this.window.connect('delete-event', Lang.bind(this, this._quit));
         this.window.connect('configure-event',
@@ -146,6 +107,28 @@ const MainWindow = new Lang.Class({
         grid.show_all();
     },
 
+    _initActions: function() {
+        Utils.initActions(this.window, [
+            {
+                properties: { name: 'about' },
+                signalHandlers: { activate: this._onAboutActivate }
+            }, {
+                properties: {
+                    name: 'map-type-menu',
+                    state: GLib.Variant.new('b', false)
+                },
+                signalHandlers: { activate: this._onMapTypeMenuActivate }
+            }, {
+                properties: {
+                    name: 'map-type',
+                    parameter_type: GLib.VariantType.new('s'),
+                    state: GLib.Variant.new('s', 'STREET')
+                },
+                signalHandlers: { activate: this._onMapTypeActivate }
+            }
+        ], this);
+    },
+
     _saveWindowGeometry: function() {
         let window = this.window.get_window();
         let state = window.get_state();
@@ -163,6 +146,29 @@ const MainWindow = new Lang.Class({
         Application.settings.set_value('window-position', variant);
     },
 
+    _restoreWindowGeometry: function() {
+        let size = Application.settings.get_value('window-size');
+        if (size.n_children() == 2) {
+            let width = size.get_child_value(0);
+            let height = size.get_child_value(1);
+
+            this.window.set_default_size(width.get_int32(),
+                                         height.get_int32());
+        }
+
+        let position = Application.settings.get_value('window-position');
+        if (position.n_children() == 2) {
+            let x = position.get_child_value(0);
+            let y = position.get_child_value(1);
+
+            this.window.move(x.get_int32(),
+                             y.get_int32());
+        }
+
+        if (Application.settings.get_boolean('window-maximized'))
+            this.window.maximize();
+    },
+
     _onConfigureEvent: function(widget, event) {
         if (this._configureId != 0) {
             Mainloop.source_remove(this._configureId);


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