From 4f89b18d5a429cbbd62e1b7b8416b7b8fbf4ac28 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Mon, 16 Jun 2014 13:02:19 -0400 Subject: [PATCH 1/2] Fixed scripts running after they were deleted and added delete item to procedure hat context menu --- src/blocks/Block.as | 25 ++++++++++++++++++------- src/scratch/BlockMenus.as | 6 +++--- src/ui/BlockPalette.as | 21 +-------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/blocks/Block.as b/src/blocks/Block.as index 1986d32..3f3f072 100644 --- a/src/blocks/Block.as +++ b/src/blocks/Block.as @@ -748,21 +748,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 addComment():void { diff --git a/src/scratch/BlockMenus.as b/src/scratch/BlockMenus.as index 231640b..8a39e13 100644 --- a/src/scratch/BlockMenus.as +++ b/src/scratch/BlockMenus.as @@ -399,7 +399,7 @@ public class BlockMenus implements DragClient { m.addItem('record...', recordSound); showMenu(m); } - + private function recordSound():void { app.setTab('sounds'); app.soundsPart.recordSound(); @@ -514,9 +514,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 6c21ed3..8e0e326 100644 --- a/src/ui/BlockPalette.as +++ b/src/ui/BlockPalette.as @@ -62,31 +62,12 @@ 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); b.restoreOriginalPosition(); // restore position in case block is undeleted - 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.']; } From 5f8401e846267415221e015b6301cd9da0aaa430 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 10:06:01 -0400 Subject: [PATCH 2/2] Removed unused reference to app --- src/ui/BlockPalette.as | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/BlockPalette.as b/src/ui/BlockPalette.as index 8e0e326..b7f1e50 100644 --- a/src/ui/BlockPalette.as +++ b/src/ui/BlockPalette.as @@ -53,7 +53,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