Expand description
The history’s projection (ADR 0014): the History panel and the
history.* commands agents drive it with, brought by
HistoryPlugin.
Experimental: may change in any release
(docs/stability.md).
- The panel (
PANEL_HISTORY, closed until asked for;showdraws it anywhere): the scopes there are, as chips (the one Ctrl+Z goes to first), then the chosen scope’s steps, oldest first, under a “Start” row. The head is the selected row; the steps a redo would make again are muted under it. A click on a row jumps there (edit.jump, vetoable like an undo); a step made by an agent, a script or another process says so after its label. When the owner supports them: the snapshots above the steps (a click restores one), a hover previewing a row, “Undo this step” in a step’s context menu, and the replaced steps behind a toggle. - The commands (agents and scripts; kept out of the palette,
where Edit > Undo and Redo already are):
history.list(every scope, whether it is active, where Undo and Redo go and what they would do),history.read(a scope’s steps),history.undo,history.redo,history.jump,history.snapshot,history.restore,history.drop_snapshotandhistory.undo_step, each withscope(none: where the keys go),if_revanddry_run. They run through the same steps as the keys, so a hook vetoing an undo vetoes an agent’s too, and in the interface, not through the host’s dispatch (which would hold the host, and with it the history owner).
use egui_pop_api::App;
use egui_pop_api::history_view::HistoryPlugin;
use egui_pop_core::lock;
use egui_pop_model::commands::Origin;
use egui_pop_model::ids::{CommandId, OwnerId};
use egui_pop_model::values::{Change, Descriptor, Set, Value};
use serde_json::json;
let mut app = App::builder().plugin(HistoryPlugin::default())
.build(&egui::Context::default()).unwrap();
let store = app.handle().store();
// The agent may write `doc/n`: it may then undo (and dry-run) its steps.
let agent = Origin::Agent("a".into());
let n = Descriptor::int("N", 0, 9, 0).writers(&[agent.writer()]);
lock(&store).declare(&OwnerId::USER, "doc/n", n).unwrap();
lock(&store).set(Set::new("doc/n", Change::To(Value::Int(3)), Origin::User)).unwrap();
let read = app
.run(&CommandId::from_static("history.read"), json!({ "scope": "app" }), Origin::Agent("a".into()))
.now().unwrap().unwrap();
let head = read["head"].as_u64().unwrap();
// A dry run says what an undo would take back, and changes nothing.
let dry = app
.run(
&CommandId::from_static("history.undo"),
json!({ "scope": "app", "if_rev": read["rev"], "dry_run": true }),
Origin::Agent("a".into()),
)
.now().unwrap().unwrap();
assert_eq!(dry["steps"][0]["id"].as_u64(), Some(head));
assert_eq!(lock(&store).get("doc/n").unwrap().value, Value::Int(3));Structs§
- History
Plugin - The history panel and the
history.*commands.
Constants§
- CMD_
DROP_ SNAPSHOT - Deletes a snapshot.
- CMD_
JUMP - Brings a scope to one of its steps.
- CMD_
LIST - Every scope, whether it is active, where Undo and Redo go.
- CMD_
READ - A scope’s steps.
- CMD_
REDO - Redoes in a scope.
- CMD_
RESTORE - Brings a scope back to one of its snapshots.
- CMD_
SNAPSHOT - Takes a snapshot of a scope.
- CMD_
UNDO - Undoes in a scope.
- CMD_
UNDO_ STEP - Undoes one step of a scope out of order.
- PANEL_
HISTORY - The history panel.
- PLUGIN
- The plugin’s id.
Functions§
- choose
- Shows
scopein the panel from now on. - row_
text - What a step’s row says: its label, and who made it when it was not the user.
- show
- The history panel’s content: the scopes as chips when there are several; the snapshots, when the owner keeps them; then the shown scope’s steps under “Start” (the replaced ones behind a toggle). A click on a row jumps there (a snapshot’s restores it); hovering a row asks the owner for a preview; a step’s context menu undoes that one step, when the owner allows it.
- shown_
scope - The scope the panel shows: the one picked, while it is there; else where Ctrl+Z goes; else the first.