From 170b16706f13347b229bb2467008e3da2ba2954b Mon Sep 17 00:00:00 2001 From: marisaleung Date: Thu, 6 Jul 2017 15:41:18 -0700 Subject: [PATCH] Modularize Rename Variable prompt and allow custom context menus for flyout. --- core/block_svg.js | 2 +- core/field_variable.js | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 6c57850ea..ac01745a2 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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); } diff --git a/core/field_variable.js b/core/field_variable.js index 7996260d6..ab8a269b3 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -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); + } + }); +};