diff options
author | Florrie <towerofnix@gmail.com> | 2018-07-02 23:44:35 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-07-02 23:44:35 -0300 |
commit | 4612f37b2a7b3402253fc7982f6829d668ed326c (patch) | |
tree | 19146f80b583266b5bcf1cc9251d0e95b69e10fb /ui.js | |
parent | 01ef36b2b1a04702af697be6c4f3435537f06cc7 (diff) |
Shift-Q to shuffle and queue selected group
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/ui.js b/ui.js index 9a5b727..21ac9df 100644 --- a/ui.js +++ b/ui.js @@ -1,6 +1,6 @@ const { getDownloaderFor } = require('./downloaders') const { getPlayer } = require('./players') -const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString } = require('./playlist-utils') +const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString, flattenGrouplike } = require('./playlist-utils') const { shuffleArray } = require('./general-util') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') @@ -55,6 +55,7 @@ class AppElement extends FocusElement { this.grouplikeListingElement.on('select (space)', item => this.handleSpacePressed( () => handleSelectFromMain(item))) this.grouplikeListingElement.on('queue', item => this.queueGrouplikeItem(item)) + this.grouplikeListingElement.on('queue (shuffled)', item => this.shuffleQueueGrouplikeItem(item)) const handleSelectFromPathElement = item => { this.form.selectInput(this.grouplikeListingElement) @@ -279,6 +280,14 @@ class AppElement extends FocusElement { this.queueListingElement.buildItems() } + shuffleQueueGrouplikeItem(item) { + if (!isGroup(item)) { + return this.queueGrouplikeItem(item) + } + + return this.queueGrouplikeItem({items: shuffleArray(flattenGrouplike(item).items)}) + } + async downloadGrouplikeItem(item) { if (isGroup(item)) { // TODO: Download all children (recursively), show a confirmation prompt @@ -524,11 +533,9 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - itemElement.on('download', () => this.emit('download', item)) - itemElement.on('remove', () => this.emit('remove', item)) - itemElement.on('select (space)', () => this.emit('select (space)', item)) - itemElement.on('select (enter)', () => this.emit('select (enter)', item)) - itemElement.on('queue', () => this.emit('queue', item)) + for (const evtName of ['download', 'remove', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)']) { + itemElement.on(evtName, () => this.emit(evtName, item)) + } form.addInput(itemElement) } } else if (!this.grouplike.isTheQueue) { @@ -674,7 +681,11 @@ class GrouplikeItemElement extends Button { if (telc.isCaselessLetter(keyBuf, 'd')) { this.emit('download') } else if (telc.isCaselessLetter(keyBuf, 'q')) { - this.emit('queue') + if (keyBuf[0] === 'q'.charCodeAt(0)) { + this.emit('queue') + } else { + this.emit('queue (shuffled)') + } } else if (telc.isBackspace(keyBuf)) { this.emit('remove') } else if (telc.isSpace(keyBuf)) { |