diff --git a/blocks.js b/blocks.js index af5542f7..159d1a20 100644 --- a/blocks.js +++ b/blocks.js @@ -2009,6 +2009,7 @@ BlockMorph.prototype.userMenu = function () { var menu = new MenuMorph(this), world = this.world(), myself = this, + alternatives, blck; menu.addItem( @@ -2066,6 +2067,14 @@ BlockMorph.prototype.userMenu = function () { ); } ); + } else if (this.definition && this.alternatives) { // custom block + alternatives = this.alternatives(); + if (alternatives.length > 0) { + menu.addItem( + 'relabel...', + function () {myself.relabel(alternatives); } + ); + } } menu.addItem( diff --git a/byob.js b/byob.js index 0f79acfd..a17f9768 100644 --- a/byob.js +++ b/byob.js @@ -106,7 +106,7 @@ SymbolMorph, isNil*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2014-Jun-04'; +modules.byob = '2014-Jun-06'; // Declarations @@ -745,6 +745,7 @@ CustomCommandBlockMorph.prototype.userMenu = function () { } else { menu.addLine(); } + // menu.addItem("export definition...", 'exportBlockDefinition'); menu.addItem("delete block definition...", 'deleteBlockDefinition'); } @@ -846,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: @@ -961,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 //////////////////////////////////////////////////// /* diff --git a/history.txt b/history.txt index 97b487e0..02fc2a00 100755 --- a/history.txt +++ b/history.txt @@ -2165,3 +2165,4 @@ ______ * Blocks, objects: enable relabelling blocks with C-Slots * Blocks: enable relabelling blocks across categories * Objects: more relabelling options for SAY, THINK, ASK +* BYOB, Blocks: relabelling custom blocks (experimental)