Warning, /plasma/plasma-desktop/applets/kickoff/package/contents/ui/ActionMenu.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2013 Aurélien Gâteau <agateau@kde.org>
0003 SPDX-FileCopyrightText: 2014-2015 Eike Hein <hein@kde.org>
0004 SPDX-FileCopyrightText: 2021 Mikel Johnson <mikel5764@gmail.com>
0005 SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
0006
0007 SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009
0010 pragma Singleton // NOTE: Singletons are shared between all instances of a plasmoid
0011
0012 import QtQuick 2.15
0013 import org.kde.plasma.core as PlasmaCore
0014 import org.kde.plasma.plasmoid 2.0
0015 import org.kde.plasma.extras 2.0 as PlasmaExtras
0016 import "code/tools.js" as Tools
0017
0018 Item {
0019 id: root
0020
0021 property var actionList: null
0022
0023 // Only one action menu can be open at a time, so this should be safe to use.
0024 property PlasmoidItem plasmoid: null
0025
0026 // Not a QQC1 Menu. It's actually a custom QObject that uses a QMenu.
0027 readonly property PlasmaExtras.Menu menu: PlasmaExtras.Menu {
0028 id: menu
0029
0030 visualParent: null
0031 placement: PlasmaExtras.Menu.BottomPosedLeftAlignedPopup
0032 }
0033
0034 visible: false
0035
0036 Instantiator {
0037 active: root.actionList !== null
0038 model: root.actionList
0039 delegate: menuItemComponent
0040 onObjectAdded: (index, object) => menu.addMenuItem(object)
0041 onObjectRemoved: (index, object) => menu.removeMenuItem(object)
0042 }
0043
0044 Component {
0045 id: menuComponent
0046
0047 PlasmaExtras.Menu {}
0048 }
0049
0050 Component {
0051 id: menuItemComponent
0052
0053 PlasmaExtras.MenuItem {
0054 id: menuItem
0055
0056 required property var modelData
0057 property PlasmaExtras.Menu subMenu: modelData.subActions
0058 ? menuComponent.createObject(menuItem, { visualParent: menuItem.action })
0059 : null
0060
0061 text: modelData.text ? modelData.text : ""
0062 enabled: modelData.type !== "title" && ("enabled" in modelData ? modelData.enabled : true)
0063 separator: modelData.type === "separator"
0064 section: modelData.type === "title"
0065 icon: modelData.icon ? modelData.icon : null
0066 checkable: modelData.hasOwnProperty("checkable") ? modelData.checkable : false
0067 checked: modelData.hasOwnProperty("checked") ? modelData.checked : false
0068
0069 property Instantiator _instantiator: Instantiator {
0070 active: menuItem.subMenu !== null
0071 model: modelData.subActions
0072 delegate: menuItemComponent
0073 onObjectAdded: (index, object) => subMenu.addMenuItem(object)
0074 onObjectRemoved: (index, object) => subMenu.removeMenuItem(object)
0075 }
0076
0077 onClicked: {
0078 const modelActionTriggered = Tools.triggerAction(
0079 menu.visualParent.view.model,
0080 menu.visualParent.index,
0081 modelData.actionId,
0082 modelData.actionArgument
0083 )
0084 if (modelActionTriggered) {
0085 kickoff.expanded = false
0086 }
0087 }
0088 }
0089 }
0090 }