Warning, /plasma/plasma-desktop/desktoppackage/contents/configuration/ConfigurationContainmentActions.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Controls 2.3 as QQC2
0009 import QtQuick.Layouts 1.0
0010 
0011 import org.kde.kirigami 2.20 as Kirigami
0012 
0013 Item {
0014     id: root
0015 
0016     signal configurationChanged
0017     implicitWidth: mainColumn.implicitWidth
0018     implicitHeight: mainColumn.implicitHeight
0019 
0020     property var prettyStrings: {
0021         "LeftButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Left-Button"),
0022         "RightButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Right-Button"),
0023         "MiddleButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Middle-Button"),
0024         "BackButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Back-Button"),
0025         "ForwardButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Forward-Button"),
0026 
0027         "wheel:Vertical": i18nd("plasma_shell_org.kde.plasma.desktop", "Vertical-Scroll"),
0028         "wheel:Horizontal": i18nd("plasma_shell_org.kde.plasma.desktop", "Horizontal-Scroll"),
0029 
0030         "ShiftModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Shift"),
0031         "ControlModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Ctrl"),
0032         "AltModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Alt"),
0033         "MetaModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Meta")
0034     }
0035 
0036     function saveConfig() {
0037         configDialog.currentContainmentActionsModel.save();
0038     }
0039 
0040     Connections {
0041         target: configDialog.currentContainmentActionsModel
0042         function onConfigurationChanged() {
0043             root.configurationChanged()
0044         }
0045     }
0046 
0047     Component {
0048         id: aboutComponent
0049 
0050         Kirigami.OverlaySheet {
0051             id: internalAboutDialog
0052 
0053             property alias metaData: aboutPluginPage.metaData
0054 
0055             width: Math.round(root.width * 0.8)
0056             onClosed: destroy()
0057 
0058             AboutPlugin {
0059                 id: aboutPluginPage
0060                 metaData: internalAboutDialog.metaData
0061             }
0062 
0063             Component.onCompleted: open();
0064         }
0065     }
0066 
0067     GridLayout {
0068         id: mainColumn
0069         flow: GridLayout.TopToBottom
0070         y: 25
0071         width: parent.width
0072 
0073         Repeater {
0074             id: actionsRepeater
0075             model: configDialog.currentContainmentActionsModel
0076 
0077             MouseEventInputButton {
0078                 Layout.column: 0
0079                 Layout.row: index
0080                 Layout.fillWidth: true
0081                 Layout.minimumWidth: implicitWidth
0082                 defaultText: {
0083                     var splitAction = model.action.split(';');
0084 
0085                     var button = splitAction[0];
0086                     var modifiers = (splitAction[1] || "").split('|').filter(function (item) {
0087                         return item !== "NoModifier";
0088                     });
0089 
0090                     var parts = modifiers;
0091                     modifiers.push(button);
0092 
0093                     return parts.map(function (item) {
0094                         return prettyStrings[item] || item;
0095                     }).join(i18ndc("plasma_shell_org.kde.plasma.desktop", "Concatenation sign for shortcuts, e.g. Ctrl+Shift", "+"));
0096                 }
0097                 eventString: model.action
0098                 onEventStringChanged: {
0099                     configDialog.currentContainmentActionsModel.update(index, eventString, model.pluginName);
0100                 }
0101             }
0102         }
0103 
0104         Repeater {
0105             model: configDialog.currentContainmentActionsModel
0106 
0107             QQC2.ComboBox {
0108                 id: pluginsCombo
0109                 // "index" argument of onActivated shadows the model index
0110                 readonly property int pluginIndex: index
0111                 Layout.fillWidth: true
0112                 Layout.column: 1
0113                 Layout.row: index
0114                 // both MouseEventInputButton and this ComboBox have fillWidth for a uniform layout
0115                 // however, their implicit sizes is taken into account and they compete against
0116                 // each other for available space. By setting an insane preferredWidth we give
0117                 // ComboBox a greater share of the available space
0118                 Layout.preferredWidth: 9000
0119                 model: configDialog.containmentActionConfigModel
0120                 textRole: "name"
0121                 property bool initialized: false
0122                 Component.onCompleted: {
0123                     for (var i = 0; i < configDialog.containmentActionConfigModel.count; ++i) {
0124                         if (configDialog.containmentActionConfigModel.get(i).pluginName === pluginName) {
0125                             pluginsCombo.currentIndex = i;
0126                             break;
0127                         }
0128                     }
0129                     pluginsCombo.initialized = true;
0130                 }
0131                 onActivated: {
0132                     if (initialized) {
0133                         var newPluginName = configDialog.containmentActionConfigModel.get(index).pluginName;
0134                         if (newPluginName !== pluginName) {
0135                             configDialog.currentContainmentActionsModel.update(pluginIndex, action, newPluginName);
0136                         }
0137                     }
0138                 }
0139             }
0140         }
0141 
0142         Repeater {
0143             model: configDialog.currentContainmentActionsModel
0144 
0145             RowLayout {
0146                 Layout.column: 2
0147                 Layout.row: index
0148 
0149                 QQC2.Button {
0150                     icon.name: "configure"
0151                     width: height
0152                     enabled: model.hasConfigurationInterface
0153                     onClicked: {
0154                         configDialog.currentContainmentActionsModel.showConfiguration(index, this);
0155                     }
0156                 }
0157                 QQC2.Button {
0158                     icon.name: "dialog-information"
0159                     width: height
0160                     onClicked: {
0161                         const metaData = configDialog.currentContainmentActionsModel.aboutMetaData(index);
0162                         if (!metaData) {
0163                             return;
0164                         }
0165                         aboutComponent.incubateObject(root.Window.window.contentItem, {
0166                             "metaData": metaData,
0167                             "title": i18ndc("plasma_shell_org.kde.plasma.desktop", "@title", "About"),
0168                         }, Qt.Asynchronous);
0169                     }
0170                 }
0171                 QQC2.Button {
0172                     icon.name: "list-remove"
0173                     width: height
0174                     onClicked: {
0175                         configDialog.currentContainmentActionsModel.remove(index);
0176                     }
0177                 }
0178             }
0179         }
0180 
0181         MouseEventInputButton {
0182             defaultText: i18nd("plasma_shell_org.kde.plasma.desktop", "Add Action");
0183             icon.name: checked ? "input-mouse-symbolic" : "list-add"
0184             onEventStringChanged: {
0185                 configDialog.currentContainmentActionsModel.append(eventString, "org.kde.contextmenu");
0186             }
0187         }
0188     }
0189 
0190 }