Update comments and use try/catch with setGroup.

This commit is contained in:
Rachel Fenichel
2018-01-09 13:31:13 -08:00
parent 30f7c915d7
commit bd4e4daebb
3 changed files with 21 additions and 13 deletions

View File

@@ -275,7 +275,9 @@ Blockly.Block.prototype.dispose = function(healStack) {
* Call initModel on all fields on the block.
* May be called more than once.
* Either initModel or initSvg must be called after creating a block and before
* first interaction with it.
* the first interaction with it. Interactions include UI actions
* (e.g. clicking and dragging) and firing events (e.g. create, delete, and
* change).
* @public
*/
Blockly.Block.prototype.initModel = function() {

View File

@@ -112,7 +112,7 @@ Blockly.Names.prototype.getNameForUserVariable_ = function(id) {
* @param {string} name The Blockly entity name (no constraints).
* @param {string} type The type of entity in Blockly
* ('VARIABLE', 'PROCEDURE', 'BUILTIN', etc...).
* @return {string} An entity name legal for the exported language.
* @return {string} An entity name that is legal in the exported language.
*/
Blockly.Names.prototype.getName = function(name, type) {
if (type == Blockly.Variables.NAME_TYPE) {
@@ -143,7 +143,7 @@ Blockly.Names.prototype.getName = function(name, type) {
* @param {string} name The Blockly entity name (no constraints).
* @param {string} type The type of entity in Blockly
* ('VARIABLE', 'PROCEDURE', 'BUILTIN', etc...).
* @return {string} An entity name legal for the exported language.
* @return {string} An entity name that is legal in the exported language.
*/
Blockly.Names.prototype.getDistinctName = function(name, type) {
var safeName = this.safeName_(name);

View File

@@ -71,13 +71,16 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) {
var conflictVar = this.getVariable(newName, type);
var blocks = this.workspace.getAllBlocks();
Blockly.Events.setGroup(true);
// The IDs may match if the rename is a simple case change (name1 -> Name1).
if (!conflictVar || conflictVar.getId() == variable.getId()) {
this.renameVariableAndUses_(variable, newName, blocks);
} else {
this.renameVariableWithConflict_(variable, newName, conflictVar, blocks);
try {
// The IDs may match if the rename is a simple case change (name1 -> Name1).
if (!conflictVar || conflictVar.getId() == variable.getId()) {
this.renameVariableAndUses_(variable, newName, blocks);
} else {
this.renameVariableWithConflict_(variable, newName, conflictVar, blocks);
}
} finally {
Blockly.Events.setGroup(false);
}
Blockly.Events.setGroup(false);
};
/**
@@ -264,11 +267,14 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) {
Blockly.VariableMap.prototype.deleteVariableInternal_ = function(variable,
uses) {
Blockly.Events.setGroup(true);
for (var i = 0; i < uses.length; i++) {
uses[i].dispose(true, false);
try {
for (var i = 0; i < uses.length; i++) {
uses[i].dispose(true, false);
}
this.deleteVariable(variable);
} finally {
Blockly.Events.setGroup(false);
}
this.deleteVariable(variable);
Blockly.Events.setGroup(false);
};
/* End functions for variable deletion. */