diff --git a/src/actions.js b/src/actions.js index 333ef749..4513e714 100644 --- a/src/actions.js +++ b/src/actions.js @@ -14,5 +14,13 @@ var actions = { }, about: { run: (window) => new Dialogs.AboutDialog(window), + }, + next_track: { + run: (window) => window.child.player.playlistWidget.nextTrack(), + accels: ['Right'], + }, + prev_track: { + run: (window) => window.child.player.playlistWidget.prevTrack(), + accels: ['Left'], } }; diff --git a/src/playlist.js b/src/playlist.js index 3b48689b..258dbdff 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -46,13 +46,12 @@ class ClapperPlaylistWidget extends Gtk.ListBox nextTrack() { - const nextRow = this.get_row_at_index(this.activeRowId + 1); - if(!nextRow) - return false; + return this._switchTrack(false); + } - nextRow.activate(); - - return true; + prevTrack() + { + return this._switchTrack(true); } getActiveRow() @@ -83,6 +82,21 @@ class ClapperPlaylistWidget extends Gtk.ListBox 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) { const { player } = this.get_ancestor(Gtk.Grid);