From 3e7df5acae5afd4281f016833de5a0eab04b695a Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 18 Oct 2012 13:01:29 -0400 Subject: [PATCH] Start work on tuning noselection for intents Reversing the order of decisions for those adding nodes. --- css/app.css | 2 +- js/iD/controller/shape/NoSelection.js | 63 ++++++++++++++------------- js/iD/controller/shape/SelectedWay.js | 4 +- js/iD/renderer/NodeUI.js | 16 +++---- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/css/app.css b/css/app.css index 13338406b..68d270d8e 100644 --- a/css/app.css +++ b/css/app.css @@ -51,7 +51,7 @@ text { } #map.state-drawing { - cursor: pointer; + cursor: crosshair; } .currentMode { diff --git a/js/iD/controller/shape/NoSelection.js b/js/iD/controller/shape/NoSelection.js index 22da0ad07..d1e3485de 100644 --- a/js/iD/controller/shape/NoSelection.js +++ b/js/iD/controller/shape/NoSelection.js @@ -26,8 +26,9 @@ define(['dojo/_base/declare','dojo/_base/lang', declare("iD.controller.shape.NoSelection", [iD.controller.ControllerState], { - constructor:function() { + constructor: function(intent) { // summary: In 'Draw shape' mode but nothing is selected. + this.intent = intent; }, exitState: function() { @@ -39,38 +40,38 @@ declare("iD.controller.shape.NoSelection", [iD.controller.ControllerState], { this.controller.stepper.show().step(0); }, - processMouseEvent:function(event, entityUI) { - var entity = entityUI ? entityUI.entity : null; - var entityType = entity ? entity.entityType : null; - var map = this.controller.map; + processMouseEvent:function(event, entityUI) { + var entity = entityUI ? entityUI.entity : null; + var entityType = entity ? entity.entityType : null; + var map = this.controller.map; - if (event.type === 'click') { - switch (entityType) { - case 'node': - // Click to select a node - var ways = entity.parentWays(); - if (!ways.length) { return new iD.controller.shape.SelectedPOINode(entity); } - // else { return new iD.controller.shape.SelectedWayNode(entity,ways[0]); } - // ** FIXME: ^^^ the above should start a new branching way, not select the node - return this; - case 'way': + if (event.type === 'click') { + if (entityType === 'node') { + // Click to select a node + var ways = entity.parentWays(); + if (!ways.length) { return new iD.controller.shape.SelectedPOINode(entity); } + // else { return new iD.controller.shape.SelectedWayNode(entity,ways[0]); } + // ** FIXME: ^^^ the above should start a new branching way, not select the node + return this; + } else if (entityType === 'way') { + if (this.intent === 'way') { // Click to select a way - return new iD.controller.shape.SelectedWay(entityUI.entity); - default: - // Click to start a new way - var undo = new iD.actions.CompositeUndoableAction(); - var startNode = this.getConnection().doCreateNode( - {}, - map.coord2lat(map.mouseY(event)), - map.coord2lon(map.mouseX(event)), lang.hitch(undo,undo.push) ); - var way = this.getConnection().doCreateWay({}, [startNode], lang.hitch(undo,undo.push) ); - this.controller.undoStack.addAction(undo); - this.controller.map.createUI(way); - return new iD.controller.shape.DrawWay(way); - } - } - return this; - } + return new iD.controller.shape.SelectedWay(entityUI.entity); + } + } else { + // Click to start a new way + var undo = new iD.actions.CompositeUndoableAction(); + var startNode = this.getConnection().doCreateNode({}, + map.coord2lat(map.mouseY(event)), + map.coord2lon(map.mouseX(event)), lang.hitch(undo,undo.push) ); + var way = this.getConnection().doCreateWay({}, [startNode], lang.hitch(undo,undo.push) ); + this.controller.undoStack.addAction(undo); + this.controller.map.createUI(way); + return new iD.controller.shape.DrawWay(way); + } + } + return this; + } }); // ---------------------------------------------------------------------- diff --git a/js/iD/controller/shape/SelectedWay.js b/js/iD/controller/shape/SelectedWay.js index ac55500c1..f175dd107 100644 --- a/js/iD/controller/shape/SelectedWay.js +++ b/js/iD/controller/shape/SelectedWay.js @@ -54,7 +54,7 @@ declare("iD.controller.shape.SelectedWay", [iD.controller.ControllerState], { var ways = entity.entity.parentWays(); if (entity.entity.hasParent(this.way)) { // start a branching way from an existing point - way = this.getConnection().doCreateWay({}, [entity], lang.hitch(this,this.undoAdder) ); + way = this.getConnection().doCreateWay({}, [entity], lang.hitch(this, this.undoAdder)); this.controller.map.createUI(way); return new iD.controller.shape.DrawWay(way); } else if (ways.length===0) { @@ -66,7 +66,7 @@ declare("iD.controller.shape.SelectedWay", [iD.controller.ControllerState], { } break; case 'way': - if (entity==this.way) { + if (entity === this.way) { // start a branching way from a new point var map = this.controller.map; var undo = new iD.actions.CompositeUndoableAction(); diff --git a/js/iD/renderer/NodeUI.js b/js/iD/renderer/NodeUI.js index eefd147d8..51f39fd2f 100755 --- a/js/iD/renderer/NodeUI.js +++ b/js/iD/renderer/NodeUI.js @@ -30,8 +30,8 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { this.refreshStyleList(tags); // Iterate through each subpart, drawing any styles on that layer - var drawn=false; - var s,p,t,w,h; + var drawn = false; + var s, p, t, w, h; for (i = 0; i < this.styleList.subparts.length; i++) { var subpart=this.styleList.subparts[i]; p = this.styleList.pointStyles[subpart]; @@ -50,7 +50,7 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { } switch (p.icon_image) { case 'square': - case 'circle': shape.setStroke(s.shapeStrokeStyler()).setFill(s.shapeFillStyler()); break; + case 'circle': shape.setStroke(s.shapeStrokeStyler()).setFill(s.shapeFillStyler()); break; } this.recordSprite(shape); @@ -64,11 +64,11 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], { hit.setFill([0,1,0,0]).setStroke( { width:2, color:[0,0,0,0] } ); this.recordSprite(hit); hit.source= this; - hit.connect("onclick" , lang.hitch(this,this.entityMouseEvent)); - hit.connect("onmousedown" , lang.hitch(this,this.entityMouseEvent)); - hit.connect("onmouseup" , lang.hitch(this,this.entityMouseEvent)); - hit.connect("onmouseenter", lang.hitch(this,this.entityMouseEvent)); - hit.connect("onmouseleave", lang.hitch(this,this.entityMouseEvent)); + hit.connect("onclick", _.bind(this.entityMouseEvent, this)); + hit.connect("onmousedown", _.bind(this.entityMouseEvent, this)); + hit.connect("onmouseup", _.bind(this.entityMouseEvent, this)); + hit.connect("onmouseenter", _.bind(this.entityMouseEvent, this)); + hit.connect("onmouseleave", _.bind(this.entityMouseEvent, this)); } } });