add ctrl/cmd+F shortcut to focus search entry

This commit is contained in:
Drew Weymouth
2023-01-19 18:15:37 -08:00
parent e04b4d1902
commit 85548a0d84
6 changed files with 54 additions and 13 deletions
+6
View File
@@ -132,6 +132,12 @@ func (a *AlbumsPage) Route() Route {
return AlbumsRoute(backend.AlbumSortOrder(a.sortOrder.Selected))
}
var _ Searchable = (*AlbumsPage)(nil)
func (a *AlbumsPage) SearchWidget() fyne.Focusable {
return a.searcher.Entry
}
func (a *AlbumsPage) SetPlayAlbumCallback(cb func(string, int)) {
a.OnPlayAlbum = cb
}
+12
View File
@@ -26,6 +26,11 @@ type SavedPage interface {
Restore() Page
}
// Searchable pages should implement this interface so their search bar can be focused by keyboard shortcut.
type Searchable interface {
SearchWidget() fyne.Focusable
}
type CanPlayAlbum interface {
SetPlayAlbumCallback(func(albumID string, startingTrack int))
}
@@ -81,6 +86,13 @@ func (b *BrowsingPane) AddNavigationButton(iconRes fyne.Resource, action func())
b.navBtnsContainer.Add(widget.NewButtonWithIcon("", iconRes, action))
}
func (b *BrowsingPane) GetSearchBarIfAny() fyne.Focusable {
if s, ok := b.curPage.(Searchable); ok {
return s.SearchWidget()
}
return nil
}
func (b *BrowsingPane) doSetPage(p Page) bool {
if b.curPage != nil && b.curPage.Route() == p.Route() {
return false
+6
View File
@@ -119,6 +119,12 @@ func (g *GenrePage) Save() SavedPage {
}
}
var _ Searchable = (*AlbumsPage)(nil)
func (g *GenrePage) SearchWidget() fyne.Focusable {
return g.searcher.Entry
}
func (a *GenrePage) onPlayAlbum(albumID string) {
if a.OnPlayAlbum != nil {
a.OnPlayAlbum(albumID, 0)