summaryrefslogtreecommitdiff
path: root/byob.js
diff options
context:
space:
mode:
authorMichael Ball <cycomachead@gmail.com>2014-06-21 11:37:25 -0700
committerMichael Ball <cycomachead@gmail.com>2014-06-21 11:37:25 -0700
commitec8b14a3758acfc852a6f02010394bd5814d7272 (patch)
tree2589fd29d40516c3a5c171a5aca6fcff80b7cff9 /byob.js
parentbf03185eb083ea4171121d25ffda3041d91be8e7 (diff)
parent7f8d5a3d1eacdc78f61da8e82ac481bbbb825938 (diff)
downloadsnap-byow-ec8b14a3758acfc852a6f02010394bd5814d7272.tar.gz
snap-byow-ec8b14a3758acfc852a6f02010394bd5814d7272.zip
Merge pull request #34 from jmoenig/master
updating cs10 branch from jmoenig 0614
Diffstat (limited to 'byob.js')
-rw-r--r--byob.js86
1 files changed, 85 insertions, 1 deletions
diff --git a/byob.js b/byob.js
index 6a10110..a17f976 100644
--- a/byob.js
+++ b/byob.js
@@ -106,7 +106,7 @@ SymbolMorph, isNil*/
// Global stuff ////////////////////////////////////////////////////////
-modules.byob = '2014-May-02';
+modules.byob = '2014-Jun-06';
// Declarations
@@ -336,6 +336,43 @@ CustomBlockDefinition.prototype.parseSpec = function (spec) {
return parts;
};
+// CustomBlockDefinition picturing
+
+CustomBlockDefinition.prototype.scriptsPicture = function () {
+ var scripts, proto, block, comment;
+
+ scripts = new ScriptsMorph();
+ scripts.cleanUpMargin = 10;
+ proto = new PrototypeHatBlockMorph(this);
+ proto.setPosition(scripts.position().add(10));
+ if (this.comment !== null) {
+ comment = this.comment.fullCopy();
+ proto.comment = comment;
+ comment.block = proto;
+ }
+ if (this.body !== null) {
+ proto.nextBlock(this.body.expression.fullCopy());
+ }
+ scripts.add(proto);
+ proto.fixBlockColor(null, true);
+ this.scripts.forEach(function (element) {
+ block = element.fullCopy();
+ block.setPosition(scripts.position().add(element.position()));
+ scripts.add(block);
+ if (block instanceof BlockMorph) {
+ block.allComments().forEach(function (comment) {
+ comment.align(block);
+ });
+ }
+ });
+ proto.allComments().forEach(function (comment) {
+ comment.align(proto);
+ });
+ proto.children[0].fixLayout();
+ scripts.fixMultiArgs();
+ return scripts.scriptsPicture();
+};
+
// CustomCommandBlockMorph /////////////////////////////////////////////
// CustomCommandBlockMorph inherits from CommandBlockMorph:
@@ -708,6 +745,7 @@ CustomCommandBlockMorph.prototype.userMenu = function () {
} else {
menu.addLine();
}
+
// menu.addItem("export definition...", 'exportBlockDefinition');
menu.addItem("delete block definition...", 'deleteBlockDefinition');
}
@@ -809,6 +847,44 @@ CustomCommandBlockMorph.prototype.popUpbubbleHelp = function (
).popUp(this.world(), this.rightCenter().add(new Point(-8, 0)));
};
+// CustomCommandBlockMorph relabelling
+
+CustomCommandBlockMorph.prototype.relabel = function (alternatives) {
+ var menu = new MenuMorph(this),
+ oldInputs = this.inputs().map(
+ function (each) {return each.fullCopy(); }
+ ),
+ myself = this;
+ alternatives.forEach(function (def) {
+ var block = def.blockInstance();
+ block.restoreInputs(oldInputs);
+ block.fixBlockColor(null, true);
+ block.addShadow(new Point(3, 3));
+ menu.addItem(
+ block,
+ function () {
+ myself.definition = def;
+ myself.refresh();
+ }
+ );
+ });
+ menu.popup(this.world(), this.bottomLeft().subtract(new Point(
+ 8,
+ this instanceof CommandBlockMorph ? this.corner : 0
+ )));
+};
+
+CustomCommandBlockMorph.prototype.alternatives = function () {
+ var rcvr = this.receiver(),
+ stage = rcvr.parentThatIsA(StageMorph),
+ allDefs = rcvr.customBlocks.concat(stage.globalBlocks),
+ myself = this;
+ return allDefs.filter(function (each) {
+ return each !== myself.definition &&
+ each.type === myself.definition.type;
+ });
+};
+
// CustomReporterBlockMorph ////////////////////////////////////////////
// CustomReporterBlockMorph inherits from ReporterBlockMorph:
@@ -924,6 +1000,14 @@ CustomReporterBlockMorph.prototype.bubbleHelp
CustomReporterBlockMorph.prototype.popUpbubbleHelp
= CustomCommandBlockMorph.prototype.popUpbubbleHelp;
+// CustomReporterBlockMorph relabelling
+
+CustomReporterBlockMorph.prototype.relabel
+ = CustomCommandBlockMorph.prototype.relabel;
+
+CustomReporterBlockMorph.prototype.alternatives
+ = CustomCommandBlockMorph.prototype.alternatives;
+
// JaggedBlockMorph ////////////////////////////////////////////////////
/*