From 3293b0b730227c14bd4f7bd53c125b48f9886764 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 5 Jun 2012 14:53:15 -0700 Subject: handle switching between multiple documents for Pen tool by having its own selection change handler --- js/tools/PenTool.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 8 deletions(-) (limited to 'js/tools') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 1536a334..4daae420 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -46,7 +46,6 @@ exports.PenTool = Montage.create(ShapeTool, { _isEscapeDown: {value: false, writable: true }, //whether we have just started a new path (may set true in mousedown, and always set false in mouse up - //todo this seems to be unnecessary _isNewPath: {value: false, writable: true}, //whether we have clicked one of the endpoints after entering the pen tool in ENTRY_SELECT_PATH edit mode @@ -73,7 +72,10 @@ exports.PenTool = Montage.create(ShapeTool, { //the center of the subpath center in stageworld space _selectedSubpathCanvasCenter: {value: null, writable: true}, - + + //this flag is set true by the Configure(true) and set false by Configure(false) or handleSelectionChange + _doesSelectionChangeNeedHandling: {value: false, writable: true}, + //constants used for picking points --- todo: these should be user-settable parameters _PICK_POINT_RADIUS: { value: 4, writable: false }, _DISPLAY_ANCHOR_RADIUS: { value: 5, writable: false }, @@ -286,7 +288,7 @@ exports.PenTool = Montage.create(ShapeTool, { //assume we are not starting a new path as we will set this to true if we create a new Subpath() this._isNewPath = false; - + //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) { this._selectedSubpath = null; @@ -691,6 +693,7 @@ exports.PenTool = Montage.create(ShapeTool, { var top = Math.round(midPt[1] - 0.5 * h); if (!canvas) { + this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); document.application.njUtils.createModelWithShape(newCanvas, "Subpath"); var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w), parseInt(h), {midPt: midPt, planeMat: planeMat}); @@ -733,8 +736,9 @@ exports.PenTool = Montage.create(ShapeTool, { //now send the event that will add this canvas to the timeline NJevent("elementAdded", newCanvas); - if(newCanvas.elementModel.isShape) //todo why is this not true for the path canvas? + if(newCanvas.elementModel.isShape) { + this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas this.application.ninja.selectionController.selectElement(newCanvas); } } //if (!canvas) { @@ -775,8 +779,9 @@ exports.PenTool = Montage.create(ShapeTool, { //TODO this will not work if there are multiple shapes in the same canvas canvas.elementModel.shapeModel.GLGeomObj = subpath; - if(canvas.elementModel.isShape) //todo why is this not true for the path canvas? + if(canvas.elementModel.isShape) { + this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas this.application.ninja.selectionController.selectElement(canvas); } } //else of if (!canvas) { @@ -843,6 +848,7 @@ exports.PenTool = Montage.create(ShapeTool, { this.ShowSelectedSubpath(); } //if (this._selectedSubpath.getNumPoints() > 0) { + //always assume that we're not starting a new path anymore this._isNewPath = false; this._editMode = this.EDIT_NONE; @@ -1404,6 +1410,8 @@ exports.PenTool = Montage.create(ShapeTool, { this._selectedSubpathCanvas = null; this._selectedSubpathPlaneMat = null; this._snapTargetIndex = -1; + //clear the canvas + this.application.ninja.stage.clearDrawingCanvas(); } }, //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called @@ -1442,9 +1450,14 @@ exports.PenTool = Montage.create(ShapeTool, { this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default"; - if (this.application.ninja.selectedElements.length === 0){ + //TODO in case of switching between docs, this call to setEntryMode may refer to the old document, + // which is why we set the _doesSelectionChangeNeedHandling flag next + this.setEntryMode(); + this._doesSelectionChangeNeedHandling = true; //this will make sure that the setEntry mode gets called by the selectionChange handler + /*if (this.application.ninja.selectedElements.length === 0){ this._entryEditMode = this.ENTRY_SELECT_NONE; } + else{ for (var i=0;i