summaryrefslogtreecommitdiff
path: root/rust/crates/commands/src/history.rs
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-07-28 19:41:16 +0200
committercashmere <cashmere@autistici.org>2026-07-28 19:41:16 +0200
commitf5a82152394fde4d8f740f664ab7737b82861618 (patch)
tree5a51b181abead1ce03d2dbfc12b77918d3be0e1b /rust/crates/commands/src/history.rs
parente837e7504379e100ff3b56282577ec67bb88bec9 (diff)
downloadopencut-f5a82152394fde4d8f740f664ab7737b82861618.tar.gz
feat: GPUI desktop port foundation
- scene crate: full project/scene/element model, serde round-trip proven against the web SerializedProject shape - transfer crate: .ocp zip container, cross-compat with web fflate archives proven in both directions - storage crate: filesystem project store replacing IndexedDB, .ocp import/export - media crate: ffmpeg-next 8 decoder (frames, audio, thumbnails, waveform summaries) - playback crate: wall-clock anchored, frame-rounded playback clock - gpu crate: native texture readback; compositor renders headless offscreen on Vulkan (spike test) - flake devshell: rust toolchain, GPUI native deps, ffmpeg dev, bindgen clang args; GPUI hello-world builds - port plan in notes/gpui-port.md
Diffstat (limited to 'rust/crates/commands/src/history.rs')
-rw-r--r--rust/crates/commands/src/history.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/rust/crates/commands/src/history.rs b/rust/crates/commands/src/history.rs
new file mode 100644
index 00000000..f8792373
--- /dev/null
+++ b/rust/crates/commands/src/history.rs
@@ -0,0 +1,68 @@
+use scene::Project;
+
+use crate::command::{Command, CommandError, CommandResult};
+
+#[derive(Default)]
+pub struct CommandHistory {
+ history: Vec<Box<dyn Command>>,
+ redo_stack: Vec<Box<dyn Command>>,
+}
+
+impl CommandHistory {
+ pub fn new() -> Self {
+ Self::default()
+ }
+
+ pub fn execute(
+ &mut self,
+ mut command: Box<dyn Command>,
+ project: &mut Project,
+ ) -> Result<Option<CommandResult>, CommandError> {
+ let result = command.execute(project)?;
+ self.history.push(command);
+ self.redo_stack.clear();
+ Ok(result)
+ }
+
+ pub fn push(&mut self, command: Box<dyn Command>) {
+ self.history.push(command);
+ self.redo_stack.clear();
+ }
+
+ pub fn undo(&mut self, project: &mut Project) {
+ let Some(mut command) = self.history.pop() else {
+ return;
+ };
+ command.undo(project);
+ self.redo_stack.push(command);
+ }
+
+ pub fn redo(
+ &mut self,
+ project: &mut Project,
+ ) -> Result<Option<CommandResult>, CommandError> {
+ let Some(mut command) = self.redo_stack.pop() else {
+ return Ok(None);
+ };
+ let result = command.redo(project)?;
+ self.history.push(command);
+ Ok(result)
+ }
+
+ pub fn can_undo(&self) -> bool {
+ !self.history.is_empty()
+ }
+
+ pub fn can_redo(&self) -> bool {
+ !self.redo_stack.is_empty()
+ }
+
+ pub fn len(&self) -> usize {
+ self.history.len()
+ }
+
+ pub fn clear(&mut self) {
+ self.history.clear();
+ self.redo_stack.clear();
+ }
+}