« get me outta code hell

Hook menu up to grouplike listing items - 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>2018-07-25 13:26:14 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-25 13:26:14 -0300
commit2d6eb315c47ea5064b8ec93b98ecba4f5da75852 (patch)
tree54a4a1518c28dab527b4dd27b928556400a8e9f3
parent22af200d04d7f3b5fbfec2a61e6a272f0476e2af (diff)
Hook menu up to grouplike listing items
-rw-r--r--todo.txt4
-rw-r--r--ui.js27
2 files changed, 19 insertions, 12 deletions
diff --git a/todo.txt b/todo.txt
index c042e74..0227763 100644
--- a/todo.txt
+++ b/todo.txt
@@ -89,3 +89,7 @@ TODO: At some point, putting mtui downloads in ~/.mtui - but preferrably with
       a more humanish structure - would be quite nice..!
 
 TODO: Press "M" to show a context menu.
+
+TODO: Figure out a keybinding for Mark (in edit mode) - probably Ctrl-M.
+      (I prefer Ctrl to be used for functions that will open a dialog of some
+      sort, though..)
diff --git a/ui.js b/ui.js
index 7dbb05b..afb2731 100644
--- a/ui.js
+++ b/ui.js
@@ -123,6 +123,7 @@ class AppElement extends FocusElement {
     grouplikeListing.on('queue', item => this.queueGrouplikeItem(item))
     grouplikeListing.on('queue (shuffled)', item => this.shuffleQueueGrouplikeItem(item))
     grouplikeListing.on('queue (play next)', item => this.queueGrouplikeItem(item, true, this.playingTrack))
+    grouplikeListing.on('menu', (item, opts) => this.menu.show(opts))
 
     const updateListingsFor = item => {
       for (const grouplikeListing of this.tabber.tabberElements) {
@@ -358,16 +359,6 @@ class AppElement extends FocusElement {
       this.tabber.nextTab()
     } else if (this.tabber.isSelected && keyBuf.equals(Buffer.from(['T'.charCodeAt(0)]))) {
       this.tabber.previousTab()
-    } else if (telc.isCharacter(keyBuf, 'm')) {
-      this.menu.show({
-        x: this.w - 10, y: this.h + 30,
-        items: [
-          'Nice.',
-          'Oh yeah.',
-          'Ooooh yeah.',
-          'N' + 'i'.repeat(200) + 'ce.'
-        ]
-      })
     } else {
       super.keyPressed(keyBuf)
     }
@@ -780,8 +771,8 @@ 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)', 'mark', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) {
-          itemElement.on(evtName, () => this.emit(evtName, item))
+        for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)', 'menu']) {
+          itemElement.on(evtName, (...data) => this.emit(evtName, item, ...data))
         }
         form.addInput(itemElement)
       }
@@ -964,8 +955,20 @@ class GrouplikeItemElement extends Button {
       this.emit('remove (backspace)')
     } else if (telc.isCaselessLetter(keyBuf, 'x')) {
       this.emit('remove (x)')
+    /*
     } else if (telc.isCaselessLetter(keyBuf, 'm')) {
       this.emit('mark')
+    */
+    } else if (telc.isCaselessLetter(keyBuf, 'm')) {
+      this.emit('menu', {
+        x: this.absLeft,
+        y: this.absTop + 1,
+        items: [
+          'Play',
+          'Play next',
+          'Play at end',
+        ]
+      })
     }
   }
 }