Start Controller documentation

This commit is contained in:
Richard Fairhurst
2012-07-12 16:51:57 +01:00
parent 7d0873b982
commit eccbf4c639
2 changed files with 18 additions and 2 deletions

View File

@@ -12,15 +12,18 @@ declare("iD.Controller", null, {
undoStack: null, // main undoStack
constructor:function(_map) {
// summary: The Controller marshalls ControllerStates and passes events to them.
this.map=_map;
this.undoStack=new iD.actions.UndoStack();
},
setStepper:function(_stepper) {
// summary: Set reference for the singleton-like class for the step-by-step instruction panel.
this.stepper=_stepper;
},
setState:function(newState) {
// summary: Enter a new ControllerState, firing exitState on the old one, and enterState on the new one.
if (newState==this.state) { return; }
if (this.state) {
this.state.exitState(newState);
@@ -33,6 +36,7 @@ declare("iD.Controller", null, {
},
entityMouseEvent:function(event,entityUI) {
// summary: Pass a MouseEvent on an EntityUI (e.g. clicking a way) to the current ControllerState.
if (!this.state) { return; }
var newState=this.state.processMouseEvent(event,entityUI);
this.setState(newState);

View File

@@ -9,36 +9,48 @@ declare("iD.controller.ControllerState", null, {
controller: null, // parent Controller
constructor:function() {
// summary: Base class for ControllerStates.
},
setController:function(_controller) {
// summary: Set a reference to the parent Controller.
this.controller=_controller;
},
processMouseEvent:function(event,entityUI) {
// summary: Process mouse events. Most of the UI handling goes on in here.
// returns: iD.controller.ControllerState The ControllerState to move to as a result of the user's actions (or just 'this' for no change).
},
enterState:function() {
// summary: Do any work required for entering the ControllerState, such as highlighting the selected entity.
},
exitState:function(newState) {
// summary: Do any work required to leave the ControllerState clearly, such as unhighlighting the selected entity.
},
stateName:function() {
// summary: Return the name of this state as a string, e.g. 'edit.NoSelection'.
// return: String
return this.stateNameAsArray.join('.');
},
stateNameAsArray:function() {
// summary: Return the name of this state as an array, e.g. ['edit','NoSelection'].
// return: Array
return this.__proto__.declaredClass.split('.').slice(2);
},
getConnection:function() {
// summary: Shorthand to return the Connection associated with this Controller (via its Map object).
// return: iD.Connection
return this.controller.map.conn;
},
undoAdder:function() {
/* This is a convenient shorthand for adding an action to the global undo stack,
setting the scope correctly. */
// summary: Shorthand for adding an action to the global undo stack, setting the scope correctly.
// return: Function
return lang.hitch(this.controller.undoStack, this.controller.undoStack.addAction);
}