AskOpenAsProjectOrModelsDialog.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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: catalog.i18nc("@title:window", "Open project file")
  13. width: UM.Theme.getSize("small_popup_dialog").width
  14. height: UM.Theme.getSize("small_popup_dialog").height
  15. backgroundColor: UM.Theme.getColor("main_background")
  16. maximumHeight: height
  17. maximumWidth: width
  18. minimumHeight: maximumHeight
  19. minimumWidth: maximumWidth
  20. modality: Qt.WindowModal
  21. property var fileUrl
  22. property var addToRecent: true //Whether to add this file to the recent files list after reading it.
  23. // load the entire project
  24. function loadProjectFile() {
  25. // update preference
  26. if (rememberChoiceCheckBox.checked) {
  27. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project")
  28. }
  29. UM.WorkspaceFileHandler.readLocalFile(base.fileUrl, base.addToRecent);
  30. base.hide()
  31. }
  32. // load the project file as separated models
  33. function loadModelFiles() {
  34. // update preference
  35. if (rememberChoiceCheckBox.checked) {
  36. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model")
  37. }
  38. CuraApplication.readLocalFile(base.fileUrl, "open_as_model", base.addToRecent)
  39. base.hide()
  40. }
  41. // override UM.Dialog accept
  42. function accept () {
  43. var openAsPreference = UM.Preferences.getValue("cura/choice_on_open_project")
  44. // when hitting 'enter', we always open as project unless open_as_model was explicitly stored as preference
  45. if (openAsPreference == "open_as_model") {
  46. loadModelFiles()
  47. } else {
  48. loadProjectFile()
  49. }
  50. }
  51. onVisibleChanged: {
  52. if (visible) {
  53. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  54. rememberChoiceCheckBox.checked = rememberMyChoice;
  55. }
  56. }
  57. Column
  58. {
  59. anchors.fill: parent
  60. spacing: UM.Theme.getSize("default_margin").height
  61. UM.Label
  62. {
  63. id: questionText
  64. width: parent.width
  65. 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?")
  66. wrapMode: Text.WordWrap
  67. }
  68. UM.CheckBox
  69. {
  70. id: rememberChoiceCheckBox
  71. text: catalog.i18nc("@text:window", "Remember my choice")
  72. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  73. }
  74. }
  75. onAccepted: loadProjectFile()
  76. onRejected: loadModelFiles()
  77. buttonSpacing: UM.Theme.getSize("thin_margin").width
  78. rightButtons:
  79. [
  80. Cura.PrimaryButton
  81. {
  82. text: catalog.i18nc("@action:button", "Open as project")
  83. onClicked: loadProjectFile()
  84. },
  85. Cura.SecondaryButton
  86. {
  87. text: catalog.i18nc("@action:button", "Import models")
  88. onClicked: loadModelFiles()
  89. }
  90. ]
  91. }