OpenFilesMenu.qml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import UM 1.6 as UM
  6. import Cura 1.0 as Cura
  7. import "../Dialogs"
  8. UM.Menu
  9. {
  10. id: openFilesMenu
  11. title: catalog.i18nc("@title:menu menubar:file", "Open File(s)...")
  12. Instantiator
  13. {
  14. id: fileProviders
  15. model: CuraApplication.getFileProviderModel()
  16. UM.MenuItem
  17. {
  18. text:
  19. {
  20. return model.displayText;
  21. }
  22. onTriggered:
  23. {
  24. if (model.index == 0) // The 0th element is the "From Disk" option, which should activate the open local file dialog
  25. {
  26. Cura.Actions.open.trigger()
  27. }
  28. else
  29. {
  30. CuraApplication.getFileProviderModel().trigger(model.name);
  31. }
  32. }
  33. // Unassign the shortcuts when the submenu is invisible (i.e. when there is only one file provider) to avoid ambiguous shortcuts.
  34. // When there is a single file provider, the openAction is assigned with the Ctrl+O shortcut instead.
  35. shortcut: openFilesMenu.visible ? model.shortcut : ""
  36. visible: openFilesMenu.visible
  37. }
  38. onObjectAdded: openFilesMenu.insertItem(index, object)
  39. onObjectRemoved: openFilesMenu.removeItem(object)
  40. }
  41. }