From f5a82152394fde4d8f740f664ab7737b82861618 Mon Sep 17 00:00:00 2001 From: cashmere Date: Tue, 28 Jul 2026 19:41:16 +0200 Subject: 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 --- rust/crates/commands/src/history.rs | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 rust/crates/commands/src/history.rs (limited to 'rust/crates/commands/src/history.rs') 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>, + redo_stack: Vec>, +} + +impl CommandHistory { + pub fn new() -> Self { + Self::default() + } + + pub fn execute( + &mut self, + mut command: Box, + project: &mut Project, + ) -> Result, CommandError> { + let result = command.execute(project)?; + self.history.push(command); + self.redo_stack.clear(); + Ok(result) + } + + pub fn push(&mut self, command: Box) { + 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, 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(); + } +} -- cgit v1.3.1