-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconceptViewer_blockly.js
172 lines (160 loc) · 5.19 KB
/
conceptViewer_blockly.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Blockly.Block.helpHandler = {
check: function(type) {
return conceptViewer.hasConcept('blockly_'+type);
},
display: function(block) {
conceptViewer.showConcept('blockly_'+block.type);
}
};
Blockly.BlockSvg.prototype.showHelp_ = function() {
if(Blockly.Block.helpHandler) {
if(Blockly.Block.helpHandler.check) {
if(Blockly.Block.helpHandler.check(this.type)) {
Blockly.Block.helpHandler.display(this);
return;
}
} else {
Blockly.Block.helpHandler(this);
return;
}
}
var url = goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl;
if (url) {
window.open(url);
}
};
/**
* Show the context menu for this block.
* @param {!Event} e Mouse event.
* @private
*/
Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
if (this.workspace.options.readOnly || !this.contextMenu) {
return;
}
// 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 (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(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;
}
}
}
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);
}
}
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(disableOption);
}
// 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);
}
};
menuOptions.push(deleteOption);
}
// Option to get help.
if(Blockly.Block.helpHandler) {
if(Blockly.Block.helpHandler.check) {
var helpAvail = Blockly.Block.helpHandler.check(this.type);
} else {
var helpAvail = true;
}
}
if(!helpAvail) {
helpAvail = !!(goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl);
}
var helpOption = {enabled: helpAvail};
helpOption.text = Blockly.Msg.HELP;
helpOption.callback = function() {
block.showHelp_();
};
menuOptions.push(helpOption);
// Allow the block to add or modify menuOptions.
if (this.customContextMenu && !block.isInFlyout) {
this.customContextMenu(menuOptions);
}
Blockly.ContextMenu.show(e, menuOptions, this.RTL);
Blockly.ContextMenu.currentBlock = this;
};