Skip to main content

Module commands

Module commands 

Source
Expand description

Commands: every action of the application, named. A menu, a key, the palette, an agent and a test all run the same command by its id, and each run says where it came from.

A CommandSpec is declared once and the rest is derived from it (its key bindings, menu entries, palette entry and agent surface). The registry is generic over the handler type so an upper layer can give handlers whatever context it has; FnHandler is the plain one.

use egui_pop_model::commands::{CommandSpec, Commands, Origin};
use egui_pop_model::ids::{CommandId, OwnerId};
use egui_pop_model::when::WhenContext;
use serde_json::json;

let mut commands = Commands::new();
let id = CommandId::from_static("demo.echo");
commands
    .register_fn(&OwnerId::FRAMEWORK, CommandSpec::new(id.clone(), "Echo", "Demo"), |args, _| {
        Ok(args.clone())
    })
    .unwrap();
let out = commands.run(&id, json!(3), Origin::User, &WhenContext::new());
assert_eq!(out, Ok(json!(3)));

Structs§

ArgMatch
A rule on a call’s arguments: the argument arg equals equals (CommandSpec::destructive_if).
CommandError
Why a command failed, for people and for the record.
CommandSpec
What a command declares.
Commands
The commands, by id, each owned.
Entry
A registered command.
KeySpec
One of a command’s default key bindings: its keys and how it listens (global or on a surface, while typing, through modals).
MenuPlacement
Where a command’s menu entry goes.
Run
One run, as the history keeps it.

Enums§

Origin
Who asked for a command: shown in the history, and used to keep an agent from fighting a human’s gesture.
RegisterError
Why a command could not be registered.
RunRefused
Why a command did not run.

Constants§

HISTORY
How many runs the history keeps.

Type Aliases§

FnHandler
The plain handler: arguments and origin in, a JSON result out.