mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 13:11:12 -05:00
Merge pull request #279 from nathan/rename-costume-update-refs
Fixed renaming costume breaking references to that costume
This commit is contained in:
commit
111dbeac8e
2 changed files with 40 additions and 7 deletions
|
@ -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 = [];
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue