Some checks failed
Security Scan / security (push) Failing after 24s
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>
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package application
|
|
|
|
import "sync"
|
|
|
|
// ContextMenu is a named Menu used as a right-click context menu.
|
|
//
|
|
// cm := manager.New()
|
|
// cm.Add("Cut").OnClick(func(*Context) { ... })
|
|
type ContextMenu struct {
|
|
*Menu
|
|
name string
|
|
}
|
|
|
|
// ContextMenuManager manages named context menus for the application.
|
|
//
|
|
// manager.Add("fileList", cm)
|
|
// menu, ok := manager.Get("fileList")
|
|
type ContextMenuManager struct {
|
|
mu sync.RWMutex
|
|
menus map[string]*ContextMenu
|
|
}
|
|
|
|
// New creates an empty, unnamed ContextMenu ready for population.
|
|
//
|
|
// cm := manager.New()
|
|
// cm.Add("Open")
|
|
func (cmm *ContextMenuManager) New() *ContextMenu {
|
|
return &ContextMenu{Menu: NewMenu()}
|
|
}
|
|
|
|
// Add registers a ContextMenu under the given name, replacing any existing entry.
|
|
//
|
|
// manager.Add("fileList", cm)
|
|
func (cmm *ContextMenuManager) Add(name string, menu *ContextMenu) {
|
|
cmm.mu.Lock()
|
|
defer cmm.mu.Unlock()
|
|
if cmm.menus == nil {
|
|
cmm.menus = make(map[string]*ContextMenu)
|
|
}
|
|
cmm.menus[name] = menu
|
|
}
|
|
|
|
// Remove unregisters the context menu with the given name.
|
|
//
|
|
// manager.Remove("fileList")
|
|
func (cmm *ContextMenuManager) Remove(name string) {
|
|
cmm.mu.Lock()
|
|
defer cmm.mu.Unlock()
|
|
delete(cmm.menus, name)
|
|
}
|
|
|
|
// Get retrieves a registered context menu by name.
|
|
//
|
|
// menu, ok := manager.Get("fileList")
|
|
func (cmm *ContextMenuManager) Get(name string) (*ContextMenu, bool) {
|
|
cmm.mu.RLock()
|
|
defer cmm.mu.RUnlock()
|
|
menu, exists := cmm.menus[name]
|
|
return menu, exists
|
|
}
|
|
|
|
// GetAll returns all registered context menus as a slice.
|
|
//
|
|
// for _, cm := range manager.GetAll() { ... }
|
|
func (cmm *ContextMenuManager) GetAll() []*ContextMenu {
|
|
cmm.mu.RLock()
|
|
defer cmm.mu.RUnlock()
|
|
result := make([]*ContextMenu, 0, len(cmm.menus))
|
|
for _, menu := range cmm.menus {
|
|
result = append(result, menu)
|
|
}
|
|
return result
|
|
}
|