This commit is contained in:
Rachel Fenichel
2017-12-15 13:44:27 -08:00
parent a75ab878af
commit 66975c8f94
3 changed files with 20 additions and 7 deletions

View File

@@ -98,11 +98,11 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
*/
customContextMenu: function(options) {
// Getter blocks have the option to create a setter block, and vice versa.
if(this.isInFlyout){
if (this.isInFlyout) {
return;
}
var opposite_type ;
var contextMenuMsg ;
var opposite_type;
var contextMenuMsg;
if (this.type == 'variables_get_dynamic') {
opposite_type = 'variables_set_dynamic';
contextMenuMsg = Blockly.Msg.VARIABLES_GET_CREATE_SET;
@@ -124,8 +124,8 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
options.push(option);
},
onchange: function() {
var name = this.getFieldValue('VAR');
var variableModel = this.workspace.getVariable(name);
var id = this.getFieldValue('VAR');
var variableModel = this.workspace.getVariableById(id);
if (this.type == 'variables_get_dynamic') {
this.outputConnection.setCheck(variableModel.type);
} else {

View File

@@ -269,6 +269,9 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) {
this.workspace_.renameVariableById =
this.targetWorkspace_.renameVariableById.bind(this.targetWorkspace_);
this.workspace_.getVariableTypes =
this.targetWorkspace_.getVariableTypes.bind(this.targetWorkspace_);
};
/**

View File

@@ -247,11 +247,21 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) {
};
/**
* Return all variable types.
* Return all variable types. This list always contains the empty string.
* @return {!Array.<string>} List of variable types.
*/
Blockly.VariableMap.prototype.getVariableTypes = function() {
return Object.keys(this.variableMap_);
var types = Object.keys(this.variableMap_);
var hasEmpty = false;
for (var i = 0; i < types.length; i++) {
if (types[i] == '') {
hasEmpty = true;
}
}
if (!hasEmpty) {
types.push('');
}
return types;
};
/**