Warning, /plasma/plasma-simplemenu/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.0
0009 
0010 import org.kde.plasma.components 2.0 as PlasmaComponents
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 != PlasmaComponents.DialogStatus.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         PlasmaComponents.ContextMenu {
0082             visualParent: root.visualParent
0083         }
0084     }
0085 
0086     Component {
0087         id: contextSubmenuItemComponent
0088 
0089         PlasmaComponents.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 variant submenu : submenu_
0098 
0099             PlasmaComponents.ContextMenu {
0100                 id: submenu_
0101                 visualParent: submenuItem.action
0102             }
0103         }
0104     }
0105 
0106     Component {
0107         id: contextMenuItemComponent
0108 
0109         PlasmaComponents.MenuItem {
0110             property variant actionItem
0111 
0112             text      : actionItem.text ? actionItem.text : ""
0113             enabled   : actionItem.type != "title" && ("enabled" in actionItem ? actionItem.enabled : true)
0114             separator : actionItem.type == "separator"
0115             section   : actionItem.type == "title"
0116             icon      : actionItem.icon ? actionItem.icon : null
0117             checkable : actionItem.checkable ? actionItem.checkable : false
0118             checked   : actionItem.checked ? actionItem.checked : false
0119 
0120             onClicked: {
0121                 actionClicked(actionItem.actionId, actionItem.actionArgument);
0122             }
0123         }
0124     }
0125 }