mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Reorganize conditionals for block context menu (#2390)
* Reorganize conditionals for block context menu * Disable comments and disabling in block factory
This commit is contained in:
@@ -647,53 +647,58 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
|
|||||||
var block = this;
|
var block = this;
|
||||||
var menuOptions = [];
|
var menuOptions = [];
|
||||||
|
|
||||||
if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
|
if (!this.isInFlyout) {
|
||||||
menuOptions.push(Blockly.ContextMenu.blockDuplicateOption(block));
|
if (this.isDeletable() && this.isMovable()) {
|
||||||
if (this.isEditable() && !this.collapsed_ &&
|
menuOptions.push(Blockly.ContextMenu.blockDuplicateOption(block));
|
||||||
this.workspace.options.comments) {
|
}
|
||||||
|
|
||||||
|
if (this.workspace.options.comments && !this.collapsed_ &&
|
||||||
|
this.isEditable()) {
|
||||||
menuOptions.push(Blockly.ContextMenu.blockCommentOption(block));
|
menuOptions.push(Blockly.ContextMenu.blockCommentOption(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option to make block inline.
|
if (this.isMovable()) {
|
||||||
if (!this.collapsed_) {
|
if (!this.collapsed_) {
|
||||||
for (var i = 1; i < this.inputList.length; i++) {
|
// Option to make block inline.
|
||||||
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
|
for (var i = 1; i < this.inputList.length; i++) {
|
||||||
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
|
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
|
||||||
// Only display this option if there are two value or dummy inputs
|
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
|
||||||
// next to each other.
|
// Only display this option if there are two value or dummy inputs
|
||||||
var inlineOption = {enabled: true};
|
// next to each other.
|
||||||
var isInline = this.getInputsInline();
|
var inlineOption = {enabled: true};
|
||||||
inlineOption.text = isInline ?
|
var isInline = this.getInputsInline();
|
||||||
Blockly.Msg['EXTERNAL_INPUTS'] : Blockly.Msg['INLINE_INPUTS'];
|
inlineOption.text = isInline ?
|
||||||
inlineOption.callback = function() {
|
Blockly.Msg['EXTERNAL_INPUTS'] : Blockly.Msg['INLINE_INPUTS'];
|
||||||
block.setInputsInline(!isInline);
|
inlineOption.callback = function() {
|
||||||
|
block.setInputsInline(!isInline);
|
||||||
|
};
|
||||||
|
menuOptions.push(inlineOption);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Option to collapse block
|
||||||
|
if (this.workspace.options.collapse) {
|
||||||
|
var collapseOption = {enabled: true};
|
||||||
|
collapseOption.text = Blockly.Msg['COLLAPSE_BLOCK'];
|
||||||
|
collapseOption.callback = function() {
|
||||||
|
block.setCollapsed(true);
|
||||||
};
|
};
|
||||||
menuOptions.push(inlineOption);
|
menuOptions.push(collapseOption);
|
||||||
break;
|
}
|
||||||
|
} else {
|
||||||
|
// Option to expand block.
|
||||||
|
if (this.workspace.options.collapse) {
|
||||||
|
var expandOption = {enabled: true};
|
||||||
|
expandOption.text = Blockly.Msg['EXPAND_BLOCK'];
|
||||||
|
expandOption.callback = function() {
|
||||||
|
block.setCollapsed(false);
|
||||||
|
};
|
||||||
|
menuOptions.push(expandOption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.workspace.options.collapse) {
|
if (this.workspace.options.disable && this.isEditable()) {
|
||||||
// Option to collapse/expand block.
|
|
||||||
if (this.collapsed_) {
|
|
||||||
var expandOption = {enabled: true};
|
|
||||||
expandOption.text = Blockly.Msg['EXPAND_BLOCK'];
|
|
||||||
expandOption.callback = function() {
|
|
||||||
block.setCollapsed(false);
|
|
||||||
};
|
|
||||||
menuOptions.push(expandOption);
|
|
||||||
} else {
|
|
||||||
var collapseOption = {enabled: true};
|
|
||||||
collapseOption.text = Blockly.Msg['COLLAPSE_BLOCK'];
|
|
||||||
collapseOption.callback = function() {
|
|
||||||
block.setCollapsed(true);
|
|
||||||
};
|
|
||||||
menuOptions.push(collapseOption);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.workspace.options.disable) {
|
|
||||||
// Option to disable/enable block.
|
// Option to disable/enable block.
|
||||||
var disableOption = {
|
var disableOption = {
|
||||||
text: this.disabled ?
|
text: this.disabled ?
|
||||||
@@ -713,7 +718,9 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
|
|||||||
menuOptions.push(disableOption);
|
menuOptions.push(disableOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
menuOptions.push(Blockly.ContextMenu.blockDeleteOption(block));
|
if (this.isDeletable()) {
|
||||||
|
menuOptions.push(Blockly.ContextMenu.blockDeleteOption(block));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
menuOptions.push(Blockly.ContextMenu.blockHelpOption(block));
|
menuOptions.push(Blockly.ContextMenu.blockHelpOption(block));
|
||||||
|
|||||||
@@ -718,6 +718,8 @@ AppController.prototype.init = function() {
|
|||||||
BlockFactory.mainWorkspace = Blockly.inject('blockly',
|
BlockFactory.mainWorkspace = Blockly.inject('blockly',
|
||||||
{collapse: false,
|
{collapse: false,
|
||||||
toolbox: toolbox,
|
toolbox: toolbox,
|
||||||
|
comments: false,
|
||||||
|
disable: false,
|
||||||
media: '../../media/'});
|
media: '../../media/'});
|
||||||
|
|
||||||
// Add tab handlers for switching between Block Factory and Block Exporter.
|
// Add tab handlers for switching between Block Factory and Block Exporter.
|
||||||
|
|||||||
Reference in New Issue
Block a user