From 6e59aebe70c29b82db1a5723993fe09d8d47d0e3 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 29 Jan 2015 17:41:28 -0500
Subject: [PATCH] appstate instead of weird properties on menus

---
 js/menus/ImportMenuView.js  |  5 +----
 js/menus/LatticeMenuView.js |  6 ++----
 js/menus/MenuWrapperView.js | 21 +++++----------------
 js/menus/PartMenuView.js    |  5 +----
 js/menus/SketchMenuView.js  |  5 +----
 5 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js
index d82590d1..c454f98d 100644
--- a/js/menus/ImportMenuView.js
+++ b/js/menus/ImportMenuView.js
@@ -15,15 +15,13 @@ ImportMenuView = Backbone.View.extend({
         "click #removeFillGeo":             "_removeMesh"
     },
 
-    currentlySelected: false,
-
     initialize: function(options){
 
         this.lattice = options.lattice;
 
         _.bindAll(this, "render", "_onMeshLoad");
         this.listenTo(this.model, "change", function(){
-            if (!this.currentlySelected) return;
+            if (options.appState.get("currentTab")!="import") return;
             this.render();
         });
 //        this.listenTo(this.model, "change:filename change:boundingBoxHelper", this.render);//boundingBoxHelper covers orientation
@@ -74,7 +72,6 @@ ImportMenuView = Backbone.View.extend({
     },
 
     render: function(){
-        this.currentlySelected = true;
         this.$el.html(this.template(this.model.attributes));
         this.lattice.set("cellMode", "cell");
     },
diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index d747d374..396f6fc2 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -12,13 +12,12 @@ LatticeMenuView = Backbone.View.extend({
         "change #latticeScale":                         "_changeScale"
     },
 
-    currentlySelected: false,
 
-    initialize: function(){
+    initialize: function(options){
 
         _.bindAll(this, "render");
         this.listenTo(this.model, "change", function(){
-            if (!this.currentlySelected) return;
+            if (options.appState.get("currentTab")!="lattice") return;
             if(!this.model.hasChanged('cellMode')){//I want to ignore cellMode changes and listen to everything else
                 this.render();
             }
@@ -44,7 +43,6 @@ LatticeMenuView = Backbone.View.extend({
     },
 
     render: function(){
-        this.currentlySelected = true;//if this causes a change, render must have been called from menu wrapper
         this.$el.html(this.template(_.extend(this.model.attributes, this._formatData())));
         this.model.set("cellMode", "cell");
     },
diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js
index 100d63e4..9c5dbd5e 100644
--- a/js/menus/MenuWrapperView.js
+++ b/js/menus/MenuWrapperView.js
@@ -16,11 +16,11 @@ MenuWrapper = Backbone.View.extend({
         _.bindAll(this, "render", "_updateCurrentTab", "_setVisibility", "_hide", "_show");
 
         //init all tab view controllers
-        this.latticeMenu = new LatticeMenuView({model:options.lattice});
-        this.importMenu = new ImportMenuView({lattice:options.lattice});
-        this.sketchMenu = new SketchMenuView({model:options.lattice});
-        this.partMenu = new PartMenuView({model:options.lattice});
-        this.scriptMenu = new ScriptMenuView();
+        this.latticeMenu = new LatticeMenuView({model:options.lattice, appState:this.model});
+        this.importMenu = new ImportMenuView({lattice:options.lattice, appState:this.model});
+        this.sketchMenu = new SketchMenuView({model:options.lattice, appState:this.model});
+        this.partMenu = new PartMenuView({model:options.lattice, appState:this.model});
+        this.scriptMenu = new ScriptMenuView({appState:this.model});
 
         //data names and titles
         this.designMenuTabs = {lattice:"Lattice", import:"Import", sketch:"Sketch", part:"Part", script:"Script"};
@@ -52,8 +52,6 @@ MenuWrapper = Backbone.View.extend({
             }
         });
 
-        this._deselectAllMenus();
-
         if (tabName == "lattice"){
             this.latticeMenu.render();
         } else if (tabName == "import"){
@@ -71,15 +69,6 @@ MenuWrapper = Backbone.View.extend({
 
     },
 
-    //todo get rid of this!!
-    _deselectAllMenus: function(){
-        this.latticeMenu.currentlySelected = false;
-        this.importMenu.currentlySelected = false;
-        this.sketchMenu.currentlySelected = false;
-        this.partMenu.currentlySelected = false;
-//        this.scriptMenu.currentlySelected = false;
-    },
-
     render: function(){
         var self = this;
         this._hide(function(){
diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js
index 21cdec39..a8c455db 100644
--- a/js/menus/PartMenuView.js
+++ b/js/menus/PartMenuView.js
@@ -9,20 +9,17 @@ PartMenuView = Backbone.View.extend({
     events: {
     },
 
-    currentlySelected: false,
-
     initialize: function(){
 
         _.bindAll(this, "render");
         this.listenTo(this.model, "change:partType", this.render);
 //        this.listenTo(this.model, "change", function(){
-//            if (!this.currentlySelected) return;
+//            if (options.appState.get("currentTab")!="part") return;
 //            this.render();
 //        });
     },
 
     render: function(){
-        this.currentlySelected = true;//if this causes a change, render must have been called from menu wrapper
         this.$el.html(this.template(this.model.attributes));
         this.model.set("cellMode", "parts");
     },
diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js
index 2ae4c709..e146cb59 100644
--- a/js/menus/SketchMenuView.js
+++ b/js/menus/SketchMenuView.js
@@ -10,19 +10,16 @@ SketchMenuView = Backbone.View.extend({
     events: {
     },
 
-    currentlySelected: false,
-
     initialize: function(){
 
         _.bindAll(this, "render");
 //        this.listenTo(this.model, "change", function(){
-//            if (!this.currentlySelected) return;
+//            if (options.appState.get("currentTab")!="sketch") return;
 //            this.render();
 //        });
     },
 
     render: function(){
-        this.currentlySelected = true;
         this.$el.html(this.template());
         this.model.set("cellMode", "cell");
     },
-- 
GitLab