RecentFilesMenu.qml 2.3 KB

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