AskOpenAsProjectOrModelsDialog.qml 3.8 KB

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