Browse Source

WIP: Refactor setMaterialName()

Lipu Fei 7 years ago
parent
commit
f7f9c68fcc
2 changed files with 10 additions and 16 deletions
  1. 9 14
      cura/Settings/ContainerManager.py
  2. 1 2
      resources/qml/Preferences/MaterialView.qml

+ 9 - 14
cura/Settings/ContainerManager.py

@@ -160,21 +160,16 @@ class ContainerManager(QObject):
 
         return container.getProperty(setting_key, property_name)
 
-    ##  Set the name of the specified container.
-    @pyqtSlot(str, str, result = bool)
-    def setContainerName(self, container_id, new_name):
-        if self._container_registry.isReadOnly(container_id):
-            Logger.log("w", "Cannot set name of read-only container %s.", container_id)
-            return False
-
-        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.
-        if not containers:
-            Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
-            return False
-
-        containers[0].setName(new_name)
+    ##  Set the name of the specified material.
+    @pyqtSlot("QVariant", str)
+    def setMaterialName(self, material_node, new_name):
+        root_material_id = material_node.metadata["base_file"]
+        if self._container_registry.isReadOnly(root_material_id):
+            Logger.log("w", "Cannot set name of read-only container %s.", root_material_id)
+            return
 
-        return True
+        material_group = self._material_manager.getMaterialGroup(root_material_id)
+        material_group.root_material_node.getContainer().setName(new_name)
 
     ##  Find instance containers matching certain criteria.
     #

+ 1 - 2
resources/qml/Preferences/MaterialView.qml

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