Make open_entry global

This commit is contained in:
aditya-K2
2023-05-02 00:34:00 +05:30
parent 44968982fc
commit 4cde2d1e4c
3 changed files with 11 additions and 56 deletions

View File

@@ -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": {},
}
)

View File

@@ -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

View File

@@ -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) {