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 --- js/document/html-document.js | 18 +++++------ js/stage/stage-deps.js | 56 +++++++++++++++++++++++++--------- js/stage/stage-view.reel/stage-view.js | 9 +++--- js/stage/stage.reel/stage.js | 10 +++--- 4 files changed, 57 insertions(+), 36 deletions(-) (limited to 'js') diff --git a/js/document/html-document.js b/js/document/html-document.js index d38709e3..c5293386 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -645,7 +645,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { 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; } @@ -656,24 +655,21 @@ exports.HTMLDocument = Montage.create(TextDocument, { 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); } - + 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._scrollLeft = this.savedTopScroll; + } + this.application.ninja.stage.handleScroll(); } } - //////////////////////////////////////////////////////////////////// }); \ No newline at end of file diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js index 316a5bb0..16f2c652 100755 --- a/js/stage/stage-deps.js +++ b/js/stage/stage-deps.js @@ -123,30 +123,56 @@ exports.StageDeps = Montage.create(Component, { }, handleOpenDocument: { - value: function() { + value: function() { - workingPlane = Vector.create( [0,0,1,0] ); + workingPlane = Vector.create( [0,0,1,0] ); - snapManager.setCurrentStage(this.currentStage); + snapManager.setCurrentStage(this.currentStage); - viewUtils.setCurrentDocument(this.currentDocument); - viewUtils.setRootElement(this.currentStage.parentNode); - viewUtils.setStageElement(this.currentStage); + viewUtils.setCurrentDocument(this.currentDocument); + viewUtils.setRootElement(this.currentStage.parentNode); + viewUtils.setStageElement(this.currentStage); - drawUtils.viewUtils = viewUtils; - drawUtils.snapManager = snapManager; - drawUtils.ElementPlanes = ElementPlanes; + drawUtils.viewUtils = viewUtils; + drawUtils.snapManager = snapManager; + drawUtils.ElementPlanes = ElementPlanes; - snapManager._isCacheInvalid=true; + snapManager._isCacheInvalid=true; - snapManager.setupDragPlaneFromPlane ( workingPlane ); + snapManager.setupDragPlaneFromPlane ( workingPlane ); - DrawingToolBase.stage = this.currentStage; - DrawingToolBase.stageComponent = this.stage; + DrawingToolBase.stage = this.currentStage; + DrawingToolBase.stageComponent = this.stage; - drawUtils.initializeFromDocument(); - } + drawUtils.initializeFromDocument(); + } + }, + + reinitializeForSwitchDocument: { + value: function() { + + workingPlane = Vector.create( [0,0,1,0] ); + + snapManager.setCurrentStage(this.currentStage); + + viewUtils.setCurrentDocument(this.currentDocument); + viewUtils.setRootElement(this.currentStage.parentNode); + viewUtils.setStageElement(this.currentStage); + + drawUtils.viewUtils = viewUtils; + drawUtils.snapManager = snapManager; + drawUtils.ElementPlanes = ElementPlanes; + + snapManager._isCacheInvalid=true; + + snapManager.setupDragPlaneFromPlane ( workingPlane ); + + DrawingToolBase.stage = this.currentStage; + DrawingToolBase.stageComponent = this.stage; + + drawUtils.initializeFromDocument(); } + } diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index 0b688c75..ab02661d 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -118,8 +118,7 @@ exports.StageView = Montage.create(Component, { } }, - - + //called for switching between html documents switchDocument:{ value: function(doc){ this.application.ninja.documentController._hideCurrentDocument(); @@ -138,8 +137,10 @@ exports.StageView = Montage.create(Component, { this.application.ninja.stage._scrollFlag = true; // TODO HACK to prevent type error on Hide/Show Iframe this.application.ninja.currentDocument = this.application.ninja.documentController.activeDocument; - this.application.ninja.stage.snapManager._isCacheInvalid=true; - this.application.ninja.stage.drawUtils.initializeFromDocument(); + //reinitialize draw-util, snapmanager and view-util + this.application.ninja.stage.stageDeps.reinitializeForSwitchDocument(); + + //this.application.ninja.stage.layout.reinitializeForSwitchDocument(); // TODO dispatch event here // appDelegateModule.MyAppDelegate.onSetActiveDocument(); diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 755c7ff1..9784f14d 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -148,12 +148,12 @@ exports.Stage = Montage.create(Component, { userContentLeft: { get: function() { return this._userContentLeft; }, - set: function(value) { this._userContentLeft = value; } + set: function(value) { this._userContentLeft = value;} }, userContentTop: { get: function() { return this._userContentTop; }, - set: function(value) { this._userContentTop = value; } + set: function(value) { this._userContentTop = value;} }, userContentBorder: { @@ -439,12 +439,11 @@ exports.Stage = Montage.create(Component, { */ handleScroll: { value: function() { - this._scrollLeft = this._iframeContainer.scrollLeft; this._scrollTop = this._iframeContainer.scrollTop; - this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; - this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; + this.userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; + this.userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; // Need to clear the snap cache and set up the drag plane //snapManager.setupDragPlaneFromPlane( workingPlane ); @@ -452,7 +451,6 @@ exports.Stage = Montage.create(Component, { this.needsDraw = true; this.layout.draw(); - //this._toolsList.action("DrawHandles"); } -- cgit v1.2.3 From 85d59d57ea556b114c5cad9b2ec67ccc27119380 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 24 Feb 2012 12:05:16 -0800 Subject: - added flag for timeline to identify new file flow - added switchDocument event for timeline Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 6 ++++++ js/stage/stage-view.reel/stage-view.js | 2 ++ 2 files changed, 8 insertions(+) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index e221df68..714d1404 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -195,6 +195,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(doc){ var response = doc || null;//default just for testing if(!!response && response.success && (response.status!== 500) && !!response.uri){ + this.creatingNewFile = true;//flag for timeline to identify new file flow this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); }else if(!!response && !response.success){ //Todo: restrict directory path to the sandbox, in the dialog itself @@ -222,6 +223,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(response){ //TODO: Add UI to handle error codes, shouldn't be alert windows if(!!response && (response.status === 204)) { + + if((typeof this.creatingNewFile === 'undefined') || (this.creatingNewFile !== true)){//not from new file flow + this.creatingNewFile = false; + } + //Sending full response object this.openDocument(response); } else if (!!response && (response.status === 404)){ diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index ab02661d..91047e51 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -146,6 +146,8 @@ exports.StageView = Montage.create(Component, { // appDelegateModule.MyAppDelegate.onSetActiveDocument(); } + NJevent("switchDocument"); + } }, -- cgit v1.2.3 From b056b4bef5982466d80d72e5cbb31e63087990e1 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 24 Feb 2012 15:30:55 -0800 Subject: - added closeDocument event for timeline - minor bug fixes Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 4 ++++ js/helper-classes/3D/draw-utils.js | 4 ++-- js/mediators/keyboard-mediator.js | 8 +++++++- js/stage/layout.js | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 714d1404..02031922 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -338,6 +338,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.hideCanvas(true); } + + NJevent("closeDocument", doc.uri); + + doc=null; } }, diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 37fc1cfc..85870097 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -126,8 +126,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { 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; + if(this.application.ninja.currentDocument._liveNodeList.length > 0){ + documentRootChildren = this.application.ninja.currentDocument._liveNodeList; for(i=0;i