diff --git a/src/blocks/Block.as b/src/blocks/Block.as index 44f00ca..f9d38cf 100644 --- a/src/blocks/Block.as +++ b/src/blocks/Block.as @@ -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 { diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index b4f33a5..35569c2 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -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('delete', block.deleteStack); + m.addLine(); m.addItem('add comment', block.addComment); } m.addItem('help', block.showHelp); diff --git a/src/ui/BlockPalette.as b/src/ui/BlockPalette.as index 0a2d6e4..6f0e28a 100644 --- a/src/ui/BlockPalette.as +++ b/src/ui/BlockPalette.as @@ -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.']; }