gui/stubs/wails/pkg/application/keybinding.go
Claude d9fa59ab04
Some checks failed
Security Scan / security (push) Failing after 24s
feat(stubs): rebuild Wails v3 stub bridge from clean dev — 15 files, 479 exports
Rebuilt from scratch on current dev (post-fleet AX passes).

Stub files:
- application.go (expanded App with 12 managers, WebviewWindow satisfies Window)
- application_options.go (Options, Mac/Win/Linux/iOS/Android, Server, TLS, Assets)
- browser_manager.go, browser_window.go (~47 no-op methods)
- clipboard.go, context_menu.go, dialog.go (full dialog builder API)
- environment.go, events.go (EventManager with On/Off/Emit/Reset)
- keybinding.go, menuitem.go (42 Role constants)
- screen.go (Rect/Point/Size geometry), services.go (generic Service[T])
- webview_window_options.go (full platform types)
- window.go (Window interface ~50 methods)

Wails v3 submodule at internal/wails3/ pinned to alpha 74.
All 16 gui packages build and test clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 17:20:22 +01:00

69 lines
2 KiB
Go

package application
import "sync"
// KeyBinding pairs an accelerator string with its callback.
// binding := &KeyBinding{Accelerator: "Ctrl+K", Callback: fn}
type KeyBinding struct {
Accelerator string
Callback func(window Window)
}
// KeyBindingManager holds all registered global key bindings in memory.
// manager.Add("Ctrl+K", fn) — manager.Remove("Ctrl+K") — manager.GetAll()
type KeyBindingManager struct {
mu sync.RWMutex
bindings map[string]func(window Window)
}
// NewKeyBindingManager constructs an empty KeyBindingManager.
// manager := NewKeyBindingManager()
func NewKeyBindingManager() *KeyBindingManager {
return &KeyBindingManager{
bindings: make(map[string]func(window Window)),
}
}
// Add registers a callback for the given accelerator string.
// manager.Add("Ctrl+Shift+P", func(w Window) { w.Focus() })
func (m *KeyBindingManager) Add(accelerator string, callback func(window Window)) {
m.mu.Lock()
m.bindings[accelerator] = callback
m.mu.Unlock()
}
// Remove deletes the binding for the given accelerator.
// manager.Remove("Ctrl+Shift+P")
func (m *KeyBindingManager) Remove(accelerator string) {
m.mu.Lock()
delete(m.bindings, accelerator)
m.mu.Unlock()
}
// Process fires the callback for accelerator if registered, returning true when handled.
// handled := manager.Process("Ctrl+K", window)
func (m *KeyBindingManager) Process(accelerator string, window Window) bool {
m.mu.RLock()
callback, exists := m.bindings[accelerator]
m.mu.RUnlock()
if exists && callback != nil {
callback(window)
return true
}
return false
}
// GetAll returns a snapshot of all registered bindings.
// for _, b := range manager.GetAll() { fmt.Println(b.Accelerator) }
func (m *KeyBindingManager) GetAll() []*KeyBinding {
m.mu.RLock()
defer m.mu.RUnlock()
result := make([]*KeyBinding, 0, len(m.bindings))
for accelerator, callback := range m.bindings {
result = append(result, &KeyBinding{
Accelerator: accelerator,
Callback: callback,
})
}
return result
}