Warning, /plasma/plasma-workspace/applets/clipboard/contents/ui/ClipboardPage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 import QtQuick 2.4
0009 import QtQuick.Controls as QQC
0010 import QtQuick.Layouts 1.1
0011 
0012 import org.kde.plasma.plasmoid 2.0
0013 import org.kde.plasma.core as PlasmaCore
0014 import org.kde.plasma.components 3.0 as PlasmaComponents3
0015 import org.kde.plasma.extras 2.0 as PlasmaExtras
0016 import org.kde.kitemmodels 1.0 as KItemModels
0017 
0018 import org.kde.kirigami 2.19 as Kirigami // for InputMethod.willShowOnActive
0019 
0020 Menu {
0021     id: clipboardMenu
0022 
0023     Keys.onPressed: event => {
0024         function forwardToFilter() {
0025             if (filter.enabled && event.text !== "" && !filter.activeFocus) {
0026                 clipboardMenu.view.currentIndex = -1
0027                 if (event.matches(StandardKey.Paste)) {
0028                     filter.paste();
0029                 } else {
0030                     filter.text = "";
0031                     filter.text += event.text;
0032                 }
0033                 filter.forceActiveFocus();
0034                 event.accepted = true;
0035             }
0036         }
0037         if (stack.currentItem !== clipboardMenu) {
0038             event.accepted = false;
0039             return;
0040         }
0041         switch(event.key) {
0042             case Qt.Key_Escape: {
0043                 if (filter.text != "") {
0044                     filter.text = "";
0045                     event.accepted = true;
0046                 }
0047                 break;
0048             }
0049             case Qt.Key_F: {
0050                 if (event.modifiers & Qt.ControlModifier) {
0051                     filter.forceActiveFocus();
0052                     filter.selectAll();
0053                     event.accepted = true;
0054                 } else {
0055                     forwardToFilter();
0056                 }
0057                 break;
0058             }
0059             case Qt.Key_Tab:
0060             case Qt.Key_Backtab: {
0061                 // prevent search filter from getting Tab key events
0062                 break;
0063             }
0064             case Qt.Key_Backspace: {
0065                 // filter.text += event.text wil break if the key is backspace
0066                 filter.forceActiveFocus();
0067                 filter.text = filter.text.slice(0, -1);
0068                 event.accepted = true;
0069                 break;
0070             }
0071             default: {
0072                 forwardToFilter();
0073             }
0074         }
0075     }
0076 
0077     Keys.forwardTo: [stack.currentItem]
0078 
0079     property var header: PlasmaExtras.PlasmoidHeading {
0080         // This uses expanded to ensure the binding gets reevaluated
0081         // when the plasmoid is shown again and that way ensure we are
0082         // always in the correct state on show.
0083         focus: main.expanded
0084 
0085         contentItem: RowLayout {
0086             enabled: clipboardMenu.model.count > 0 || filter.text.length > 0
0087 
0088             PlasmaExtras.SearchField {
0089                 id: filter
0090                 Layout.fillWidth: true
0091 
0092                 focus: !Kirigami.InputMethod.willShowOnActive
0093 
0094                 KeyNavigation.up: dialogItem.KeyNavigation.up /* ToolBar */
0095                 KeyNavigation.down: clipboardMenu.contentItem.count > 0 ? clipboardMenu.contentItem /* ListView */ : null
0096                 KeyNavigation.right: clearHistoryButton.visible ? clearHistoryButton : null
0097                 Keys.onDownPressed: event => {
0098                     clipboardMenu.view.incrementCurrentIndex();
0099                     event.accepted = false;
0100                 }
0101 
0102                 Connections {
0103                     target: main
0104                     function onClearSearchField() {
0105                         filter.clear()
0106                     }
0107                 }
0108             }
0109             PlasmaComponents3.ToolButton {
0110                 id: clearHistoryButton
0111                 visible: !(Plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentDrawsPlasmoidHeading) && main.clearHistoryAction.visible
0112 
0113                 icon.name: "edit-clear-history"
0114 
0115                 display: PlasmaComponents3.AbstractButton.IconOnly
0116                 text: main.clearHistoryAction.text
0117 
0118                 onClicked: {
0119                     clipboardSource.service("", "clearHistory")
0120                     filter.clear()
0121                 }
0122 
0123                 PlasmaComponents3.ToolTip {
0124                     text: parent.text
0125                 }
0126             }
0127         }
0128     }
0129 
0130     model: KItemModels.KSortFilterProxyModel {
0131         sourceModel: clipboardSource.models.clipboard
0132         filterRoleName: "DisplayRole"
0133         filterRegularExpression: RegExp(filter.text, "i")
0134     }
0135     supportsBarcodes: {
0136         try {
0137             let prisonTest = Qt.createQmlObject("import QtQml 2.0; import org.kde.prison 1.0; QtObject {}", this);
0138             prisonTest.destroy();
0139         } catch (e) {
0140             console.log("Barcodes not supported:", e);
0141             return false;
0142         }
0143         return true;
0144     }
0145     onItemSelected: uuid => clipboardSource.service(uuid, "select")
0146     onRemove: uuid => clipboardSource.service(uuid, "remove")
0147     onEdit: uuid => {
0148         const m = clipboardMenu.model;
0149         const index = m.index(clipboardMenu.view.currentIndex, 0);
0150         const text = m.data(index, Qt.DisplayRole);
0151         stack.push(Qt.resolvedUrl("EditPage.qml"), { text, uuid });
0152     }
0153     onBarcode: text => {
0154         stack.push(Qt.resolvedUrl("BarcodePage.qml"), {
0155             text: text
0156         });
0157     }
0158     onTriggerAction: uuid => clipboardSource.service(uuid, "action")
0159 }