summaryrefslogtreecommitdiff
path: root/byob.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 /byob.js
parentcc0bf15c1a9172c494fd527ad4c15a31014fee75 (diff)
downloadsnap-81654e72997c1577181d6729660c110ed1b9e20f.tar.gz
snap-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 'byob.js')
-rw-r--r--byob.js47
1 files changed, 41 insertions, 6 deletions
diff --git a/byob.js b/byob.js
index d282b07..3455171 100644
--- a/byob.js
+++ b/byob.js
@@ -106,7 +106,7 @@ SymbolMorph, isNil*/
// Global stuff ////////////////////////////////////////////////////////
-modules.byob = '2013-November-12';
+modules.byob = '2013-November-15';
// Declarations
@@ -137,7 +137,8 @@ function CustomBlockDefinition(spec, receiver) {
this.isGlobal = false;
this.type = 'command';
this.spec = spec || '';
- this.declarations = {}; // {'inputName' : [type, default, options]}
+ // format: {'inputName' : [type, default, options, readonly]}
+ this.declarations = {};
this.comment = null;
this.codeMapping = null; // experimental, generate text code
this.codeHeader = null; // experimental, generate text code
@@ -193,6 +194,7 @@ CustomBlockDefinition.prototype.prototypeInstance = function () {
part.fragment.type = slot[0];
part.fragment.defaultValue = slot[1];
part.fragment.options = slot[2];
+ part.fragment.isReadonly = slot[3] || false;
}
}
});
@@ -271,6 +273,16 @@ CustomBlockDefinition.prototype.dropDownMenuOfInputIdx = function (idx) {
return this.dropDownMenuOf(inputName);
};
+CustomBlockDefinition.prototype.isReadOnlyInputIdx = function (idx) {
+ var inputName = this.inputNames()[idx];
+ return this.isReadOnlyInput(inputName);
+};
+
+CustomBlockDefinition.prototype.inputOptionsOfIdx = function (idx) {
+ var inputName = this.inputNames()[idx];
+ return this.inputOptionsOf(inputName);
+};
+
CustomBlockDefinition.prototype.dropDownMenuOf = function (inputName) {
var dict = {};
if (this.declarations[inputName] && this.declarations[inputName][2]) {
@@ -283,6 +295,18 @@ CustomBlockDefinition.prototype.dropDownMenuOf = function (inputName) {
return null;
};
+CustomBlockDefinition.prototype.isReadOnlyInput = function (inputName) {
+ return this.declarations[inputName] &&
+ this.declarations[inputName][3] === true;
+};
+
+CustomBlockDefinition.prototype.inputOptionsOf = function (inputName) {
+ return [
+ this.dropDownMenuOf(inputName),
+ this.isReadOnlyInput(inputName)
+ ];
+};
+
CustomBlockDefinition.prototype.inputNames = function () {
var vNames = [],
parts = this.parseSpec(this.spec);
@@ -355,8 +379,7 @@ CustomCommandBlockMorph.prototype.refresh = function () {
} else { // update all input slots' drop-downs
this.inputs().forEach(function (inp, i) {
if (inp instanceof InputSlotMorph) {
- inp.choices = def.dropDownMenuOfInputIdx(i);
- inp.fixLayout();
+ inp.setChoices.apply(inp, def.inputOptionsOfIdx(i));
}
});
}
@@ -565,7 +588,8 @@ CustomCommandBlockMorph.prototype.declarationsFromFragments = function () {
ans[part.fragment.labelString] = [
part.fragment.type,
part.fragment.defaultValue,
- part.fragment.options
+ part.fragment.options,
+ part.fragment.isReadOnly
];
}
});
@@ -1888,6 +1912,7 @@ function BlockLabelFragment(labelString) {
this.type = '%s'; // null for label, a spec for an input
this.defaultValue = '';
this.options = '';
+ this.isReadOnly = false; // for input slots
this.isDeleted = false;
}
@@ -1938,6 +1963,7 @@ BlockLabelFragment.prototype.copy = function () {
ans.type = this.type;
ans.defaultValue = this.defaultValue;
ans.options = this.options;
+ ans.isReadOnly = this.isReadOnly;
return ans;
};
@@ -2832,8 +2858,17 @@ InputSlotDialogMorph.prototype.addSlotsMenu = function () {
this.slots.userMenu = function () {
if (contains(['%s', '%n', '%txt', '%anyUE'], myself.fragment.type)) {
- var menu = new MenuMorph(myself);
+ var menu = new MenuMorph(myself),
+ on = '\u2611 ',
+ off = '\u2610 ';
menu.addItem('options...', 'editSlotOptions');
+ menu.addItem(
+ (myself.fragment.isReadOnly ? on : off) +
+ localize('read-only'),
+ function () {myself.fragment.isReadOnly =
+ !myself.fragment.isReadOnly;
+ }
+ );
return menu;
}
return Morph.prototype.userMenu.call(myself);