gui/pkg/contextmenu/platform.go
Snider 94c17b88c2 feat(contextmenu): add contextmenu core.Service with Platform interface and IPC
Completes full Wails v3 Manager API coverage through the IPC bus.
Service maintains in-memory registry, delegates to Platform for native
context menu operations, broadcasts ActionItemClicked on menu item clicks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 14:51:33 +00:00

41 lines
1.8 KiB
Go

// pkg/contextmenu/platform.go
package contextmenu
// Platform abstracts the context menu backend (Wails v3).
// The Add callback must broadcast ActionItemClicked via s.Core().ACTION()
// when a menu item is clicked — the adapter translates MenuItemDef.ActionID
// to a callback that does this.
type Platform interface {
// Add registers a context menu by name.
// The onItemClick callback is called with (menuName, actionID, data)
// when any item in the menu is clicked. The adapter creates per-item
// OnClick handlers that call this with the appropriate ActionID.
Add(name string, menu ContextMenuDef, onItemClick func(menuName, actionID, data string)) error
// Remove unregisters a context menu by name.
Remove(name string) error
// Get returns a context menu definition by name, or false if not found.
Get(name string) (*ContextMenuDef, bool)
// GetAll returns all registered context menu definitions.
GetAll() map[string]ContextMenuDef
}
// ContextMenuDef describes a context menu and its items.
type ContextMenuDef struct {
Name string `json:"name"`
Items []MenuItemDef `json:"items"`
}
// MenuItemDef describes a single item in a context menu.
// Items may be nested (submenu children via Items field).
type MenuItemDef struct {
Label string `json:"label"`
Type string `json:"type,omitempty"` // "" (normal), "separator", "checkbox", "radio", "submenu"
Accelerator string `json:"accelerator,omitempty"`
Enabled *bool `json:"enabled,omitempty"` // nil = true (default)
Checked bool `json:"checked,omitempty"`
ActionID string `json:"actionId,omitempty"` // identifies which item was clicked
Items []MenuItemDef `json:"items,omitempty"` // submenu children (recursive)
}