Skip to main content

Module history_view

Module history_view 

Source
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; show draws 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_snapshot and history.undo_step, each with scope (none: where the keys go), if_rev and dry_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§

HistoryPlugin
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 scope in 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.