old_contents: # Copyright (c) 2017 Ultimaker B.V.
  # Cura is released under the terms of the AGPLv3 or higher.
  
  from PyQt5.QtCore import QObject, pyqtSlot #To expose data to QML.
  
  from UM.Logger import Logger
  from UM.Message import Message #To create a warning message about material diameter.
  from UM.i18n import i18nCatalog #Translated strings.
  from UM.Settings.ContainerRegistry import ContainerRegistry #To find the material containers we need.
  
  catalog = i18nCatalog("cura")
  
  ##  Handles material-related data, processing requests to change them and
  #   providing data for the GUI.
  #
  #   TODO: Move material-related managing over from the machine manager to here.
  class MaterialManager(QObject):
      ##  Creates the global values for the material manager to use.
      def __init__(self, parent = None):
          super().__init__(parent)
  
          #Material diameter changed warning message.
          self._material_diameter_warning_message = Message(catalog.i18nc("@info:status Has a cancel button next to it.",
              "The selected material diameter causes the material to become incompatible with the current printer."))
          self._material_diameter_warning_message.addAction("Undo", catalog.i18nc("@action:button", "Undo"), None, catalog.i18nc("@action", "Undo changing the material diameter."))
          self._material_diameter_warning_message.actionTriggered = self._materialWarningMessageAction
  
      ##  Creates an instance of the MaterialManager.
      #
      #   This should only be called by PyQt to create the singleton instance of
      #   this class.
      @staticmethod
      def createMaterialManager(engine = None, script_engine = None):
          return MaterialManager()
  
      @pyqtSlot(str, str)
      def showMaterialWarningMessage(self, material_id, previous_diameter):
          self._material_diameter_warning_message.previous_diameter = previous_diameter #Make sure that the undo button can properly undo the action.
          self._material_diameter_warning_message.material_id = material_id
          self._material_diameter_warning_message.show()
  
      ##  Called when clicking "undo" on the warning dialogue for disappeared
      #   materials.
      #
      #   This executes the undo action, restoring the material diameter.
      #
      #   \param button The identifier of the button that was pressed.
      def _materialWarningMessageAction(self, button):
          if button == "Undo":
              container_registry = ContainerRegistry.getInstance()
              matches = container_registry.findInstanceContainers(type = "material", id = self._material_diameter_warning_message.material_id)
              if matches:
                  matches[0].setMetaDataEntry("diameter", self._material_diameter_warning_message.previous_diameter)
              #No matches? Then the material has been deleted in the meanwhile.
          else:
              Logger.log("w", "Unknown button action for material diameter warning message: {action}".format(action = button))
new_contents: # Copyright (c) 2017 Ultimaker B.V.
  # Cura is released under the terms of the AGPLv3 or higher.
  
  from PyQt5.QtCore import QObject, pyqtSlot #To expose data to QML.
  
  from UM.Logger import Logger
  from UM.Message import Message #To create a warning message about material diameter.
  from UM.i18n import i18nCatalog #Translated strings.
  from UM.Settings.ContainerRegistry import ContainerRegistry #To find the material containers we need.
  
  catalog = i18nCatalog("cura")
  
  ##  Handles material-related data, processing requests to change them and
  #   providing data for the GUI.
  #
  #   TODO: Move material-related managing over from the machine manager to here.
  class MaterialManager(QObject):
      ##  Creates the global values for the material manager to use.
      def __init__(self, parent = None):
          super().__init__(parent)
  
          #Material diameter changed warning message.
          self._material_diameter_warning_message = Message(catalog.i18nc("@info:status Has a cancel button next to it.",
              "The selected material diameter causes the material to become incompatible with the current printer."))
          self._material_diameter_warning_message.addAction("Undo", catalog.i18nc("@action:button", "Undo"), None, catalog.i18nc("@action", "Undo changing the material diameter."))
          self._material_diameter_warning_message.actionTriggered.connect(self._materialWarningMessageAction)
  
      ##  Creates an instance of the MaterialManager.
      #
      #   This should only be called by PyQt to create the singleton instance of
      #   this class.
      @staticmethod
      def createMaterialManager(engine = None, script_engine = None):
          return MaterialManager()
  
      @pyqtSlot(str, str)
      def showMaterialWarningMessage(self, material_id, previous_diameter):
          self._material_diameter_warning_message.previous_diameter = previous_diameter #Make sure that the undo button can properly undo the action.
          self._material_diameter_warning_message.material_id = material_id
          self._material_diameter_warning_message.show()
  
      ##  Called when clicking "undo" on the warning dialogue for disappeared
      #   materials.
      #
      #   This executes the undo action, restoring the material diameter.
      #
      #   \param button The identifier of the button that was pressed.
      def _materialWarningMessageAction(self, message, button):
          if button == "Undo":
              container_registry = ContainerRegistry.getInstance()
              matches = container_registry.findInstanceContainers(type = "material", id = self._material_diameter_warning_message.material_id)
              if matches:
                  matches[0].setMetaDataEntry("diameter", self._material_diameter_warning_message.previous_diameter)
              #No matches? Then the material has been deleted in the meanwhile.
              message.hide()
          else:
              Logger.log("w", "Unknown button action for material diameter warning message: {action}".format(action = button))
subject: Fix connecting undo action to undo button