« get me outta code hell

^E to edit notes of selected track/group - 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-10-28 20:32:51 -0300
committerFlorrie <towerofnix@gmail.com>2019-10-28 20:32:51 -0300
commit8aaaf17fab07c215007aff475fc6a9b8e079dfe1 (patch)
tree3684463bf476f147a01a8a209a93b5f51fda8388
parentda6c99a2a52c46bf547c64ff90a3afb8196a5324 (diff)
^E to edit notes of selected track/group
-rw-r--r--README.md1
-rw-r--r--todo.txt2
-rw-r--r--ui.js28
3 files changed, 26 insertions, 5 deletions
diff --git a/README.md b/README.md
index 8360989..5161077 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,7 @@ You're also welcome to share any ideas, suggestions, and questions through there
 * t, T: switch between playlist tabs
 * Ctrl+T: open the current playlist in a new tab (so, clone the current tab)
 * Ctrl+W: close the current tab
+* Ctrl+E: edit the notes of the selected track/group
 * Meta+c: create a new music player (for listening to multiple tracks at once, or swapping between two tracks without losing playback position)
 * Meta+Up/Down, Meta+p/n: select the previous/next music player (each player has its own independent queue, pause status, etc)
 * Meta+a, Meta+!: mark the selected music player so that any keyboard actions - seeking, pausing, etc - apply to it and any other marked players (if no player is marked, which is the default case, actions will apply to the selected music player)
diff --git a/todo.txt b/todo.txt
index f56bd7a..e0531f0 100644
--- a/todo.txt
+++ b/todo.txt
@@ -455,3 +455,5 @@ TODO: I lied when I said I finished text editor stuff. Still to-do:
 TODO: Have a context menu option for creating a text file for notes on a
       playable, when there is no existing adjacent file.
       (Done!)
+
+TODO: Delete notes files which are totally empty (or just a single line break).
diff --git a/ui.js b/ui.js
index 66a7745..3753ff0 100644
--- a/ui.js
+++ b/ui.js
@@ -110,6 +110,7 @@ const keyBindings = [
   ['isActOnPlayer', [0x1b, 'a']],
   ['isActOnPlayer', [0x1b, '!']],
 
+  ['isFocusTextEditor', [0x05]], // ^E
   ['isSaveTextEditor', [0x13]], // ^S
   ['isDeselectTextEditor', [0x18]], // ^X
   ['isDeselectTextEditor', telc.isEscape],
@@ -703,6 +704,10 @@ class AppElement extends FocusElement {
     grouplikeListing.pathElement.on('select', item => this.reveal(item))
     grouplikeListing.on('menu', (item, el) => this.showMenuForItemElement(el, grouplikeListing))
     grouplikeListing.on('selected', item => this.editNotesFile(item, false))
+    grouplikeListing.on('edit-notes', item => {
+      this.reveal(item)
+      this.editNotesFile(item, true)
+    })
   }
 
   showContextMenu(opts) {
@@ -832,6 +837,10 @@ class AppElement extends FocusElement {
       return
     }
 
+    if (getCorrespondingFileForItem(item, '.txt')) {
+      return
+    }
+
     let itemPath
     try {
       itemPath = url.fileURLToPath(item.url)
@@ -850,7 +859,6 @@ class AppElement extends FocusElement {
 
     const { items } = item[parentSymbol]
     items.splice(items.indexOf(item), 0, file)
-    await this.editNotesFile(item, true)
   }
 
   async editNotesFile(item, focus) {
@@ -858,6 +866,14 @@ class AppElement extends FocusElement {
       return
     }
 
+    // Creates it, if it doesn't exist.
+    // We only do this when we're manually selecting the file (and expect to
+    // focus it). Otherwise we'd create a notes file for every track hovered
+    // over!
+    if (focus) {
+      await this.createNotesFile(item)
+    }
+
     const doubleCheckItem = () => item === this.tabber.currentElement.currentItem
 
     const status = await this.textEditor.openItem(item, {doubleCheckItem})
@@ -1012,7 +1028,7 @@ class AppElement extends FocusElement {
         canProcessMetadata && isTrack(item) && {label: 'Process metadata', action: () => this.processMetadata(item, true)},
         isOpenable(item) && item.url.endsWith('.json') && {label: 'Open (JSON Playlist)', action: () => this.openSpecialOrThroughSystem(item)},
         isOpenable(item) && {label: 'Open (System)', action: () => this.openThroughSystem(item)},
-        !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.createNotesFile(item)},
+        !hasNotesFile && isPlayable(item) && {label: 'Create notes file', action: () => this.editNotesFile(item, true)},
         hasNotesFile && isPlayable(item) && {label: 'Edit notes file', action: () => this.editNotesFile(item, true)},
         canControlQueue && isPlayable(item) && {label: 'Remove from queue', action: () => this.unqueue(item)},
         {divider: true},
@@ -1155,6 +1171,7 @@ class AppElement extends FocusElement {
         this.textInfoPane.h = 8
       } else {
         this.textEditor.w = this.textInfoPane.contentW
+        this.textEditor.rebuildUiLines()
         this.textInfoPane.h = Math.min(8, this.textEditor.getOptimalHeight() + 2)
       }
 
@@ -1295,8 +1312,6 @@ class AppElement extends FocusElement {
         }
         this.menubar.select()
       }
-    } else if (keyBuf.equals(Buffer.from([5]))) { // Ctrl-E
-      this.editMode = !this.editMode
     } else if (this.editMode && keyBuf.equals(Buffer.from([14]))) { // ctrl-N
       this.newEmptyTab()
     } else if (keyBuf.equals(Buffer.from([15]))) { // ctrl-O
@@ -1760,10 +1775,11 @@ class GrouplikeListingElement extends Form {
     for (const evtName of [
       'browse',
       'download',
-      'paste',
+      'edit-notes',
       'mark',
       'menu',
       'open',
+      'paste',
       'queue',
       'remove',
       'unqueue'
@@ -2688,6 +2704,8 @@ class InteractiveGrouplikeItemElement extends BasicGrouplikeItemElement {
       this.emit('remove')
     } else if (input.isMenu(keyBuf)) {
       this.emit('menu', this)
+    } else if (input.isFocusTextEditor(keyBuf)) {
+      this.emit('edit-notes')
     } else if (input.isFocusLabels(keyBuf)) {
       this.labelsSelected = true
       this.expandLabels = true