Skip to content

Commit

Permalink
Improve keyboard navigation in File Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Apr 10, 2023
1 parent 7a6770b commit 43e93d8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 22 deletions.
42 changes: 37 additions & 5 deletions application/components/FileManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
62 changes: 45 additions & 17 deletions application/components/FileManagerDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Item {

onTriggered: beginDelete();
}

function rightClick(mouse) {
delegate.GridView.view.currentIndex = delegate.index
forceActiveFocus(Qt.MouseFocusReason);
Expand Down Expand Up @@ -317,7 +317,7 @@ Item {
nameLabel.text = newName;
editBox.visible = false;
}

function beginDelete() {
const doRemove = function() {
Backend.fileManager.remove(delegate.fileName, delegate.isDirectory);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 43e93d8

Please sign in to comment.