Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions blockly_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 93 additions & 89 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,110 +707,114 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
// Save the current block in a variable for use in closures.
var block = this;
var menuOptions = [];

if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
// Option to duplicate this block.
var duplicateOption = {
text: Blockly.Msg.DUPLICATE_BLOCK,
enabled: true,
callback: function() {
Blockly.duplicate_(block);
if (!block.isInFlyout) {
var isNotConfigView = this.workspace.checkInTask.indexOf('robConf') === -1;
if(this.isDeletable() && this.isMovable()) {
// Option to duplicate this block.
var duplicateOption = {
text: Blockly.Msg.DUPLICATE_BLOCK,
enabled: true,
callback: function() {
Blockly.duplicate_(block);
}
};
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
duplicateOption.enabled = false;
}
};
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
duplicateOption.enabled = false;
}
menuOptions.push(duplicateOption);

if (this.isEditable() && !this.collapsed_ &&
this.workspace.options.comments) {
// Option to add/remove a comment.
var commentOption = {enabled: !goog.userAgent.IE};
if (this.comment) {
commentOption.text = Blockly.Msg.REMOVE_COMMENT;
commentOption.callback = function() {
block.setCommentText(null);
};
} else {
commentOption.text = Blockly.Msg.ADD_COMMENT;
commentOption.callback = function() {
block.setCommentText('');
};
menuOptions.push(duplicateOption);

if (this.isEditable() && !this.collapsed_ &&
this.workspace.options.comments) {
// Option to add/remove a comment.
var commentOption = { enabled: !goog.userAgent.IE };
if (this.comment) {
commentOption.text = Blockly.Msg.REMOVE_COMMENT;
commentOption.callback = function() {
block.setCommentText(null);
};
} else {
commentOption.text = Blockly.Msg.ADD_COMMENT;
commentOption.callback = function() {
block.setCommentText('');
};
}
menuOptions.push(commentOption);
}
menuOptions.push(commentOption);
}

// Option to make block inline.
if (!this.collapsed_) {
for (var i = 1; i < this.inputList.length; i++) {
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
// Only display this option if there are two value or dummy inputs
// next to each other.
var inlineOption = {enabled: true};
var isInline = this.getInputsInline();
inlineOption.text = isInline ?
Blockly.Msg.EXTERNAL_INPUTS : Blockly.Msg.INLINE_INPUTS;
inlineOption.callback = function() {
block.setInputsInline(!isInline);
};
menuOptions.push(inlineOption);
break;
// Option to make block inline.
if (!this.collapsed_) {
for (var i = 1; i < this.inputList.length; i++) {
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
// Only display this option if there are two value or dummy inputs
// next to each other.
var inlineOption = { enabled: true };
var isInline = this.getInputsInline();
inlineOption.text = isInline ?
Blockly.Msg.EXTERNAL_INPUTS : Blockly.Msg.INLINE_INPUTS;
inlineOption.callback = function() {
block.setInputsInline(!isInline);
};
menuOptions.push(inlineOption);
break;
}
}
}
}

if (this.workspace.options.collapse) {
// 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);
if (this.workspace.options.disable) {
// Option to disable/enable block.
var disableOption = {
text: this.disabled ?
Blockly.Msg.ENABLE_BLOCK : Blockly.Msg.DISABLE_BLOCK,
enabled: !this.getInheritedDisabled(),
callback: function() {
block.setDisabled(!block.disabled);
}
};
menuOptions.push(collapseOption);
menuOptions.push(disableOption);
}
}

if (this.workspace.options.disable) {
// Option to disable/enable block.
var disableOption = {
text: this.disabled ?
Blockly.Msg.ENABLE_BLOCK : Blockly.Msg.DISABLE_BLOCK,
enabled: !this.getInheritedDisabled(),
// Option to delete this block.
// Count the number of blocks that are nested in this block.
var descendantCount = this.getDescendants().length;
var nextBlock = this.getNextBlock();
if (nextBlock) {
// Blocks in the current stack would survive this block's deletion.
descendantCount -= nextBlock.getDescendants().length;
}
var deleteOption = {
text: descendantCount == 1 ? Blockly.Msg.DELETE_BLOCK :
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(descendantCount)),
enabled: true,
callback: function() {
block.setDisabled(!block.disabled);
Blockly.Events.setGroup(true);
block.dispose(true, true);
Blockly.Events.setGroup(false);
}
};
menuOptions.push(disableOption);
menuOptions.push(deleteOption);
}

// Option to delete this block.
// Count the number of blocks that are nested in this block.
var descendantCount = this.getDescendants().length;
var nextBlock = this.getNextBlock();
if (nextBlock) {
// Blocks in the current stack would survive this block's deletion.
descendantCount -= nextBlock.getDescendants().length;
}
var deleteOption = {
text: descendantCount == 1 ? Blockly.Msg.DELETE_BLOCK :
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(descendantCount)),
enabled: true,
callback: function() {
Blockly.Events.setGroup(true);
block.dispose(true, true);
Blockly.Events.setGroup(false);
if((this.isDeletable() && this.isMovable()) || isNotConfigView){
if (this.workspace.options.collapse) {
// 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);
}
}
};
menuOptions.push(deleteOption);
}
}

// Option to get help.
Expand Down