Select from last open files by using arrow keys. Fixes #889

This commit is contained in:
Dennis Ploeger 2018-12-28 08:14:36 +01:00
parent 0d85a08955
commit 223827ad76
2 changed files with 28 additions and 1 deletions

View File

@ -164,6 +164,7 @@ const AppView = Backbone.View.extend({
this.showOpenFile();
const lastOpenFile = this.model.fileInfos.getLast();
if (lastOpenFile) {
this.views.open.currentSelectedIndex = 0;
this.views.open.showOpenFileInfo(lastOpenFile);
}
},

View File

@ -47,6 +47,7 @@ const OpenView = Backbone.View.extend({
params: null,
passwordInput: null,
busy: false,
currentSelectedIndex: -1,
initialize: function () {
this.views = {};
@ -66,6 +67,8 @@ const OpenView = Backbone.View.extend({
KeyHandler.onKey(Keys.DOM_VK_TAB, this.tabKeyPress, this);
KeyHandler.onKey(Keys.DOM_VK_ENTER, this.enterKeyPress, this);
KeyHandler.onKey(Keys.DOM_VK_RETURN, this.enterKeyPress, this);
KeyHandler.onKey(Keys.DOM_VK_DOWN, this.moveOpenFileSelectionDown, this);
KeyHandler.onKey(Keys.DOM_VK_UP, this.moveOpenFileSelectionUp, this);
},
render: function () {
@ -813,7 +816,30 @@ const OpenView = Backbone.View.extend({
this.params.fileData = null;
this.displayOpenFile();
}
}
},
moveOpenFileSelection: function(steps) {
let lastOpenFiles = this.getLastOpenFiles();
if (this.currentSelectedIndex + steps >= 0 &&
this.currentSelectedIndex + steps <= lastOpenFiles.length - 1) {
this.currentSelectedIndex = this.currentSelectedIndex + steps;
}
const fileInfo = this.model.fileInfos.get(lastOpenFiles[this.currentSelectedIndex].id);
this.showOpenFileInfo(fileInfo);
if (fileInfo && Launcher && Launcher.fingerprints) {
this.openFileWithFingerprint(fileInfo);
}
},
moveOpenFileSelectionDown: function() {
this.moveOpenFileSelection(1);
},
moveOpenFileSelectionUp: function() {
this.moveOpenFileSelection(-1);
},
});
module.exports = OpenView;