ExtensionMenu.qml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.4
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Cura.Menu
  8. {
  9. id: extensionMenu
  10. title: catalog.i18nc("@title:menu menubar:toplevel", "E&xtensions")
  11. property var extensionModel: UM.ExtensionModel { }
  12. Component
  13. {
  14. id: extensionsMenuItem
  15. Cura.MenuItem
  16. {
  17. text: modelText
  18. onTriggered: extensionsModel.subMenuTriggered(extensionName, modelText)
  19. }
  20. }
  21. Component
  22. {
  23. id: extensionsMenuSeparator
  24. Cura.MenuSeparator {}
  25. }
  26. Instantiator
  27. {
  28. id: extensions
  29. model: extensionModel
  30. Cura.Menu
  31. {
  32. id: sub_menu
  33. title: model.name
  34. shouldBeVisible: actions !== undefined
  35. enabled: actions != null
  36. Instantiator
  37. {
  38. model: actions
  39. Loader
  40. {
  41. property var extensionsModel: extensions.model
  42. property var modelText: model.text
  43. property var extensionName: name
  44. sourceComponent: modelText.trim() == "" ? extensionsMenuSeparator : extensionsMenuItem
  45. }
  46. onObjectAdded: function(index, object) { sub_menu.insertItem(index, object.item)}
  47. onObjectRemoved: function(object) { sub_menu.removeItem(object.item)}
  48. }
  49. }
  50. onObjectAdded: function(index, object) { extensionMenu.insertMenu(index, object) }
  51. onObjectRemoved: function(object) { extensionMenu.removeMenu(object)}
  52. }
  53. }