AskOpenAsProjectOrModelsDialog.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. property var addToRecent: true //Whether to add this file to the recent files list after reading it.
  25. // load the entire project
  26. function loadProjectFile() {
  27. // update preference
  28. if (rememberChoiceCheckBox.checked) {
  29. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
  30. }
  31. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, base.addToRecent);
  32. base.hide()
  33. }
  34. // load the project file as separated models
  35. function loadModelFiles() {
  36. // update preference
  37. if (rememberChoiceCheckBox.checked) {
  38. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
  39. }
  40. CuraApplication.readLocalFile(base.fileUrl, "open_as_model", base.addToRecent)
  41. base.hide()
  42. }
  43. // override UM.Dialog accept
  44. function accept () {
  45. var openAsPreference = UM.Preferences.getValue("cura/choice_on_open_project")
  46. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  47. if (openAsPreference == "open_as_model") {
  48. loadModelFiles()
  49. } else {
  50. loadProjectFile()
  51. }
  52. }
  53. onVisibleChanged: {
  54. if (visible) {
  55. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  56. rememberChoiceCheckBox.checked = rememberMyChoice;
  57. }
  58. }
  59. Column
  60. {
  61. anchors.fill: parent
  62. anchors.leftMargin: 20 * screenScaleFactor
  63. anchors.rightMargin: 20 * screenScaleFactor
  64. anchors.bottomMargin: 10 * screenScaleFactor
  65. spacing: 10 * screenScaleFactor
  66. Label
  67. {
  68. id: questionText
  69. 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?")
  70. anchors.left: parent.left
  71. anchors.right: parent.right
  72. font: UM.Theme.getFont("default")
  73. wrapMode: Text.WordWrap
  74. }
  75. CheckBox
  76. {
  77. id: rememberChoiceCheckBox
  78. text: catalog.i18nc("@text:window", "Remember my choice")
  79. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  80. style: CheckBoxStyle {
  81. label: Label {
  82. text: control.text
  83. font: UM.Theme.getFont("default")
  84. }
  85. }
  86. }
  87. // Buttons
  88. Item {
  89. id: buttonBar
  90. anchors.right: parent.right
  91. anchors.left: parent.left
  92. height: childrenRect.height
  93. Button {
  94. id: openAsProjectButton
  95. text: catalog.i18nc("@action:button", "Open as project")
  96. anchors.right: importModelsButton.left
  97. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  98. isDefault: true
  99. onClicked: loadProjectFile()
  100. }
  101. Button {
  102. id: importModelsButton
  103. text: catalog.i18nc("@action:button", "Import models")
  104. anchors.right: parent.right
  105. onClicked: loadModelFiles()
  106. }
  107. }
  108. }
  109. }