From bf6f1ec9d724ae144c8be682821f3660a257767f Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 4 Jul 2018 23:35:16 -0300 Subject: Open in new tab --- ui.js | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 43039e1..148d2a6 100644 --- a/ui.js +++ b/ui.js @@ -78,6 +78,7 @@ class AppElement extends FocusElement { this.setupDialog(this.openPlaylistDialog) this.openPlaylistDialog.on('source selected', source => this.handlePlaylistSource(source)) + this.openPlaylistDialog.on('source selected (new tab)', source => this.handlePlaylistSource(source, true)) this.alertDialog = new AlertDialog() this.setupDialog(this.alertDialog) @@ -90,6 +91,7 @@ class AppElement extends FocusElement { newGrouplikeListing() { const grouplikeListing = new GrouplikeListingElement(this.recordStore) this.tabber.addTab(grouplikeListing) + this.tabber.selectTab(grouplikeListing) const handleSelectFromMain = item => { if (isGroup(item)) { @@ -118,9 +120,11 @@ class AppElement extends FocusElement { // this.form.addInput(grouplikeListing.pathElement, false) grouplikeListing.pathElement.on('select', item => handleSelectFromPathElement(item)) + + return grouplikeListing } - async handlePlaylistSource(source) { + async handlePlaylistSource(source, newTab = false) { this.openPlaylistDialog.close() this.alertDialog.showMessage('Opening playlist...', false) @@ -143,7 +147,13 @@ class AppElement extends FocusElement { this.root.select(this.form) grouplike = await processSmartPlaylist(grouplike) - this.tabber.currentElement.loadGrouplike(grouplike) + + if (newTab) { + const grouplikeListing = this.newGrouplikeListing() + grouplikeListing.loadGrouplike(grouplike) + } else { + this.tabber.currentElement.loadGrouplike(grouplike) + } } openPlaylist(arg) { @@ -232,6 +242,10 @@ class AppElement extends FocusElement { this.form.updateSelectedElement() } else if (keyBuf.equals(Buffer.from([15]))) { // ctrl-O this.openPlaylistDialog.open() + } else if (this.tabber.isSelected && keyBuf.equals(Buffer.from(['t'.charCodeAt(0)]))) { + this.tabber.nextTab() + } else if (this.tabber.isSelected && keyBuf.equals(Buffer.from(['T'.charCodeAt(0)]))) { + this.tabber.previousTab() } else { super.keyPressed(keyBuf) } @@ -745,7 +759,6 @@ class GrouplikeItemElement extends Button { } keyPressed(keyBuf) { - // TODO: Helper function for this if (telc.isCaselessLetter(keyBuf, 'd')) { this.emit('download') } else if (telc.isCaselessLetter(keyBuf, 'q')) { @@ -929,11 +942,20 @@ class OpenPlaylistDialog extends Dialog { this.button = new Button('Open') this.form.addInput(this.button) + this.buttonNewTab = new Button('..in New Tab') + this.form.addInput(this.buttonNewTab) + this.button.on('pressed', () => { if (this.input.value) { this.emit('source selected', this.input.value) } }) + + this.buttonNewTab.on('pressed', () => { + if (this.input.value) { + this.emit('source selected (new tab)', this.input.value) + } + }) } opened() { @@ -946,7 +968,7 @@ class OpenPlaylistDialog extends Dialog { super.fixLayout() this.pane.w = Math.min(60, this.contentW) - this.pane.h = 5 + this.pane.h = 6 this.pane.centerInParent() this.label.centerInParent() @@ -960,6 +982,9 @@ class OpenPlaylistDialog extends Dialog { this.button.centerInParent() this.button.y = 1 + + this.buttonNewTab.centerInParent() + this.buttonNewTab.y = 2 } selected() { @@ -1044,14 +1069,27 @@ class Tabber extends FocusElement { this.updateVisibleElement() } + selectTab(element) { + if (!this.tabberElements.includes(element)) { + throw new Error('That tab does not exist! (Perhaps it was removed, somehow, or was never added?)') + } + + this.currentElementIndex = this.tabberElements.indexOf(element) + this.updateVisibleElement() + } + updateVisibleElement() { - const len = this.tabberElements.length + const len = this.tabberElements.length - 1 this.currentElementIndex = Math.min(len, Math.max(0, this.currentElementIndex)) this.tabberElements.forEach((el, i) => { el.visible = (i === this.currentElementIndex) }) + if (this.isSelected && this.currentElement) { + this.root.select(this.currentElement) + } + this.fixLayout() } -- cgit 1.3.0-6-gf8a5