diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 34372c9..3f79385 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -685,6 +685,21 @@ public class ScratchRuntime { app.setSaveNeeded(); } + public function renameSprite(newName:String):void { + var obj:ScratchObj = app.viewedObj(); + var oldName:String = obj.objName; + obj.objName = ''; + newName = app.stagePane.unusedSpriteName(newName || 'Sprite1'); + obj.objName = newName; + for each (var lw:ListWatcher in app.viewedObj().lists) { + lw.updateTitle(); + } + for each (var a:BlockArg in allUsesOfSprite(oldName)) { + a.setArgValue(newName); + } + app.setSaveNeeded(); + } + public function clearRunFeedback():void { if(app.editMode) { for each (var stack:Block in allStacks()) { @@ -765,6 +780,20 @@ public class ScratchRuntime { return result; } + public function allUsesOfSprite(spriteName:String):Array { + var spriteMenus:Array = ["spriteOnly", "spriteOrMouse", "spriteOrStage", "touching"]; + var result:Array = []; + for each (var stack:Block in allStacks()) { + // for each block in stack + stack.allBlocksDo(function (b:Block):void { + for each (var a:BlockArg in b.args) { + if (spriteMenus.indexOf(a.menuName) != -1 && a.argValue == spriteName) 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/SpriteInfoPart.as b/src/ui/parts/SpriteInfoPart.as index a625383..4637d0e 100644 --- a/src/ui/parts/SpriteInfoPart.as +++ b/src/ui/parts/SpriteInfoPart.as @@ -340,11 +340,8 @@ public class SpriteInfoPart extends UIPart implements DragClient { } private function nameChanged():void { - app.viewedObj().objName = spriteName.contents(); - for each (var lw:ListWatcher in app.viewedObj().lists) { - lw.updateTitle(); - } - app.setSaveNeeded(); + app.runtime.renameSprite(spriteName.contents()); + spriteName.setContents(app.viewedObj().objName); } public function updateThumbnail():void {