mirror of
https://github.com/google/blockly.git
synced 2026-01-11 19:07:08 +01:00
Update comments and use try/catch with setGroup.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user