AskOpenAsProjectOrModelsDialog.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import QtQuick.Dialogs 1.1
  8. import QtQuick.Window 2.1
  9. import UM 1.3 as UM
  10. import Cura 1.0 as Cura
  11. UM.Dialog
  12. {
  13. // This dialog asks the user whether he/she wants to open a project file as a project or import models.
  14. id: base
  15. title: catalog.i18nc("@title:window", "Open project file")
  16. width: UM.Theme.getSize("small_popup_dialog").width
  17. height: UM.Theme.getSize("small_popup_dialog").height
  18. maximumHeight: height
  19. maximumWidth: width
  20. minimumHeight: maximumHeight
  21. minimumWidth: maximumWidth
  22. modality: Qt.WindowModal
  23. property var fileUrl
  24. // load the entire project
  25. function loadProjectFile() {
  26. // update preference
  27. if (rememberChoiceCheckBox.checked) {
  28. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
  29. }
  30. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl)
  31. base.hide()
  32. }
  33. // load the project file as separated models
  34. function loadModelFiles() {
  35. // update preference
  36. if (rememberChoiceCheckBox.checked) {
  37. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
  38. }
  39. CuraApplication.readLocalFile(base.fileUrl, "open_as_model")
  40. base.hide()
  41. }
  42. // override UM.Dialog accept
  43. function accept () {
  44. var openAsPreference = UM.Preferences.getValue("cura/choice_on_open_project")
  45. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  46. if (openAsPreference == "open_as_model") {
  47. loadModelFiles()
  48. } else {
  49. loadProjectFile()
  50. }
  51. }
  52. onVisibleChanged: {
  53. if (visible) {
  54. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  55. rememberChoiceCheckBox.checked = rememberMyChoice;
  56. }
  57. }
  58. Column
  59. {
  60. anchors.fill: parent
  61. anchors.leftMargin: 20 * screenScaleFactor
  62. anchors.rightMargin: 20 * screenScaleFactor
  63. anchors.bottomMargin: 10 * screenScaleFactor
  64. spacing: 10 * screenScaleFactor
  65. Label
  66. {
  67. id: questionText
  68. text: 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?")
  69. anchors.left: parent.left
  70. anchors.right: parent.right
  71. font: UM.Theme.getFont("default")
  72. wrapMode: Text.WordWrap
  73. }
  74. CheckBox
  75. {
  76. id: rememberChoiceCheckBox
  77. text: catalog.i18nc("@text:window", "Remember my choice")
  78. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  79. style: CheckBoxStyle {
  80. label: Label {
  81. text: control.text
  82. font: UM.Theme.getFont("default")
  83. }
  84. }
  85. }
  86. // Buttons
  87. Item {
  88. id: buttonBar
  89. anchors.right: parent.right
  90. anchors.left: parent.left
  91. height: childrenRect.height
  92. Button {
  93. id: openAsProjectButton
  94. text: catalog.i18nc("@action:button", "Open as project")
  95. anchors.right: importModelsButton.left
  96. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  97. isDefault: true
  98. onClicked: loadProjectFile()
  99. }
  100. Button {
  101. id: importModelsButton
  102. text: catalog.i18nc("@action:button", "Import models")
  103. anchors.right: parent.right
  104. onClicked: loadModelFiles()
  105. }
  106. }
  107. }
  108. }