1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +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>DEL</td>
<td>Delete selected torrents</td> <td>Delete selected torrents</td>
</tr> </tr>
<tr>
<td>i</td>
<td>Toggle inspector</td>
</tr>
<tr>
<td>l</td>
<td>Move torrent/Set location</td>
</tr>
<tr> <tr>
<td>m</td> <td>m</td>
<td>Move torrent/Set location</td> <td>Move torrent/Set location</td>

View file

@ -455,11 +455,17 @@ Transmission.prototype = {
keyDown: function (ev) { keyDown: function (ev) {
var handled = false; var handled = false;
var rows = this._rows; 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 up_key = ev.keyCode === 38; // up key pressed
var dn_key = ev.keyCode === 40; // down key pressed var dn_key = ev.keyCode === 40; // down key pressed
var a_key = ev.keyCode === 65; // a key pressed var a_key = ev.keyCode === 65; // a key pressed
var c_key = ev.keyCode === 67; // c key pressed var c_key = ev.keyCode === 67; // c key pressed
var d_key = ev.keyCode === 68; // d 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 m_key = ev.keyCode === 77; // m key pressed
var o_key = ev.keyCode === 79; // o key pressed var o_key = ev.keyCode === 79; // o key pressed
var p_key = ev.keyCode === 80; // p 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 esc_key = ev.keyCode === 27; // esc key pressed
var comma_key = ev.keyCode === 188; // comma 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) { if (enter_key) {
// handle other dialogs // handle other dialogs
if (dialog && dialog.isVisible()) { if (dialog && dialog.isVisible()) {
@ -582,42 +532,107 @@ Transmission.prototype = {
} }
} }
if ((up_key || dn_key) && rows.length) { // Some hotkeys can only be used if the following conditions are met:
var last = this.indexOfLastTorrent(), // 1. when no input fields are focused
i = last, // 2. when no other dialogs are visible
anchor = this._shift_index, // 3. when the meta or ctrl key isn't pressed (i.e. opening dev tools shouldn't trigger the info panel)
r, if (!isInputFocused && !isDialogVisible && !ev.metaKey && !ev.ctrlKey) {
min = 0, if (comma_key) {
max = rows.length - 1; this.togglePrefsDialogClicked();
handled = true;
if (dn_key && (i + 1 <= max)) { }
++i;
} else if (up_key && (i - 1 >= min)) { if (slash_key) {
--i; this.showHotkeysDialog();
}; handled = true;
}
var r = rows[i];
if (a_key) {
if (anchor >= 0) { if (ev.shiftKey) {
// user is extending the selection this.deselectAll();
// with the shift + arrow keys... } else {
if (((anchor <= last) && (last < i)) || ((anchor >= last) && (last > i))) { this.selectAll();
this.selectRow(r); }
} else if (((anchor >= last) && (i > last)) || ((anchor <= last) && (last > i))) { handled = true;
this.deselectRow(rows[last]); }
}
} else { if (c_key) {
if (ev.shiftKey) { this.toggleCompactClicked();
this.selectRange(r); handled = true;
} else { }
this.setSelectedRow(r);
}; 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,
anchor = this._shift_index,
r,
min = 0,
max = rows.length - 1;
if (dn_key && (i + 1 <= max)) {
++i;
} else if (up_key && (i - 1 >= min)) {
--i;
};
var r = rows[i];
if (anchor >= 0) {
// user is extending the selection
// with the shift + arrow keys...
if (((anchor <= last) && (last < i)) || ((anchor >= last) && (last > i))) {
this.selectRow(r);
} else if (((anchor >= last) && (i > last)) || ((anchor <= last) && (last > i))) {
this.deselectRow(rows[last]);
}
} else {
if (ev.shiftKey) {
this.selectRange(r);
} else {
this.setSelectedRow(r);
};
}
this._last_torrent_clicked = r.getTorrentId();
this.scrollToRow(r);
handled = true;
} else if (shift_key) {
this._shift_index = this.indexOfLastTorrent();
} }
this._last_torrent_clicked = r.getTorrentId();
this.scrollToRow(r);
handled = true;
} else if (shift_key) {
this._shift_index = this.indexOfLastTorrent();
} }
return !handled; return !handled;
@ -841,74 +856,74 @@ Transmission.prototype = {
remote.savePrefs(o); remote.savePrefs(o);
} else { } else {
switch (id) { switch (id) {
case 'statistics': case 'statistics':
this.showStatsDialog(); this.showStatsDialog();
break; break;
case 'hotkeys': case 'hotkeys':
this.showHotkeysDialog(); this.showHotkeysDialog();
break; break;
case 'about-button': case 'about-button':
o = 'Transmission ' + this.serverVersion; o = 'Transmission ' + this.serverVersion;
$('#about-dialog #about-title').html(o); $('#about-dialog #about-title').html(o);
$('#about-dialog').dialog({ $('#about-dialog').dialog({
title: 'About', title: 'About',
show: 'fade', show: 'fade',
hide: 'fade' hide: 'fade'
}); });
break; break;
case 'homepage': case 'homepage':
window.open('https://transmissionbt.com/'); window.open('https://transmissionbt.com/');
break; break;
case 'tipjar': case 'tipjar':
window.open('https://transmissionbt.com/donate/'); window.open('https://transmissionbt.com/donate/');
break; break;
case 'unlimited_download_rate': case 'unlimited_download_rate':
o = {}; o = {};
o[RPC._DownSpeedLimited] = false; o[RPC._DownSpeedLimited] = false;
remote.savePrefs(o); remote.savePrefs(o);
break; break;
case 'limited_download_rate': case 'limited_download_rate':
o = {}; o = {};
o[RPC._DownSpeedLimited] = true; o[RPC._DownSpeedLimited] = true;
remote.savePrefs(o); remote.savePrefs(o);
break; break;
case 'unlimited_upload_rate': case 'unlimited_upload_rate':
o = {}; o = {};
o[RPC._UpSpeedLimited] = false; o[RPC._UpSpeedLimited] = false;
remote.savePrefs(o); remote.savePrefs(o);
break; break;
case 'limited_upload_rate': case 'limited_upload_rate':
o = {}; o = {};
o[RPC._UpSpeedLimited] = true; o[RPC._UpSpeedLimited] = true;
remote.savePrefs(o); remote.savePrefs(o);
break; break;
case 'reverse_sort_order': case 'reverse_sort_order':
if (element.menuItemIsSelected()) { if (element.menuItemIsSelected()) {
dir = Prefs._SortAscending; dir = Prefs._SortAscending;
element.deselectMenuItem(); element.deselectMenuItem();
} else { } else {
dir = Prefs._SortDescending; dir = Prefs._SortDescending;
element.selectMenuItem(); element.selectMenuItem();
} }
this.setSortDirection(dir); this.setSortDirection(dir);
break; break;
case 'toggle_notifications': case 'toggle_notifications':
Notifications && Notifications.toggle(); Notifications && Notifications.toggle();
break; break;
default: default:
console.log('unhandled: ' + id); console.log('unhandled: ' + id);
break; break;
}; };
}; };
}, },