Skip to content

Commit

Permalink
ensure clicking anywhere outside tracklists can unselect all
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 15, 2024
1 parent 46153f5 commit 1d342bf
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 48 deletions.
8 changes: 5 additions & 3 deletions ui/browsing/albumpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ func (a *AlbumPage) Reload() {
go a.load()
}

func (a *AlbumPage) Tapped(*fyne.PointEvent) {
a.tracklist.UnselectAll()
}
var _ CanSelectAll = (*AlbumPage)(nil)

func (a *AlbumPage) SelectAll() {
a.tracklist.SelectAll()
}

func (a *AlbumPage) UnselectAll() {
a.tracklist.UnselectAll()
}

var _ Scrollable = (*AlbumPage)(nil)

func (a *AlbumPage) Scroll(scrollAmt float32) {
Expand Down
12 changes: 6 additions & 6 deletions ui/browsing/artistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ func newArtistPage(artistID string, cfg *backend.ArtistPageConfig, pool *util.Wi
return a
}

func (a *ArtistPage) Tapped(*fyne.PointEvent) {
if a.tracklistCtr != nil {
a.tracklistCtr.Objects[0].(*widgets.Tracklist).UnselectAll()
}
}

var _ CanSelectAll = (*ArtistPage)(nil)

func (a *ArtistPage) SelectAll() {
Expand All @@ -124,6 +118,12 @@ func (a *ArtistPage) SelectAll() {
}
}

func (a *ArtistPage) UnselectAll() {
if a.tracklistCtr != nil {
a.tracklistCtr.Objects[0].(*widgets.Tracklist).UnselectAll()
}
}

func (a *ArtistPage) Route() controller.Route {
return controller.ArtistRoute(a.artistID)
}
Expand Down
7 changes: 7 additions & 0 deletions ui/browsing/browsingpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Searchable interface {
// Pages with selection should implement this interface to receive Ctrl+A events
type CanSelectAll interface {
SelectAll()
UnselectAll()
}

// Pages that have one main scrollable view should implement this interface
Expand Down Expand Up @@ -199,6 +200,12 @@ func (b *BrowsingPane) SelectAll() {
}
}

func (b *BrowsingPane) UnselectAll() {
if s, ok := b.curPage.(CanSelectAll); ok {
s.UnselectAll()
}
}

func (b *BrowsingPane) ScrollUp() {
b.scrollBy(-75)
}
Expand Down
12 changes: 6 additions & 6 deletions ui/browsing/favoritespage.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ func (a *FavoritesPage) Route() controller.Route {
return controller.FavoritesRoute()
}

func (a *FavoritesPage) Tapped(*fyne.PointEvent) {
if tr := a.tracklistOrNil(); tr != nil {
tr.UnselectAll()
}
}

func (a *FavoritesPage) Reload() {
// reload favorite albums view
if a.searchText != "" {
Expand Down Expand Up @@ -287,6 +281,12 @@ func (a *FavoritesPage) SelectAll() {
}
}

func (a *FavoritesPage) UnselectAll() {
if a.toggleBtns.ActivatedButtonIndex() == 2 /*songs*/ && a.tracklistCtr != nil {
a.tracklistOrNil().UnselectAll() // can't be nil in this case
}
}

func (a *FavoritesPage) Refresh() {
if a.albumGrid != nil {
a.albumGrid.ShowSuffix = a.cfg.ShowAlbumYears
Expand Down
37 changes: 18 additions & 19 deletions ui/browsing/nowplayingpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,31 +470,30 @@ func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64, seeked bool) {
}
}

func (a *NowPlayingPage) currentTracklistOrNil() *widgets.PlayQueueList {
if a.tabs != nil {

switch a.tabs.SelectedIndex() {
case 0: /*queue*/
return a.queueList
case 2: /*related*/
return a.relatedList
}
}
return nil
}

var _ CanSelectAll = (*NowPlayingPage)(nil)

func (a *NowPlayingPage) SelectAll() {
if a.tabs == nil {
return
}
switch a.tabs.SelectedIndex() {
case 0: /*queue*/
a.queueList.SelectAll()
case 2: /*related*/
a.relatedList.SelectAll()
if l := a.currentTracklistOrNil(); l != nil {
l.SelectAll()
}
}

var _ fyne.Tappable = (*NowPlayingPage)(nil)

func (a *NowPlayingPage) Tapped(*fyne.PointEvent) {
if a.tabs == nil {
return
}
switch a.tabs.SelectedIndex() {
case 0: /*queue*/
a.queueList.UnselectAll()
case 2: /*related*/
a.relatedList.UnselectAll()
func (a *NowPlayingPage) UnselectAll() {
if l := a.currentTracklistOrNil(); l != nil {
l.UnselectAll()
}
}

Expand Down
8 changes: 5 additions & 3 deletions ui/browsing/playlistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ func (a *PlaylistPage) Reload() {
go a.load()
}

func (a *PlaylistPage) Tapped(*fyne.PointEvent) {
a.tracklist.UnselectAll()
}
var _ CanSelectAll = (*PlaylistPage)(nil)

func (a *PlaylistPage) SelectAll() {
a.tracklist.SelectAll()
}

func (a *PlaylistPage) UnselectAll() {
a.tracklist.UnselectAll()
}

var _ Scrollable = (*PlaylistPage)(nil)

func (a *PlaylistPage) Scroll(scrollAmt float32) {
Expand Down
16 changes: 16 additions & 0 deletions ui/browsing/trackspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ func (t *TracksPage) Route() controller.Route {
return controller.TracksRoute()
}

var _ CanSelectAll = (*TracksPage)(nil)

func (t *TracksPage) SelectAll() {
// deliberate no-op since we don't want to give the impression
// that you can select all tracks from the server, since only
// some of them are actually loaded into the model
}

func (t *TracksPage) UnselectAll() {
t.currentTracklist().UnselectAll()
}

func (t *TracksPage) Reload() {
t.tracklist.Clear()
iter := t.mp.IterateTracks("")
Expand Down Expand Up @@ -161,6 +173,10 @@ func (t *TracksPage) doSearch(query string) {
t.Refresh()
}

func (t *TracksPage) currentTracklist() *widgets.Tracklist {
return t.container.Objects[0].(*fyne.Container).Objects[0].(*widgets.Tracklist)
}

func (t *TracksPage) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(t.container)
}
Expand Down
30 changes: 22 additions & 8 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ type CurPageFunc func() Route

type Controller struct {
visualizationData
AppVersion string
App *backend.App
MainWindow fyne.Window
NavHandler NavigationHandler
CurPageFunc CurPageFunc
ReloadFunc func()
RefreshPageFunc func()
SelectAllPageFunc func()
AppVersion string
App *backend.App
MainWindow fyne.Window
NavHandler NavigationHandler
CurPageFunc CurPageFunc
ReloadFunc func()
RefreshPageFunc func()
SelectAllPageFunc func()
UnselectAllPageFunc func()

popUpQueueMutex sync.Mutex
popUpQueue *widget.PopUp
Expand Down Expand Up @@ -101,6 +102,19 @@ func (m *Controller) SelectAll() {
}
}

func (m *Controller) UnselectAll() {
m.popUpQueueMutex.Lock()
if m.popUpQueue != nil && m.popUpQueue.Visible() {
m.popUpQueueList.UnselectAll()
m.popUpQueueMutex.Unlock()
return
}
m.popUpQueueMutex.Unlock()
if m.SelectAllPageFunc != nil {
m.UnselectAllPageFunc()
}
}

func (m *Controller) NavigateTo(route Route) {
m.NavHandler(route)
}
Expand Down
31 changes: 28 additions & 3 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type MainWindow struct {
theme *theme.MyTheme
haveSystemTray bool
alreadyConnected bool // tracks if we have already connected to a server before
container *fyne.Container
content *mainWindowContent

// needs to bes shown/hidden when switching between servers based on whether they support radio
radioBtn fyne.CanvasObject
Expand Down Expand Up @@ -68,6 +68,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.Controller.CurPageFunc = m.BrowsingPane.CurrentPage
m.Controller.RefreshPageFunc = m.BrowsingPane.RefreshPage
m.Controller.SelectAllPageFunc = m.BrowsingPane.SelectAll
m.Controller.UnselectAllPageFunc = m.BrowsingPane.UnselectAll

if runtime.GOOS == "darwin" {
// Fyne will extract out an "About" menu item and
Expand Down Expand Up @@ -136,8 +137,9 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.BrowsingPane.DisableNavigationButtons()
m.addShortcuts()

m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas()))
m.content = newMainWindowContent(container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane),
m.Controller.UnselectAll)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.content, m.Window.Canvas()))
m.setInitialSize()
m.Window.SetCloseIntercept(func() {
m.SaveWindowSize()
Expand Down Expand Up @@ -433,3 +435,26 @@ func (m *MainWindow) SaveWindowSize() {
&m.App.Config.Application.WindowWidth,
&m.App.Config.Application.WindowHeight)
}

// widget just so we can catch a tap event that doesn't land anywhere else
// and call BrowsingPane.UnselectAll()
type mainWindowContent struct {
widget.BaseWidget

content fyne.CanvasObject
onTapped func()
}

func newMainWindowContent(content fyne.CanvasObject, onTapped func()) *mainWindowContent {
w := &mainWindowContent{content: content, onTapped: onTapped}
w.ExtendBaseWidget(w)
return w
}

func (m *mainWindowContent) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(m.content)
}

func (m *mainWindowContent) Tapped(*fyne.PointEvent) {
m.onTapped()
}

0 comments on commit 1d342bf

Please sign in to comment.