87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package model
|
|
|
|
import (
|
|
"cliamp/theme"
|
|
)
|
|
|
|
// openThemePicker re-loads themes from disk (picking up new user files)
|
|
// and opens the theme selector overlay.
|
|
func (m *Model) openThemePicker() {
|
|
m.themes = theme.LoadAll()
|
|
m.themePicker.visible = true
|
|
m.themePicker.savedIdx = m.themeIdx
|
|
// Position cursor on the currently active theme.
|
|
// Picker list: 0 = Default, 1..N = themes[0..N-1]
|
|
m.themePicker.cursor = m.themeIdx + 1
|
|
}
|
|
|
|
// themePickerApply applies the theme under the cursor for live preview.
|
|
func (m *Model) themePickerApply() {
|
|
if m.themePicker.cursor == 0 {
|
|
m.themeIdx = -1
|
|
applyThemeAll(theme.Default())
|
|
} else {
|
|
m.themeIdx = m.themePicker.cursor - 1
|
|
applyThemeAll(m.themes[m.themeIdx])
|
|
}
|
|
}
|
|
|
|
// themePickerSelect confirms the current selection and closes the picker.
|
|
func (m *Model) themePickerSelect() {
|
|
m.themePickerApply()
|
|
m.themePicker.visible = false
|
|
}
|
|
|
|
// themePickerCancel restores the theme from before the picker was opened.
|
|
func (m *Model) themePickerCancel() {
|
|
m.themeIdx = m.themePicker.savedIdx
|
|
if m.themeIdx < 0 {
|
|
applyThemeAll(theme.Default())
|
|
} else {
|
|
applyThemeAll(m.themes[m.themeIdx])
|
|
}
|
|
m.themePicker.visible = false
|
|
}
|
|
|
|
// openPlaylistManager loads playlist metadata and opens the manager overlay.
|
|
func (m *Model) openPlaylistManager() {
|
|
m.plMgrRefreshList()
|
|
m.plManager.screen = plMgrScreenList
|
|
m.plManager.confirmDel = false
|
|
m.plManager.visible = true
|
|
}
|
|
|
|
// plMgrEnterTrackList loads the tracks for a playlist and switches to screen 1.
|
|
func (m *Model) plMgrEnterTrackList(name string) {
|
|
tracks, err := m.localProvider.Tracks(name)
|
|
if err != nil {
|
|
m.status.Showf(statusTTLDefault, "Load failed: %s", err)
|
|
return
|
|
}
|
|
m.plManager.selPlaylist = name
|
|
m.plManager.tracks = tracks
|
|
m.plManager.screen = plMgrScreenTracks
|
|
m.plManager.cursor = 0
|
|
m.plManager.confirmDel = false
|
|
}
|
|
|
|
// plMgrRefreshList reloads playlist names and counts from disk and clamps the cursor.
|
|
func (m *Model) plMgrRefreshList() {
|
|
if m.localProvider == nil {
|
|
return
|
|
}
|
|
playlists, err := m.localProvider.Playlists()
|
|
if err != nil {
|
|
m.status.Showf(statusTTLDefault, "Load failed: %s", err)
|
|
}
|
|
m.plManager.playlists = playlists
|
|
// +1 for the "+ New Playlist..." entry
|
|
total := len(m.plManager.playlists) + 1
|
|
if m.plManager.cursor >= total {
|
|
m.plManager.cursor = total - 1
|
|
}
|
|
if m.plManager.cursor < 0 {
|
|
m.plManager.cursor = 0
|
|
}
|
|
}
|