AskOpenAsProjectOrModelsDialog.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. UM.Dialog
  9. {
  10. // This dialog asks the user whether he/she wants to open a project file as a project or import models.
  11. id: base
  12. title: base.is_ucp
  13. ? catalog.i18nc("@title:window Don't translate 'Universal Cura Project'", "Open Universal Cura Project (UCP) file")
  14. : catalog.i18nc("@title:window", "Open project file")
  15. width: UM.Theme.getSize("small_popup_dialog").width
  16. height: UM.Theme.getSize("small_popup_dialog").height
  17. backgroundColor: UM.Theme.getColor("main_background")
  18. maximumHeight: height
  19. maximumWidth: width
  20. minimumHeight: maximumHeight
  21. minimumWidth: maximumWidth
  22. modality: Qt.ApplicationModal
  23. property var fileUrl
  24. property var addToRecent: true //Whether to add this file to the recent files list after reading it.
  25. property bool is_ucp: false
  26. // load the entire project
  27. function loadProjectFile() {
  28. // update preference
  29. if (rememberChoiceCheckBox.checked) {
  30. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
  31. }
  32. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, base.addToRecent);
  33. base.hide()
  34. }
  35. // load the project file as separated models
  36. function loadModelFiles() {
  37. // update preference
  38. if (rememberChoiceCheckBox.checked) {
  39. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
  40. }
  41. CuraApplication.readLocalFile(base.fileUrl, "open_as_model", base.addToRecent)
  42. base.hide()
  43. }
  44. // override UM.Dialog accept
  45. function accept () {
  46. var openAsPreference = UM.Preferences.getValue("cura/choice_on_open_project")
  47. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  48. if (openAsPreference == "open_as_model") {
  49. loadModelFiles()
  50. } else {
  51. loadProjectFile()
  52. }
  53. }
  54. onVisibleChanged: {
  55. if (visible) {
  56. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  57. rememberChoiceCheckBox.checked = rememberMyChoice;
  58. }
  59. }
  60. Column
  61. {
  62. anchors.fill: parent
  63. spacing: UM.Theme.getSize("default_margin").height
  64. UM.Label
  65. {
  66. id: questionText
  67. width: parent.width
  68. text: base.is_ucp
  69. ? catalog.i18nc("@text:window", "This is a Cura Universal project file. Would you like to open it as a Cura Universal Project or import the models from it?")
  70. : catalog.i18nc("@text:window", "This is a Cura project file. Would you like to open it as a project or import the models from it?")
  71. wrapMode: Text.WordWrap
  72. }
  73. UM.CheckBox
  74. {
  75. id: rememberChoiceCheckBox
  76. text: catalog.i18nc("@text:window", "Remember my choice")
  77. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  78. }
  79. }
  80. onAccepted: loadProjectFile()
  81. onRejected: loadModelFiles()
  82. buttonSpacing: UM.Theme.getSize("thin_margin").width
  83. rightButtons:
  84. [
  85. Cura.PrimaryButton
  86. {
  87. text: catalog.i18nc("@action:button", "Open as UCP")
  88. iconSource: UM.Theme.getIcon("CuraShareIcon")
  89. onClicked: loadProjectFile()
  90. visible: base.is_ucp
  91. },
  92. Cura.PrimaryButton
  93. {
  94. text: catalog.i18nc("@action:button", "Open as project")
  95. onClicked: loadProjectFile()
  96. visible: !base.is_ucp
  97. },
  98. Cura.SecondaryButton
  99. {
  100. text: catalog.i18nc("@action:button", "Import models")
  101. onClicked: loadModelFiles()
  102. }
  103. ]
  104. }