[gnome-weather] Factor out a WorldView class



commit 23579851f766903373c5da74609b2845f54138f4
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Mar 13 00:06:47 2013 +0100

    Factor out a WorldView class
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695735

 src/main.js   |    2 ++
 src/window.js |   20 +++++++-------------
 src/world.js  |   15 +++++++++++++++
 3 files changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/src/main.js b/src/main.js
index 2a878df..cc1c429 100644
--- a/src/main.js
+++ b/src/main.js
@@ -34,6 +34,7 @@ pkg.require({ 'Gd': '1.0',
 
 const Util = imports.util;
 const Window = imports.window;
+const World = imports.world;
 
 const Application = new Lang.Class({
     Name: 'WeatherApplication',
@@ -68,6 +69,7 @@ const Application = new Lang.Class({
         settings.gtk_application_prefer_dark_theme = true;
 
         this.world = GWeather.Location.new_world(false);
+        this.model = new World.WorldModel(this.world);
 
         Util.initActions(this,
                          [{ name: 'quit',
diff --git a/src/window.js b/src/window.js
index fe52d77..bd55d83 100644
--- a/src/window.js
+++ b/src/window.js
@@ -96,7 +96,6 @@ const MainWindow = new Lang.Class({
         this.parent(params);
 
         this._world = this.application.world;
-        this._model = new World.WorldModel(this._world);
         this._currentInfo = null;
         this._currentPage = Page.WORLD;
         this._pageWidgets = [[],[]];
@@ -151,14 +150,11 @@ const MainWindow = new Lang.Class({
                                                 vexpand: true });
         this._stack.add(this._cityView);
 
-        this._worldView = new Gd.MainView({ view_type: Gd.MainViewType.ICON });
-        this._worldView.model = this._model;
-        this._worldView.connect('item-activated', Lang.bind(this, this._itemActivated));
-        this._worldView.connect('selection-mode-request', Lang.bind(this, function() {
-            this._worldView.selection_mode = true;
-        }));
+        this._worldView = new World.WorldView(this.application.model);
         this._stack.add(this._worldView);
 
+        this._worldView.connect('item-activated', Lang.bind(this, this._itemActivated));
+
         select.connect('clicked', Lang.bind(this, function() {
             this._worldView.selection_mode = true;
         }));
@@ -166,9 +162,7 @@ const MainWindow = new Lang.Class({
             this._worldView.selection_mode = false;
         }));
         this._worldView.connect('notify::selection-mode', Lang.bind(this, function() {
-            let mode = this._worldView.selection_mode;
-
-            if (mode) {
+            if (this._worldView.selection_mode) {
                 this._header.get_style_context().add_class('selection-mode');
                 this._header.set_custom_title(this._selectionMenuButton);
             } else {
@@ -261,8 +255,8 @@ const MainWindow = new Lang.Class({
     },
 
     _itemActivated: function(view, id, path) {
-        let [ok, iter] = this._model.get_iter(path);
-        let info = this._model.get_value(iter, World.Columns.INFO);
+        let [ok, iter] = this._worldView.model.get_iter(path);
+        let info = this._worldView.model.get_value(iter, World.Columns.INFO);
 
         this._cityView.info = info;
         this._stack.set_visible_child(this._cityView);
@@ -306,7 +300,7 @@ const MainWindow = new Lang.Class({
             if (!location)
                 return;
 
-            this._model.addLocation(entry.location);
+            this._worldView.model.addLocation(entry.location);
         }));
         dialog.show_all();
     },
diff --git a/src/world.js b/src/world.js
index 6cd4564..b5c4049 100644
--- a/src/world.js
+++ b/src/world.js
@@ -159,3 +159,18 @@ const WorldModel = new Lang.Class({
         this._settings.set_value('locations', new GLib.Variant('av', newLocations));
     },
 });
+
+const WorldView = new Lang.Class({
+    Name: 'WorldView',
+    Extends: Gd.MainView,
+
+    _init: function(model, params) {
+        params = Params.fill(params, { view_type: Gd.MainViewType.ICON });
+        this.parent(params);
+        this.model = model;
+
+        this.connect('selection-mode-request', Lang.bind(this, function() {
+            this.selection_mode = true;
+        }));
+    }
+});


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