[the-board] [ui] Get rid of addThingFromId, use addThingFromState instead



commit 987475bdb26c96d328aeeea40a8f46449cb59414
Author: Lucas Rocha <lucasr gnome org>
Date:   Sat Nov 27 01:18:29 2010 +0000

    [ui] Get rid of addThingFromId, use addThingFromState instead
    
    The right way to add things to current page is to add actor then loading
    state on them.

 src/js/ui/application.js   |   14 +++-----------
 src/js/ui/mainWindow.js    |   11 ++++++-----
 src/js/ui/page.js          |   34 ++++++++++++++--------------------
 src/js/ui/toolBoxThings.js |    2 +-
 4 files changed, 24 insertions(+), 37 deletions(-)
---
diff --git a/src/js/ui/application.js b/src/js/ui/application.js
index 6994ddb..5126f0a 100644
--- a/src/js/ui/application.js
+++ b/src/js/ui/application.js
@@ -103,21 +103,13 @@ Application.prototype = {
     addThing : function(args) {
         log('Application: addThing via DBus');
 
-        if (!('thingId' in args)) {
-            log('Application: addThing needs a thingId argument');
+        if (!('id' in args)) {
+            log('Application: addThing needs an id argument');
             return;
         }
 
-        let thingId = args.thingId;
-
-        // Any extra values in args are considered as
-        // thing-specific arguments
-        delete args.thingId;
-        let thingArgs = args;
-
         if (this._mainWindow.currentPage) {
-            this._mainWindow.currentPage.addThingFromId(thingId,
-                                                        thingArgs);
+            this._mainWindow.currentPage.addThingFromState(args);
         }
     },
 
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 2c0e901..467d516 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -655,7 +655,8 @@ MainWindow.prototype = {
             thingId = "note";
         }
 
-        this._currentPage.addThingFromId(thingId, { text: text });
+        this._currentPage.addThingFromState({ id: thingId,
+                                              text: text });
     },
 
     _onStartupBoxTimeout : function() {
@@ -689,16 +690,16 @@ MainWindow.prototype = {
         } else if (key == Clutter.Escape) {
             this._hideGtkWindow();
         } else if (text == 't') {
-            this._currentPage.addThingFromId('note');
+            this._currentPage.addThingFromState({ id: 'note' });
             return true;
         } else if (text == 'l') {
-            this._currentPage.addThingFromId('label');
+            this._currentPage.addThingFromState({ id: 'label' });
             return true;
         } else if (text == 'p') {
-            this._currentPage.addThingFromId('photo');
+            this._currentPage.addThingFromState({ id: 'photo' });
             return true;
         } else if (text == 'v') {
-            this._currentPage.addThingFromId('video');
+            this._currentPage.addThingFromState({ id: 'video' });
             return true;
         } else if (text == 'q') {
             this._quitApp();
diff --git a/src/js/ui/page.js b/src/js/ui/page.js
index e1e6e27..ddd74b0 100644
--- a/src/js/ui/page.js
+++ b/src/js/ui/page.js
@@ -193,7 +193,7 @@ Page.prototype = {
 
         for (let i = 0; i < things.length; ++i) {
             let state = things[i];
-            this.addThingFromState(state);
+            this.addThingFromState(state, false /* add to model */);
         }
     },
 
@@ -260,15 +260,6 @@ Page.prototype = {
                              Tb.BoxPackFlags.FIXED);
 
         this._things.push(thing);
-
-        // no animation if loading from state
-        if (!state) {
-            state = thing.onGetState();
-            this._model.addThing(state);
-
-            this.setActiveThing(thing);
-            this._animateNewThing(thing);
-        }
     },
 
     _getAnimationAnchorForNewThing : function(thing) {
@@ -400,17 +391,12 @@ Page.prototype = {
         this.emit("active-thing-changed");
     },
 
-    addThingFromId : function(thingId, args) {
-        args = args || {};
-
-        args.parentActor = this._mainBox;
-        args.context = this._context;
-
-        let thing = Thing.createThingFromId(thingId, args);
-        this._addThing(thing, null);
-    },
+    addThingFromState : function(state, addToModel) {
+        // add to model by default
+        if (addToModel === undefined) {
+            addToModel = true;
+        }
 
-    addThingFromState : function(state) {
         let thingId = state.id;
 
         let args = { parentActor: this._mainBox,
@@ -420,6 +406,14 @@ Page.prototype = {
         thing.onLoadState(state);
 
         this._addThing(thing, state);
+
+        if (addToModel) {
+            this._model.addThing(state);
+
+            // animate only new things
+            this.setActiveThing(thing);
+            this._animateNewThing(thing);
+        }
     },
 
     removeThing : function(thing) {
diff --git a/src/js/ui/toolBoxThings.js b/src/js/ui/toolBoxThings.js
index 006144f..b62b2e8 100644
--- a/src/js/ui/toolBoxThings.js
+++ b/src/js/ui/toolBoxThings.js
@@ -72,7 +72,7 @@ ToolBoxThings.prototype = {
     },
 
     _onThingButtonClicked : function(button, thing) {
-        this._mainWindow.currentPage.addThingFromId(thing.id);
+        this._mainWindow.currentPage.addThingFromState({ id: thing.id });
     },
 
     destroy : function() {



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