HammeriteEditorCommand
Editor. Inherits RefCounted
One thing the editor can be asked to do, and how it is asked.
The point of these existing at all is that a keystroke used to be the only handle on a command: the binding, the label and the code were the same match branch, so nothing could list what the editor could do, show what a key was bound to, or say whether it would work right now.
Properties
| Type | Name | Default |
|---|---|---|
StringName | id | &"" |
String | label | "" |
StringName | menu | &"" |
Shortcut | shortcut | null |
Callable | action | Callable() |
Callable | enabled_predicate | Callable() |
Callable | checked_predicate | Callable() |
StringName | owner_tool | &"" |
bool | before_tool | false |
StringName | radio_group | &"" |
StringName[] | contexts | [] |
Callable | label_provider | Callable() |
StringName | action_id | &"" |
String | keywords | "" |
String | typed | "" |
Methods
Property descriptions
id
var id: StringName = &""
Stable name, for menus and addons to refer to a command by. Not shown to anyone.
label
var label: String = ""
What a menu calls it, drawn as given: pass it already translated (tr("...")), as the editor's own table does.
menu
var menu: StringName = &""
Which menu it belongs under, or empty for a command with a key and no menu entry.
shortcut
var shortcut: Shortcut = null
What it is bound to: every key and click bound_to() and bound_to_mouse() added, the first of them drawn down the menu's right-hand side.
action
var action: Callable = Callable()
What it does.
enabled_predicate
var enabled_predicate: Callable = Callable()
Asked whether it can be done right now: greys the menu item and refuses the keystroke. Unset means always. Ask through is_enabled().
checked_predicate
var checked_predicate: Callable = Callable()
For a toggle, asked whether it is on now; unset means it is not a toggle. Ask through is_checked().
owner_tool
var owner_tool: StringName = &""
Non-empty means the binding belongs to that tool and is never dispatched globally - the tool asks for it by id while it is running. This is how Space can be "toggle selected lights" everywhere and "cycle clip mode" inside the clip tool without the two fighting.
before_tool
var before_tool: bool = false
Runs before the active tool sees the event, rather than after. Narrowing does: it is how you get out of a narrowed view, and a tool holding the keyboard must not be able to trap you in one.
radio_group
var radio_group: StringName = &""
Non-empty makes this one option among several - the visualization modes - drawn as a radio item.
contexts
var contexts: StringName[] = []
Which right-click contexts offer this command, by HammeriteEditorCommands CTX_* name. Empty means the context menu never draws it. A command may name several: mirroring applies to a brush and to an entity alike.
label_provider
var label_provider: Callable = Callable()
Asked what this command calls itself right now, when that depends on state - "Resume Simulation" once something is paused. Unset means label. Ask through current_label().
action_id
var action_id: StringName = &""
The entity action (get_actions()) this command runs, if it runs one. The context menu offers every action the selection has that no command already covers, and this is how it knows which those are - otherwise Trigger is drawn twice, once from the table and once from the entity.
keywords
var keywords: String = ""
Other words an author might look for this command by in the launcher, when theirs is not the label's: "join" for merging.
typed
var typed: String = ""
A character that runs it when typed with no Cmd, Ctrl or Alt held, whatever key the layout puts it on: / is Shift-7 on a Nordic keyboard, and a binding to the slash KEY never fired there.
Method descriptions
in_menu()
func in_menu(m: StringName) -> HammeriteEditorCommand
Files the command under menu m (see the menu names on HammeriteEditorCommands). Like every builder here it returns the command itself, so a table of commands reads as a table rather than as thirty blocks of assignment.
bound_to()
func bound_to(keycode: int, command: bool = false, shift: bool = false, ctrl: bool = false, alt: bool = false) -> HammeriteEditorCommand
Bind a keystroke to it, beside any it has: the numpad's Enter as well as Enter, say. command is Cmd on macOS and Ctrl elsewhere. ctrl is Ctrl on macOS and Alt elsewhere, because there Ctrl is already taken by command and the Windows key is the system's.
bound_also_to()
func bound_also_to(keycode: int, command: bool = false, shift: bool = false, ctrl: bool = false, alt: bool = false) -> HammeriteEditorCommand
The same as bound_to(), for a table that reads better saying so.
bound_to_mouse()
func bound_to_mouse(button: int, command: bool = false, shift: bool = false, ctrl: bool = false, alt: bool = false) -> HammeriteEditorCommand
Bind a click to it, beside any key or click it has: Alt+click and the like. No menu draws these, but they are bindings and they live in the table with the rest rather than in a second place.
is_mac()
static func is_mac() -> bool
Whether the editor is on a Mac, where Cmd is the command key. The web build asks the browser.
command_key_name()
static func command_key_name() -> String
What the command key is called here, for text that names it.
typed_as()
func typed_as(character: String) -> HammeriteEditorCommand
Also run by typing character - see typed.
with_keywords()
func with_keywords(words: String) -> HammeriteEditorCommand
Sets keywords.
is_typed_by()
func is_typed_by(event: InputEvent) -> bool
Whether event types typed.
owned_by()
func owned_by(tool_name: StringName) -> HammeriteEditorCommand
Makes the binding tool_name's alone; see owner_tool. The tool asks for it with HammeriteEditorCommands.matches().
running_before_tools()
func running_before_tools() -> HammeriteEditorCommand
Sets before_tool.
enabled_when()
func enabled_when(predicate: Callable) -> HammeriteEditorCommand
Sets enabled_predicate: predicate takes no arguments and returns a bool.
checked_when()
func checked_when(predicate: Callable) -> HammeriteEditorCommand
Makes this a toggle, ticked while predicate (no arguments, returns a bool) says so.
in_radio_group()
func in_radio_group(group: StringName) -> HammeriteEditorCommand
Sets radio_group. Ticked as checked_when() says, like any toggle.
in_context()
func in_context(names: StringName[]) -> HammeriteEditorCommand
Offer this command when the right-click lands on one of names. See CTX_* on HammeriteEditorCommands.
labelled_by()
func labelled_by(f: Callable) -> HammeriteEditorCommand
Sets label_provider: f takes no arguments and returns the label, or an empty string to fall back on label.
runs_action()
func runs_action(id: StringName) -> HammeriteEditorCommand
Sets action_id.
is_enabled()
func is_enabled() -> bool
Whether it can be run now: asks enabled_predicate, and true when that is unset.
is_toggle()
func is_toggle() -> bool
Whether this is a toggle at all: whether it has a checked_predicate.
is_checked()
func is_checked() -> bool
Whether a toggle is on now: asks checked_predicate, and false when that is unset.
current_label()
func current_label() -> String
What to draw it as. Asked at the moment a menu opens, never cached: a label that depends on state is only true for as long as the state is.
accelerator_text()
func accelerator_text() -> String
The keystroke, as a person would write it. For the menu, and for anything that has to say what a command is bound to without a menu to draw it in.