summaryrefslogtreecommitdiff
path: root/blocks.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-11-15 11:18:45 +0100
committerjmoenig <jens@moenig.org>2013-11-15 11:18:45 +0100
commit81654e72997c1577181d6729660c110ed1b9e20f (patch)
tree7a03fd5c340f72ca557cd3b6c93a87c0d19435cb /blocks.js
parentcc0bf15c1a9172c494fd527ad4c15a31014fee75 (diff)
downloadsnap-yow-81654e72997c1577181d6729660c110ed1b9e20f.tar.gz
snap-yow-81654e72997c1577181d6729660c110ed1b9e20f.zip
„read-only“ option for editable custom block input slots
also custom block input slots reverting to default now show their default value (useful in combination with the new "read-only" option
Diffstat (limited to 'blocks.js')
-rw-r--r--blocks.js34
1 files changed, 28 insertions, 6 deletions
diff --git a/blocks.js b/blocks.js
index b2b38c4..8f675c4 100644
--- a/blocks.js
+++ b/blocks.js
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2013-November-12';
+modules.blocks = '2013-November-15';
var SyntaxElementMorph;
var BlockMorph;
@@ -518,10 +518,13 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) {
if (this instanceof BlockMorph) {
deflt = this.labelPart(this.parseSpec(this.blockSpec)[idx]);
if (deflt instanceof InputSlotMorph && this.definition) {
- deflt.choices = this.definition.dropDownMenuOfInputIdx(
- this.inputs().indexOf(arg)
+ deflt.setChoices.apply(
+ deflt,
+ this.definition.inputOptionsOfIdx(inp)
+ );
+ deflt.setContents(
+ this.definition.defaultValueOfInputIdx(inp)
);
- deflt.fixLayout();
}
} else if (this instanceof MultiArgMorph) {
deflt = this.labelPart(this.slotSpec);
@@ -1912,8 +1915,10 @@ BlockMorph.prototype.setSpec = function (spec) {
myself.add(myself.placeHolder());
}
if (part instanceof InputSlotMorph && myself.definition) {
- part.choices = myself.definition.dropDownMenuOfInputIdx(inputIdx);
- part.fixLayout(); // needed when de-serializing
+ part.setChoices.apply(
+ part,
+ myself.definition.inputOptionsOfIdx(inputIdx)
+ );
}
});
this.blockSpec = spec;
@@ -6593,6 +6598,23 @@ InputSlotMorph.prototype.getVarNamesDict = function () {
return {};
};
+InputSlotMorph.prototype.setChoices = function (dict, readonly) {
+ // externally specify choices and read-only status,
+ // used for custom blocks
+ var cnts = this.contents();
+ this.choices = dict;
+ this.isReadOnly = readonly || false;
+ if (this.parent instanceof BlockMorph) {
+ this.parent.fixLabelColor();
+ if (!readonly) {
+ cnts.shadowOffset = new Point();
+ cnts.shadowColor = null;
+ cnts.setColor(new Color(0, 0, 0));
+ }
+ }
+ this.fixLayout();
+};
+
// InputSlotMorph layout:
InputSlotMorph.prototype.fixLayout = function () {