DiscardOrKeepProfileChangesDialog.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //Copyright (c) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.15
  5. import UM 1.6 as UM
  6. import Cura 1.6 as Cura
  7. UM.Dialog
  8. {
  9. id: base
  10. title: catalog.i18nc("@title:window", "Discard or Keep changes")
  11. onAccepted: CuraApplication.discardOrKeepProfileChangesClosed("discard")
  12. onRejected: CuraApplication.discardOrKeepProfileChangesClosed("keep")
  13. minimumWidth: UM.Theme.getSize("popup_dialog").width
  14. minimumHeight: UM.Theme.getSize("popup_dialog").height
  15. width: minimumWidth
  16. height: minimumHeight
  17. backgroundColor: UM.Theme.getColor("background_1")
  18. margin: UM.Theme.getSize("thick_margin").width
  19. property var changesModel: Cura.UserChangesModel { id: userChangesModel }
  20. onVisibilityChanged:
  21. {
  22. if(visible)
  23. {
  24. changesModel.forceUpdate()
  25. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  26. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  27. {
  28. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  29. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  30. {
  31. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  32. break;
  33. }
  34. }
  35. }
  36. }
  37. UM.Label
  38. {
  39. id: infoText
  40. 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.activeQualityDisplayNameMap["main"])
  41. anchors.left: parent.left
  42. anchors.right: parent.right
  43. wrapMode: Text.WordWrap
  44. UM.I18nCatalog
  45. {
  46. id: catalog
  47. name: "cura"
  48. }
  49. }
  50. Item
  51. {
  52. anchors.topMargin: UM.Theme.getSize("default_margin").height
  53. anchors.top: infoText.bottom
  54. anchors.bottom: parent.bottom
  55. anchors.left: parent.left
  56. anchors.right: parent.right
  57. Cura.TableView
  58. {
  59. id: tableView
  60. anchors.fill: parent
  61. columnHeaders: [
  62. catalog.i18nc("@title:column", "Profile settings"),
  63. Cura.MachineManager.activeQualityDisplayNameMap["main"],
  64. catalog.i18nc("@title:column", "Current changes")
  65. ]
  66. model: UM.TableModel
  67. {
  68. headers: ["label", "original_value", "user_value"]
  69. rows: userChangesModel.items
  70. }
  71. sectionRole: "category"
  72. }
  73. }
  74. buttonSpacing: UM.Theme.getSize("thin_margin").width
  75. leftButtons: [
  76. Cura.ComboBox
  77. {
  78. implicitHeight: UM.Theme.getSize("combobox").height
  79. implicitWidth: UM.Theme.getSize("combobox").width
  80. id: discardOrKeepProfileChangesDropDownButton
  81. textRole: "text"
  82. model: ListModel
  83. {
  84. id: discardOrKeepProfileListModel
  85. Component.onCompleted: {
  86. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  87. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  88. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  89. }
  90. }
  91. onActivated:
  92. {
  93. var code = model.get(index).code;
  94. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  95. if (code == "always_keep") {
  96. keepButton.enabled = true;
  97. discardButton.enabled = false;
  98. }
  99. else if (code == "always_discard") {
  100. keepButton.enabled = false;
  101. discardButton.enabled = true;
  102. }
  103. else {
  104. keepButton.enabled = true;
  105. discardButton.enabled = true;
  106. }
  107. }
  108. }
  109. ]
  110. rightButtons:
  111. [
  112. Cura.PrimaryButton
  113. {
  114. id: discardButton
  115. text: catalog.i18nc("@action:button", "Discard changes")
  116. onClicked: base.accept()
  117. },
  118. Cura.SecondaryButton
  119. {
  120. id: keepButton
  121. text: catalog.i18nc("@action:button", "Keep changes")
  122. onClicked: base.reject()
  123. }
  124. ]
  125. }