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/stage/stage-deps.js | 38 ++++++++++++++++++++-------------- js/stage/stage-view.reel/stage-view.js | 14 +++++-------- js/stage/stage.reel/stage.js | 4 ++++ 3 files changed, 31 insertions(+), 25 deletions(-) (limited to 'js/stage') diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js index d46e2b81..316a5bb0 100755 --- a/js/stage/stage-deps.js +++ b/js/stage/stage-deps.js @@ -23,6 +23,10 @@ exports.StageDeps = Montage.create(Component, { value: snapManager }, + drawUtils: { + value: drawUtils + }, + currentStage: { value: null }, @@ -119,29 +123,31 @@ 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.setDrawingSurfaceElement(this.stage.canvas); - drawUtils.setSourceSpaceElement( this.currentStage ); - drawUtils.setWorkingPlane( workingPlane ); - drawUtils.viewUtils = viewUtils; - drawUtils.snapManager = snapManager; - drawUtils.ElementPlanes = ElementPlanes; + 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(); + } } - } + + }); \ No newline at end of file diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js index dc9980f0..0b688c75 100755 --- a/js/stage/stage-view.reel/stage-view.js +++ b/js/stage/stage-view.reel/stage-view.js @@ -122,10 +122,6 @@ exports.StageView = Montage.create(Component, { switchDocument:{ value: function(doc){ - //save editor cursor position - if(!!this.application.ninja.documentController.activeDocument && !!this.application.ninja.documentController.activeDocument.editor){ - this.application.ninja.documentController.activeDocument.hline = this.application.ninja.documentController.activeDocument.editor.getCursor(true); - } this.application.ninja.documentController._hideCurrentDocument(); this.application.ninja.documentController.activeDocument = doc; @@ -133,17 +129,17 @@ exports.StageView = Montage.create(Component, { this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe this.application.ninja.documentController._showCurrentDocument(); - var documentController = this.application.ninja.documentController; - - //restore editor cursor position + //focus current document if(!!this.application.ninja.documentController.activeDocument && !!this.application.ninja.documentController.activeDocument.editor){ - this.application.ninja.documentController.activeDocument.editor.setCursor(this.application.ninja.documentController.activeDocument.hline); document.getElementById("codeMirror_"+this.application.ninja.documentController.activeDocument.uuid).getElementsByClassName("CodeMirror")[0].focus(); } if(this.application.ninja.documentController.activeDocument.currentView === "design") { 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.currentDocument = this.application.ninja.documentController.activeDocument; + + this.application.ninja.stage.snapManager._isCacheInvalid=true; + this.application.ninja.stage.drawUtils.initializeFromDocument(); // TODO dispatch event here // appDelegateModule.MyAppDelegate.onSetActiveDocument(); diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 44e14827..6bb626c2 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -37,6 +37,10 @@ exports.Stage = Montage.create(Component, { get: function() { return this.stageDeps.snapManager; } }, + drawUtils: { + get: function() { return this.stageDeps.drawUtils; } + }, + resizeCanvases: { get: function() { return this._resizeCanvases; -- cgit v1.2.3