Skip to content

Commit

Permalink
Fix name deduplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie-git committed Mar 26, 2021
1 parent e9e70d9 commit 892aba8
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/logo.cds
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
0.0,
56.0
],
"text": "for _ in range(4):\n for _ in range(4):\n fd(100)\n rt(90)\n",
"text": "for _ in range(4):\n fd(100)\n rt(90)\n",
"alignment": "Left",
"textColor": "black",
"font": "Mono",
Expand Down Expand Up @@ -774,5 +774,5 @@
}
],
"CardStock_stack_format": 1,
"CardStock_stack_version": "0.8.7"
"CardStock_stack_version": "0.8.8.1"
}
2 changes: 1 addition & 1 deletion stackManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def GroupModelsInternal(self, models, group=None, name=None):
if not group:
group = GroupModel(self)
if not name:
name = "group_"
name = "group"
group.SetProperty("name", card.GetNextAvailableNameInCard(name), False)
validModels = []
for m in models:
Expand Down
2 changes: 1 addition & 1 deletion uiButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UiButton(UiView):
def __init__(self, parent, stackManager, model=None):
if not model:
model = ButtonModel(stackManager)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("button_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("button"), False)

self.stackManager = stackManager
self.button = self.CreateButton(stackManager, model)
Expand Down
3 changes: 2 additions & 1 deletion uiCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UiCard(UiView):

def __init__(self, parent, stackManager, model):
if not model.GetProperty("name"):
model.SetProperty("name", model.GetNextAvailableNameInCard("card_"), False)
model.SetProperty("name", model.GetNextAvailableNameInCard("card"), False)

super().__init__(parent, stackManager, model, stackManager.view)
self.stackManager.stackModel.SetProperty("size", self.view.GetSize(), False)
Expand Down Expand Up @@ -193,6 +193,7 @@ def AddNewObject(self, typeStr, name, size, points=None):
if not isinstance(name, str):
raise TypeError("name is not a string")
model = generator.StackGenerator.ModelFromType(self.stackManager, typeStr)
model.SetProperty("name", name)
self.DeduplicateNamesForModels([model])
if size:
model.SetProperty("size", size)
Expand Down
2 changes: 1 addition & 1 deletion uiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UiGroup(UiView):

def __init__(self, parent, stackManager, model):
if not model.GetProperty("name"):
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("group_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("group"), False)

self.uiViews = []

Expand Down
2 changes: 1 addition & 1 deletion uiImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UiImage(UiView):
def __init__(self, parent, stackManager, model=None):
if not model:
model = ImageModel(stackManager)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("image_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("image"), False)

super().__init__(parent, stackManager, model, None)
self.rotatedBitmap = None
Expand Down
2 changes: 1 addition & 1 deletion uiShape.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UiShape(UiView):
def __init__(self, parent, stackManager, shapeType, model=None):
if not model:
model = self.CreateModelForType(stackManager, shapeType)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("shape_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("shape"), False)

super().__init__(parent, stackManager, model, None)

Expand Down
2 changes: 1 addition & 1 deletion uiTextField.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UiTextField(UiTextBase):
def __init__(self, parent, stackManager, model=None):
if not model:
model = TextFieldModel(stackManager)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("field_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("field"), False)

self.stackManager = stackManager
self.isInlineEditing = False
Expand Down
2 changes: 1 addition & 1 deletion uiTextLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UiTextLabel(UiTextBase):
def __init__(self, parent, stackManager, model=None):
if not model:
model = TextLabelModel(stackManager)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("label_"), False)
model.SetProperty("name", stackManager.uiCard.model.GetNextAvailableNameInCard("label"), False)

self.stackManager = stackManager
label = self.CreateLabel(stackManager, model)
Expand Down
6 changes: 3 additions & 3 deletions uiView.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,14 @@ def StopAnimations(self):
def DeduplicateName(self, name, existingNames):
existingNames.extend(self.reservedNames) # disallow globals
if name in existingNames:
name = name.rstrip("0123456789")
if name[-1:] != "_":
name = name + "_"
name = name.rstrip("0123456789_")
name = self.GetNextAvailableName(name, existingNames)
return name

def GetNextAvailableName(self, base, existingNames):
i = 0
if base[-1] != "_":
base += "_"
while True:
i += 1
name = base+str(i)
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION='0.8.8.1'
VERSION='0.8.8.2'

0 comments on commit 892aba8

Please sign in to comment.