[gnome-maps/wip/gtk-builder: 2/2] MainWindow: use more GtkBuilder



commit 8c60fde2fb85208f4dd9971a771945e3855f42a3
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Mon Jun 17 22:13:35 2013 +0200

    MainWindow: use more GtkBuilder
    
    Move the appwindow into the ui-file and load it with Utils.getUIObject.

 src/mainWindow.js |   33 +++++++++++++++------------------
 1 files changed, 15 insertions(+), 18 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 6cb3ee5..4fa7ce2 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -104,38 +104,34 @@ const MainWindow = new Lang.Class({
         this.window.connect('window-state-event',
                             Lang.bind(this, this._onWindowStateEvent));
 
-        let builder = new Gtk.Builder();
-        builder.add_from_resource('/org/gnome/maps/main-window.ui');
+        this._ui = Utils.getUIObject('main-window', ['window-content',
+                                                     'search-entry',
+                                                     'track-user-button']);
+        this._ui['window-content'].set_orientation (Gtk.Orientation.VERTICAL);
+        this.window.add(this._ui['window-content']);
 
-        let grid = builder.get_object('window-content');
-        grid.set_orientation (Gtk.Orientation.VERTICAL);
-        this.window.add(grid);
-
-        this._searchEntry = builder.get_object('search-entry');
-        this._searchEntry.connect('activate', Lang.bind(this, this._onSearchActivate));
+        this._ui['search-entry'].connect('activate', Lang.bind(this, this._onSearchActivate));
 
         this.mapView = new MapView.MapView();
 
         let trackUserLocation = Application.settings.get_boolean('track-user-location');
 
-        let toggle = builder.get_object('track-user-button');
-
         let onViewMoved = Lang.bind(this,
             function () {
                 if (!this.mapView.userLocationVisible())
-                    toggle.active = false;
+                    this._ui['track-user-button'].active = false;
             });
 
         // Disable animation for goto animation on startup only
         let animateGotoUserLocation = !trackUserLocation;
-        toggle.connect('toggled', Lang.bind(this,
+        this._ui['track-user-button'].connect('toggled', Lang.bind(this,
             function() {
                 if (this._onViewMovedId > 0) {
                     this.mapView.disconnect(this._onViewMovedId);
                     this._onViewMovedId = 0;
                 }
 
-                if (toggle.active) {
+                if (this._ui['track-user-button'].active) {
                     let goneToUserLocationId = this.mapView.connect('gone-to-user-location', Lang.bind(this,
                         function () {
                             this.mapView.disconnect(goneToUserLocationId);
@@ -146,13 +142,14 @@ const MainWindow = new Lang.Class({
                         animateGotoUserLocation = true;
                 }
 
-                Application.settings.set_boolean('track-user-location', toggle.active);
+                Application.settings.set_boolean('track-user-location',
+                                                 this._ui['track-user-button'].active);
             }));
-        toggle.active = trackUserLocation;
+        this._ui['track-user-button'].active = trackUserLocation;
 
-        grid.add(this.mapView);
+        this._ui['window-content'].add(this.mapView);
 
-        grid.show_all();
+        this._ui['window-content'].show_all();
     },
 
     _saveWindowGeometry: function() {
@@ -197,7 +194,7 @@ const MainWindow = new Lang.Class({
     },
 
     _onSearchActivate: function() {
-        let string = this._searchEntry.get_text();
+        let string = this._ui['search-entry'].get_text();
 
         this.mapView.geocodeSearch(string);
     },


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