From ed7d22edf3cbca82ae43a4e3373a93a8666ba4a1 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 27 Apr 2012 10:47:42 -0700 Subject: add event handlers for open, close, and switch document to pen tool, fixes: 1532 Pen: Anchor points get carried over to the new document --- js/tools/PenTool.js | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'js/tools') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 8cc32536..016d6ded 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -1278,10 +1278,45 @@ exports.PenTool = Montage.create(ShapeTool, { } //value: function() { }, //DrawSubpathAnchors { + deselectPenTool:{ + value: function() { + this._selectedSubpath = null; + this._selectedSubpathCanvas = null; + this._selectedSubpathPlaneMat = null; + this._snapTargetIndex = -1; + } + }, + //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called + handleOpenDocument: { + value: function() { + this.deselectPenTool(); + //clear the canvas + this.application.ninja.stage.clearDrawingCanvas(); + } + }, + //if the document is switched with the pen tool being active, we do the same thing as when configure(false) is called + handleSwitchDocument: { + value: function() { + this.deselectPenTool(); + //clear the canvas + this.application.ninja.stage.clearDrawingCanvas(); + } + }, + //if the document is closed with the pen tool being active, we do the same thing as when configure(false) is called + handleCloseDocument: { + value: function() { + this.deselectPenTool(); + //clear the canvas + this.application.ninja.stage.clearDrawingCanvas(); + } + }, Configure: { value: function (wasSelected) { if (wasSelected) { + //first nullify any set values + this.deselectPenTool(); + defaultEventManager.addEventListener("resetPenTool", this, false); this.application.ninja.elementMediator.deleteDelegate = this; this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; @@ -1335,17 +1370,21 @@ exports.PenTool = Montage.create(ShapeTool, { if (this._trackMouseMoveWhenUp){ NJevent("enableStageMove"); } + this.eventManager.addEventListener("openDocument", this, false); + this.eventManager.addEventListener("switchDocument", this, false); + this.eventManager.addEventListener("closeDocument", this, false); } //if the pen tool was selected else { if (this._trackMouseMoveWhenUp){ NJevent("disableStageMove"); } - this._selectedSubpath = null; - this._selectedSubpathCanvas = null; - this._selectedSubpathPlaneMat = null; - this._snapTargetIndex = -1; + this.deselectPenTool(); defaultEventManager.removeEventListener("resetPenTool", this, false); this.application.ninja.elementMediator.deleteDelegate = null; + + this.eventManager.removeEventListener("openDocument", this, false); + this.eventManager.removeEventListener("switchDocument", this, false); + this.eventManager.removeEventListener("closeDocument", this, false); } //if the pen tool was de-selected } }, -- cgit v1.2.3