From 43e93d8f0704e27801e33a84b607a49aec524496 Mon Sep 17 00:00:00 2001 From: Georgii Surkov Date: Mon, 10 Apr 2023 14:02:02 +0300 Subject: [PATCH] Improve keyboard navigation in File Manager --- application/components/FileManager.qml | 42 +++++++++++-- .../components/FileManagerDelegate.qml | 62 ++++++++++++++----- 2 files changed, 82 insertions(+), 22 deletions(-) diff --git a/application/components/FileManager.qml b/application/components/FileManager.qml index 600cfe90..1a9f5750 100644 --- a/application/components/FileManager.qml +++ b/application/components/FileManager.qml @@ -295,15 +295,47 @@ Item { } Keys.onPressed: function(event) { - if ((event.key === Qt.Key_Backspace) && Backend.fileManager.canGoBack) { + switch(event.key) { + case Qt.Key_Backspace: + if(Backend.fileManager.canGoBack) { Backend.fileManager.historyBack(); - event.accepted = true; - } else if((event.key === Qt.Key_L) && (event.modifiers & Qt.ControlModifier)) { + } + event.accepted = true; + return; + + case Qt.Key_L: + if(Backend.fileManager.isRoot) { + event.accepted = false; + } else if(event.modifiers & Qt.ControlModifier) { beginUpload(); - } else if((event.key === Qt.Key_N) && (event.modifiers & Qt.ControlModifier)) { + event.accepted = true; + } else { + event.accepted = false; + } + return; + + case Qt.Key_N: + if(Backend.fileManager.isRoot) { + event.accepted = false; + } else if(event.modifiers & Qt.ControlModifier) { Backend.fileManager.beginMkDir(); - } else if((event.key === Qt.Key_G) && (event.modifiers & Qt.ControlModifier)) { + event.accepted = true; + } else { + event.accepted = false; + } + return; + + case Qt.Key_G: + if(event.modifiers & Qt.ControlModifier) { Backend.fileManager.refresh() + event.accepted = true; + } else { + event.accepted = false; } + return; + + default: + event.accepted = false; + } } } diff --git a/application/components/FileManagerDelegate.qml b/application/components/FileManagerDelegate.qml index 846ead06..0e3642d8 100644 --- a/application/components/FileManagerDelegate.qml +++ b/application/components/FileManagerDelegate.qml @@ -270,7 +270,7 @@ Item { onTriggered: beginDelete(); } - + function rightClick(mouse) { delegate.GridView.view.currentIndex = delegate.index forceActiveFocus(Qt.MouseFocusReason); @@ -317,7 +317,7 @@ Item { nameLabel.text = newName; editBox.visible = false; } - + function beginDelete() { const doRemove = function() { Backend.fileManager.remove(delegate.fileName, delegate.isDirectory); @@ -345,31 +345,59 @@ Item { } Keys.onPressed: function(event) { - if (editBox.visible) { + if(editBox.visible) { event.accepted = false; return; } - if((event.key === Qt.Key_Delete) && (event.modifiers & Qt.ShiftModifier)) { - Backend.fileManager.remove(delegate.fileName, delegate.isDirectory); - event.accepted = true; - } else if((event.key === Qt.Key_Delete) && !(event.modifiers & Qt.ShiftModifier)) { - beginDelete(); - event.accepted = true; - } else if (event.key === Qt.Key_Return) { - if (!delegate.isDirectory || editFlag) { - editFlag = false; + + switch(event.key) { + case Qt.Key_Delete: + if(Backend.fileManager.isRoot) { event.accepted = false; - return; + } else if(event.modifiers & Qt.ShiftModifier) { + Backend.fileManager.remove(delegate.fileName, delegate.isDirectory); + event.accepted = true; } else { + beginDelete(); + event.accepted = true; + } + return; + + case Qt.Key_Return: + if(delegate.isDirectory && !editFlag) { Backend.fileManager.cd(delegate.fileName); event.accepted = true; + } else { + editFlag = false; + event.accepted = false; } - } else if ((event.key === Qt.Key_D) && (event.modifiers & Qt.ControlModifier)) { - beginDownload(); - } else if ((event.key === Qt.Key_E) && (event.modifiers & Qt.ControlModifier)) { - beginEdit(); + return; + + case Qt.Key_E: + if(Backend.fileManager.isRoot) { + event.accepted = false; + } else if(event.modifiers & Qt.ControlModifier) { + beginEdit(); + event.accepted = true; + } else { + event.accepted = false; + } + return; + + case Qt.Key_D: + if(event.modifiers & Qt.ControlModifier) { + beginDownload(); + event.accepted = true; + } else { + event.accepted = false; + } + return; + + default: + event.accepted = false; } } + Connections { target: confirmationDialog function onVisibleChanged() {