mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-12 09:01:18 -05:00
Merge branch 'stop-deleted-scripts'
Conflicts: src/ui/BlockPalette.as
This commit is contained in:
commit
3cfe0db587
3 changed files with 21 additions and 30 deletions
|
@ -807,21 +807,32 @@ public class Block extends Sprite {
|
|||
Scratch.app.gh.grabOnMouseUp(newStack);
|
||||
}
|
||||
|
||||
public function deleteStack():void {
|
||||
if (isProcDef() || isEmbeddedInProcHat()) return; // don't delete procedure definition this way for now
|
||||
if (parent == null) return;
|
||||
public function deleteStack():Boolean {
|
||||
if (op == 'proc_declaration') {
|
||||
return (parent as Block).deleteStack();
|
||||
}
|
||||
var app:Scratch = Scratch.app;
|
||||
var top:Block = topBlock();
|
||||
if (op == Specs.PROCEDURE_DEF && app.runtime.allCallsOf(spec, app.viewedObj()).length) {
|
||||
DialogBox.notify('Cannot Delete', 'To delete a block definition, first remove all uses of the block.', stage);
|
||||
return false;
|
||||
}
|
||||
if (top == this && app.interp.isRunning(top, app.viewedObj())) {
|
||||
app.interp.toggleThread(top, app.viewedObj());
|
||||
}
|
||||
// TODO: Remove any waiting reporter data in the Scratch.app.extensionManager
|
||||
if (parent is Block) Block(parent).removeBlock(this);
|
||||
else parent.removeChild(this);
|
||||
else if (parent) parent.removeChild(this);
|
||||
this.cacheAsBitmap = false;
|
||||
// set position for undelete
|
||||
x = top.x;
|
||||
y = top.y;
|
||||
if (top != this) x += top.width + 5;
|
||||
Scratch.app.runtime.recordForUndelete(this, x, y, 0, Scratch.app.viewedObj());
|
||||
Scratch.app.scriptsPane.saveScripts();
|
||||
Scratch.app.runtime.checkForGraphicEffects();
|
||||
app.runtime.recordForUndelete(this, x, y, 0, app.viewedObj());
|
||||
app.scriptsPane.saveScripts();
|
||||
app.runtime.checkForGraphicEffects();
|
||||
app.updatePalette();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function attachedCommentsIn(scriptsPane:ScriptsPane):Array {
|
||||
|
|
|
@ -523,9 +523,9 @@ public class BlockMenus implements DragClient {
|
|||
if (!isInPalette(block)) {
|
||||
if (!block.isProcDef()) {
|
||||
m.addItem('duplicate', duplicateStack);
|
||||
}
|
||||
m.addItem('delete', block.deleteStack);
|
||||
m.addLine();
|
||||
}
|
||||
m.addItem('add comment', block.addComment);
|
||||
}
|
||||
m.addItem('help', block.showHelp);
|
||||
|
|
|
@ -54,7 +54,6 @@ public class BlockPalette extends ScrollFrameContents {
|
|||
|
||||
public function handleDrop(obj:*):Boolean {
|
||||
// Delete blocks and stacks dropped onto the palette.
|
||||
var app:Scratch = root as Scratch;
|
||||
var c:ScratchComment = obj as ScratchComment;
|
||||
if (c) {
|
||||
c.x = c.y = 20; // postion for undelete
|
||||
|
@ -63,30 +62,11 @@ public class BlockPalette extends ScrollFrameContents {
|
|||
}
|
||||
var b:Block = obj as Block;
|
||||
if (b) {
|
||||
if ((b.op == Specs.PROCEDURE_DEF) && hasCallers(b, app)) {
|
||||
DialogBox.notify('Cannot Delete', 'To delete a block definition, first remove all uses of the block.', stage);
|
||||
return false;
|
||||
}
|
||||
if (b.parent) b.parent.removeChild(b);
|
||||
Scratch.app.runtime.recordForUndelete(b, b.x, b.y, 0, Scratch.app.viewedObj());
|
||||
app.scriptsPane.saveScripts();
|
||||
app.updatePalette();
|
||||
return true;
|
||||
return b.deleteStack();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function hasCallers(def:Block, app:Scratch):Boolean {
|
||||
var callCount:int;
|
||||
for each (var stack:Block in app.viewedObj().scripts) {
|
||||
// for each block in stack
|
||||
stack.allBlocksDo(function (b:Block):void {
|
||||
if ((b.op == Specs.CALL) && (b.spec == def.spec)) callCount++;
|
||||
});
|
||||
}
|
||||
return callCount > 0;
|
||||
}
|
||||
|
||||
public static function strings():Array {
|
||||
return ['Cannot Delete', 'To delete a block definition, first remove all uses of the block.'];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue