mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-08 14:19:00 +08:00
Fix creating a unique name for profiles
CURA-1585
This commit is contained in:
parent
a2db4740b9
commit
0b57728d9d
@ -9,7 +9,8 @@ from UM.Logger import Logger
|
||||
import UM.Settings
|
||||
from UM.Settings.Validator import ValidatorState
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
class MachineManagerModel(QObject):
|
||||
def __init__(self, parent = None):
|
||||
@ -118,7 +119,7 @@ class MachineManagerModel(QObject):
|
||||
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id=definition_id)
|
||||
if definitions:
|
||||
definition = definitions[0]
|
||||
name = self._createUniqueStackName(name, definition.getName())
|
||||
name = self._createUniqueName("machine", name, definition.getName())
|
||||
|
||||
new_global_stack = UM.Settings.ContainerStack(name)
|
||||
new_global_stack.addMetaDataEntry("type", "machine")
|
||||
@ -168,7 +169,7 @@ class MachineManagerModel(QObject):
|
||||
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
||||
|
||||
# Create a name that is not empty and unique
|
||||
def _createUniqueStackName(self, name, fallback_name):
|
||||
def _createUniqueName(self, object_type, name, fallback_name):
|
||||
name = name.strip()
|
||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||
if(num_check):
|
||||
@ -179,10 +180,16 @@ class MachineManagerModel(QObject):
|
||||
i = 1
|
||||
|
||||
# Check both the id and the name, because they may not be the same and it is better if they are both unique
|
||||
while UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = unique_name, type = "machine") or \
|
||||
UM.Settings.ContainerRegistry.getInstance().findContainerStacks(name = unique_name, type = "machine"):
|
||||
i += 1
|
||||
unique_name = "%s #%d" % (name, i)
|
||||
if object_type == "machine":
|
||||
while UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = unique_name, type = "machine") or \
|
||||
UM.Settings.ContainerRegistry.getInstance().findContainerStacks(name = unique_name, type = "machine"):
|
||||
i += 1
|
||||
unique_name = "%s #%d" % (name, i)
|
||||
else:
|
||||
while UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = unique_name, type = object_type) or \
|
||||
UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(name = unique_name, type = object_type):
|
||||
i += 1
|
||||
unique_name = "%s #%d" % (name, i)
|
||||
|
||||
return unique_name
|
||||
|
||||
@ -282,7 +289,7 @@ class MachineManagerModel(QObject):
|
||||
if not self._global_container_stack:
|
||||
return
|
||||
|
||||
name = self._createUniqueStackName("Custom profile", "")
|
||||
name = self._createUniqueName("quality", self.activeQualityName, catalog.i18nc("@label", "Custom profile"))
|
||||
user_settings = self._global_container_stack.getTop()
|
||||
new_quality_container = InstanceContainer("")
|
||||
|
||||
@ -311,7 +318,7 @@ class MachineManagerModel(QObject):
|
||||
return
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=container_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueStackName(containers[0].getName(), "")
|
||||
new_name = self._createUniqueName("quality", containers[0].getName(), catalog.i18nc("@label", "Custom profile"))
|
||||
|
||||
new_container = InstanceContainer("")
|
||||
|
||||
@ -424,7 +431,7 @@ class MachineManagerModel(QObject):
|
||||
def renameMachine(self, machine_id, new_name):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueStackName(new_name, containers[0].getBottom().getName())
|
||||
new_name = self._createUniqueName("machine", new_name, containers[0].getBottom().getName())
|
||||
containers[0].setName(new_name)
|
||||
self.globalContainerChanged.emit()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user