kopia lustrzana https://github.com/backface/turtlestitch
relabelling custom blocks (experimental)
rodzic
a5eace927a
commit
7f8d5a3d1e
|
@ -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(
|
||||
|
|
49
byob.js
49
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 ////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue