Browse Source

Build correct states for safe profiles flow (except actual safe).

Re-use Discard Or Keep dialogue, but have different buttons. (Safe to New/Override instead of Keep/Discard.) The actual safa action is still the old one though (for either new button, it still goes to the old 'make a new profile' action). Besides that, some cosmetics have to be done to the texts as well still.

part of CURA-9347
Remco Burema 2 years ago
parent
commit
c13deba1ea

+ 1 - 1
cura/CuraApplication.py

@@ -709,8 +709,8 @@ class CuraApplication(QtApplication):
         self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon)
 
     showDiscardOrKeepProfileChanges = pyqtSignal()
+    showCompareAndSaveProfileChanges = pyqtSignal(str)
 
-    @pyqtSlot()
     def discardOrKeepProfileChanges(self) -> bool:
         has_user_interaction = False
         choice = self.getPreferences().getValue("cura/choice_on_profile_override")

+ 3 - 1
resources/qml/Cura.qml

@@ -816,11 +816,13 @@ UM.MainWindow
     Connections
     {
         target: CuraApplication
-        function onShowDiscardOrKeepProfileChanges()
+        function onShowCompareAndSaveProfileChanges(profileState)
         {
             discardOrKeepProfileChangesDialogLoader.sourceComponent = discardOrKeepProfileChangesDialogComponent
+            discardOrKeepProfileChangesDialogLoader.item.state = profileState
             discardOrKeepProfileChangesDialogLoader.item.show()
         }
+        function onShowDiscardOrKeepProfileChanges() { onShowCompareAndSaveProfileChanges("") }
     }
 
     Cura.WizardDialog

+ 45 - 3
resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml

@@ -12,8 +12,10 @@ UM.Dialog
     id: base
     title: catalog.i18nc("@title:window", "Discard or Keep changes")
 
-    onAccepted: CuraApplication.discardOrKeepProfileChangesClosed("discard")
-    onRejected: CuraApplication.discardOrKeepProfileChangesClosed("keep")
+    property alias state: alternateStates.state
+
+    onAccepted: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger()
+    onRejected: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.addProfile.trigger()
 
     minimumWidth: UM.Theme.getSize("popup_dialog").width
     minimumHeight: UM.Theme.getSize("popup_dialog").height
@@ -98,9 +100,26 @@ UM.Dialog
 
     buttonSpacing: UM.Theme.getSize("thin_margin").width
 
-    leftButtons: [
+    Rectangle
+    {
+        // Use a rectangle to get access to states. For some reason top-levels like Dialog/Window ect. don't have them.
+        // NOTE: The default state is 'switch profiles', alternate states are used for 'save from [built-in|custom]'.
+        id: alternateStates
+        width: 0
+        height: 0
+        states:
+        [
+            State { name: "saveFromBuiltIn" },
+            State { name: "saveFromCustom" }
+        ]
+    }
+
+    leftButtons:
+    [
         Cura.ComboBox
         {
+            visible: alternateStates.state == ""
+
             implicitHeight: UM.Theme.getSize("combobox").height
             implicitWidth: UM.Theme.getSize("combobox").width
 
@@ -136,6 +155,13 @@ UM.Dialog
                     discardButton.enabled = true;
                 }
             }
+        },
+        Rectangle
+        {
+            // Workaround: If this placeholder isn't in here, then on repeated state-changes of the window, the rightButtons will be in the center (despite initially showing up right).
+            visible: alternateStates.state != ""
+            implicitHeight: UM.Theme.getSize("combobox").height
+            implicitWidth: UM.Theme.getSize("combobox").width
         }
     ]
 
@@ -146,12 +172,28 @@ UM.Dialog
             id: discardButton
             text: catalog.i18nc("@action:button", "Discard changes")
             onClicked: base.accept()
+            visible: alternateStates.state == ""
         },
         Cura.SecondaryButton
         {
             id: keepButton
             text: catalog.i18nc("@action:button", "Keep changes")
             onClicked: base.reject()
+            visible: alternateStates.state == ""
+        },
+        Cura.SecondaryButton
+        {
+            id: overwriteButton
+            text: catalog.i18nc("@action:button", "Save as new custom profile")
+            onClicked: base.accept()
+            visible: alternateStates.state != ""
+        },
+        Cura.PrimaryButton
+        {
+            id: saveButton
+            text: catalog.i18nc("@action:button", "Save changes")
+            onClicked: base.reject()
+            visible: alternateStates.state == "saveFromCustom"
         }
     ]
 }

+ 1 - 1
resources/qml/PrintSetupSelector/ProfileWarningReset.qml

@@ -139,7 +139,7 @@ Item
         hoverColor: UM.Theme.getColor("primary_hover")
 
         enabled: Cura.SimpleModeSettingsManager.isProfileCustomized
-        onClicked: Cura.MachineManager.hasCustomQuality ? CuraApplication.discardOrKeepProfileChanges() : Cura.Actions.addProfile.trigger()
+        onClicked: CuraApplication.showCompareAndSaveProfileChanges(Cura.MachineManager.hasCustomQuality ? "saveFromCustom" : "saveFromBuiltIn")
 
         UM.ToolTip
         {