1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

Rework hotkeys for focused input fields and open dialogs

Also added 2 hotkeys:
    1. `i` Toggle inspector
    2. `l` Set location
This commit is contained in:
Sven Depondt 2017-07-30 13:54:13 +02:00
parent 0978dbf890
commit d94f44b777
2 changed files with 171 additions and 148 deletions

View file

@ -330,6 +330,14 @@
<td>DEL</td>
<td>Delete selected torrents</td>
</tr>
<tr>
<td>i</td>
<td>Toggle inspector</td>
</tr>
<tr>
<td>l</td>
<td>Move torrent/Set location</td>
</tr>
<tr>
<td>m</td>
<td>Move torrent/Set location</td>

View file

@ -455,11 +455,17 @@ Transmission.prototype = {
keyDown: function (ev) {
var handled = false;
var rows = this._rows;
var isInputFocused = $(ev.target).is('input');
var isDialogVisible = ($('.dialog_heading:visible').length > 0 || $('.ui-dialog:visible').length > 0);
// hotkeys
var up_key = ev.keyCode === 38; // up key pressed
var dn_key = ev.keyCode === 40; // down key pressed
var a_key = ev.keyCode === 65; // a key pressed
var c_key = ev.keyCode === 67; // c key pressed
var d_key = ev.keyCode === 68; // d key pressed
var i_key = ev.keyCode === 73; // i key pressed
var l_key = ev.keyCode === 76; // l key pressed
var m_key = ev.keyCode === 77; // m key pressed
var o_key = ev.keyCode === 79; // o key pressed
var p_key = ev.keyCode === 80; // p key pressed
@ -474,62 +480,6 @@ Transmission.prototype = {
var esc_key = ev.keyCode === 27; // esc key pressed
var comma_key = ev.keyCode === 188; // comma key pressed
if ($('.dialog_heading:visible').length == 0) {
if (comma_key) {
this.togglePrefsDialogClicked();
handled = true;
}
if (a_key) {
if (ev.shiftKey) {
this.deselectAll();
} else {
this.selectAll();
}
handled = true;
}
if (c_key) {
this.toggleCompactClicked();
handled = true;
}
if ((backspace_key || del_key || d_key) && rows.length) {
this.removeSelectedTorrents();
handled = true;
}
if (m_key) {
this.moveSelectedTorrents()
handled = true;
}
if (o_key || u_key) {
this.openTorrentClicked(ev);
handled = true;
}
if (p_key) {
this.stopSelectedTorrents();
handled = true;
}
if (r_key) {
this.startSelectedTorrents();
handled = true;
}
if (t_key) {
this.toggleTurtleClicked();
handled = true;
}
}
if (slash_key) {
this.showHotkeysDialog();
handled = true;
}
if (enter_key) {
// handle other dialogs
if (dialog && dialog.isVisible()) {
@ -582,6 +532,70 @@ Transmission.prototype = {
}
}
// Some hotkeys can only be used if the following conditions are met:
// 1. when no input fields are focused
// 2. when no other dialogs are visible
// 3. when the meta or ctrl key isn't pressed (i.e. opening dev tools shouldn't trigger the info panel)
if (!isInputFocused && !isDialogVisible && !ev.metaKey && !ev.ctrlKey) {
if (comma_key) {
this.togglePrefsDialogClicked();
handled = true;
}
if (slash_key) {
this.showHotkeysDialog();
handled = true;
}
if (a_key) {
if (ev.shiftKey) {
this.deselectAll();
} else {
this.selectAll();
}
handled = true;
}
if (c_key) {
this.toggleCompactClicked();
handled = true;
}
if ((backspace_key || del_key || d_key) && rows.length) {
this.removeSelectedTorrents();
handled = true;
}
if (i_key) {
this.toggleInspector();
handled = true;
}
if (m_key || l_key) {
this.moveSelectedTorrents()
handled = true;
}
if (o_key || u_key) {
this.openTorrentClicked(ev);
handled = true;
}
if (p_key) {
this.stopSelectedTorrents();
handled = true;
}
if (r_key) {
this.startSelectedTorrents();
handled = true;
}
if (t_key) {
this.toggleTurtleClicked();
handled = true;
}
if ((up_key || dn_key) && rows.length) {
var last = this.indexOfLastTorrent(),
i = last,
@ -619,6 +633,7 @@ Transmission.prototype = {
} else if (shift_key) {
this._shift_index = this.indexOfLastTorrent();
}
}
return !handled;
},