From a5ffe6a882598edc8b67fed12de78642fd6d1a5a Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 5 Jul 2018 17:34:01 -0300 Subject: Mark --- ui.js | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index c4c2307..0bddc64 100644 --- a/ui.js +++ b/ui.js @@ -32,9 +32,13 @@ class AppElement extends FocusElement { this.player = null this.recordStore = new RecordStore() this.undoManager = new UndoManager() - this.queueGrouplike = {isTheQueue: true, items: []} + this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []} + this.markGrouplike = {name: 'Marked', items: []} this.editMode = false + // Crude hack... + this.recordStore.app = this + this.rootDirectory = process.env.HOME + '/.mtui' this.form = new Form() @@ -143,6 +147,33 @@ class AppElement extends FocusElement { } }) + grouplikeListing.on('mark', item => { + if (this.editMode) { + if (!this.markGrouplike.items.includes(item)) { + this.undoManager.pushAction({ + activate: () => { + this.markGrouplike.items.push(item) + }, + undo: () => { + // It SHOULD always be on the top, but juuust in case it isn't... + const index = this.markGrouplike.items.indexOf(item) + this.markGrouplike.items.splice(index, 1) + } + }) + } else { + const index = this.markGrouplike.items.indexOf(item) + this.undoManager.pushAction({ + activate: () => { + this.markGrouplike.items.splice(index, 1) + }, + undo: () => { + this.markGrouplike.items.splice(index, 0, item) + } + }) + } + } + }) + const handleSelectFromPathElement = item => { this.form.selectInput(grouplikeListing) if (isGroup(item)) { @@ -674,7 +705,7 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) { + for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) { itemElement.on(evtName, () => this.emit(evtName, item)) } form.addInput(itemElement) @@ -809,7 +840,12 @@ class GrouplikeItemElement extends Button { const record = this.recordStore.getRecord(this.item) - writable.write(' ') + if (this.recordStore.app.editMode && this.recordStore.app.markGrouplike.items.includes(this.item)) { + writable.write('M') + } else { + writable.write(' ') + } + if (isGroup(this.item)) { writable.write('G') } else if (record.downloading) { @@ -819,6 +855,7 @@ class GrouplikeItemElement extends Button { } else { writable.write(' ') } + writable.write(' ') } @@ -837,8 +874,10 @@ class GrouplikeItemElement extends Button { } } else if (telc.isBackspace(keyBuf)) { this.emit('remove (backspace)') - } else if (telc.isCharacter(keyBuf, 'x')) { + } else if (telc.isCaselessLetter(keyBuf, 'x')) { this.emit('remove (x)') + } else if (telc.isCaselessLetter(keyBuf, 'm')) { + this.emit('mark') } else if (telc.isSpace(keyBuf)) { this.emit('select (space)') } else if (telc.isEnter(keyBuf)) { -- cgit 1.3.0-6-gf8a5