From 209ec9524a987a8f8bc20c57e2a76ac55be15fd9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 24 May 2012 11:11:47 -0700 Subject: Fixed selection bug when switching/opening documents. Also, use saved scroll values when switching between documents. Signed-off-by: Nivesh Rajbhandari --- js/controllers/selection-controller.js | 5 ++--- js/stage/stage-deps.js | 2 -- js/stage/stage.reel/stage.js | 40 +++++++++++++++++++--------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 1092615a..214b9032 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -67,10 +67,9 @@ exports.SelectionController = Montage.create(Component, { this._isDocument = true; if(currentSelectionArray) { - if(currentSelectionArray.length >= 1) { + this.application.ninja.selectedElements = currentSelectionArray; + if(currentSelectionArray.length) { this._isDocument = false; - - this.application.ninja.selectedElements = currentSelectionArray; NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); } } diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js index d018b03b..64adc01c 100755 --- a/js/stage/stage-deps.js +++ b/js/stage/stage-deps.js @@ -30,8 +30,6 @@ exports.StageDeps = Montage.create(Component, { value: function() { this.eventManager.addEventListener("appLoaded", this, false); -// this.eventManager.addEventListener("openDocument", this, false); -// this.eventManager.addEventListener("switchDocument", this, false); // Initialize Deps // HACK diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index ad05f1cc..6d421e4b 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -117,9 +117,6 @@ exports.Stage = Montage.create(Component, { _userContentTop: { value: 0 }, _userContentBorder: { value: 0 }, - _maxHorizontalScroll: { value: 0 }, - _maxVerticalScroll: { value: 0 }, - viewport: { get: function () { return this._viewport; }, set: function(value) { this._viewport = value; } @@ -262,18 +259,18 @@ exports.Stage = Montage.create(Component, { // Event details will contain the active document prior to opening a new one handleOpenDocument: { value: function(evt) { - this._initFromDocument(evt); + this.initWithDocument(); } }, handleSwitchDocument: { value: function(evt) { - this._initFromDocument(evt); + this.initWithDocument(true); } }, - _initFromDocument: { - value: function(evt) { + initWithDocument: { + value: function(didSwitch) { var designView = this.application.ninja.currentDocument.model.views.design; this.hideCanvas(false); @@ -282,12 +279,22 @@ exports.Stage = Montage.create(Component, { this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ; this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; - this._maxHorizontalScroll = this.application.ninja.currentDocument.documentRoot.scrollWidth - this._canvas.width - 11; - this._maxVerticalScroll = this.application.ninja.currentDocument.documentRoot.scrollHeight - this._canvas.height - 11; designView.iframe.contentWindow.addEventListener("scroll", this, false); this.addPropertyChangeListener("appModel.show3dGrid", this, false); + this._userPaddingLeft = 0; + this._userPaddingTop = 0; + + this._documentOffsetLeft = 0; + this._documentOffsetTop = 0; + + this._userContentLeft = 0; + this._userContentTop = 0; + + this._scrollLeft = 0; + this._scrollTop = 0; + this.stageDeps.handleOpenDocument(); this.layout.handleOpenDocument(); @@ -302,7 +309,13 @@ exports.Stage = Montage.create(Component, { } } - this.centerStage(); + if(didSwitch) { + this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft = this.application.ninja.currentDocument.model.scrollLeft; + this.application.ninja.currentDocument.model.views.design.document.body.scrollTop = this.application.ninja.currentDocument.model.scrollTop; + this.handleScroll(); + } else { + this.centerStage(); + } // TODO - We will need to modify this once we support switching between multiple documents this.application.ninja.toolsData.selectedToolInstance._configure(true); @@ -488,13 +501,6 @@ exports.Stage = Montage.create(Component, { this.userContentLeft = this._documentOffsetLeft - this._scrollLeft; this.userContentTop = this._documentOffsetTop - this._scrollTop; - // TODO - scroll events are not dependable. We may need to use a timer to simulate - // scrollBegin and scrollEnd. For now, the Pan Tool will keep track of the stage's scroll values - // on mouse down. - // this._maxHorizontalScroll = this.application.ninja.currentDocument.documentRoot.scrollWidth - this._canvas.width - 11; - // this._maxVerticalScroll = this.application.ninja.currentDocument.documentRoot.scrollHeight - this._canvas.height - 11; - - // Need to clear the snap cache and set up the drag plane //snapManager.setupDragPlaneFromPlane( workingPlane ); this.stageDeps.snapManager._isCacheInvalid = true; -- cgit v1.2.3