AskOpenAsProjectOrModelsDialog.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 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: 450
  17. height: 150
  18. maximumHeight: height
  19. maximumWidth: width
  20. minimumHeight: maximumHeight
  21. minimumWidth: maximumWidth
  22. modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
  23. property var fileUrl
  24. function loadProjectFile(projectFile)
  25. {
  26. UM.WorkspaceFileHandler.readLocalFile(projectFile);
  27. var meshName = backgroundItem.getMeshName(projectFile.toString());
  28. backgroundItem.hasMesh(decodeURIComponent(meshName));
  29. }
  30. function loadModelFiles(fileUrls)
  31. {
  32. for (var i in fileUrls)
  33. {
  34. CuraApplication.readLocalFile(fileUrls[i]);
  35. }
  36. var meshName = backgroundItem.getMeshName(fileUrls[0].toString());
  37. backgroundItem.hasMesh(decodeURIComponent(meshName));
  38. }
  39. onVisibleChanged:
  40. {
  41. if (visible)
  42. {
  43. var rememberMyChoice = UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask";
  44. rememberChoiceCheckBox.checked = rememberMyChoice;
  45. }
  46. }
  47. Column
  48. {
  49. anchors.fill: parent
  50. anchors.leftMargin: 20
  51. anchors.rightMargin: 20
  52. anchors.bottomMargin: 20
  53. spacing: 10
  54. Label
  55. {
  56. 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?")
  57. anchors.left: parent.left
  58. anchors.right: parent.right
  59. font: UM.Theme.getFont("default")
  60. wrapMode: Text.WordWrap
  61. }
  62. CheckBox
  63. {
  64. id: rememberChoiceCheckBox
  65. text: catalog.i18nc("@text:window", "Remember my choice")
  66. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  67. }
  68. // Buttons
  69. Item
  70. {
  71. anchors.right: parent.right
  72. anchors.left: parent.left
  73. height: childrenRect.height
  74. Button
  75. {
  76. id: openAsProjectButton
  77. text: catalog.i18nc("@action:button", "Open as project");
  78. anchors.right: importModelsButton.left
  79. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  80. isDefault: true
  81. onClicked:
  82. {
  83. // update preference
  84. if (rememberChoiceCheckBox.checked)
  85. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project");
  86. // load this file as project
  87. base.hide();
  88. loadProjectFile(base.fileUrl);
  89. }
  90. }
  91. Button
  92. {
  93. id: importModelsButton
  94. text: catalog.i18nc("@action:button", "Import models");
  95. anchors.right: parent.right
  96. onClicked:
  97. {
  98. // update preference
  99. if (rememberChoiceCheckBox.checked)
  100. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model");
  101. // load models from this project file
  102. base.hide();
  103. loadModelFiles([base.fileUrl]);
  104. }
  105. }
  106. }
  107. }
  108. }