Merge pull request #2618 from alschmiedt/dynamic_variable_error

Fixes bug with using dynamic variable in toolbox
This commit is contained in:
alschmiedt
2019-07-09 16:29:11 -07:00
committed by GitHub
3 changed files with 13 additions and 5 deletions

View File

@@ -150,7 +150,7 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
*/
onchange: function(_e) {
var id = this.getFieldValue('VAR');
var variableModel = this.workspace.getVariableById(id);
var variableModel = Blockly.Variables.getVariable(this.workspace, id);
if (this.type == 'variables_get_dynamic') {
this.outputConnection.setCheck(variableModel.type);
} else {

View File

@@ -348,12 +348,20 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) {
};
/**
* Return all variable types. This list always contains the empty string.
* Return all variable and potential variable types. This list always contains
* the empty string.
* @param {?Blockly.Workspace} ws The workspace used to look for potential
* variables. This can be different than the workspace stored on this object
* if the passed in ws is a flyout workspace.
* @return {!Array.<string>} List of variable types.
* @package
*/
Blockly.VariableMap.prototype.getVariableTypes = function() {
var types = Object.keys(this.variableMap_);
Blockly.VariableMap.prototype.getVariableTypes = function(ws) {
var potentialTypes = [];
if (ws && ws.getPotentialVariableMap()) {
potentialTypes = Object.keys(ws.getPotentialVariableMap().variableMap_);
}
var types = Object.keys(this.variableMap_).concat(potentialTypes);
var hasEmpty = false;
for (var i = 0; i < types.length; i++) {
if (types[i] == '') {

View File

@@ -491,7 +491,7 @@ Blockly.Workspace.prototype.getVariablesOfType = function(type) {
* @package
*/
Blockly.Workspace.prototype.getVariableTypes = function() {
return this.variableMap_.getVariableTypes();
return this.variableMap_.getVariableTypes(this);
};
/**