mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 01:39:03 +08:00
Prevent the deletion of materials that are still active
This commit is contained in:
parent
e376404e5c
commit
8b3290fb1e
@ -553,10 +553,24 @@ class MaterialManager(QObject):
|
|||||||
#
|
#
|
||||||
# Methods for GUI
|
# Methods for GUI
|
||||||
#
|
#
|
||||||
|
@pyqtSlot("QVariant", result=bool)
|
||||||
|
def canMaterialBeRemoved(self, material_node: "MaterialNode"):
|
||||||
|
# Check if the material is active in any extruder train. In that case, the material shouldn't be removed!
|
||||||
|
# In the future we might enable this again, but right now, it's causing a ton of issues if we do (since it
|
||||||
|
# corrupts the configuration)
|
||||||
|
root_material_id = material_node.getMetaDataEntry("base_file")
|
||||||
|
material_group = self.getMaterialGroup(root_material_id)
|
||||||
|
if not material_group:
|
||||||
|
return False
|
||||||
|
|
||||||
|
nodes_to_remove = [material_group.root_material_node] + material_group.derived_material_node_list
|
||||||
|
ids_to_remove = [node.getMetaDataEntry("id", "") for node in nodes_to_remove]
|
||||||
|
|
||||||
|
for extruder_stack in self._container_registry.findContainerStacks(type="extruder_train"):
|
||||||
|
if extruder_stack.material.getId() in ids_to_remove:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
#
|
|
||||||
# Sets the new name for the given material.
|
|
||||||
#
|
|
||||||
@pyqtSlot("QVariant", str)
|
@pyqtSlot("QVariant", str)
|
||||||
def setMaterialName(self, material_node: "MaterialNode", name: str) -> None:
|
def setMaterialName(self, material_node: "MaterialNode", name: str) -> None:
|
||||||
root_material_id = material_node.getMetaDataEntry("base_file")
|
root_material_id = material_node.getMetaDataEntry("base_file")
|
||||||
|
@ -127,7 +127,7 @@ Item
|
|||||||
{
|
{
|
||||||
text: catalog.i18nc("@action:button", "Remove")
|
text: catalog.i18nc("@action:button", "Remove")
|
||||||
iconName: "list-remove"
|
iconName: "list-remove"
|
||||||
enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated
|
enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && base.materialManager.canMaterialBeRemoved(base.currentItem.container_node)
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user