diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 543132d..7f3f374 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -665,6 +665,19 @@ public class ScratchRuntime { // Script utilities //------------------------------ + public function renameCostume(newName:String):void { + var obj:ScratchObj = app.viewedObj(); + var costume:ScratchCostume = obj.currentCostume(); + var oldName:String = costume.costumeName; + if (obj.isCostumeNameUsed(newName)) return; + costume.costumeName = newName; + var uses:Array = obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName); + for each (var a:BlockArg in uses) { + a.setArgValue(newName); + } + app.setSaveNeeded(); + } + public function clearRunFeedback():void { if(app.editMode) { for each (var stack:Block in allStacks()) { @@ -721,6 +734,30 @@ public class ScratchRuntime { return false; } + public function allUsesOfBackdrop(backdropName:String):Array { + var result:Array = []; + allStacksAndOwnersDo(function (stack:Block, target:ScratchObj):void { + stack.allBlocksDo(function (b:Block):void { + for each (var a:BlockArg in b.args) { + if (a.menuName == 'backdrop' && a.argValue == backdropName) result.push(a); + } + }); + }); + return result; + } + + public function allUsesOfCostume(costumeName:String):Array { + var result:Array = []; + for each (var stack:Block in app.viewedObj().scripts) { + stack.allBlocksDo(function (b:Block):void { + for each (var a:BlockArg in b.args) { + if (a.menuName == 'costume' && a.argValue == costumeName) result.push(a); + } + }); + } + return result; + } + public function allUsesOfVariable(varName:String, owner:ScratchObj):Array { var variableBlocks:Array = [Specs.SET_VAR, Specs.CHANGE_VAR, "showVariable:", "hideVariable:"]; var result:Array = []; diff --git a/src/ui/parts/ImagesPart.as b/src/ui/parts/ImagesPart.as index eb05d00..4ebdbb2 100644 --- a/src/ui/parts/ImagesPart.as +++ b/src/ui/parts/ImagesPart.as @@ -200,13 +200,9 @@ public class ImagesPart extends UIPart { } private function nameChanged():void { - var obj:ScratchObj = app.viewedObj(); - if(!obj.isCostumeNameUsed(nameField.contents())) { - obj.currentCostume().costumeName = nameField.contents(); - (listFrame.contents as MediaPane).refresh(); - } - else - nameField.setContents(obj.currentCostume().costumeName); + app.runtime.renameCostume(nameField.contents()); + nameField.setContents(app.viewedObj().currentCostume().costumeName); + (listFrame.contents as MediaPane).refresh(); } private function addNewCostumeButtons():void {