DiscardOrKeepProfileChangesDialog.qml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. enum ButtonsType { DiscardOrKeep, SaveFromBuiltIn, SaveFromCustom}
  12. property int buttonState: DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  13. onAccepted: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
  14. CuraApplication.discardOrKeepProfileChangesClosed("discard") : Cura.Actions.addProfile.trigger()
  15. onRejected: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep ?
  16. CuraApplication.discardOrKeepProfileChangesClosed("keep") : Cura.Actions.updateProfile.trigger()
  17. minimumWidth: UM.Theme.getSize("popup_dialog").width
  18. minimumHeight: UM.Theme.getSize("popup_dialog").height
  19. width: minimumWidth
  20. height: minimumHeight
  21. backgroundColor: UM.Theme.getColor("background_1")
  22. margin: UM.Theme.getSize("thick_margin").width
  23. property var changesModel: Cura.UserChangesModel { id: userChangesModel }
  24. // Hack to make sure that when the data of our model changes the tablemodel is also updated
  25. // If we directly set the rows (So without the clear being called) it doesn't seem to
  26. // get updated correctly.
  27. property var modelRows: userChangesModel.items
  28. onModelRowsChanged:
  29. {
  30. tableModel.clear()
  31. tableModel.rows = modelRows
  32. }
  33. onVisibilityChanged:
  34. {
  35. if(visible)
  36. {
  37. changesModel.forceUpdate()
  38. discardOrKeepProfileChangesDropDownButton.currentIndex = 0;
  39. for (var i = 0; i < discardOrKeepProfileChangesDropDownButton.model.count; ++i)
  40. {
  41. var code = discardOrKeepProfileChangesDropDownButton.model.get(i).code;
  42. if (code == UM.Preferences.getValue("cura/choice_on_profile_override"))
  43. {
  44. discardOrKeepProfileChangesDropDownButton.currentIndex = i;
  45. break;
  46. }
  47. }
  48. }
  49. }
  50. UM.Label
  51. {
  52. id: infoText
  53. 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(" - "))
  54. anchors.left: parent.left
  55. anchors.right: parent.right
  56. wrapMode: Text.WordWrap
  57. UM.I18nCatalog
  58. {
  59. id: catalog
  60. name: "cura"
  61. }
  62. }
  63. Item
  64. {
  65. anchors.topMargin: UM.Theme.getSize("default_margin").height
  66. anchors.top: infoText.bottom
  67. anchors.bottom: parent.bottom
  68. anchors.left: parent.left
  69. anchors.right: parent.right
  70. Cura.TableView
  71. {
  72. id: tableView
  73. anchors.fill: parent
  74. columnHeaders: [
  75. catalog.i18nc("@title:column", "Profile settings"),
  76. Cura.MachineManager.activeQualityDisplayNameMainStringParts.join(" - "),
  77. catalog.i18nc("@title:column", "Current changes")
  78. ]
  79. model: UM.TableModel
  80. {
  81. id: tableModel
  82. headers: ["label", "original_value", "user_value"]
  83. rows: modelRows
  84. }
  85. sectionRole: "category"
  86. }
  87. }
  88. buttonSpacing: UM.Theme.getSize("thin_margin").width
  89. leftButtons:
  90. [
  91. Cura.ComboBox
  92. {
  93. visible: buttonState === DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  94. implicitHeight: UM.Theme.getSize("combobox").height
  95. implicitWidth: UM.Theme.getSize("combobox").width
  96. id: discardOrKeepProfileChangesDropDownButton
  97. textRole: "text"
  98. model: ListModel
  99. {
  100. id: discardOrKeepProfileListModel
  101. Component.onCompleted: {
  102. append({ text: catalog.i18nc("@option:discardOrKeep", "Always ask me this"), code: "always_ask" })
  103. append({ text: catalog.i18nc("@option:discardOrKeep", "Discard and never ask again"), code: "always_discard" })
  104. append({ text: catalog.i18nc("@option:discardOrKeep", "Keep and never ask again"), code: "always_keep" })
  105. }
  106. }
  107. onActivated:
  108. {
  109. const code = model.get(index).code;
  110. UM.Preferences.setValue("cura/choice_on_profile_override", code);
  111. switch (code) {
  112. case "always_keep":
  113. keepButton.enabled = true;
  114. discardButton.enabled = false;
  115. break;
  116. case "always_discard":
  117. keepButton.enabled = false;
  118. discardButton.enabled = true;
  119. break;
  120. default:
  121. keepButton.enabled = true;
  122. discardButton.enabled = true;
  123. break;
  124. }
  125. }
  126. }
  127. ]
  128. rightButtons:
  129. [
  130. Cura.PrimaryButton
  131. {
  132. id: discardButton
  133. text: catalog.i18nc("@action:button", "Discard changes")
  134. onClicked: base.accept()
  135. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  136. },
  137. Cura.SecondaryButton
  138. {
  139. id: keepButton
  140. text: catalog.i18nc("@action:button", "Keep changes")
  141. onClicked: base.reject()
  142. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  143. },
  144. Cura.SecondaryButton
  145. {
  146. id: overwriteButton
  147. text: catalog.i18nc("@action:button", "Save as new custom profile")
  148. visible: buttonState != DiscardOrKeepProfileChangesDialog.ButtonsType.DiscardOrKeep
  149. onClicked: base.accept()
  150. },
  151. Cura.PrimaryButton
  152. {
  153. id: saveButton
  154. text: catalog.i18nc("@action:button", "Save changes")
  155. visible: buttonState == DiscardOrKeepProfileChangesDialog.ButtonsType.SaveFromCustom
  156. onClicked: base.reject()
  157. }
  158. ]
  159. }