“Undrop / Redrop” support for sticky comments

pull/29/head
jmoenig 2016-11-23 10:38:59 +01:00
rodzic dae8e7a7bb
commit 64efff58cf
3 zmienionych plików z 44 dodań i 16 usunięć

Wyświetl plik

@ -149,7 +149,7 @@ isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process*/
// Global stuff //////////////////////////////////////////////////////// // Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2016-November-22'; modules.blocks = '2016-November-23';
var SyntaxElementMorph; var SyntaxElementMorph;
var BlockMorph; var BlockMorph;
@ -5685,6 +5685,7 @@ ScriptsMorph.prototype.userMenu = function () {
blockEditor, blockEditor,
myself = this, myself = this,
obj = this.owner, obj = this.owner,
hasUndropQueue,
stage = obj.parentThatIsA(StageMorph); stage = obj.parentThatIsA(StageMorph);
if (!ide) { if (!ide) {
@ -5695,6 +5696,7 @@ ScriptsMorph.prototype.userMenu = function () {
} }
if (this.dropRecord) { if (this.dropRecord) {
if (this.dropRecord.lastRecord) { if (this.dropRecord.lastRecord) {
hasUndropQueue = true;
menu.addItem( menu.addItem(
'undrop', 'undrop',
'undrop', 'undrop',
@ -5702,13 +5704,16 @@ ScriptsMorph.prototype.userMenu = function () {
); );
} }
if (this.dropRecord.nextRecord) { if (this.dropRecord.nextRecord) {
hasUndropQueue = true;
menu.addItem( menu.addItem(
'redrop', 'redrop',
'redrop', 'redrop',
'redo the last undone\nblock drop\nin this pane' 'redo the last undone\nblock drop\nin this pane'
); );
} }
menu.addLine(); if (hasUndropQueue) {
menu.addLine();
}
} }
menu.addItem('clean up', 'cleanUp', 'arrange scripts\nvertically'); menu.addItem('clean up', 'cleanUp', 'arrange scripts\nvertically');
@ -5815,7 +5820,15 @@ ScriptsMorph.prototype.scriptsPicture = function () {
}; };
ScriptsMorph.prototype.addComment = function () { ScriptsMorph.prototype.addComment = function () {
new CommentMorph().pickUp(this.world()); var ide = this.parentThatIsA(IDE_Morph),
world = this.world();
new CommentMorph().pickUp(world);
if (ide) {
world.hand.grabOrigin = {
origin: ide.palette,
position: ide.palette.center()
};
}
}; };
ScriptsMorph.prototype.undrop = function () { ScriptsMorph.prototype.undrop = function () {
@ -5861,7 +5874,7 @@ ScriptsMorph.prototype.recoverLastDrop = function (forRedrop) {
} }
dropped = rec.lastDroppedBlock; dropped = rec.lastDroppedBlock;
parent = dropped.parent; parent = dropped.parent;
if (rec.lastDroppedBlock instanceof CommandBlockMorph) { if (dropped instanceof CommandBlockMorph) {
if (rec.lastNextBlock) { if (rec.lastNextBlock) {
if (rec.action === 'delete') { if (rec.action === 'delete') {
if (forRedrop) { if (forRedrop) {
@ -5925,7 +5938,7 @@ ScriptsMorph.prototype.recoverLastDrop = function (forRedrop) {
cslot.fixLayout(); cslot.fixLayout();
} }
} }
} else { // ReporterBlockMorph } else if (dropped instanceof ReporterBlockMorph) {
if (rec.lastDropTarget) { if (rec.lastDropTarget) {
rec.lastDropTarget.replaceInput( rec.lastDropTarget.replaceInput(
rec.lastDroppedBlock, rec.lastDroppedBlock,
@ -5938,15 +5951,27 @@ ScriptsMorph.prototype.recoverLastDrop = function (forRedrop) {
}); });
} }
} }
} else if (dropped instanceof CommentMorph) {
if (forRedrop && rec.lastDropTarget) {
onBeforeDrop = function () {
rec.lastDropTarget.element.comment = dropped;
dropped.block = rec.lastDropTarget.element;
dropped.align();
};
}
} else {
throw new Error('unsupported action for ' + dropped);
} }
this.clearDropInfo(); this.clearDropInfo();
dropped.prepareToBeGrabbed(this.world().hand); dropped.prepareToBeGrabbed(this.world().hand);
if (dropped instanceof CommentMorph) {
dropped.removeShadow();
}
this.add(dropped); this.add(dropped);
parent.reactToGrabOf(dropped); parent.reactToGrabOf(dropped);
if (dropped instanceof ReporterBlockMorph && parent instanceof BlockMorph) { if (dropped instanceof ReporterBlockMorph && parent instanceof BlockMorph) {
parent.changed(); parent.changed();
} }
if (rec.action === 'delete') { if (rec.action === 'delete') {
if (forRedrop && rec.lastNextBlock) { if (forRedrop && rec.lastNextBlock) {
if (parent instanceof CommandBlockMorph) { if (parent instanceof CommandBlockMorph) {
@ -5961,7 +5986,6 @@ ScriptsMorph.prototype.recoverLastDrop = function (forRedrop) {
dropped.moveBy(new Point(-100, -20)); dropped.moveBy(new Point(-100, -20));
} }
} }
return onBeforeDrop; return onBeforeDrop;
}; };
@ -12109,7 +12133,7 @@ CommentMorph.prototype.show = function () {
// CommentMorph dragging & dropping // CommentMorph dragging & dropping
CommentMorph.prototype.prepareToBeGrabbed = function () { CommentMorph.prototype.prepareToBeGrabbed = function (hand) {
// disassociate from the block I'm posted to // disassociate from the block I'm posted to
if (this.block) { if (this.block) {
this.block.comment = null; this.block.comment = null;
@ -12132,13 +12156,7 @@ CommentMorph.prototype.snap = function (hand) {
if (!(scripts instanceof ScriptsMorph)) { if (!(scripts instanceof ScriptsMorph)) {
return null; return null;
} }
scripts.clearDropInfo(); scripts.clearDropInfo();
scripts.lastDroppedBlock = this;
if (hand) {
scripts.recordDrop(hand.grabOrigin);
}
target = scripts.closestBlock(this, hand); target = scripts.closestBlock(this, hand);
if (target !== null) { if (target !== null) {
target.comment = this; target.comment = this;
@ -12146,8 +12164,14 @@ CommentMorph.prototype.snap = function (hand) {
if (this.snapSound) { if (this.snapSound) {
this.snapSound.play(); this.snapSound.play();
} }
scripts.lastDropTarget = {element: target};
} }
this.align(); this.align();
scripts.lastDroppedBlock = this;
if (hand) {
scripts.recordDrop(hand.grabOrigin);
}
}; };
// CommentMorph sticking to blocks // CommentMorph sticking to blocks

Wyświetl plik

@ -3125,5 +3125,8 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
161122 161122
------ ------
* Blocks, GUI: “Undrop / Redrop” for deleting blocks via the context menu or in keyboard edit mode * Blocks, GUI: “Undrop / Redrop” for deleting blocks via the context menu or in keyboard edit mode
* Morphic: support optional “onBeforeDrop” callback parameter in Morph.slideBackTo() * Morphic: support “onBeforeDrop” callback parameter in slideBackTo()
161123
------
* Blocks, Morphic: “Undrop / Redrop” support for sticky comments

Wyświetl plik

@ -1103,7 +1103,7 @@
/*global window, HTMLCanvasElement, FileReader, Audio, FileList*/ /*global window, HTMLCanvasElement, FileReader, Audio, FileList*/
var morphicVersion = '2016-November-22'; var morphicVersion = '2016-November-23';
var modules = {}; // keep track of additional loaded modules var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -3622,6 +3622,7 @@ Morph.prototype.slideBackTo = function (situation, inSteps, onBeforeDrop) {
if (stepCount === steps) { if (stepCount === steps) {
situation.origin.add(myself); situation.origin.add(myself);
if (onBeforeDrop) {onBeforeDrop(); } if (onBeforeDrop) {onBeforeDrop(); }
if (myself.justDropped) {myself.justDropped(); }
if (situation.origin.reactToDropOf) { if (situation.origin.reactToDropOf) {
situation.origin.reactToDropOf(myself); situation.origin.reactToDropOf(myself);
} }