Browse Source

Add extension menu to application menu

CURA-8683
Jaime van Kessel 3 years ago
parent
commit
d1461c5d7f

+ 2 - 0
resources/qml/MainWindow/ApplicationMenu.qml

@@ -64,6 +64,8 @@ Item
             title: (Qt.platform.os == "osx") ? "&Settings" : catalog.i18nc("@title:menu menubar:toplevel", "&Settings")
         }
 
+        ExtensionMenu {}
+
     }
 
     /*UM.ApplicationMenu

+ 64 - 0
resources/qml/Menus/ExtensionMenu.qml

@@ -0,0 +1,64 @@
+// Copyright (c) 2022 Ultimaker B.V.
+// Cura is released under the terms of the LGPLv3 or higher.
+
+import QtQuick 2.7
+import QtQuick.Controls 2.4
+
+import UM 1.5 as UM
+import Cura 1.0 as Cura
+
+UM.Menu
+{
+    id: extensionMenu
+    title: catalog.i18nc("@title:menu menubar:toplevel", "E&xtensions")
+
+    Component
+    {
+        id: extensionsMenuItem
+
+        UM.MenuItem
+        {
+            text: modelText
+            onTriggered: extensionsModel.subMenuTriggered(extensionName, modelText)
+        }
+    }
+
+    Component
+    {
+        id: extensionsMenuSeparator
+
+        MenuSeparator {}
+    }
+
+    Instantiator
+    {
+        id: extensions
+        model: UM.ExtensionModel { }
+
+        UM.Menu
+        {
+            id: sub_menu
+            title: model.name
+            shouldBeVisible: actions !== undefined
+            enabled: actions != null
+            Instantiator
+            {
+                model: actions
+                Loader
+                {
+                    property var extensionsModel: extensions.model
+                    property var modelText: model.text
+                    property var extensionName: name
+
+                    sourceComponent: modelText.trim() == "" ? extensionsMenuSeparator : extensionsMenuItem
+                }
+
+                onObjectAdded: sub_menu.insertItem(index, object.item)
+                onObjectRemoved: sub_menu.removeItem(object.item)
+            }
+        }
+
+        onObjectAdded: extensionMenu.insertMenu(index, object)
+        onObjectRemoved: extensionMenu.removeMenu(object)
+    }
+}

+ 3 - 3
resources/qml/Menus/MaterialMenu.qml

@@ -1,10 +1,10 @@
-//Copyright (c) 2022 Ultimaker B.V.
-//Cura is released under the terms of the LGPLv3 or higher.
+// Copyright (c) 2022 Ultimaker B.V.
+// Cura is released under the terms of the LGPLv3 or higher.
 
 import QtQuick 2.7
 import QtQuick.Controls 2.4
 
-import UM 1.6 as UM
+import UM 1.5 as UM
 import Cura 1.0 as Cura
 
 UM.Menu