add ctrl/cmd+F shortcut to focus search entry
This commit is contained in:
@@ -132,6 +132,12 @@ func (a *AlbumsPage) Route() Route {
|
|||||||
return AlbumsRoute(backend.AlbumSortOrder(a.sortOrder.Selected))
|
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)) {
|
func (a *AlbumsPage) SetPlayAlbumCallback(cb func(string, int)) {
|
||||||
a.OnPlayAlbum = cb
|
a.OnPlayAlbum = cb
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ type SavedPage interface {
|
|||||||
Restore() Page
|
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 {
|
type CanPlayAlbum interface {
|
||||||
SetPlayAlbumCallback(func(albumID string, startingTrack int))
|
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))
|
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 {
|
func (b *BrowsingPane) doSetPage(p Page) bool {
|
||||||
if b.curPage != nil && b.curPage.Route() == p.Route() {
|
if b.curPage != nil && b.curPage.Route() == p.Route() {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -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) {
|
func (a *GenrePage) onPlayAlbum(albumID string) {
|
||||||
if a.OnPlayAlbum != nil {
|
if a.OnPlayAlbum != nil {
|
||||||
a.OnPlayAlbum(albumID, 0)
|
a.OnPlayAlbum(albumID, 0)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build darwin
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import "fyne.io/fyne/v2"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ControlModifier = fyne.KeyModifierSuper
|
||||||
|
AltModifier = fyne.KeyModifierSuper
|
||||||
|
)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build !darwin
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import "fyne.io/fyne/v2"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ControlModifier = fyne.KeyModifierControl
|
||||||
|
AltModifier = fyne.KeyModifierAlt
|
||||||
|
)
|
||||||
+10
-13
@@ -1,7 +1,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
"supersonic/res"
|
"supersonic/res"
|
||||||
"supersonic/ui/browsing"
|
"supersonic/ui/browsing"
|
||||||
@@ -15,10 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: fyne.KeyModifierAlt}
|
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: AltModifier}
|
||||||
ShortcutBackDarwin = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: fyne.KeyModifierSuper}
|
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: AltModifier}
|
||||||
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: fyne.KeyModifierAlt}
|
ShortcutSearch = desktop.CustomShortcut{KeyName: fyne.KeyF, Modifier: ControlModifier}
|
||||||
ShortcutForwardDarwin = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: fyne.KeyModifierSuper}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MainWindow struct {
|
type MainWindow struct {
|
||||||
@@ -88,18 +86,17 @@ func (m *MainWindow) addNavigationButtons() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MainWindow) addShortcuts() {
|
func (m *MainWindow) addShortcuts() {
|
||||||
back := &ShortcutBack
|
m.Canvas().AddShortcut(&ShortcutBack, func(_ fyne.Shortcut) {
|
||||||
fwd := &ShortcutForward
|
|
||||||
if runtime.GOOS == "darwin" {
|
|
||||||
back = &ShortcutBackDarwin
|
|
||||||
fwd = &ShortcutForwardDarwin
|
|
||||||
}
|
|
||||||
m.Canvas().AddShortcut(back, func(_ fyne.Shortcut) {
|
|
||||||
m.BrowsingPane.GoBack()
|
m.BrowsingPane.GoBack()
|
||||||
})
|
})
|
||||||
m.Canvas().AddShortcut(fwd, func(_ fyne.Shortcut) {
|
m.Canvas().AddShortcut(&ShortcutForward, func(_ fyne.Shortcut) {
|
||||||
m.BrowsingPane.GoForward()
|
m.BrowsingPane.GoForward()
|
||||||
})
|
})
|
||||||
|
m.Canvas().AddShortcut(&ShortcutSearch, func(_ fyne.Shortcut) {
|
||||||
|
if s := m.BrowsingPane.GetSearchBarIfAny(); s != nil {
|
||||||
|
m.Window.Canvas().Focus(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
m.Canvas().SetOnTypedKey(func(e *fyne.KeyEvent) {
|
m.Canvas().SetOnTypedKey(func(e *fyne.KeyEvent) {
|
||||||
if e.Name == fyne.KeySpace {
|
if e.Name == fyne.KeySpace {
|
||||||
|
|||||||
Reference in New Issue
Block a user