command

package
v0.0.0-...-58b9e34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package command shares an action between a toolbar, shortcuts and a native menu.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleShortcuts

func HandleShortcuts(c *ui.Context, commands ...Command) bool

HandleShortcuts runs the first enabled command that matches the current key event. Use it in views where native menu accelerators aren't already handling these commands.

Types

type Command

type Command struct {
	// ID is a stable identifier, unique among the commands in a menu or toolbar.
	ID string
	// Label names the action in buttons and menus.
	Label string
	// Icon is optional artwork for the toolbar button.
	Icon *ui.SVG
	// Shortcut uses Hotkey syntax, such as "mod+shift+i".
	Shortcut string
	// Enabled reports the current availability. Nil enables the action when Execute is set.
	Enabled func() bool
	// Checked makes the command a toggle and reports its current value.
	Checked func() bool
	// Execute performs the action, including updating the value of a toggle.
	Execute func()
}

func (Command) Available

func (cmd Command) Available() bool

Available reports whether the command can run.

func (Command) MenuItem

func (cmd Command) MenuItem() *mygo.MenuItem

MenuItem builds a MyGo native menu item with the same action and shortcut.

func (Command) Run

func (cmd Command) Run() bool

Run invokes the action only when it is currently available.

func (Command) SyncMenuItem

func (cmd Command) SyncMenuItem(item *mygo.MenuItem)

SyncMenuItem updates a menu item after the app changes the command's availability or value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL