WIP: Refactor setMaterialName()

This commit is contained in:
Lipu Fei 2018-02-16 14:17:35 +01:00
parent e5cc7efdf2
commit f7f9c68fcc
2 changed files with 10 additions and 16 deletions

View file

@ -160,21 +160,16 @@ class ContainerManager(QObject):
return container.getProperty(setting_key, property_name) return container.getProperty(setting_key, property_name)
## Set the name of the specified container. ## Set the name of the specified material.
@pyqtSlot(str, str, result = bool) @pyqtSlot("QVariant", str)
def setContainerName(self, container_id, new_name): def setMaterialName(self, material_node, new_name):
if self._container_registry.isReadOnly(container_id): root_material_id = material_node.metadata["base_file"]
Logger.log("w", "Cannot set name of read-only container %s.", container_id) if self._container_registry.isReadOnly(root_material_id):
return False Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
return
containers = self._container_registry.findContainers(id = container_id) #We need to get the full container, not just metadata, since we need to know whether it's read-only. material_group = self._material_manager.getMaterialGroup(root_material_id)
if not containers: material_group.root_material_node.getContainer().setName(new_name)
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
return False
containers[0].setName(new_name)
return True
## Find instance containers matching certain criteria. ## Find instance containers matching certain criteria.
# #

View file

@ -454,14 +454,13 @@ TabView
// update the display name of the material // update the display name of the material
function updateMaterialDisplayName (old_name, new_name) { function updateMaterialDisplayName (old_name, new_name) {
// don't change when new name is the same // don't change when new name is the same
if (old_name == new_name) { if (old_name == new_name) {
return return
} }
// update the values // update the values
Cura.ContainerManager.setContainerName(base.containerId, new_name) Cura.ContainerManager.setMaterialName(base.currentMaterialNode, new_name)
materialProperties.name = new_name materialProperties.name = new_name
} }