mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
Modularize Rename Variable prompt and allow custom context menus for flyout.
This commit is contained in:
@@ -690,7 +690,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
|
||||
menuOptions.push(helpOption);
|
||||
|
||||
// Allow the block to add or modify menuOptions.
|
||||
if (this.customContextMenu && !block.isInFlyout) {
|
||||
if (this.customContextMenu) {
|
||||
this.customContextMenu(menuOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -196,15 +196,8 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
|
||||
}
|
||||
else if (id == Blockly.RENAME_VARIABLE_ID) {
|
||||
// Rename variable.
|
||||
var oldName = this.getText();
|
||||
Blockly.hideChaff();
|
||||
Blockly.Variables.promptName(
|
||||
Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', oldName), oldName,
|
||||
function(newName) {
|
||||
if (newName) {
|
||||
workspace.renameVariable(oldName, newName);
|
||||
}
|
||||
});
|
||||
var currentName = this.getText();
|
||||
Blockly.FieldVariable.renameVariablePrompt(workspace, currentName);
|
||||
return;
|
||||
} else if (id == Blockly.DELETE_VARIABLE_ID) {
|
||||
// Delete variable.
|
||||
@@ -219,3 +212,20 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
|
||||
this.setValue(itemText);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Prompt the user to rename a variable.
|
||||
* @param {Blockly.Workspace} workspace Workspace the variable to rename is in.
|
||||
* @param {string} currentName Current name of the variable to rename.
|
||||
*/
|
||||
Blockly.FieldVariable.renameVariablePrompt = function(workspace, currentName) {
|
||||
// Rename variable.
|
||||
Blockly.hideChaff();
|
||||
Blockly.Variables.promptName(
|
||||
Blockly.Msg.RENAME_VARIABLE_TITLE.replace('%1', currentName), currentName,
|
||||
function(newName) {
|
||||
if (newName) {
|
||||
workspace.renameVariable(currentName, newName);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user