From e1fe603a7c002073f8ac13623f8cc8dc43efb59d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 31 May 2012 10:27:46 -0700 Subject: fixing selection when switching documents Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 16 +++------ js/controllers/selection-controller.js | 64 +++++++++++++++++++++++++++------ js/document/models/base.js | 5 +++ js/document/models/html.js | 5 --- js/ninja.reel/ninja.html | 4 ++- js/ninja.reel/ninja.js | 22 +----------- js/panels/properties.reel/properties.js | 26 +++++++++++--- 7 files changed, 88 insertions(+), 54 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 13ab33cc..c9557a57 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -53,9 +53,11 @@ exports.DocumentController = Montage.create(Component, { document.getElementById("iframeContainer").style.display = "block"; document.getElementById("codeViewContainer").style.display = "block"; } else if(this._currentDocument.currentView === "design") { - + this._currentDocument.model.currentView.show(); + this._currentDocument.model.views.design._liveNodeList = this._currentDocument.model.documentRoot.getElementsByTagName('*'); } else { document.getElementById("iframeContainer").style.display = "none"; + this._currentDocument.model.currentView.show(); } } @@ -354,14 +356,8 @@ exports.DocumentController = Montage.create(Component, { if(currentDocument) { if(currentDocument.currentView === "design") { currentDocument.serializeDocument(); - this.application.ninja._currentSelectedContainer = this.application.ninja.selectionController._selectionContainer = null; - currentDocument.model.views.design.propertiesPanel.clear(); } - currentDocument.model.isActive = false; - - currentDocument.model.currentView.hide(); - if(currentDocument.model.parentContainer !== newDocument.model.parentContainer) { currentDocument.model.parentContainer.style["display"] = "none"; newDocument.model.parentContainer.style["display"] = "block"; @@ -382,13 +378,9 @@ exports.DocumentController = Montage.create(Component, { this.application.ninja.stage.hideRulers(); } -// this.application.ninja.stage.clearAllCanvas(); - if(didCreate) { -// newDocument.model.currentView.show(); - if(newDocument.currentView === "design") { - NJevent("onOpenDocument", newDocument); + } else { newDocument.model.parentContainer.style["display"] = "block"; } diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 848355da..a219c597 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -20,6 +20,60 @@ exports.SelectionController = Montage.create(Component, { } }, + _currentDocument: { + value : null + }, + + currentDocument : { + get : function() { + return this._currentDocument; + }, + set : function(value) { + if (value === this._currentDocument) { + return; + } + + if(this._currentDocument) { + this._currentDocument.model.selection = this.application.ninja.selectedElements; + this._currentDocument.model.selectionContainer = this.application.ninja._currentSelectedContainer; + } + + this._currentDocument = value; + + if(!value) { + } else if(this._currentDocument.currentView === "design") { + } else { + } + + } + }, + + _selectedElements: { + value: null + }, + + selectedElements: { + get: function() { + return this._selectedElements; + }, + set: function(value) { + if(value) { + this._selectedElements = value; + + this.application.ninja.selectedElements = this._selectedElements; + this.application.ninja._currentSelectedContainer = this._selectionContainer = this.application.ninja.currentDocument.model.documentRoot; + + if(this._selectedElements.length === 0) { + this.executeSelectElement(); + } else { + this.executeSelectElement(this._selectedElements); + } + + + } + } + }, + // Bound property to the ninja currentSelectedContainer _selectionContainer: { value: null @@ -44,16 +98,6 @@ exports.SelectionController = Montage.create(Component, { this.eventManager.addEventListener("elementsRemoved", this, false); this.eventManager.addEventListener("elementReplaced", this, false); this.eventManager.addEventListener("selectAll", this, false); - this.eventManager.addEventListener("switchDocument", this, false); - } - }, - - handleSwitchDocument: { - value: function() { -// if(this.application.ninja.documentController.activeDocument.currentView === "design"){ - this._isDocument = this.application.ninja.selectedElements.length === 0; - NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); -// } } }, diff --git a/js/document/models/base.js b/js/document/models/base.js index 6d9d2e89..886a4ef0 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js @@ -62,6 +62,11 @@ exports.BaseDocumentModel = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // + selection: { + value: [] + }, + //////////////////////////////////////////////////////////////////// + // fileTemplate: { value: null }, diff --git a/js/document/models/html.js b/js/document/models/html.js index fd42d4de..9f5599a2 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -19,11 +19,6 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { }, //////////////////////////////////////////////////////////////////// // - selection: { - value: [] - }, - //////////////////////////////////////////////////////////////////// - // selectionContainer: { value: [] }, diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html index d9bebc36..031d68e9 100755 --- a/js/ninja.reel/ninja.html +++ b/js/ninja.reel/ninja.html @@ -278,7 +278,9 @@ "selectionController": { "prototype": "js/controllers/selection-controller", "bindings" : { - "selectionContainer": {"<-": "@owner.currentSelectedContainer"} + "selectionContainer": {"<-": "@owner.currentSelectedContainer"}, + "currentDocument": {"<-": "@documentList.selectedObjects.0"}, + "selectedElements": {"<-": "@documentList.selectedObjects.0.model.selection"} } }, diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js index 3c60bb41..4c1efff4 100755 --- a/js/ninja.reel/ninja.js +++ b/js/ninja.reel/ninja.js @@ -151,7 +151,6 @@ exports.Ninja = Montage.create(Component, { } }, - selectedElements: { value: [] }, @@ -196,7 +195,6 @@ exports.Ninja = Montage.create(Component, { this.eventManager.addEventListener("selectTool", this, false); this.eventManager.addEventListener("selectSubTool", this, false); - this.eventManager.addEventListener("onSwitchDocument", this, false); this.addPropertyChangeListener("appModel.livePreview", this.executeLivePreview, false); this.addPropertyChangeListener("appModel.chromePreview", this.executeChromePreview, false); @@ -311,15 +309,9 @@ exports.Ninja = Montage.create(Component, { this.currentSelectedContainer = doc.model.documentRoot; } -// if(this.currentDocument.model.documentRoot) { -// this.currentSelectedContainer = this.currentDocument.model.documentRoot; -// } else { -// alert("The current document has not loaded yet"); -// return; -// } // this.appModel.show3dGrid = this.currentDocument.draw3DGrid; -// NJevent("openDocument"); + } }, @@ -332,18 +324,6 @@ exports.Ninja = Montage.create(Component, { } }, - handleOnSwitchDocument: { - value: function() { - this.currentDocument = this.documentController.activeDocument; - - if(this.currentDocument.model.documentRoot) { - this._currentSelectedContainer = this.selectionController._selectionContainer = this.currentDocument.model.documentRoot; - } - - NJevent("switchDocument"); - } - }, - executeLivePreview: { value: function() { var background, overflow, transitionStopRule; diff --git a/js/panels/properties.reel/properties.js b/js/panels/properties.reel/properties.js index d05fb058..934a3851 100755 --- a/js/panels/properties.reel/properties.js +++ b/js/panels/properties.reel/properties.js @@ -28,15 +28,17 @@ exports.Properties = Montage.create(Component, { this._currentDocument = value; - if(!value) { +// if(!value) { this.clear(); - } else if(this._currentDocument.currentView === "design") { - // Save a reference of the pi inside the document view to be able to clear - this._currentDocument.model.views.design.propertiesPanel = this; +// } + /* + else if(this._currentDocument.currentView === "design") { // Display the default document root PI - this.displayElementProperties(this._currentDocument.model.documentRoot); + //this.displayElementProperties(this._currentDocument.model.documentRoot); +// this.displaySelection(this._currentDocument.model.selection); } + */ } }, @@ -181,6 +183,20 @@ exports.Properties = Montage.create(Component, { } }, + displaySelection: { + value: function(selection) { + if(selection.length === 0) { + this.displayElementProperties(this._currentDocument.model.documentRoot); + } else { + if(selection.length === 1) { + this.displayElementProperties(this.application.ninja.selectedElements[0]); + } else { + this.displayGroupProperties(this.application.ninja.selectedElements); + } + } + } + }, + clear: { value: function() { this.elementName.value = ""; -- cgit v1.2.3