Use Ctrl+Left/Right to switch playlist items. Closes #63

This commit is contained in:
Rafał Dzięgiel
2021-04-22 14:32:02 +02:00
parent 084f78a851
commit edfa85b5cc
2 changed files with 28 additions and 6 deletions

View File

@@ -14,5 +14,13 @@ var actions = {
}, },
about: { about: {
run: (window) => new Dialogs.AboutDialog(window), run: (window) => new Dialogs.AboutDialog(window),
},
next_track: {
run: (window) => window.child.player.playlistWidget.nextTrack(),
accels: ['<Ctrl>Right'],
},
prev_track: {
run: (window) => window.child.player.playlistWidget.prevTrack(),
accels: ['<Ctrl>Left'],
} }
}; };

View File

@@ -46,13 +46,12 @@ class ClapperPlaylistWidget extends Gtk.ListBox
nextTrack() nextTrack()
{ {
const nextRow = this.get_row_at_index(this.activeRowId + 1); return this._switchTrack(false);
if(!nextRow) }
return false;
nextRow.activate(); prevTrack()
{
return true; return this._switchTrack(true);
} }
getActiveRow() getActiveRow()
@@ -83,6 +82,21 @@ class ClapperPlaylistWidget extends Gtk.ListBox
button.icon_name = 'list-remove-symbolic'; button.icon_name = 'list-remove-symbolic';
} }
_switchTrack(isPrevious)
{
const rowId = (isPrevious)
? this.activeRowId - 1
: this.activeRowId + 1;
const row = this.get_row_at_index(rowId);
if(!row)
return false;
row.activate();
return true;
}
_onRowActivated(listBox, row) _onRowActivated(listBox, row)
{ {
const { player } = this.get_ancestor(Gtk.Grid); const { player } = this.get_ancestor(Gtk.Grid);