Fixed renaming of profiles.

They are now correctly renamed (and saved under different name on disk as well)

CURA-1683
This commit is contained in:
Jaime van Kessel 2016-06-10 09:38:47 +02:00
parent 070a522abb
commit 962b4e84a9

View File

@ -6,6 +6,7 @@ from UM.Application import Application
from UM.Preferences import Preferences from UM.Preferences import Preferences
from UM.Logger import Logger from UM.Logger import Logger
from UM.Resources import Resources from UM.Resources import Resources
import copy
import os import os
import urllib import urllib
@ -303,26 +304,32 @@ class MachineManagerModel(QObject):
return "" return ""
@pyqtSlot(str, str) @pyqtSlot(str, str)
def renameQualityContainer(self, container_id, new_name): def renameQualityContainer(self, container_id, new_name):
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id, type = "quality") containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id, type = "quality")
if containers: if containers:
new_name = self._createUniqueName("quality", containers[0].getName(), new_name,
catalog.i18nc("@label", "Custom profile"))
# Remove old container form drive. # As we also want the id of the container to be changed (so that profile name is the name of the file
old_id = containers[0].getId() # on disk. We need to create a new instance and remove it (so the old file of the container is removed)
file_name = urllib.parse.quote_plus(old_id) + ".inst.cfg" # If we don't do that, we might get duplicates & other weird issues.
path = Resources.getStoragePath(cura.CuraApplication.CuraApplication.ResourceTypes.QualityInstanceContainer, new_container = InstanceContainer("")
file_name) new_container.deserialize(containers[0].serialize())
os.remove(path)
## Check if the new name is allowed. # Actually set the name
new_name = self._createUniqueName("quality", containers[0].getName(), new_name, catalog.i18nc("@label", "Custom profile")) new_container.setName(new_name)
new_container._id = new_name # Todo: Fix proper id change function for this.
containers[0].setName(new_name) # Add the "new" container.
containers[0]._id = new_name # Todo: Fix proper id change function for this. UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
self.activeQualityChanged.emit()
# Ensure that the renamed profile is saved -before- we remove the old profile.
Application.getInstance().saveSettings()
# Actually set & remove new / old quality.
self.setActiveQuality(new_name)
self.removeQualityContainer(containers[0].getId())
@pyqtSlot(str) @pyqtSlot(str)
def removeQualityContainer(self, container_id): def removeQualityContainer(self, container_id):