« get me outta code hell

Support disabling controlling the queue - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-07-06 14:31:34 -0300
committerFlorrie <towerofnix@gmail.com>2019-07-06 14:31:34 -0300
commit52e2d625df4631d5c67e7610f824bc83da485e7e (patch)
treecfc95dd5fa177e5bb960e964086de38ab146e855
parente973550703ebc7f93b6bbb6b36a294d2823ad5ee (diff)
Support disabling controlling the queue
-rw-r--r--telnet-server.js3
-rw-r--r--ui.js58
2 files changed, 46 insertions, 15 deletions
diff --git a/telnet-server.js b/telnet-server.js
index 1e06c78..93b4a5b 100644
--- a/telnet-server.js
+++ b/telnet-server.js
@@ -28,8 +28,9 @@ class TelnetServer {
       interfacer,
       appConfig: {
         canControlPlayback: false,
+        canControlQueue: false,
         canSuspend: false,
-        showLeftPane: false,
+        showLeftPane: true,
         stopPlayingUponQuit: false,
         menubarColor: 2
       }
diff --git a/ui.js b/ui.js
index b577568..766b4eb 100644
--- a/ui.js
+++ b/ui.js
@@ -144,6 +144,7 @@ class AppElement extends FocusElement {
 
     this.config = Object.assign({
       canControlPlayback: true,
+      canControlQueue: true,
       canSuspend: true,
       menubarColor: 4, // blue
       showLeftPane: true,
@@ -258,7 +259,7 @@ class AppElement extends FocusElement {
           playingTrack && {element: this.playingControl},
           {element: this.loopingControl},
           {element: this.volumeSlider},
-          (next || previous) && {divider: true},
+          {divider: true},
           previous && {label: `Previous (${previous.name})`, action: () => this.backend.playPrevious(playingTrack)},
           next && {label: `Next (${next.name})`, action: () => this.backend.playNext(playingTrack)},
           next && {label: '- Play later', action: () => this.playLater(next)}
@@ -270,7 +271,7 @@ class AppElement extends FocusElement {
 
         return [
           {label: `(Queue - ${curIndex >= 0 ? `${curIndex + 1}/` : ''}${items.length} items.)`},
-          items.length && {divider: true},
+          {divider: true},
           items.length && {label: 'Shuffle', action: () => this.shuffleQueue()},
           items.length && {label: 'Clear', action: () => this.clearQueue()}
         ]
@@ -474,10 +475,18 @@ class AppElement extends FocusElement {
   }
 
   play(item) {
+    if (!this.config.canControlQueue) {
+      return
+    }
+
     this.backend.play(item)
   }
 
   unqueue(item) {
+    if (!this.config.canControlQueue) {
+      return
+    }
+
     let focusItem = this.queueListingElement.currentItem
     focusItem = this.backend.unqueue(item, focusItem)
 
@@ -490,6 +499,10 @@ class AppElement extends FocusElement {
   }
 
   playSooner(item) {
+    if (!this.config.canControlQueue) {
+      return
+    }
+
     this.backend.playSooner(item)
     // It may not have queued as soon as the user wants; in that case, they'll
     // want to queue it sooner again. Automatically reselect the track so that
@@ -498,6 +511,10 @@ class AppElement extends FocusElement {
   }
 
   playLater(item) {
+    if (!this.config.canControlQueue) {
+      return
+    }
+
     this.backend.playLater(item)
     // Just for consistency with playSooner (you can press ^-L to quickly get
     // back to the current track).
@@ -515,16 +532,17 @@ class AppElement extends FocusElement {
 
     const { item, isGroup, isMarked } = el
     const { editMode } = this
+    const { canControlQueue } = this.config
     const anyMarked = editMode && this.markGrouplike.items.length > 0
 
     let items;
     if (listing.grouplike.isTheQueue) {
       items = [
-        {label: 'Reveal', action: () => this.reveal(item)},
+        this.paneLeft.visible && {label: 'Reveal', action: () => this.reveal(item)},
         {divider: true},
-        {label: 'Play later', action: () => this.playLater(item)},
-        {label: 'Play sooner', action: () => this.playSooner(item)},
-        {label: 'Remove from queue', action: () => this.unqueue(item)}
+        canControlQueue && {label: 'Play later', action: () => this.playLater(item)},
+        canControlQueue && {label: 'Play sooner', action: () => this.playSooner(item)},
+        canControlQueue && {label: 'Remove from queue', action: () => this.unqueue(item)}
       ]
     } else {
       items = [
@@ -551,17 +569,17 @@ class AppElement extends FocusElement {
         anyMarked && {label: 'Paste (above)', action: () => el.emit('paste', {where: 'above'})},
         anyMarked && {label: 'Paste (below)', action: () => el.emit('paste', {where: 'below'})},
         // anyMarked && !this.isReal && {label: 'Paste', action: () => this.emit('paste')}, // No "above" or "elow" in the label because the "fake" item/row will be replaced (it'll disappear, since there'll be an item in the group)
-        editMode && {divider: true},
+        {divider: true},
 
-        {element: this.whereControl},
-        isGroup && {element: this.orderControl},
-        {label: 'Play!', action: emitControls(true)},
-        {label: 'Queue!', action: emitControls(false)},
+        canControlQueue && {element: this.whereControl},
+        canControlQueue && isGroup && {element: this.orderControl},
+        canControlQueue && {label: 'Play!', action: emitControls(true)},
+        canControlQueue && {label: 'Queue!', action: emitControls(false)},
         {divider: true},
 
         {label: 'Process metadata (new entries)', action: () => this.processMetadata(item, false)},
         {label: 'Process metadata (reprocess)', action: () => this.processMetadata(item, true)},
-        {label: 'Remove from queue', action: () => this.unqueue(item)}
+        canControlQueue && {label: 'Remove from queue', action: () => this.unqueue(item)}
       ]
     }
 
@@ -2454,13 +2472,25 @@ class ContextMenu extends FocusElement {
     this.y = y
     this.visible = true
 
+    // This code is so that we don't show two dividers beside each other, or
+    // end a menu with a divider!
+    let wantDivider = false
+    const addDividerIfWanted = () => {
+      if (wantDivider) {
+        const element = new HorizontalRule()
+        this.form.addInput(element)
+        wantDivider = false
+      }
+    }
+
     for (const item of items.filter(Boolean)) {
       if (item.element) {
+        addDividerIfWanted()
         this.form.addInput(item.element)
       } else if (item.divider) {
-        const element = new HorizontalRule()
-        this.form.addInput(element)
+        wantDivider = true
       } else {
+        addDividerIfWanted()
         const button = new Button(item.label)
         button.keyboardIdentifier = item.keyboardIdentifier || item.label
         if (item.action) {