Cura/resources/qml/Dialogs/DiscardOrKeepProfileChangesDialog.qml
Remco Burema 8f65af61e5 Connect compare-and-safe profile dialog buttons to actions.
Some rework was needed as to not get the entire Preferences window to show up, which previously came along with the add profile action.

part of CURA-9347
2022-11-30 18:48:07 +01:00

200 lines
6.7 KiB
QML

//Copyright (c) 2022 Ultimaker B.V.
//Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Controls 2.15
import UM 1.6 as UM
import Cura 1.6 as Cura
UM.Dialog
{
id: base
title: catalog.i18nc("@title:window", "Discard or Keep changes")
property alias state: alternateStates.state
onAccepted: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger()
onRejected: alternateStates.state == "" ? CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.updateProfile.trigger()
minimumWidth: UM.Theme.getSize("popup_dialog").width
minimumHeight: UM.Theme.getSize("popup_dialog").height
width: minimumWidth
height: minimumHeight
backgroundColor: UM.Theme.getColor("background_1")
margin: UM.Theme.getSize("thick_margin").width
property var changesModel: Cura.UserChangesModel { id: userChangesModel }
// Hack to make sure that when the data of our model changes the tablemodel is also updated
// If we directly set the rows (So without the clear being called) it doesn't seem to
// get updated correctly.
property var modelRows: userChangesModel.items
onModelRowsChanged:
{
tableModel.clear()
tableModel.rows = modelRows
}
onVisibilityChanged:
{
if(visible)
{
changesModel.forceUpdate()
discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
{
var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
{
discardOrKeepProfileChangesDropDownButton.currentIndex = i;
break;
}
}
}
}
UM.Label
{
id: infoText
text: catalog.i18nc("@text:window, %1 is a profile name", "You have customized some profile settings. Would you like to Keep these changed settings after switching profiles? Alternatively, you can discard the changes to load the defaults from '%1'.").arg(Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "))
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
UM.I18nCatalog
{
id: catalog
name: "cura"
}
}
Item
{
anchors.topMargin: UM.Theme.getSize("default_margin").height
anchors.top: infoText.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
Cura.TableView
{
id: tableView
anchors.fill: parent
columnHeaders: [
catalog.i18nc("@title:column", "Profile settings"),
Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "),
catalog.i18nc("@title:column", "Current changes")
]
model: UM.TableModel
{
id: tableModel
headers: ["label", "original_value", "user_value"]
rows: modelRows
}
sectionRole: "category"
}
}
buttonSpacing: UM.Theme.getSize("thin_margin").width
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
id: discardOrKeepProfileChangesDropDownButton
textRole: "text"
model: ListModel
{
id: discardOrKeepProfileListModel
Component.onCompleted: {
append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
}
}
onActivated:
{
var code = model.get(index).code;
UM.Preferences.setValue("cura/choice_on_profile_override", code);
if (code == "always_keep") {
keepButton.enabled = true;
discardButton.enabled = false;
}
else if (code == "always_discard") {
keepButton.enabled = false;
discardButton.enabled = true;
}
else {
keepButton.enabled = true;
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 != ""
color: base.backgroundColor
implicitHeight: UM.Theme.getSize("combobox").height
implicitWidth: UM.Theme.getSize("combobox").width
}
]
rightButtons:
[
Cura.PrimaryButton
{
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"
}
]
}