make sure to stop active processes when deleting a block

upd4.1
Jens Mönig 2017-06-20 08:51:55 +02:00
rodzic 4fd6190ca0
commit 9b497c2132
5 zmienionych plików z 39 dodań i 19 usunięć

Wyświetl plik

@ -150,7 +150,7 @@ CustomCommandBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2017-June-19';
modules.blocks = '2017-June-20';
var SyntaxElementMorph;
var BlockMorph;
@ -3897,6 +3897,7 @@ BlockMorph.prototype.allComments = function () {
};
BlockMorph.prototype.destroy = function (justThis) {
// private - use IDE_Morph.removeBlock() to first stop all my processes
if (justThis) {
if (!isNil(this.comment)) {
this.comment.destroy();
@ -3906,17 +3907,6 @@ BlockMorph.prototype.destroy = function (justThis) {
comment.destroy();
});
}
/* +++ needs tweaking:
// stop active process(es) for this block
// for this we need access to the stage...
if ((!this.parent || !this.parent.topBlock)
&& this.activeProcess()) {
this.activeProcess().stop();
}
*/
BlockMorph.uber.destroy.call(this);
};
@ -4343,6 +4333,7 @@ CommandBlockMorph.prototype.userDestroy = function () {
}
var scripts = this.parentThatIsA(ScriptsMorph),
ide = this.parentThatIsA(IDE_Morph),
parent = this.parentThatIsA(SyntaxElementMorph),
cslot = this.parentThatIsA(CSlotMorph);
@ -4354,7 +4345,12 @@ CommandBlockMorph.prototype.userDestroy = function () {
scripts.dropRecord.action = 'delete';
}
this.destroy();
if (ide) {
// also stop all active processes hatted by this block
ide.removeBlock(this);
} else {
this.destroy();
}
if (cslot) {
cslot.fixLayout();
}
@ -4366,6 +4362,7 @@ CommandBlockMorph.prototype.userDestroy = function () {
CommandBlockMorph.prototype.userDestroyJustThis = function () {
// delete just this one block, reattach next block to the previous one,
var scripts = this.parentThatIsA(ScriptsMorph),
ide = this.parentThatIsA(IDE_Morph),
cs = this.parentThatIsA(CommandSlotMorph),
pb,
nb = this.nextBlock(),
@ -4391,7 +4388,12 @@ CommandBlockMorph.prototype.userDestroyJustThis = function () {
} else if (cs && (cs.nestedBlock() === this)) {
above = cs;
}
this.destroy(true); // just this block
if (ide) {
// also stop all active processes hatted by this block
ide.removeBlock(this, true); // just this block
} else {
this.destroy(true); // just this block
}
if (nb) {
if (above instanceof CommandSlotMorph) {
above.nestedBlock(nb);

10
gui.js
Wyświetl plik

@ -74,7 +74,7 @@ isRetinaSupported, SliderMorph, Animation*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2017-May-31';
modules.gui = '2017-June-20';
// Declarations
@ -1063,6 +1063,7 @@ IDE_Morph.prototype.createPalette = function (forSearching) {
myself.currentSprite.wearCostume(null);
droppedMorph.perish();
} else if (droppedMorph instanceof BlockMorph) {
myself.stage.threads.stopAllForBlock(droppedMorph);
if (hand && hand.grabOrigin.origin instanceof ScriptsMorph) {
hand.grabOrigin.origin.clearDropInfo();
hand.grabOrigin.origin.lastDroppedBlock = droppedMorph;
@ -2188,6 +2189,13 @@ IDE_Morph.prototype.newSpriteName = function (name, ignoredSprite) {
return newName;
};
// IDE_Morph deleting scripts
IDE_Morph.prototype.removeBlock = function (aBlock, justThis) {
this.stage.threads.stopAllForBlock(aBlock);
aBlock.destroy(justThis);
};
// IDE_Morph menus
IDE_Morph.prototype.userMenu = function () {

Wyświetl plik

@ -3445,6 +3445,10 @@ Fixes:
* threads: fixed #1767 (optimized thread-launch and highlighting)
* threads, blocks: optimized thread count indicator for “glow” halos
170620
------
* threads, blocks, ide: make sure to stop active processes when deleting a block
Features:
* polymorphic sprite-local custom blocks

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/
modules.objects = '2017-May-31';
modules.objects = '2017-June-20';
var SpriteMorph;
var StageMorph;

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph, ColorSlotMorph, isSnapObject*/
modules.threads = '2017-June-19';
modules.threads = '2017-June-20';
var ThreadManager;
var Process;
@ -253,6 +253,12 @@ ThreadManager.prototype.stopAllForReceiver = function (rcvr, excpt) {
});
};
ThreadManager.prototype.stopAllForBlock = function (aTopBlock) {
this.processesForBlock(aTopBlock, true).forEach(function (proc) {
proc.stop();
});
};
ThreadManager.prototype.stopProcess = function (block, receiver) {
var active = this.findProcess(block, receiver);
if (active) {
@ -385,8 +391,8 @@ ThreadManager.prototype.findProcess = function (block, receiver) {
);
};
ThreadManager.prototype.processesForBlock = function (block) {
var top = block.topBlock();
ThreadManager.prototype.processesForBlock = function (block, only) {
var top = only ? block : block.topBlock();
return this.processes.filter(function (each) {
return each.topBlock === top &&
each.isRunning() &&