Skip to content

Commit 672c16f

Browse files
committed
adds collapse/expand option to start-blocks
1 parent 15e21b2 commit 672c16f

File tree

2 files changed

+99
-94
lines changed

2 files changed

+99
-94
lines changed

blockly_compressed.js

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/block_svg.js

Lines changed: 93 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -707,110 +707,114 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
707707
// Save the current block in a variable for use in closures.
708708
var block = this;
709709
var menuOptions = [];
710-
711-
if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
712-
// Option to duplicate this block.
713-
var duplicateOption = {
714-
text: Blockly.Msg.DUPLICATE_BLOCK,
715-
enabled: true,
716-
callback: function() {
717-
Blockly.duplicate_(block);
710+
if (!block.isInFlyout) {
711+
var isNotConfigView = this.workspace.checkInTask.indexOf('robConf') === -1;
712+
if(this.isDeletable() && this.isMovable()) {
713+
// Option to duplicate this block.
714+
var duplicateOption = {
715+
text: Blockly.Msg.DUPLICATE_BLOCK,
716+
enabled: true,
717+
callback: function() {
718+
Blockly.duplicate_(block);
719+
}
720+
};
721+
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
722+
duplicateOption.enabled = false;
718723
}
719-
};
720-
if (this.getDescendants().length > this.workspace.remainingCapacity()) {
721-
duplicateOption.enabled = false;
722-
}
723-
menuOptions.push(duplicateOption);
724-
725-
if (this.isEditable() && !this.collapsed_ &&
726-
this.workspace.options.comments) {
727-
// Option to add/remove a comment.
728-
var commentOption = {enabled: !goog.userAgent.IE};
729-
if (this.comment) {
730-
commentOption.text = Blockly.Msg.REMOVE_COMMENT;
731-
commentOption.callback = function() {
732-
block.setCommentText(null);
733-
};
734-
} else {
735-
commentOption.text = Blockly.Msg.ADD_COMMENT;
736-
commentOption.callback = function() {
737-
block.setCommentText('');
738-
};
724+
menuOptions.push(duplicateOption);
725+
726+
if (this.isEditable() && !this.collapsed_ &&
727+
this.workspace.options.comments) {
728+
// Option to add/remove a comment.
729+
var commentOption = { enabled: !goog.userAgent.IE };
730+
if (this.comment) {
731+
commentOption.text = Blockly.Msg.REMOVE_COMMENT;
732+
commentOption.callback = function() {
733+
block.setCommentText(null);
734+
};
735+
} else {
736+
commentOption.text = Blockly.Msg.ADD_COMMENT;
737+
commentOption.callback = function() {
738+
block.setCommentText('');
739+
};
740+
}
741+
menuOptions.push(commentOption);
739742
}
740-
menuOptions.push(commentOption);
741-
}
742743

743-
// Option to make block inline.
744-
if (!this.collapsed_) {
745-
for (var i = 1; i < this.inputList.length; i++) {
746-
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
747-
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
748-
// Only display this option if there are two value or dummy inputs
749-
// next to each other.
750-
var inlineOption = {enabled: true};
751-
var isInline = this.getInputsInline();
752-
inlineOption.text = isInline ?
753-
Blockly.Msg.EXTERNAL_INPUTS : Blockly.Msg.INLINE_INPUTS;
754-
inlineOption.callback = function() {
755-
block.setInputsInline(!isInline);
756-
};
757-
menuOptions.push(inlineOption);
758-
break;
744+
// Option to make block inline.
745+
if (!this.collapsed_) {
746+
for (var i = 1; i < this.inputList.length; i++) {
747+
if (this.inputList[i - 1].type != Blockly.NEXT_STATEMENT &&
748+
this.inputList[i].type != Blockly.NEXT_STATEMENT) {
749+
// Only display this option if there are two value or dummy inputs
750+
// next to each other.
751+
var inlineOption = { enabled: true };
752+
var isInline = this.getInputsInline();
753+
inlineOption.text = isInline ?
754+
Blockly.Msg.EXTERNAL_INPUTS : Blockly.Msg.INLINE_INPUTS;
755+
inlineOption.callback = function() {
756+
block.setInputsInline(!isInline);
757+
};
758+
menuOptions.push(inlineOption);
759+
break;
760+
}
759761
}
760762
}
761-
}
762763

763-
if (this.workspace.options.collapse) {
764-
// Option to collapse/expand block.
765-
if (this.collapsed_) {
766-
var expandOption = {enabled: true};
767-
expandOption.text = Blockly.Msg.EXPAND_BLOCK;
768-
expandOption.callback = function() {
769-
block.setCollapsed(false);
770-
};
771-
menuOptions.push(expandOption);
772-
} else {
773-
var collapseOption = {enabled: true};
774-
collapseOption.text = Blockly.Msg.COLLAPSE_BLOCK;
775-
collapseOption.callback = function() {
776-
block.setCollapsed(true);
764+
if (this.workspace.options.disable) {
765+
// Option to disable/enable block.
766+
var disableOption = {
767+
text: this.disabled ?
768+
Blockly.Msg.ENABLE_BLOCK : Blockly.Msg.DISABLE_BLOCK,
769+
enabled: !this.getInheritedDisabled(),
770+
callback: function() {
771+
block.setDisabled(!block.disabled);
772+
}
777773
};
778-
menuOptions.push(collapseOption);
774+
menuOptions.push(disableOption);
779775
}
780-
}
781776

782-
if (this.workspace.options.disable) {
783-
// Option to disable/enable block.
784-
var disableOption = {
785-
text: this.disabled ?
786-
Blockly.Msg.ENABLE_BLOCK : Blockly.Msg.DISABLE_BLOCK,
787-
enabled: !this.getInheritedDisabled(),
777+
// Option to delete this block.
778+
// Count the number of blocks that are nested in this block.
779+
var descendantCount = this.getDescendants().length;
780+
var nextBlock = this.getNextBlock();
781+
if (nextBlock) {
782+
// Blocks in the current stack would survive this block's deletion.
783+
descendantCount -= nextBlock.getDescendants().length;
784+
}
785+
var deleteOption = {
786+
text: descendantCount == 1 ? Blockly.Msg.DELETE_BLOCK :
787+
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(descendantCount)),
788+
enabled: true,
788789
callback: function() {
789-
block.setDisabled(!block.disabled);
790+
Blockly.Events.setGroup(true);
791+
block.dispose(true, true);
792+
Blockly.Events.setGroup(false);
790793
}
791794
};
792-
menuOptions.push(disableOption);
795+
menuOptions.push(deleteOption);
793796
}
794797

795-
// Option to delete this block.
796-
// Count the number of blocks that are nested in this block.
797-
var descendantCount = this.getDescendants().length;
798-
var nextBlock = this.getNextBlock();
799-
if (nextBlock) {
800-
// Blocks in the current stack would survive this block's deletion.
801-
descendantCount -= nextBlock.getDescendants().length;
802-
}
803-
var deleteOption = {
804-
text: descendantCount == 1 ? Blockly.Msg.DELETE_BLOCK :
805-
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(descendantCount)),
806-
enabled: true,
807-
callback: function() {
808-
Blockly.Events.setGroup(true);
809-
block.dispose(true, true);
810-
Blockly.Events.setGroup(false);
798+
if((this.isDeletable() && this.isMovable()) || isNotConfigView){
799+
if (this.workspace.options.collapse) {
800+
// Option to collapse/expand block.
801+
if (this.collapsed_) {
802+
var expandOption = { enabled: true };
803+
expandOption.text = Blockly.Msg.EXPAND_BLOCK;
804+
expandOption.callback = function() {
805+
block.setCollapsed(false);
806+
};
807+
menuOptions.push(expandOption);
808+
} else {
809+
var collapseOption = { enabled: true };
810+
collapseOption.text = Blockly.Msg.COLLAPSE_BLOCK;
811+
collapseOption.callback = function() {
812+
block.setCollapsed(true);
813+
};
814+
menuOptions.push(collapseOption);
815+
}
811816
}
812-
};
813-
menuOptions.push(deleteOption);
817+
}
814818
}
815819

816820
// Option to get help.

0 commit comments

Comments
 (0)