From 7283884c39df537694b21419a3ea9e3ca7793b4b Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 23 Feb 2012 13:43:35 -0800 Subject: switch html document - re-initialize draw-utils and snap-manager on opening a document and while switching documents Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 6 +-- js/controllers/elements/element-controller.js | 6 ++- js/controllers/selection-controller.js | 9 ++++ js/document/html-document.js | 59 ++++++++++++++++++++++++++- js/helper-classes/3D/draw-utils.js | 20 +++++++++ js/helper-classes/3D/snap-manager.js | 1 + js/stage/stage-deps.js | 38 +++++++++-------- js/stage/stage-view.reel/stage-view.js | 14 +++---- js/stage/stage.reel/stage.js | 4 ++ 9 files changed, 126 insertions(+), 31 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 48e33267..f323ed99 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -321,7 +321,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // Event Detail: Contains the current ActiveDocument _onOpenDocument: { value: function(doc){ - //var data = DocumentManager.activeDocument; + this.application.ninja.currentDocument = doc; this._hideCurrentDocument(); this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); @@ -405,7 +405,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { if(this.activeDocument) { if(this.activeDocument.currentView === "design"){ - this.application.ninja.stage.saveScroll(); + this.activeDocument.saveAppState(); this.activeDocument.container.parentNode.style["display"] = "none"; this.application.ninja.stage.hideCanvas(true); this.application.ninja.stage.stageView.hideRulers(); @@ -422,7 +422,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument.container.style["display"] = "block"; if(this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; - this.application.ninja.stage.restoreScroll(); + this.activeDocument.restoreAppState(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); }else{ diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index ac14def4..d6f2bc56 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js @@ -27,7 +27,11 @@ var ElementController = exports.ElementController = Montage.create(NJComponent, getProperty: { value: function(el, prop, fallbackOnComputed, isStageElement) { - return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); + if(el.nodeType !== 3){ + return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); + }else{ + return null; + } } }, diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index d69b53e0..f50762f3 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -58,6 +58,7 @@ exports.SelectionController = Montage.create(Component, { handleOpenDocument: { value: function() { // Handle initializing the selection array here. + this.initWithDocument([]); } }, @@ -70,6 +71,14 @@ exports.SelectionController = Montage.create(Component, { if(currentSelectionArray.length >= 1) { this._selectedItems = currentSelectionArray; this._isDocument = false; + + + + this.application.ninja.selectedElements = currentSelectionArray; + NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); + + + } } diff --git a/js/document/html-document.js b/js/document/html-document.js index 02e9918f..f260b665 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -53,6 +53,11 @@ exports.HTMLDocument = Montage.create(TextDocument, { }, + //drawUtils state + _gridHorizontalSpacing: {value:0}, + _gridVerticalSpacing: {value:0}, + //end - drawUtils state + // GETTERS / SETTERS @@ -71,6 +76,16 @@ exports.HTMLDocument = Montage.create(TextDocument, { set: function(value) { this._savedTopScroll = value} }, + gridHorizontalSpacing:{ + get: function() { return this._gridHorizontalSpacing; }, + set: function(value) { this._gridHorizontalSpacing = value} + }, + + gridVerticalSpacing:{ + get: function() { return this._gridVerticalSpacing; }, + set: function(value) { this._gridVerticalSpacing = value} + }, + selectionExclude: { get: function() { return this._selectionExclude; }, set: function(value) { this._selectionExclude = value; } @@ -444,7 +459,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { this._styles = this._document.styleSheets[1]; this._stylesheets = this._document.styleSheets; // Entire stlyesheets array - console.log(this._document.styleSheets); + //console.log(this._document.styleSheets); //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// @@ -570,7 +585,47 @@ exports.HTMLDocument = Montage.create(TextDocument, { //Error } } - } + }, //////////////////////////////////////////////////////////////////// + saveAppState:{ + enumerable: false, + value: function () { + + this.savedLeftScroll = this.application.ninja.stage._iframeContainer.scrollLeft; + this.savedTopScroll = this.application.ninja.stage._iframeContainer.scrollTop; + + this.gridHorizontalSpacing = this.application.ninja.stage.drawUtils.gridHorizontalSpacing; + this.gridVerticalSpacing = this.application.ninja.stage.drawUtils.gridVerticalSpacing; + + //TODO:selection should be saved as an element state data, to avoid duplicate dom elements store in memory + if(typeof this.application.ninja.selectedElements !== 'undefined'){ + this.selectionModel = this.application.ninja.selectedElements; + } + } + }, + + //////////////////////////////////////////////////////////////////// + restoreAppState:{ + enumerable: false, + value: function () { + if((this.savedLeftScroll!== null) && (this.savedTopScroll !== null)){ + this.application.ninja.stage._iframeContainer.scrollLeft = this.savedLeftScroll; + this.application.ninja.stage._scrollLeft = this.savedLeftScroll; + this.application.ninja.stage._iframeContainer.scrollTop = this.savedTopScroll; + this.application.ninja.stage._scrollTop = this.savedTopScroll; + } + + this.application.ninja.stage.drawUtils.gridHorizontalSpacing = this.gridHorizontalSpacing; + this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing; + + //TODO:selectionController.initWithDocument should loop over elements in documentRoot to repopulate + if((typeof this.selectionModel !== 'undefined') && (this.selectionModel !== null) && (this.selectionModel.length > 0)){ + this.application.ninja.selectionController.initWithDocument(this.selectionModel); + } + + + } + } + //////////////////////////////////////////////////////////////////// }); \ No newline at end of file diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index c07391db..37fc1cfc 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -115,6 +115,26 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } }, + initializeFromDocument:{ + value:function(){ + var documentRootChildren = null, i; + //initialize with current document + this._eltArray = []; + this._planesArray = []; + this.setDrawingSurfaceElement(this.application.ninja.stage.canvas); + this.setSourceSpaceElement( this.application.ninja.stage.stageDeps.currentStage ); + this.setWorkingPlane( Vector.create( [0,0,1,0] ) ); + + //Loop through all the top-level children of the current document and call drawUtils.addElement on them + if(this.application.ninja.currentDocument.documentRoot.hasChildNodes()){ + documentRootChildren = this.application.ninja.currentDocument.documentRoot.childNodes; + for(i=0;i