Fix context menus on blocks with variables

This commit is contained in:
Rachel Fenichel
2018-04-12 14:58:11 -07:00
parent 5c541c6f99
commit 23666664fa
7 changed files with 37 additions and 23 deletions

View File

@@ -261,13 +261,13 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = {
if (this.isInFlyout){
return;
}
var varName = this.getFieldValue('VAR');
var variable = this.getField('VAR').getVariable();
var varName = variable.name;
if (!this.isCollapsed() && varName != null) {
var option = {enabled: true};
option.text =
Blockly.Msg.VARIABLES_SET_CREATE_GET.replace('%1', varName);
var xmlField = goog.dom.createDom('field', null, varName);
xmlField.setAttribute('name', 'VAR');
Blockly.Msg.VARIABLES_SET_CREATE_GET.replace('%1', varName);
var xmlField = Blockly.Variables.generateVariableFieldDom(variable);
var xmlBlock = goog.dom.createDom('block', null, xmlField);
xmlBlock.setAttribute('type', 'variables_get');
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);

View File

@@ -371,12 +371,13 @@ Blockly.Blocks['procedures_defnoreturn'] = {
// Add options to create getters for each parameter.
if (!this.isCollapsed()) {
for (var i = 0; i < this.arguments_.length; i++) {
for (var i = 0; i < this.argumentVarModels_.length; i++) {
var option = {enabled: true};
var name = this.arguments_[i];
var argVar = this.argumentVarModels_[i];
var name = argVar.name;
option.text = Blockly.Msg.VARIABLES_SET_CREATE_GET.replace('%1', name);
var xmlField = goog.dom.createDom('field', null, name);
xmlField.setAttribute('name', 'VAR');
var xmlField = Blockly.Variables.generateVariableFieldDom(argVar);
var xmlBlock = goog.dom.createDom('block', null, xmlField);
xmlBlock.setAttribute('type', 'variables_get');
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);

View File

@@ -113,7 +113,7 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = {
}
var option = {enabled: this.workspace.remainingCapacity() > 0};
var name = this.getFieldValue('VAR');
var name = this.getField('VAR').getText();
option.text = contextMenuMsg.replace('%1', name);
var xmlField = goog.dom.createDom('field', null, name);
xmlField.setAttribute('name', 'VAR');

View File

@@ -110,13 +110,11 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI
contextMenuMsg = Blockly.Msg.VARIABLES_SET_CREATE_GET;
}
var option = { enabled: this.workspace.remainingCapacity() > 0 };
var name = this.getFieldValue('VAR');
var option = {enabled: this.workspace.remainingCapacity() > 0};
var name = this.getField('VAR').getText();
option.text = contextMenuMsg.replace('%1', name);
var xmlField = goog.dom.createDom('field', null, name);
xmlField.setAttribute('name', 'VAR');
var variableModel = this.workspace.getVariable(name);
xmlField.setAttribute('variabletype', variableModel.type);
var xmlBlock = goog.dom.createDom('block', null, xmlField);
xmlBlock.setAttribute('type', opposite_type);
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);