kopia lustrzana https://github.com/backface/turtlestitch
"Undrop" Reporters feature (in script areas' context menus)
first rough passpull/3/merge
rodzic
060c5fcb9d
commit
4e409623b3
77
blocks.js
77
blocks.js
|
@ -414,8 +414,21 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
|
|||
var scripts = this.parentThatIsA(ScriptsMorph),
|
||||
replacement = newArg,
|
||||
idx = this.children.indexOf(oldArg),
|
||||
i = 0,
|
||||
nb;
|
||||
|
||||
// try to find the ArgLabel embedding the newArg,
|
||||
// used for the undrop() feature
|
||||
if (idx === -1 && newArg instanceof MultiArgMorph) {
|
||||
this.children.forEach(function (morph) {
|
||||
if (morph instanceof ArgLabelMorph &&
|
||||
morph.argMorph() === oldArg) {
|
||||
idx = i;
|
||||
}
|
||||
i += 1;
|
||||
});
|
||||
}
|
||||
|
||||
if ((idx === -1) || (scripts === null)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -423,7 +436,6 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
|
|||
if (newArg.parent) {
|
||||
newArg.parent.removeChild(newArg);
|
||||
}
|
||||
|
||||
if (oldArg instanceof MultiArgMorph) {
|
||||
oldArg.inputs().forEach(function (inp) { // preserve nested reporters
|
||||
oldArg.replaceInput(inp, new InputSlotMorph());
|
||||
|
@ -432,7 +444,6 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
|
|||
replacement = new ArgLabelMorph(newArg);
|
||||
}
|
||||
}
|
||||
|
||||
replacement.parent = this;
|
||||
this.children[idx] = replacement;
|
||||
if (oldArg instanceof ReporterBlockMorph) {
|
||||
|
@ -450,7 +461,6 @@ SyntaxElementMorph.prototype.replaceInput = function (oldArg, newArg) {
|
|||
nb.fixBlockColor();
|
||||
}
|
||||
}
|
||||
|
||||
if (replacement instanceof MultiArgMorph
|
||||
|| replacement instanceof ArgLabelMorph
|
||||
|| replacement.constructor === CommandSlotMorph) {
|
||||
|
@ -3142,10 +3152,16 @@ CommandBlockMorph.prototype.closestAttachTarget = function (newParent) {
|
|||
|
||||
CommandBlockMorph.prototype.snap = function () {
|
||||
var target = this.closestAttachTarget(),
|
||||
scripts = this.parentThatIsA(ScriptsMorph),
|
||||
next,
|
||||
offsetY,
|
||||
affected;
|
||||
|
||||
scripts.lastDroppedBlock = null;
|
||||
scripts.parent.lastReplacedInput = null;
|
||||
scripts.parent.lastDropTarget = null;
|
||||
scripts.lastPreservedBlocks = null;
|
||||
|
||||
if (target === null) {
|
||||
this.startLayout();
|
||||
this.fixBlockColor();
|
||||
|
@ -3796,13 +3812,26 @@ ReporterBlockMorph.prototype.init = function (isPredicate) {
|
|||
|
||||
ReporterBlockMorph.prototype.snap = function (hand) {
|
||||
// passing the hand is optional (for when blocks are dragged & dropped)
|
||||
if (!this.parent instanceof ScriptsMorph) {
|
||||
var scripts = this.parent,
|
||||
target;
|
||||
|
||||
if (!scripts instanceof ScriptsMorph) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var target = this.parent.closestInput(this, hand);
|
||||
scripts.lastDroppedBlock = this;
|
||||
scripts.parent.lastReplacedInput = null;
|
||||
scripts.parent.lastDropTarget = null;
|
||||
scripts.lastPreservedBlocks = null;
|
||||
|
||||
target = scripts.closestInput(this, hand);
|
||||
if (target !== null) {
|
||||
scripts.lastReplacedInput = target;
|
||||
scripts.lastDropTarget = target.parent;
|
||||
if (target instanceof MultiArgMorph) {
|
||||
scripts.lastPreservedBlocks = target.inputs();
|
||||
scripts.lastReplacedInput = target.fullCopy();
|
||||
}
|
||||
target.parent.replaceInput(target, this);
|
||||
if (this.snapSound) {
|
||||
this.snapSound.play();
|
||||
|
@ -4428,6 +4457,12 @@ ScriptsMorph.prototype.init = function (owner) {
|
|||
this.feedbackColor = SyntaxElementMorph.prototype.feedbackColor;
|
||||
this.feedbackMorph = new BoxMorph();
|
||||
|
||||
// "undrop" attributes:
|
||||
this.lastDroppedBlock = null;
|
||||
this.lastReplacedInput = null;
|
||||
this.lastDropTarget = null;
|
||||
this.lastPreservedBlocks = null;
|
||||
|
||||
ScriptsMorph.uber.init.call(this);
|
||||
this.setColor(new Color(70, 70, 70));
|
||||
};
|
||||
|
@ -4738,6 +4773,9 @@ ScriptsMorph.prototype.userMenu = function () {
|
|||
}
|
||||
menu.addItem('clean up', 'cleanUp', 'arrange scripts\nvertically');
|
||||
menu.addItem('add comment', 'addComment');
|
||||
if (this.lastDroppedBlock) {
|
||||
menu.addItem('undrop', 'undrop');
|
||||
}
|
||||
menu.addItem(
|
||||
'scripts pic...',
|
||||
'exportScriptsPicture',
|
||||
|
@ -4829,6 +4867,23 @@ ScriptsMorph.prototype.addComment = function () {
|
|||
new CommentMorph().pickUp(this.world());
|
||||
};
|
||||
|
||||
ScriptsMorph.prototype.undrop = function () {
|
||||
if (!this.lastDroppedBlock) {return; }
|
||||
if (this.lastDropTarget) {
|
||||
this.lastDropTarget.replaceInput(
|
||||
this.lastDroppedBlock,
|
||||
this.lastReplacedInput
|
||||
);
|
||||
this.lastDropTarget.fixBlockColor(null, true);
|
||||
if (this.lastPreservedBlocks) {
|
||||
this.lastPreservedBlocks.forEach(function (morph) {
|
||||
morph.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
this.lastDroppedBlock.pickUp(this.world());
|
||||
};
|
||||
|
||||
// ScriptsMorph blocks layout fix
|
||||
|
||||
ScriptsMorph.prototype.fixMultiArgs = function () {
|
||||
|
@ -10089,11 +10144,19 @@ CommentMorph.prototype.prepareToBeGrabbed = function () {
|
|||
|
||||
CommentMorph.prototype.snap = function (hand) {
|
||||
// passing the hand is optional (for when blocks are dragged & dropped)
|
||||
if (!this.parent instanceof ScriptsMorph) {
|
||||
var scripts = this.parent,
|
||||
target;
|
||||
|
||||
if (!scripts instanceof ScriptsMorph) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var target = this.parent.closestBlock(this, hand);
|
||||
scripts.lastDroppedBlock = null;
|
||||
scripts.parent.lastReplacedInput = null;
|
||||
scripts.parent.lastDropTarget = null;
|
||||
scripts.lastPreservedBlocks = null;
|
||||
|
||||
target = this.parent.closestBlock(this, hand);
|
||||
|
||||
if (target !== null) {
|
||||
target.comment = this;
|
||||
|
|
|
@ -1838,3 +1838,4 @@ ______
|
|||
------
|
||||
* Blocks, Threads: "whitespace" & other options in SPLIT reporter's dropdown
|
||||
* Blocks: Italicize editable input options (e.g. for the SPLT block)
|
||||
* Blocks: Undrop Reporters feature (in script areas' context menus)
|
||||
|
|
Ładowanie…
Reference in New Issue