mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
createVariable(..) => createVariableButtonHandler(..)
Clarifying the role of Blockly.Variables.createVariableButtonHandler(..). Updating documentation a making sure it (and its deprecated previous name) are properly exported.
This commit is contained in:
@@ -144,7 +144,7 @@ Blockly.Variables.flyoutCategory = function(workspace) {
|
||||
button.setAttribute('callbackKey', 'CREATE_VARIABLE');
|
||||
|
||||
workspace.registerButtonCallback('CREATE_VARIABLE', function(button) {
|
||||
Blockly.Variables.createVariable(button.getTargetWorkspace());
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace());
|
||||
});
|
||||
|
||||
xmlList.push(button);
|
||||
@@ -257,16 +257,24 @@ Blockly.Variables.generateUniqueName = function(workspace) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new variable on the given workspace.
|
||||
* Handles "Create Variable" button in the default variables toolbox category.
|
||||
* It will prompt the user for a varibale name, including re-prompts if a name
|
||||
* is already in use among the workspace's variables.
|
||||
*
|
||||
* Custom button handlers can delegate to this function, allowing variables
|
||||
* types and after-creation processing. More complex customization (e.g.,
|
||||
* prompting for variable type) is beyond the scope of this function.
|
||||
*
|
||||
* @param {!Blockly.Workspace} workspace The workspace on which to create the
|
||||
* variable.
|
||||
* @param {function(?string=)=} opt_callback A callback. It will
|
||||
* be passed an acceptable new variable name, or null if change is to be
|
||||
* aborted (cancel button), or undefined if an existing variable was chosen.
|
||||
* @param {function(?string=)=} opt_callback A callback. It will be passed an
|
||||
* acceptable new variable name, or null if change is to be aborted (cancel
|
||||
* button), or undefined if an existing variable was chosen.
|
||||
* @param {string=} opt_type The type of the variable like 'int', 'string', or
|
||||
* ''. This will default to '', which is a specific type.
|
||||
*/
|
||||
Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) {
|
||||
Blockly.Variables.createVariableButtonHandler = function(
|
||||
workspace, opt_callback, opt_type) {
|
||||
// This function needs to be named so it can be called recursively.
|
||||
var promptAndCheckWithAlert = function(defaultName) {
|
||||
Blockly.Variables.promptName(Blockly.Msg.NEW_VARIABLE_TITLE, defaultName,
|
||||
@@ -294,6 +302,25 @@ Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) {
|
||||
};
|
||||
promptAndCheckWithAlert('');
|
||||
};
|
||||
goog.exportSymbol('Blockly.Variables.createVariableButtonHandler',
|
||||
Blockly.Variables.createVariableButtonHandler);
|
||||
|
||||
/**
|
||||
* Original name of Blockly.Variables.createVariableButtonHandler(..).
|
||||
* @deprecated Use Blockly.Variables.createVariableButtonHandler(..).
|
||||
*
|
||||
* @param {!Blockly.Workspace} workspace The workspace on which to create the
|
||||
* variable.
|
||||
* @param {function(?string=)=} opt_callback A callback. It will be passed an
|
||||
* acceptable new variable name, or null if change is to be aborted (cancel
|
||||
* button), or undefined if an existing variable was chosen.
|
||||
* @param {string=} opt_type The type of the variable like 'int', 'string', or
|
||||
* ''. This will default to '', which is a specific type.
|
||||
*/
|
||||
Blockly.Variables.createVariable =
|
||||
Blockly.Variables.createVariableButtonHandler;
|
||||
goog.exportSymbol('Blockly.Variables.createVariable',
|
||||
Blockly.Variables.createVariable);
|
||||
|
||||
/**
|
||||
* Rename a variable with the given workspace, variableType, and oldName.
|
||||
|
||||
@@ -37,13 +37,13 @@ goog.require('goog.string');
|
||||
|
||||
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {
|
||||
Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'String');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'String');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Number = function(button) {
|
||||
Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'Number');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'Number');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) {
|
||||
Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'Colour');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'Colour');
|
||||
};
|
||||
/**
|
||||
* Construct the elements (blocks and button) required by the flyout for the
|
||||
|
||||
Reference in New Issue
Block a user