From 6e66f411ba02eaaeb33471115345ecf3c7ce4ce9 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 23 Feb 2012 17:55:59 -0800 Subject: refresh draw-utils, snap-manager, view-utils for html document stitching Signed-off-by: Ananya Sen --- 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