Commands
All custom controls, windows (including modal windows), and the desktop support a set of commands that are associated with their functionality.
To define such commands, use the commands attribute when defining a window, modal window, desktop, or custom control:
#[Window(commands = <list of commands>)]
The list of commands can be added in two ways:
- use
[command1, command2, ... command-n]format - use
command1+command2+...command-nformat
Example
#[Window(commands = [Save, Load, New])]
and
#[Window(commands = Save+Load+New)]
are identical and create three commands that are supported by the new window (Save, Load, and New).
Enum
Including a command attribute implicitly generates an enum within a module. The module's name is derived from the desktop, window, or custom control for which the commands are created, using its name in lowercase.
For example, the following definition:
#[Window(commands = Save+Load+New)]
struct MyWindow { /* data members */ }
will create the following:
mod mywindow {
#[repr(u32)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Commands {
Save = 0,
Load = 1,
New = 2,
}
}
Notice that the module name mywindow is the lowercase name of the window MyWindow.
You can further use these commands for menus or the command bar (via mywindow::Commands::Save, mywindow::Commands::Load, and so on).
You can also use them for parameter cmd in the macro definition for menus or menu items. If the macro parameter defines the name of the class via the parameter class (e.g. class = MyWindow) you don't have to write the full qualifier in the macro, you can write the name of the command alone.
For example, the following are equivalent:
cmd="mywin::Commands::Save"
and
cmd="Save", class="MyWin"