[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
wilder-5.24
Bharadwaj Raju 4 years ago committed by Nate Graham
parent 63d438a42f
commit 4644b9ec24
  1. 7
      applets/clipboard/contents/ui/BarcodePage.qml
  2. 14
      applets/clipboard/contents/ui/ClipboardItemDelegate.qml
  3. 62
      applets/clipboard/contents/ui/ClipboardPage.qml
  4. 6
      applets/clipboard/contents/ui/DelegateToolButtons.qml
  5. 9
      applets/clipboard/contents/ui/Menu.qml

@ -19,6 +19,13 @@ ColumnLayout {
property alias text: barcodeItem.content property alias text: barcodeItem.content
Keys.onPressed: {
if (event.key == Qt.Key_Escape) {
stack.pop()
event.accepted = true;
}
}
property var header: PlasmaExtras.PlasmoidHeading { property var header: PlasmaExtras.PlasmoidHeading {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent

@ -10,10 +10,10 @@ import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore 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 import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
PlasmaExtras.ListItem { PlasmaComponents2.ListItem {
id: menuItem id: menuItem
property bool supportsBarcodes property bool supportsBarcodes
@ -41,13 +41,7 @@ PlasmaExtras.ListItem {
if (plasmoid.hideOnWindowDeactivate) if (plasmoid.hideOnWindowDeactivate)
plasmoid.expanded = false; plasmoid.expanded = false;
} }
onContainsMouseChanged: {
if (containsMouse) {
menuListView.currentIndex = index
} else {
menuListView.currentIndex = -1
}
}
Keys.onDeletePressed: { Keys.onDeletePressed: {
remove(UuidRole); remove(UuidRole);
} }
@ -130,6 +124,8 @@ PlasmaExtras.ListItem {
onActiveChanged: { onActiveChanged: {
if (active) { if (active) {
menuItem.KeyNavigation.tab = toolButtonsLoader.item.children[0]
menuItem.KeyNavigation.right = toolButtonsLoader.item.children[0]
// break binding, once it was loaded, never unload // break binding, once it was loaded, never unload
active = true; active = true;
} }

@ -15,14 +15,45 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
ColumnLayout { ColumnLayout {
Keys.onPressed: { 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) { switch(event.key) {
case Qt.Key_Up: { 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; event.accepted = true;
break; break;
} }
case Qt.Key_Down: { case Qt.Key_Down: {
clipboardMenu.view.incrementCurrentIndex(); clipboardMenu.view.incrementCurrentIndex();
goToCurrent();
event.accepted = true; event.accepted = true;
break; break;
} }
@ -47,26 +78,29 @@ ColumnLayout {
} }
break; break;
} }
default: { // forward key to filter case Qt.Key_F: {
// filter.text += event.text wil break if the key is backspace if (event.modifiers & Qt.ControlModifier) {
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(); filter.forceActiveFocus();
filter.selectAll();
event.accepted = true; 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 { property var header: PlasmaExtras.PlasmoidHeading {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent

@ -15,6 +15,7 @@ RowLayout {
visible: menuItem.ListView.isCurrentItem visible: menuItem.ListView.isCurrentItem
PlasmaComponents3.ToolButton { PlasmaComponents3.ToolButton {
id: actionToolButton
// TODO: only show for items supporting actions? // TODO: only show for items supporting actions?
icon.name: "system-run" icon.name: "system-run"
onClicked: menuItem.action(UuidRole) onClicked: menuItem.action(UuidRole)
@ -22,6 +23,7 @@ RowLayout {
PlasmaComponents3.ToolTip { PlasmaComponents3.ToolTip {
text: i18n("Invoke action") text: i18n("Invoke action")
} }
KeyNavigation.right: barcodeToolButton
} }
PlasmaComponents3.ToolButton { PlasmaComponents3.ToolButton {
id: barcodeToolButton id: barcodeToolButton
@ -32,8 +34,10 @@ RowLayout {
PlasmaComponents3.ToolTip { PlasmaComponents3.ToolTip {
text: i18n("Show QR code") text: i18n("Show QR code")
} }
KeyNavigation.right: editToolButton
} }
PlasmaComponents3.ToolButton { PlasmaComponents3.ToolButton {
id: editToolButton
icon.name: "document-edit" icon.name: "document-edit"
enabled: !clipboardSource.editing enabled: !clipboardSource.editing
visible: TypeRole === 0 visible: TypeRole === 0
@ -42,8 +46,10 @@ RowLayout {
PlasmaComponents3.ToolTip { PlasmaComponents3.ToolTip {
text: i18n("Edit contents") text: i18n("Edit contents")
} }
KeyNavigation.right: deleteToolButton
} }
PlasmaComponents3.ToolButton { PlasmaComponents3.ToolButton {
id: deleteToolButton
icon.name: "edit-delete" icon.name: "edit-delete"
onClicked: menuItem.remove(UuidRole) onClicked: menuItem.remove(UuidRole)

@ -4,7 +4,8 @@
SPDX-License-Identifier: GPL-2.0-or-later 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.extras 2.0 as PlasmaExtras
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight
@ -49,6 +50,12 @@ PlasmaComponents3.ScrollView {
onEdit: menu.edit(uuid) onEdit: menu.edit(uuid)
onBarcode: menu.barcode(text) onBarcode: menu.barcode(text)
onAction: menu.action(uuid) onAction: menu.action(uuid)
Binding {
target: menuListView; when: containsMouse
property: "currentIndex"; value: index
restoreMode: Binding.RestoreBinding
}
} }
PlasmaExtras.PlaceholderMessage { PlasmaExtras.PlaceholderMessage {

Loading…
Cancel
Save