AskOpenAsProjectOrModelsDialog.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: 420 * Screen.devicePixelRatio
  17. height: 140 * Screen.devicePixelRatio
  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.margins: 20 * Screen.devicePixelRatio
  51. spacing: 10 * Screen.devicePixelRatio
  52. Label
  53. {
  54. text: catalog.i18nc("@text:window", "This is a Cura project file. Would you like to open it as a project\nor import the models from it?")
  55. anchors.margins: UM.Theme.getSize("default_margin").width
  56. font: UM.Theme.getFont("default")
  57. wrapMode: Text.WordWrap
  58. }
  59. CheckBox
  60. {
  61. id: rememberChoiceCheckBox
  62. text: catalog.i18nc("@text:window", "Remember my choice")
  63. anchors.margins: UM.Theme.getSize("default_margin").width
  64. checked: UM.Preferences.getValue("cura/choice_on_open_project") != "always_ask"
  65. }
  66. // Buttons
  67. Item
  68. {
  69. anchors.right: parent.right
  70. anchors.left: parent.left
  71. height: childrenRect.height
  72. Button
  73. {
  74. id: openAsProjectButton
  75. text: catalog.i18nc("@action:button", "Open as project");
  76. anchors.right: importModelsButton.left
  77. anchors.rightMargin: UM.Theme.getSize("default_margin").width * Screen.devicePixelRatio
  78. isDefault: true
  79. onClicked:
  80. {
  81. // update preference
  82. if (rememberChoiceCheckBox.checked)
  83. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_project");
  84. // load this file as project
  85. base.hide();
  86. loadProjectFile(base.fileUrl);
  87. }
  88. }
  89. Button
  90. {
  91. id: importModelsButton
  92. text: catalog.i18nc("@action:button", "Import models");
  93. anchors.right: parent.right
  94. onClicked:
  95. {
  96. // update preference
  97. if (rememberChoiceCheckBox.checked)
  98. UM.Preferences.setValue("cura/choice_on_open_project", "open_as_model");
  99. // load models from this project file
  100. base.hide();
  101. loadModelFiles([base.fileUrl]);
  102. }
  103. }
  104. }
  105. }
  106. }