mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 07:52:12 +08:00
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package application
|
|
|
|
type Context struct {
|
|
// contains filtered or unexported fields
|
|
data map[string]any
|
|
}
|
|
|
|
func newContext() *Context {
|
|
return &Context{
|
|
data: make(map[string]any),
|
|
}
|
|
}
|
|
|
|
const (
|
|
clickedMenuItem string = "clickedMenuItem"
|
|
menuItemIsChecked string = "menuItemIsChecked"
|
|
contextMenuData string = "contextMenuData"
|
|
)
|
|
|
|
func (c *Context) ClickedMenuItem() *MenuItem {
|
|
result, exists := c.data[clickedMenuItem]
|
|
if !exists {
|
|
return nil
|
|
}
|
|
return result.(*MenuItem)
|
|
}
|
|
|
|
func (c *Context) IsChecked() bool {
|
|
result, exists := c.data[menuItemIsChecked]
|
|
if !exists {
|
|
return false
|
|
}
|
|
return result.(bool)
|
|
}
|
|
func (c *Context) ContextMenuData() any {
|
|
return c.data[contextMenuData]
|
|
}
|
|
|
|
func (c *Context) withClickedMenuItem(menuItem *MenuItem) *Context {
|
|
c.data[clickedMenuItem] = menuItem
|
|
return c
|
|
}
|
|
|
|
func (c *Context) withChecked(checked bool) {
|
|
c.data[menuItemIsChecked] = checked
|
|
}
|
|
|
|
func (c *Context) withContextMenuData(data *ContextMenuData) *Context {
|
|
if data == nil {
|
|
return c
|
|
}
|
|
c.data[contextMenuData] = data.Data
|
|
return c
|
|
}
|