summaryrefslogtreecommitdiff
path: root/gui.js
diff options
context:
space:
mode:
Diffstat (limited to 'gui.js')
-rw-r--r--gui.js54
1 files changed, 33 insertions, 21 deletions
diff --git a/gui.js b/gui.js
index 6770465..51498e0 100644
--- a/gui.js
+++ b/gui.js
@@ -69,7 +69,7 @@ SpeechBubbleMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.gui = '2014-July-18';
+modules.gui = '2014-July-24';
// Declarations
@@ -1011,11 +1011,13 @@ IDE_Morph.prototype.createSpriteBar = function () {
this.spriteBar.add(nameField);
nameField.drawNew();
nameField.accept = function () {
- myself.currentSprite.setName(nameField.getValue());
- };
- this.spriteBar.reactToEdit = function () {
- myself.currentSprite.setName(nameField.getValue());
+ var newName = nameField.getValue();
+ myself.currentSprite.setName(
+ myself.newSpriteName(newName, myself.currentSprite)
+ );
+ nameField.setContents(myself.currentSprite.name);
};
+ this.spriteBar.reactToEdit = nameField.accept;
// padlock
padlock = new ToggleMorph(
@@ -1780,8 +1782,7 @@ IDE_Morph.prototype.addNewSprite = function () {
var sprite = new SpriteMorph(this.globalVariables),
rnd = Process.prototype.reportRandom;
- sprite.name = sprite.name
- + (this.corral.frame.contents.children.length + 1);
+ sprite.name = this.newSpriteName(sprite.name);
sprite.setCenter(this.stage.center());
this.stage.add(sprite);
@@ -1802,8 +1803,7 @@ IDE_Morph.prototype.paintNewSprite = function () {
cos = new Costume(),
myself = this;
- sprite.name = sprite.name +
- (this.corral.frame.contents.children.length + 1);
+ sprite.name = this.newSpriteName(sprite.name);
sprite.setCenter(this.stage.center());
this.stage.add(sprite);
this.sprites.add(sprite);
@@ -1824,7 +1824,7 @@ IDE_Morph.prototype.paintNewSprite = function () {
IDE_Morph.prototype.duplicateSprite = function (sprite) {
var duplicate = sprite.fullCopy();
- duplicate.name = sprite.name + '(2)';
+ duplicate.name = this.newSpriteName(sprite.name);
duplicate.setPosition(this.world().hand.position());
this.stage.add(duplicate);
duplicate.keepWithin(this.stage);
@@ -1855,6 +1855,23 @@ IDE_Morph.prototype.removeSprite = function (sprite) {
this.selectSprite(this.currentSprite);
};
+IDE_Morph.prototype.newSpriteName = function (name, ignoredSprite) {
+ var ix = name.indexOf('('),
+ stem = (ix < 0) ? name : name.substring(0, ix),
+ count = 1,
+ newName = stem,
+ all = this.sprites.asArray().filter(
+ function (each) {return each !== ignoredSprite; }
+ ).map(
+ function (each) {return each.name; }
+ );
+ while (contains(all, newName)) {
+ count += 1;
+ newName = stem + '(' + count + ')';
+ }
+ return newName;
+};
+
// IDE_Morph menus
IDE_Morph.prototype.userMenu = function () {
@@ -5540,7 +5557,10 @@ CostumeIconMorph.prototype.renameCostume = function () {
null,
function (answer) {
if (answer && (answer !== costume.name)) {
- costume.name = wardrobe.sprite.newCostumeName(answer);
+ costume.name = wardrobe.sprite.newCostumeName(
+ answer,
+ costume
+ );
costume.version = Date.now();
ide.hasChangedMedia = true;
}
@@ -5555,16 +5575,8 @@ CostumeIconMorph.prototype.renameCostume = function () {
CostumeIconMorph.prototype.duplicateCostume = function () {
var wardrobe = this.parentThatIsA(WardrobeMorph),
ide = this.parentThatIsA(IDE_Morph),
- newcos = this.object.copy(),
- split = newcos.name.split(" ");
- if (split[split.length - 1] === "copy") {
- newcos.name += " 2";
- } else if (isNaN(split[split.length - 1])) {
- newcos.name = newcos.name + " copy";
- } else {
- split[split.length - 1] = Number(split[split.length - 1]) + 1;
- newcos.name = split.join(" ");
- }
+ newcos = this.object.copy();
+ newcos.name = wardrobe.sprite.newCostumeName(newcos.name);
wardrobe.sprite.addCostume(newcos);
wardrobe.updateList();
if (ide) {