Fire VAR events and test.

This commit is contained in:
marisaleung
2017-06-05 16:35:56 -07:00
parent 7b29eca8e7
commit 833c2d0c40
5 changed files with 406 additions and 6 deletions

View File

@@ -86,11 +86,19 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) {
} else if (variableIndex == newVariableIndex ||
variableIndex != -1 && newVariableIndex == -1) {
// Only changing case, or renaming to a completely novel name.
this.variableMap_[type][variableIndex].name = newName;
var variableToRename = this.variableMap_[type][variableIndex];
Blockly.Events.fire(new Blockly.Events.VarRename(variableToRename,
newName));
variableToRename.name = newName;
} else if (variableIndex != -1 && newVariableIndex != -1) {
// Renaming one existing variable to another existing variable.
// The case might have changed, so we update the destination ID.
this.variableMap_[type][newVariableIndex].name = newName;
var variableToRename = this.variableMap_[type][newVariableIndex];
Blockly.Events.fire(new Blockly.Events.VarRename(variableToRename,
newName));
var variableToDelete = this.variableMap_[type][variableIndex];
Blockly.Events.fire(new Blockly.Events.VarDelete(variableToDelete));
variableToRename.name = newName;
this.variableMap_[type].splice(variableIndex, 1);
}
};
@@ -148,6 +156,7 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) {
for (var i = 0, tempVar; tempVar = variableList[i]; i++) {
if (tempVar.getId() == variable.getId()) {
variableList.splice(i, 1);
Blockly.Events.fire(new Blockly.Events.VarDelete(variable));
return;
}
}

View File

@@ -75,6 +75,8 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) {
* @private
*/
this.id_ = opt_id || Blockly.utils.genUid();
Blockly.Events.fire(new Blockly.Events.VarCreate(this));
};
/**

View File

@@ -267,9 +267,8 @@ Blockly.Workspace.prototype.renameVariableInternal_ = function(variable, newName
blocks[i].renameVar(oldCase, newName);
}
}
Blockly.Events.setGroup(false);
this.variableMap_.renameVariable(variable, newName);
Blockly.Events.setGroup(false);
};
@@ -400,9 +399,8 @@ Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable) {
for (var i = 0; i < uses.length; i++) {
uses[i].dispose(true, false);
}
Blockly.Events.setGroup(false);
this.variableMap_.deleteVariable(variable);
Blockly.Events.setGroup(false);
};
/**