diff --git a/cura/Machines/Models/MaterialManagementModel.py b/cura/Machines/Models/MaterialManagementModel.py index 9cc7cb07c9..1b7774c4d3 100644 --- a/cura/Machines/Models/MaterialManagementModel.py +++ b/cura/Machines/Models/MaterialManagementModel.py @@ -4,6 +4,8 @@ from PyQt5.QtCore import QObject, pyqtSlot # To allow the preference page proxy to be used from the actual preferences page. from typing import TYPE_CHECKING +from UM.Logger import Logger + from cura.Settings.CuraContainerRegistry import CuraContainerRegistry # To find the sets of materials belonging to each other, and currently loaded extruder stacks. if TYPE_CHECKING: @@ -22,6 +24,7 @@ class MaterialManagementModel(QObject): # future we might enable this functionality again (deleting the material # from those stacks) but for now it is easier to prevent the user from # doing this. + # \param material_node The ContainerTree node of the material to check. # \return Whether or not the material can be removed. @pyqtSlot("QVariant", result = bool) def canMaterialBeRemoved(self, material_node: "MaterialNode"): @@ -30,4 +33,16 @@ class MaterialManagementModel(QObject): for extruder_stack in container_registry.findContainerStacks(type = "extruder_train"): if extruder_stack.material.getId() in ids_to_remove: return False - return True \ No newline at end of file + return True + + ## Change the user-visible name of a material. + # \param material_node The ContainerTree node of the material to rename. + # \param name The new name for the material. + @pyqtSlot("QVariant", str) + def setMaterialName(self, material_node: "MaterialNode", name: str) -> None: + container_registry = CuraContainerRegistry.getInstance() + root_material_id = material_node.base_file + if container_registry.isReadOnly(root_material_id): + Logger.log("w", "Cannot set name of read-only container %s.", root_material_id) + return + return container_registry.findContainers(id = root_material_id)[0].setName(name) \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index 30b2474e09..8302f5f65a 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -565,7 +565,7 @@ TabView } // update the values - CuraApplication.getMaterialManager().setMaterialName(base.currentMaterialNode, new_name) + base.materialManagement.setMaterialName(base.currentMaterialNode, new_name) properties.name = new_name }