From 69a1f5a9ef3cf64d5971c07d9a28f58ee643c008 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 17 Oct 2012 15:40:50 -0400 Subject: [PATCH] Fix tracing functionality --- index.html | 4 ++- js/iD/Connection.js | 4 +-- js/iD/actions/AddNodeToWayAction.js | 25 ++++++++++-------- js/iD/controller/shape/DrawWay.js | 40 +++++++++++++++++------------ js/iD/tags/TagEditor.js | 2 +- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/index.html b/index.html index e838daa92..db2486586 100755 --- a/index.html +++ b/index.html @@ -32,7 +32,9 @@ require(["dojo/_base/lang","dojo/dom-geometry","dojo/dom-class","dojo/on","dojo/dom","dojo/Evented", "dijit/form/Button","dijit/form/ToggleButton", "dojox/layout/FloatingPane", - "iD/actions/UndoStack","iD/actions/CreatePOIAction", + "iD/actions/UndoStack", + "iD/actions/CreatePOIAction", + "iD/actions/AddNodeToWayAction", "iD/Controller", "iD/actions/CreateEntityAction", "iD/controller/edit/NoSelection", diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 84cab1645..af6ef99ea 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -105,10 +105,10 @@ iD.Connection.prototype = { }); }, - refreshEntity:function(_entity) { + refreshEntity: function(entity) { // summary: Redraw a particular entity on all the Map objects that take data from this Connection. _.each(this.maps, function(map) { - map.refreshUI(_entity); + map.refreshUI(entity); }); }, diff --git a/js/iD/actions/AddNodeToWayAction.js b/js/iD/actions/AddNodeToWayAction.js index 8bdaf2ca3..6d43e4e4d 100644 --- a/js/iD/actions/AddNodeToWayAction.js +++ b/js/iD/actions/AddNodeToWayAction.js @@ -22,39 +22,44 @@ declare("iD.actions.AddNodeToWayAction", [iD.actions.UndoableEntityAction], { this.autoDelete = autoDelete; }, - doAction:function() { - var way=this.entity; // shorthand + doAction: function() { + var way = this.entity; // shorthand // undelete way if it was deleted before (only happens on redo) if (way.deleted) { way.setDeletedState(false); - if (!this.firstNode.hasParentWays()) this.firstNode.connection.unregisterPOI(firstNode); + if (!this.firstNode.hasParentWays()) { + this.firstNode.connection.unregisterPOI(firstNode); + } this.firstNode.addParent(way); } // add the node - if (this.index==-1) this.index=this.nodeList.length; - this.node.addParent(way); + if (this.index === -1) this.index = this.nodeList.length; + this.node.entity.addParent(way); this.node.connection.unregisterPOI(this.node); this.nodeList.splice(this.index, 0, this.node); this.markDirty(); way.expandBbox(this.node); - way.refresh(); + way.connection.refreshEntity(way); return this.SUCCESS; }, - undoAction:function() { + undoAction: function() { // summary: Remove the added node. Fixme: if the way is now 1-length, we should // do something like deleting it and converting the remaining node to a POI. var way=this.entity; // shorthand - if (this.autoDelete && way.length()==2 && way.parentRelations().length()) return this.FAIL; + if (this.autoDelete && way.length() === 2 && + way.parentRelations().length()) return this.FAIL; // remove node var removed=nodeList.splice(index, 1); - if (this.nodeList.indexOf(removed[0])==-1) { removed[0].removeParent(way); } + if (!_.contains(this.nodeList, removed[0])) { + removed[0].removeParent(way); + } this.markClean(); - way.refresh(); + way.connection.refreshEntity(way); return this.SUCCESS; } diff --git a/js/iD/controller/shape/DrawWay.js b/js/iD/controller/shape/DrawWay.js index 68df1ab04..b3a246e29 100644 --- a/js/iD/controller/shape/DrawWay.js +++ b/js/iD/controller/shape/DrawWay.js @@ -29,14 +29,14 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { constructor: function(way) { this.way = way; }, - enterState:function() { - this.wayUI=this.controller.map.getUI(this.way); + enterState: function() { + this.wayUI = this.controller.map.getUI(this.way); this.wayUI.setStateClass('selected'); this.wayUI.setStateClass('shownodes'); this.wayUI.redraw(); this.controller.stepper.highlight('draw'); }, - exitState:function() { + exitState: function() { this.controller.map.clearElastic(); this.wayUI.resetStateClass('selected'); this.wayUI.resetStateClass('shownodes'); @@ -46,8 +46,8 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { processMouseEvent:function(event,entityUI) { var entity=entityUI ? entityUI.entity : null; var entityType=entity ? entity.entityType : null; - var map=this.controller.map; - var ways; + var map = this.controller.map; + var ways, undo, action; if (event.type=='mouseover' && entityType=='way' && entityUI!=this.wayUI) { // Mouse over way, show hover highlight @@ -62,7 +62,12 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { // Find what object we're moving into var into=shape.byId((event.hasOwnProperty('toElement') ? event.toElement : event.relatedTarget).__gfxObject__); // If it's a nodeUI that belongs to a hovering way, don't deselect - if (into && into.hasOwnProperty('source') && into.source.hasStateClass('hoverway') && into.source.entity.hasParent(entity)) { return this; } + if (into && + into.hasOwnProperty('source') && + into.source.hasStateClass('hoverway') && + into.source.entity.entity.hasParent(entity)) { + return this; + } entityUI.resetStateClass('shownodeshover'); entityUI.redraw(); this.wayUI.redraw(); @@ -71,9 +76,9 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { } else if (event.type=='mouseout' && entityType=='node') { // Mouse left node, remove hover highlight from parent way too - ways=entity.parentWays(); + ways = entity.entity.parentWays(); for (var i in ways) { - var ui=this.controller.map.getUI(ways[i]); + var ui = this.controller.map.getUI(ways[i]); if (ui && ui.hasStateClass('shownodeshover')) { ui.resetStateClass('shownodeshover'); ui.redraw(); @@ -92,11 +97,11 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { switch (entityType) { case 'node': // Click on node - if (entity==this.getDrawingNode()) { + if (entity === this.getDrawingNode()) { // Double-click, so complete drawing this.controller.stepper.highlight('tag'); return new iD.controller.edit.SelectedWay(this.way, null); - } else if (entity==this.getStartNode()) { + } else if (entity === this.getStartNode()) { // Start of this way, so complete drawing this.appendNode(entity, this.undoAdder() ); this.controller.stepper.highlight('tag'); @@ -110,19 +115,22 @@ declare("iD.controller.shape.DrawWay", [iD.controller.ControllerState], { case 'way': // Click on way, add new junction node to way - ways=[entity]; // ** needs to find all the ways under the mouse - var undo=new iD.actions.CompositeUndoableAction(); + ways = [entity]; // ** needs to find all the ways under the mouse + undo = new iD.actions.CompositeUndoableAction(); var node=this.appendNewNode(event, undo); - array.forEach(ways, function(w) { w.doInsertNodeAtClosestPosition(node, true, lang.hitch(undo,undo.push)); } ); - var action=this.undoAdder(); action(undo); + _.each(ways, function(w) { + w.doInsertNodeAtClosestPosition(node, true, lang.hitch(undo, undo.push)); + }); + action = this.undoAdder(); + action(undo); return this; } } else if (event.type=='click') { // Click on empty space, add new node to way - var undo=new iD.actions.CompositeUndoableAction(); + undo = new iD.actions.CompositeUndoableAction(); this.appendNewNode(event, undo); - var action=this.undoAdder(); action(undo); + action = this.undoAdder(); action(undo); return this; } diff --git a/js/iD/tags/TagEditor.js b/js/iD/tags/TagEditor.js index c231a7375..39ebce774 100644 --- a/js/iD/tags/TagEditor.js +++ b/js/iD/tags/TagEditor.js @@ -11,7 +11,7 @@ declare("iD.tags.TagEditor", null, { dialog: null, editorContainers: null, // hash of DOM nodes to put editors in - constructor:function(entity, controller) { + constructor: function(entity, controller) { // summary: Construct a tag editor dialog box. this.entity = entity; this.controller = controller;