Warning, /plasma/plasma-desktop/applets/kicker/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 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 import QtQuick 2.15
0009 
0010 import org.kde.plasma.extras 2.0 as PlasmaExtras
0011 
0012 Item {
0013     id: root
0014 
0015     property QtObject menu
0016     property Item visualParent
0017     property variant actionList
0018     property bool opened: menu ? (menu.status !== PlasmaExtras.Menu.Closed) : false
0019 
0020     signal actionClicked(string actionId, variant actionArgument)
0021     signal closed
0022 
0023     onActionListChanged: refreshMenu();
0024 
0025     onOpenedChanged: {
0026         if (!opened) {
0027             closed();
0028         }
0029     }
0030 
0031     function open(x, y) {
0032         if (!actionList) {
0033             return;
0034         }
0035 
0036         if (x && y) {
0037             menu.open(x, y);
0038         } else {
0039             menu.open();
0040         }
0041     }
0042 
0043     function refreshMenu() {
0044         if (menu) {
0045             menu.destroy();
0046         }
0047 
0048         if (!actionList) {
0049             return;
0050         }
0051 
0052         menu = contextMenuComponent.createObject(root);
0053 
0054         fillMenu(menu, actionList);
0055     }
0056 
0057     function fillMenu(menu, items) {
0058         items.forEach(function(actionItem) {
0059             if (actionItem.subActions) {
0060                 // This is a menu
0061                 var submenuItem = contextSubmenuItemComponent.createObject(
0062                                           menu, { "actionItem" : actionItem });
0063 
0064                 fillMenu(submenuItem.submenu, actionItem.subActions);
0065 
0066             } else {
0067                 var item = contextMenuItemComponent.createObject(
0068                                 menu,
0069                                 {
0070                                     "actionItem": actionItem,
0071                                 }
0072                 );
0073             }
0074         });
0075 
0076     }
0077 
0078     Component {
0079         id: contextMenuComponent
0080 
0081         PlasmaExtras.Menu {
0082             visualParent: root.visualParent
0083         }
0084     }
0085 
0086     Component {
0087         id: contextSubmenuItemComponent
0088 
0089         PlasmaExtras.MenuItem {
0090             id: submenuItem
0091 
0092             property variant actionItem
0093 
0094             text: actionItem.text ? actionItem.text : ""
0095             icon: actionItem.icon ? actionItem.icon : null
0096 
0097             property PlasmaExtras.Menu submenu: PlasmaExtras.Menu {
0098                 visualParent: submenuItem.action
0099             }
0100         }
0101     }
0102 
0103     Component {
0104         id: contextMenuItemComponent
0105 
0106         PlasmaExtras.MenuItem {
0107             property variant actionItem
0108 
0109             text      : actionItem.text ? actionItem.text : ""
0110             enabled   : actionItem.type !== "title" && ("enabled" in actionItem ? actionItem.enabled : true)
0111             separator : actionItem.type === "separator"
0112             section   : actionItem.type === "title"
0113             icon      : actionItem.icon ? actionItem.icon : null
0114             checkable : actionItem.checkable ? actionItem.checkable : false
0115             checked   : actionItem.checked ? actionItem.checked : false
0116 
0117             onClicked: {
0118                 root.actionClicked(actionItem.actionId, actionItem.actionArgument);
0119             }
0120         }
0121     }
0122 }