Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing flyout behavior for broadcast blocks (e.g. #1270) and ensuring…
Browse files Browse the repository at this point in the history
… that the message1 shows in the dropdown by defualt. 'message1' gets created as a variable on the flyout's target workspace upon dropdownCreate.
kchadha committed Dec 8, 2017
1 parent 235142c commit f9458a6
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions core/field_variable.js
Original file line number Diff line number Diff line change
@@ -205,9 +205,13 @@ Blockly.FieldVariable.dropdownCreate = function() {
}
}
// Ensure that the currently selected variable is an option.
// TODO (#1270): Remove isBroadcastType check here when flyout variables fixed.
if (createSelectedVariable && workspace && !isBroadcastType) {
var newVar = workspace.createVariable(name);
if (createSelectedVariable && workspace) {
var newVar = null;
if (isBroadcastType && workspace.isFlyout) {
newVar = workspace.targetWorkspace.createVariable(name, Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE);
} else {
newVar = workspace.createVariable(name);
}
variableModelList.push(newVar);
}
variableModelList.sort(Blockly.VariableModel.compareByName);
@@ -217,10 +221,7 @@ Blockly.FieldVariable.dropdownCreate = function() {
options[i] = [variableModelList[i].name, variableModelList[i].getId()];
}
if (isBroadcastType) {
// TODO (#1270): Re-enable create broadcast message dropdown in flyout when fixed.
if (!workspace.isFlyout) {
options.push([Blockly.Msg.NEW_BROADCAST_MESSAGE, Blockly.NEW_BROADCAST_MESSAGE_ID]);
}
options.push([Blockly.Msg.NEW_BROADCAST_MESSAGE, Blockly.NEW_BROADCAST_MESSAGE_ID]);
} else {
options.push([Blockly.Msg.RENAME_VARIABLE, Blockly.RENAME_VARIABLE_ID]);
if (Blockly.Msg.DELETE_VARIABLE) {
@@ -265,7 +266,8 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
var setName = function(newName) {
thisField.setValue(newName);
};
Blockly.Variables.createVariable(workspace, setName, Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE);
var broadcastMsgWkspc = workspace.isFlyout ? workspace.targetWorkspace : workspace;
Blockly.Variables.createVariable(broadcastMsgWkspc, setName, Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE);
return;
}

2 changes: 1 addition & 1 deletion core/workspace_svg.js
Original file line number Diff line number Diff line change
@@ -1083,7 +1083,7 @@ Blockly.WorkspaceSvg.prototype.createVariable = function(name, opt_type, opt_id)
opt_type, opt_id);
// For performance reasons, only refresh the the toolbox for new variables.
// Variables that already exist should already be there.
if (!variableInMap) {
if (!variableInMap && !(opt_type == Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE)) {
this.refreshToolboxSelection_();
}
return newVar;

0 comments on commit f9458a6

Please sign in to comment.