AskOpenAsProjectOrModelsDialog.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. var addToRecent = UM.WorkspaceFileHandler.getAddToRecentFilesHint(base.fileUrl);
  31. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, 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. var addToRecent = UM.WorkspaceFileHandler.getAddToRecentFilesHint(base.fileUrl);
  41. CuraApplication.readLocalFile(base.fileUrl, "open_as_model", 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. anchors.leftMargin: 20 * screenScaleFactor
  64. anchors.rightMargin: 20 * screenScaleFactor
  65. anchors.bottomMargin: 10 * screenScaleFactor
  66. spacing: 10 * screenScaleFactor
  67. Label
  68. {
  69. id: questionText
  70. 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?")
  71. anchors.left: parent.left
  72. anchors.right: parent.right
  73. font: UM.Theme.getFont("default")
  74. wrapMode: Text.WordWrap
  75. }
  76. CheckBox
  77. {
  78. id: rememberChoiceCheckBox
  79. text: catalog.i18nc("@text:window", "Remember my choice")
  80. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  81. style: CheckBoxStyle {
  82. label: Label {
  83. text: control.text
  84. font: UM.Theme.getFont("default")
  85. }
  86. }
  87. }
  88. // Buttons
  89. Item {
  90. id: buttonBar
  91. anchors.right: parent.right
  92. anchors.left: parent.left
  93. height: childrenRect.height
  94. Button {
  95. id: openAsProjectButton
  96. text: catalog.i18nc("@action:button", "Open as project")
  97. anchors.right: importModelsButton.left
  98. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  99. isDefault: true
  100. onClicked: loadProjectFile()
  101. }
  102. Button {
  103. id: importModelsButton
  104. text: catalog.i18nc("@action:button", "Import models")
  105. anchors.right: parent.right
  106. onClicked: loadModelFiles()
  107. }
  108. }
  109. }
  110. }