From 4cde2d1e4cbf9abb52e9ef36b9503db2c428773a Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Tue, 2 May 2023 00:34:00 +0530 Subject: [PATCH] Make open_entry global --- config/key.go | 25 ++++++------------------- ui/app.go | 41 ++++------------------------------------- ui/view.go | 1 + 3 files changed, 11 insertions(+), 56 deletions(-) diff --git a/config/key.go b/config/key.go index ad3c0d8..7034afe 100644 --- a/config/key.go +++ b/config/key.go @@ -13,21 +13,14 @@ var ( DefaultMappings = map[string]map[string]map[Key]string{ "recently_played_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", - {R: 'a'}: "add_to_playlist", + {R: 'a'}: "add_to_playlist", }, "visual": { {R: 'a'}: "add_to_playlist", }, }, - "nav_menu": { - "normal": { - {K: tcell.KeyEnter}: "open_entry", - }, - }, "search_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", }, }, @@ -44,18 +37,17 @@ var ( {R: 'n'}: "next", {R: 'p'}: "previous", {K: tcell.KeyCtrlO}: "open_current_context", + {K: tcell.KeyEnter}: "open_entry", }, }, "playlist_nav": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", }, }, "playlist_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", - {R: 'a'}: "add_to_playlist", + {R: 'a'}: "add_to_playlist", }, "visual": { {R: 'a'}: "add_to_playlist", @@ -63,14 +55,12 @@ var ( }, "top_tracks_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", }, }, "liked_songs_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", - {R: 'a'}: "add_to_playlist", + {R: 'a'}: "add_to_playlist", }, "visual": { {R: 'a'}: "add_to_playlist", @@ -78,32 +68,29 @@ var ( }, "artists_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", }, }, "artist_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", }, }, "albums_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", {K: tcell.KeyCtrlP}: "play_entry", {R: 'q'}: "queue_entry", }, }, "album_view": { "normal": { - {K: tcell.KeyEnter}: "open_entry", - {R: 'a'}: "add_to_playlist", + {R: 'a'}: "add_to_playlist", }, "visual": { {R: 'a'}: "add_to_playlist", }, }, + "nav_menu": {}, } ) diff --git a/ui/app.go b/ui/app.go index c924c63..b675ab9 100644 --- a/ui/app.go +++ b/ui/app.go @@ -127,6 +127,10 @@ func NewApplication() *tview.Application { // Define Actions globalActions := map[string]*Action{ + "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { + GetCurrentView().OpenEntry() + return nil + }, progressBar), "focus_search": NewAction(func(e *tcell.EventKey) *tcell.EventKey { App.SetFocus(searchbar) return nil @@ -227,81 +231,48 @@ func NewApplication() *tview.Application { nil), })) playlistView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(*tcell.EventKey) *tcell.EventKey { - playlistView.OpenEntry() - return nil - }, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { playlistView.AddToPlaylist() return nil }, nil), })) recentlyPlayedView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(*tcell.EventKey) *tcell.EventKey { - recentlyPlayedView.OpenEntry() - return nil - }, - progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { recentlyPlayedView.AddToPlaylist() return nil }, nil), })) topTracksView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - topTracksView.OpenEntry() - return nil - }, progressBar), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { topTracksView.PlaySelectedEntry() return nil }, progressBar), })) likedSongsView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - likedSongsView.OpenEntry() - return nil - }, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { likedSongsView.AddToPlaylist() return nil }, nil), })) searchView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - searchView.OpenEntry() - return nil - }, nil), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { searchView.PlayEntry() return nil }, progressBar), })) artistsView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - artistsView.OpenEntry() - return nil - }, nil), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { artistsView.PlayEntry() return nil }, nil), })) artistView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - artistView.OpenEntry() - return nil - }, progressBar), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { artistView.PlayEntry() return nil }, progressBar), })) albumsView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - albumsView.OpenEntry() - return nil - }, nil), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { albumsView.PlayEntry() return nil @@ -312,10 +283,6 @@ func NewApplication() *tview.Application { }, progressBar), })) albumView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - albumView.OpenEntry() - return nil - }, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { albumView.AddToPlaylist() return nil diff --git a/ui/view.go b/ui/view.go index d2a78b1..90797cb 100644 --- a/ui/view.go +++ b/ui/view.go @@ -21,6 +21,7 @@ type View interface { ExternalInputCapture() func(e *tcell.EventKey) *tcell.EventKey VisualCapture() func(start, end int, e *tcell.EventKey) *tcell.EventKey Name() string + OpenEntry() } func SetCurrentView(v View) {