diff --git a/blocks/variables_dynamic.js b/blocks/variables_dynamic.js
index a16ed3a8b..5d523f7e3 100644
--- a/blocks/variables_dynamic.js
+++ b/blocks/variables_dynamic.js
@@ -56,8 +56,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"colour": "%{BKY_VARIABLES_DYNAMIC_HUE}",
"helpUrl": "%{BKY_VARIABLES_GET_HELPURL}",
"tooltip": "%{BKY_VARIABLES_GET_TOOLTIP}",
- "extensions": ["contextMenu_variableDynamicSetterGetter"],
- "mutator":"contextMenu_variableDynamicMutation"
+ "extensions": ["contextMenu_variableDynamicSetterGetter"]
},
// Block for variable setter.
{
@@ -78,8 +77,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
"colour": "%{BKY_VARIABLES_DYNAMIC_HUE}",
"tooltip": "%{BKY_VARIABLES_SET_TOOLTIP}",
"helpUrl": "%{BKY_VARIABLES_SET_HELPURL}",
- "extensions": ["contextMenu_variableDynamicSetterGetter"],
- "mutator":"contextMenu_variableDynamicMutation"
+ "extensions": ["contextMenu_variableDynamicSetterGetter"]
}
]); // END JSON EXTRACT (Do not delete this comment.)
@@ -128,7 +126,6 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
onchange: function() {
var name = this.getFieldValue('VAR');
var variableModel = this.workspace.getVariable(name);
- this.getField('VAR').variableTypes = [variableModel.type];
if (this.type == 'variables_get_dynamic') {
this.outputConnection.setCheck(variableModel.type);
} else {
@@ -137,26 +134,5 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
}
};
-/**
- * This mutator make sure the type check work before any event trigger.
- * Some event handler check the type , and disconnect the connection which not match.
- * @readonly
- */
-Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_MUTATION = {
- mutationToDom: function() {
- var container = document.createElement('mutation');
- var name = this.getFieldValue('VAR');
- var variableModel = this.workspace.getVariable(name);
- if (this.type == 'variables_get_dynamic') {
- this.outputConnection.setCheck(variableModel.type);
- } else {
- this.getInput('VALUE').connection.setCheck(variableModel.type);
- }
- return container;
- },
- domToMutation: function() {}
-};
Blockly.Extensions.registerMixin('contextMenu_variableDynamicSetterGetter',
Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN);
-Blockly.Extensions.registerMutator('contextMenu_variableDynamicMutation',
- Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_MUTATION);
diff --git a/core/field_variable.js b/core/field_variable.js
index 3fa227c39..77310987e 100644
--- a/core/field_variable.js
+++ b/core/field_variable.js
@@ -48,7 +48,7 @@ goog.require('goog.string');
*/
Blockly.FieldVariable = function(varname, opt_validator, opt_variableTypes) {
Blockly.FieldVariable.superClass_.constructor.call(this,
- Blockly.FieldVariable.dropdownCreate, opt_validator);
+ Blockly.FieldVariable.dropdownCreate, opt_validator);
this.setValue(varname || '');
this.variableTypes = opt_variableTypes;
};
@@ -73,8 +73,8 @@ Blockly.FieldVariable.prototype.initModel = function() {
// Variables without names get uniquely named for this workspace.
var workspace =
this.sourceBlock_.isInFlyout ?
- this.sourceBlock_.workspace.targetWorkspace :
- this.sourceBlock_.workspace;
+ this.sourceBlock_.workspace.targetWorkspace :
+ this.sourceBlock_.workspace;
this.setValue(Blockly.Variables.generateUniqueName(workspace));
}
// If the selected variable doesn't exist yet, create it.
@@ -91,7 +91,7 @@ Blockly.FieldVariable.prototype.initModel = function() {
*/
Blockly.FieldVariable.prototype.setSourceBlock = function(block) {
goog.asserts.assert(!block.isShadow(),
- 'Variable fields are not allowed to exist on shadow blocks.');
+ 'Variable fields are not allowed to exist on shadow blocks.');
Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block);
};
@@ -124,7 +124,7 @@ Blockly.FieldVariable.prototype.setValue = function(value) {
}
if (Blockly.Events.isEnabled()) {
Blockly.Events.fire(new Blockly.Events.BlockChange(
- this.sourceBlock_, 'field', this.name, this.value_, newValue));
+ this.sourceBlock_, 'field', this.name, this.value_, newValue));
}
}
this.value_ = newValue;
@@ -139,7 +139,7 @@ Blockly.FieldVariable.prototype.setValue = function(value) {
*/
Blockly.FieldVariable.prototype.getVariableTypes_ = function() {
var variableTypes = this.variableTypes;
- if (variableTypes === null) {
+ if (variableTypes === null || variableTypes === undefined) {
// If variableTypes is null, return all variable types.
if (this.sourceBlock_) {
var workspace = this.sourceBlock_.workspace;
@@ -203,7 +203,7 @@ Blockly.FieldVariable.dropdownCreate = function() {
options.push([Blockly.Msg.RENAME_VARIABLE, Blockly.RENAME_VARIABLE_ID]);
if (Blockly.Msg.DELETE_VARIABLE) {
options.push([Blockly.Msg.DELETE_VARIABLE.replace('%1', name),
- Blockly.DELETE_VARIABLE_ID]);
+ Blockly.DELETE_VARIABLE_ID]);
}
return options;
};
diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js
index a899c04c6..fb114fae0 100644
--- a/core/variables_dynamic.js
+++ b/core/variables_dynamic.js
@@ -41,8 +41,8 @@ Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {
Blockly.VariablesDynamic.onCreateVariableButtonClick_Number = function(button) {
Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'Number');
};
-Blockly.VariablesDynamic.onCreateVariableButtonClick_Color = function(button) {
- Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'Color');
+Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) {
+ Blockly.Variables.createVariable(button.getTargetWorkspace(), null, 'Colour');
};
/**
* Construct the elements (blocks and button) required by the flyout for the
@@ -53,23 +53,23 @@ Blockly.VariablesDynamic.onCreateVariableButtonClick_Color = function(button) {
Blockly.VariablesDynamic.flyoutCategory = function(workspace) {
var xmlList = [];
var button = goog.dom.createDom('button');
- button.setAttribute('text', Blockly.Msg.NEW_VARIABLE);
+ button.setAttribute('text', Blockly.Msg.NEW_STRING_VARIABLE);
button.setAttribute('callbackKey', 'CREATE_VARIABLE_STRING');
xmlList.push(button);
button = goog.dom.createDom('button');
- button.setAttribute('text', Blockly.Msg.NEW_VARIABLE);
+ button.setAttribute('text', Blockly.Msg.NEW_NUMBER_VARIABLE);
button.setAttribute('callbackKey', 'CREATE_VARIABLE_NUMBER');
xmlList.push(button);button = goog.dom.createDom('button');
- button.setAttribute('text', Blockly.Msg.NEW_VARIABLE);
- button.setAttribute('callbackKey', 'CREATE_VARIABLE_COLOR');
+ button.setAttribute('text', Blockly.Msg.NEW_COLOUR_VARIABLE);
+ button.setAttribute('callbackKey', 'CREATE_VARIABLE_COLOUR');
xmlList.push(button);
workspace.registerButtonCallback('CREATE_VARIABLE_STRING',
Blockly.VariablesDynamic.onCreateVariableButtonClick_String);
workspace.registerButtonCallback('CREATE_VARIABLE_NUMBER',
Blockly.VariablesDynamic.onCreateVariableButtonClick_Number);
- workspace.registerButtonCallback('CREATE_VARIABLE_COLOR',
- Blockly.VariablesDynamic.onCreateVariableButtonClick_Color);
+ workspace.registerButtonCallback('CREATE_VARIABLE_COLOUR',
+ Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour);
var blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace);
@@ -89,6 +89,17 @@ Blockly.VariablesDynamic.flyoutCategoryBlocks = function(workspace) {
var xmlList = [];
if (variableModelList.length > 0) {
+ if (Blockly.Blocks['variables_set_dynamic']) {
+ var firstVariable = variableModelList[0];
+ var gap = 24;
+ var blockText = '' +
+ '' +
+ Blockly.Variables.generateVariableFieldXml_(firstVariable) +
+ '' +
+ '';
+ var block = Blockly.Xml.textToDom(blockText).firstChild;
+ xmlList.push(block);
+ }
for (var i = 0, variable; variable = variableModelList[i]; i++) {
if (Blockly.Blocks['variables_get_dynamic']) {
var blockText = '' +
@@ -99,16 +110,6 @@ Blockly.VariablesDynamic.flyoutCategoryBlocks = function(workspace) {
var block = Blockly.Xml.textToDom(blockText).firstChild;
xmlList.push(block);
}
- if (Blockly.Blocks['variables_set_dynamic']) {
- var gap = Blockly.Blocks['variables_get'] ? 20 : 8;
- var blockText = '' +
- '' +
- Blockly.Variables.generateVariableFieldXml_(variable) +
- '' +
- '';
- var block = Blockly.Xml.textToDom(blockText).firstChild;
- xmlList.push(block);
- }
}
}
return xmlList;
diff --git a/msg/messages.js b/msg/messages.js
index ab35f0914..1cd48b8fb 100644
--- a/msg/messages.js
+++ b/msg/messages.js
@@ -123,6 +123,12 @@ Blockly.Msg.RENAME_VARIABLE_TITLE = 'Rename all "%1" variables to:';
// Variable creation
/// button text - Text on the button used to launch the variable creation dialogue.
Blockly.Msg.NEW_VARIABLE = 'Create variable...';
+/// button text - Text on the button used to launch the variable creation dialogue.
+Blockly.Msg.NEW_STRING_VARIABLE = 'Create string variable...';
+/// button text - Text on the button used to launch the variable creation dialogue.
+Blockly.Msg.NEW_NUMBER_VARIABLE = 'Create number variable...';
+/// button text - Text on the button used to launch the variable creation dialogue.
+Blockly.Msg.NEW_COLOUR_VARIABLE = 'Create colour variable...';
/// prompt - Prompts the user to enter the type for a variable.
Blockly.Msg.NEW_VARIABLE_TYPE_TITLE = 'New variable type:';
/// prompt - Prompts the user to enter the name for a new variable. See [https://github.com/google/blockly/wiki/Variables#dropdown-menu https://github.com/google/blockly/wiki/Variables#dropdown-menu].