#[non_exhaustive]pub struct CommandSpec {Show 19 fields
pub id: CommandId,
pub title: String,
pub category: String,
pub description: String,
pub when: String,
pub checked: String,
pub keys: Vec<KeySpec>,
pub menus: Vec<MenuPlacement>,
pub palette: bool,
pub agent: bool,
pub read_only: bool,
pub destructive: bool,
pub destructive_if: Vec<ArgMatch>,
pub private: bool,
pub args: Value,
pub icon: Option<String>,
pub icon_on: Option<String>,
pub menu_note: Option<String>,
pub opens_link: bool,
}Expand description
What a command declares.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: CommandIdStable, never translated: view.palette.
title: String§category: String§description: StringWhat it does, for the palette and agents.
when: StringWhere the command applies; empty: everywhere.
checked: StringWhen its menu entries show ticked (a toggle that is on, the theme in use); empty: never.
keys: Vec<KeySpec>Its default key bindings (Ctrl+K, Ctrl+K Ctrl+S).
Its menu entries.
palette: boolListed in the command palette.
agent: boolOffered to agents through the debug bridge.
read_only: boolIt only reads: running it changes nothing in the application
(about.read, value.get). The debug bridge reports it
(commands.run does not mutate then) and a read-only bridge runs
only these.
destructive: boolIt destroys or discards what cannot easily be had back (deletes files, empties a trash, drops unsaved work). Asked by anyone but the user (an agent), it waits for the user to confirm it first: the agent socket asks, through a dialog. The user’s own runs are never asked.
destructive_if: Vec<ArgMatch>The calls that are destructive by their arguments, when the
command is not destructive whole: a run whose arguments match one
of these (CommandSpec::destructive_if) is asked about as a
destructive command’s is; the others run at once. An export that
only overwrites with clash: "overwrite" says so here.
private: boolIts result carries the user’s private data: places (GPS), people
(faces, names), absolute file paths. An agent whose grant
withholds private data is refused it (the agent socket’s
Grant::private); the user’s own runs are never held.
args: ValueIts arguments: a JSON Schema (CommandSpec::schema), or a free
description (an example, a text); null when it takes none. A
schema (an object of schema keywords naming a type, see
egui_pop_core::debug::is_schema) is enforced: a run whose
arguments do not match is refused before its handler, whoever
asks it (command.refused, by: "pop.command.args"). A free
description checks nothing.
icon: Option<String>Its icon’s name (save, phosphor:export, my-plugin:crop):
every surface running the command shows it. Checked against the
icon vocabulary when the application resolves its declarations.
icon_on: Option<String>The icon shown instead while checked holds (eye-off for a
toggle whose icon is the eye).
A note at the end of its menu entries, muted, in the keys’ column (a version, “sessions kept”); its keys, if any, come first.
opens_link: boolIt opens a page outside the application: its menu entries end with ↗.
Implementations§
Source§impl CommandSpec
impl CommandSpec
pub fn new(id: CommandId, title: &str, category: &str) -> Self
Sourcepub fn icon(self, name: &str) -> Self
pub fn icon(self, name: &str) -> Self
Its icon, by name: egui-pop’s (save), a Phosphor glyph’s
(phosphor:export) or a registered one (my-plugin:crop).
Declared once, shown by every surface running the command.
Sourcepub fn icon_on(self, name: &str) -> Self
pub fn icon_on(self, name: &str) -> Self
The icon shown while its checked clause holds, by name.
A note at the end of its menu entries (CommandSpec::menu_note).
Sourcepub fn opens_link(self, link: bool) -> Self
pub fn opens_link(self, link: bool) -> Self
Its menu entries end with ↗: it opens a page outside the
application (CommandSpec::opens_link).
Sourcepub fn icon_for(&self, checked: bool) -> Option<&str>
pub fn icon_for(&self, checked: bool) -> Option<&str>
The icon’s name to show: icon_on while checked (when declared),
else icon.
pub fn when(self, when: &str) -> Self
pub fn description(self, text: &str) -> Self
Sourcepub fn key(self, keys: &str) -> Self
pub fn key(self, keys: &str) -> Self
Adds a default global key binding (a text input keeps plain
keys, see keymap::Typing).
Sourcepub fn key_with(self, keys: &str, options: BindOptions) -> Self
pub fn key_with(self, keys: &str, options: BindOptions) -> Self
Adds a default key binding listening as options say: on a
surface, while typing, through modals.
Adds a menu entry.
Kept out of the palette.
Sourcepub fn read_only(self) -> Self
pub fn read_only(self) -> Self
It only reads: running it changes nothing in the application (no value, file, window or state of any kind). Say it only when true: a read-only debug bridge runs these and refuses the others.
Sourcepub fn destructive(self) -> Self
pub fn destructive(self) -> Self
It destroys or discards what cannot easily be had back
(CommandSpec::destructive): an agent’s run waits for the
user’s confirmation.
Sourcepub fn destructive_if(self, arg: &str, value: Json) -> Self
pub fn destructive_if(self, arg: &str, value: Json) -> Self
A call whose argument arg equals value is destructive
(CommandSpec::destructive_if): an agent’s run with it waits
for the user’s confirmation, other runs do not. arg is a
top-level argument’s name, or a JSON Pointer (/options/clash).
Several rules: any one matching makes the call destructive.
CommandSpec::destructive still makes every call destructive.
Sourcepub fn is_destructive(&self, args: &Json) -> bool
pub fn is_destructive(&self, args: &Json) -> bool
Whether a call with args is destructive: the command is
(CommandSpec::destructive), or its arguments match one of
CommandSpec::destructive_if.
Sourcepub fn private(self) -> Self
pub fn private(self) -> Self
Its result carries private data (CommandSpec::private): an
agent whose grant withholds private data is refused it. A command
whose result only partly is private may instead leave the private
parts out for such an agent (the agent socket’s
grants::reads_private).
Sourcepub fn args(self, args: Json) -> Self
pub fn args(self, args: Json) -> Self
Describes the arguments (CommandSpec::args): a JSON Schema is
enforced, a free description (an example) only shown.
Sourcepub fn schema(self, schema: Json) -> Self
pub fn schema(self, schema: Json) -> Self
Its arguments’ JSON Schema, enforced before every run: arguments
that do not match are refused before the handler runs
(command.refused, by: "pop.command.args"). The checked subset
is egui_pop_core::schema’s (types, required, enum, ranges,
lengths, items, additionalProperties, combinators). null
arguments are checked as {} when the schema is an object’s. The
same as CommandSpec::args, said for what it is.
Trait Implementations§
Source§impl Clone for CommandSpec
impl Clone for CommandSpec
Source§fn clone(&self) -> CommandSpec
fn clone(&self) -> CommandSpec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more