mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Merge branch 'rename-sound-update-refs'
Conflicts: src/scratch/ScratchRuntime.as
This commit is contained in:
commit
55652f899b
3 changed files with 34 additions and 4 deletions
|
@ -133,11 +133,19 @@ public class ScratchObj extends Sprite {
|
|||
}
|
||||
|
||||
public function isCostumeNameUsed(name:String):Boolean {
|
||||
var existingNames:Array = [];
|
||||
name = name.toLowerCase();
|
||||
for each (var c:ScratchCostume in costumes) {
|
||||
existingNames.push(c.costumeName.toLowerCase());
|
||||
if (c.costumeName.toLowerCase() == name) return true;
|
||||
}
|
||||
return (existingNames.indexOf(name.toLowerCase()) > -1);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSoundNameUsed(name:String):Boolean {
|
||||
name = name.toLowerCase();
|
||||
for each (var s:ScratchSound in sounds) {
|
||||
if (s.soundName.toLowerCase() == name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unusedCostumeName(baseName:String = ''):String {
|
||||
|
|
|
@ -700,6 +700,17 @@ public class ScratchRuntime {
|
|||
app.setSaveNeeded();
|
||||
}
|
||||
|
||||
public function renameSound(s:ScratchSound, newName:String):void {
|
||||
var obj:ScratchObj = app.viewedObj();
|
||||
var oldName:String = s.soundName;
|
||||
if (obj.isSoundNameUsed(newName)) return;
|
||||
s.soundName = newName;
|
||||
allUsesOfSoundDo(oldName, function (a:BlockArg):void {
|
||||
a.setArgValue(newName);
|
||||
});
|
||||
app.setSaveNeeded();
|
||||
}
|
||||
|
||||
public function clearRunFeedback():void {
|
||||
if(app.editMode) {
|
||||
for each (var stack:Block in allStacks()) {
|
||||
|
@ -808,6 +819,16 @@ public class ScratchRuntime {
|
|||
return result;
|
||||
}
|
||||
|
||||
public function allUsesOfSoundDo(soundName:String, f:Function):void {
|
||||
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 == 'sound' && a.argValue == soundName) f(a);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function allCallsOf(callee:String, owner:ScratchObj):Array {
|
||||
var result:Array = [];
|
||||
for each (var stack:Block in owner.scripts) {
|
||||
|
|
|
@ -201,7 +201,8 @@ public class SoundsPart extends UIPart {
|
|||
private function nameChanged():void {
|
||||
currentIndex = Math.min(currentIndex, app.viewedObj().sounds.length - 1);
|
||||
var current:ScratchSound = app.viewedObj().sounds[currentIndex] as ScratchSound;
|
||||
current.soundName = nameField.contents();
|
||||
app.runtime.renameSound(current, nameField.contents());
|
||||
nameField.setContents(current.soundName);
|
||||
(listFrame.contents as MediaPane).refresh();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue