From 4644b9ec241b0e575b233c61d9549f59f9ce7690 Mon Sep 17 00:00:00 2001 From: Bharadwaj Raju Date: Wed, 13 Oct 2021 20:50:11 +0000 Subject: [PATCH] [applets/clipboard] Better keyboard navigation - Up/Down now ensures item is completely in view - Ctrl+F works - Tab/Shift+Tab events are no longer eaten by the search field - Tab/Shift+Tab now resolve to actions on the selected item first - Can use Escape key to go back from from QR code page --- applets/clipboard/contents/ui/BarcodePage.qml | 7 +++ .../contents/ui/ClipboardItemDelegate.qml | 14 ++--- .../clipboard/contents/ui/ClipboardPage.qml | 62 ++++++++++++++----- .../contents/ui/DelegateToolButtons.qml | 6 ++ applets/clipboard/contents/ui/Menu.qml | 9 ++- 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/applets/clipboard/contents/ui/BarcodePage.qml b/applets/clipboard/contents/ui/BarcodePage.qml index ded518aa3..e5bb16c85 100644 --- a/applets/clipboard/contents/ui/BarcodePage.qml +++ b/applets/clipboard/contents/ui/BarcodePage.qml @@ -19,6 +19,13 @@ ColumnLayout { property alias text: barcodeItem.content + Keys.onPressed: { + if (event.key == Qt.Key_Escape) { + stack.pop() + event.accepted = true; + } + } + property var header: PlasmaExtras.PlasmoidHeading { RowLayout { anchors.fill: parent diff --git a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml index 79f215a79..20963a9ed 100644 --- a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml +++ b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml @@ -10,10 +10,10 @@ import QtQuick.Layouts 1.1 import QtGraphicalEffects 1.0 import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.components 2.0 as PlasmaExtras +import org.kde.plasma.components 2.0 as PlasmaComponents2 import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons -PlasmaExtras.ListItem { +PlasmaComponents2.ListItem { id: menuItem property bool supportsBarcodes @@ -41,13 +41,7 @@ PlasmaExtras.ListItem { if (plasmoid.hideOnWindowDeactivate) plasmoid.expanded = false; } - onContainsMouseChanged: { - if (containsMouse) { - menuListView.currentIndex = index - } else { - menuListView.currentIndex = -1 - } - } + Keys.onDeletePressed: { remove(UuidRole); } @@ -130,6 +124,8 @@ PlasmaExtras.ListItem { onActiveChanged: { if (active) { + menuItem.KeyNavigation.tab = toolButtonsLoader.item.children[0] + menuItem.KeyNavigation.right = toolButtonsLoader.item.children[0] // break binding, once it was loaded, never unload active = true; } diff --git a/applets/clipboard/contents/ui/ClipboardPage.qml b/applets/clipboard/contents/ui/ClipboardPage.qml index 7cc52cb2d..631ff8811 100644 --- a/applets/clipboard/contents/ui/ClipboardPage.qml +++ b/applets/clipboard/contents/ui/ClipboardPage.qml @@ -15,14 +15,45 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras ColumnLayout { Keys.onPressed: { + function goToCurrent() { + clipboardMenu.view.positionViewAtIndex(clipboardMenu.view.currentIndex, ListView.Contain); + if (clipboardMenu.view.currentIndex != -1) { + clipboardMenu.view.currentItem.forceActiveFocus(); + } + } + function forwardToFilter() { + // filter.text += event.text wil break if the key is backspace + if (event.key === Qt.Key_Backspace && filter.text == "") { + return; + } + if (event.text !== "" && !filter.activeFocus) { + clipboardMenu.view.currentIndex = -1 + if (event.matches(StandardKey.Paste)) { + filter.paste(); + } else { + filter.text = ""; + filter.text += event.text; + } + filter.forceActiveFocus(); + event.accepted = true; + } + } switch(event.key) { case Qt.Key_Up: { - clipboardMenu.view.decrementCurrentIndex(); + if (clipboardMenu.view.currentIndex == 0) { + clipboardMenu.view.currentIndex = -1; + filter.forceActiveFocus(); + filter.selectAll(); + } else { + clipboardMenu.view.decrementCurrentIndex(); + goToCurrent(); + } event.accepted = true; break; } case Qt.Key_Down: { clipboardMenu.view.incrementCurrentIndex(); + goToCurrent(); event.accepted = true; break; } @@ -47,26 +78,29 @@ ColumnLayout { } break; } - default: { // forward key to filter - // filter.text += event.text wil break if the key is backspace - if (event.key === Qt.Key_Backspace && filter.text == "") { - return; - } - if (event.text !== "" && !filter.activeFocus) { - clipboardMenu.view.currentIndex = -1 - if (event.matches(StandardKey.Paste)) { - filter.paste(); - } else { - filter.text = ""; - filter.text += event.text; - } + case Qt.Key_F: { + if (event.modifiers & Qt.ControlModifier) { filter.forceActiveFocus(); + filter.selectAll(); event.accepted = true; + } else { + forwardToFilter(); } + break; + } + case Qt.Key_Tab: + case Qt.Key_Backtab: { + // prevent search filter from getting Tab key events + break; + } + default: { + forwardToFilter(); } } } + Keys.forwardTo: [stack.currentPage] + property var header: PlasmaExtras.PlasmoidHeading { RowLayout { anchors.fill: parent diff --git a/applets/clipboard/contents/ui/DelegateToolButtons.qml b/applets/clipboard/contents/ui/DelegateToolButtons.qml index bf977639f..6a92fb3b0 100644 --- a/applets/clipboard/contents/ui/DelegateToolButtons.qml +++ b/applets/clipboard/contents/ui/DelegateToolButtons.qml @@ -15,6 +15,7 @@ RowLayout { visible: menuItem.ListView.isCurrentItem PlasmaComponents3.ToolButton { + id: actionToolButton // TODO: only show for items supporting actions? icon.name: "system-run" onClicked: menuItem.action(UuidRole) @@ -22,6 +23,7 @@ RowLayout { PlasmaComponents3.ToolTip { text: i18n("Invoke action") } + KeyNavigation.right: barcodeToolButton } PlasmaComponents3.ToolButton { id: barcodeToolButton @@ -32,8 +34,10 @@ RowLayout { PlasmaComponents3.ToolTip { text: i18n("Show QR code") } + KeyNavigation.right: editToolButton } PlasmaComponents3.ToolButton { + id: editToolButton icon.name: "document-edit" enabled: !clipboardSource.editing visible: TypeRole === 0 @@ -42,8 +46,10 @@ RowLayout { PlasmaComponents3.ToolTip { text: i18n("Edit contents") } + KeyNavigation.right: deleteToolButton } PlasmaComponents3.ToolButton { + id: deleteToolButton icon.name: "edit-delete" onClicked: menuItem.remove(UuidRole) diff --git a/applets/clipboard/contents/ui/Menu.qml b/applets/clipboard/contents/ui/Menu.qml index d8ff4adc2..3dcdbc6bf 100644 --- a/applets/clipboard/contents/ui/Menu.qml +++ b/applets/clipboard/contents/ui/Menu.qml @@ -4,7 +4,8 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -import QtQuick 2.0 +import QtQuick 2.15 +import QtQml 2.15 import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight @@ -49,6 +50,12 @@ PlasmaComponents3.ScrollView { onEdit: menu.edit(uuid) onBarcode: menu.barcode(text) onAction: menu.action(uuid) + + Binding { + target: menuListView; when: containsMouse + property: "currentIndex"; value: index + restoreMode: Binding.RestoreBinding + } } PlasmaExtras.PlaceholderMessage {