RecentFilesMenu.qml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2016 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 UM 1.3 as UM
  6. import Cura 1.0 as Cura
  7. import "../Dialogs"
  8. Menu
  9. {
  10. id: menu
  11. title: catalog.i18nc("@title:menu menubar:file", "Open &Recent")
  12. iconName: "document-open-recent";
  13. enabled: CuraApplication.recentFiles.length > 0;
  14. Instantiator
  15. {
  16. model: CuraApplication.recentFiles
  17. MenuItem
  18. {
  19. text:
  20. {
  21. var path = modelData.toString()
  22. return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
  23. }
  24. onTriggered:
  25. {
  26. var toShowDialog = false;
  27. var toOpenAsProject = false;
  28. var toOpenAsModel = false;
  29. if (CuraApplication.checkIsValidProjectFile(modelData)) {
  30. // check preference
  31. var choice = UM.Preferences.getValue("cura/choice_on_open_project");
  32. if (choice == "open_as_project")
  33. {
  34. toOpenAsProject = true;
  35. }else if (choice == "open_as_model"){
  36. toOpenAsModel = true;
  37. }else{
  38. toShowDialog = true;
  39. }
  40. }
  41. else {
  42. toOpenAsModel = true;
  43. }
  44. if (toShowDialog) {
  45. askOpenAsProjectOrModelsDialog.fileUrl = modelData;
  46. askOpenAsProjectOrModelsDialog.show();
  47. return;
  48. }
  49. // open file in the prefered way
  50. if (toOpenAsProject)
  51. {
  52. UM.WorkspaceFileHandler.readLocalFile(modelData);
  53. }
  54. else if (toOpenAsModel)
  55. {
  56. CuraApplication.readLocalFile(modelData, true);
  57. }
  58. var meshName = backgroundItem.getMeshName(modelData.toString())
  59. backgroundItem.hasMesh(decodeURIComponent(meshName))
  60. }
  61. }
  62. onObjectAdded: menu.insertItem(index, object)
  63. onObjectRemoved: menu.removeItem(object)
  64. }
  65. Cura.AskOpenAsProjectOrModelsDialog
  66. {
  67. id: askOpenAsProjectOrModelsDialog
  68. }
  69. }