forked from ArgLab/Snap--Build-Your-Own-Blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage-inputs.js
More file actions
40 lines (33 loc) · 1.32 KB
/
message-inputs.js
File metadata and controls
40 lines (33 loc) · 1.32 KB
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
/* global BlockMorph, StageMorph, StructInputSlotMorph */
// MessageInputSlotMorph //////////////////////////////////////////////
// I am a dropdown menu with an associated message type
// InputSlotMorph inherits from ArgMorph:
MessageInputSlotMorph.prototype = new StructInputSlotMorph();
MessageInputSlotMorph.prototype.constructor = MessageInputSlotMorph;
MessageInputSlotMorph.uber = StructInputSlotMorph.prototype;
// MessageInputSlotMorph instance creation:
function MessageInputSlotMorph() {
StructInputSlotMorph.call(this, null, false, 'messageTypesMenu', 'getMsgFields', true);
}
MessageInputSlotMorph.prototype.setContents = function(name, values, msgType) {
if (msgType) {
this.cachedMsgType = msgType;
} else {
this.cachedMsgType = null;
}
MessageInputSlotMorph.uber.setContents.call(this, name, values);
};
MessageInputSlotMorph.prototype.getMsgFields = function(name) {
var block = this.parentThatIsA(BlockMorph),
messageType = null,
stage,
fields;
if (block && block.receiver()) {
stage = block.receiver().parentThatIsA(StageMorph);
messageType = stage.messageTypes.getMsgType(name);
fields = messageType && messageType.fields;
} else {
fields = this.cachedMsgType && this.cachedMsgType.fields;
}
return fields || [];
};