Prevent video and audio clips from overlapping
This commit is contained in:
@@ -49,15 +49,17 @@ impl AddLayerAction {
|
||||
}
|
||||
|
||||
impl Action for AddLayerAction {
|
||||
fn execute(&mut self, document: &mut Document) {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
// Add layer to the document's root
|
||||
let layer_id = document.root_mut().add_child(self.layer.clone());
|
||||
|
||||
// Store the ID for rollback
|
||||
self.created_layer_id = Some(layer_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) {
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
// Remove the created layer if it exists
|
||||
if let Some(layer_id) = self.created_layer_id {
|
||||
document.root_mut().remove_child(&layer_id);
|
||||
@@ -65,6 +67,8 @@ impl Action for AddLayerAction {
|
||||
// Clear the stored ID
|
||||
self.created_layer_id = None;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
@@ -88,7 +92,7 @@ mod tests {
|
||||
|
||||
// Create and execute action
|
||||
let mut action = AddLayerAction::new_vector("New Layer");
|
||||
action.execute(&mut document);
|
||||
action.execute(&mut document).unwrap();
|
||||
|
||||
// Verify layer was added
|
||||
assert_eq!(document.root.children.len(), 1);
|
||||
@@ -97,7 +101,7 @@ mod tests {
|
||||
assert!(matches!(layer, AnyLayer::Vector(_)));
|
||||
|
||||
// Rollback
|
||||
action.rollback(&mut document);
|
||||
action.rollback(&mut document).unwrap();
|
||||
|
||||
// Verify layer was removed
|
||||
assert_eq!(document.root.children.len(), 0);
|
||||
@@ -116,8 +120,8 @@ mod tests {
|
||||
let mut action1 = AddLayerAction::new_vector("Layer 1");
|
||||
let mut action2 = AddLayerAction::new_vector("Layer 2");
|
||||
|
||||
action1.execute(&mut document);
|
||||
action2.execute(&mut document);
|
||||
action1.execute(&mut document).unwrap();
|
||||
action2.execute(&mut document).unwrap();
|
||||
|
||||
assert_eq!(document.root.children.len(), 2);
|
||||
assert_eq!(document.root.children[0].layer().name, "Layer 1");
|
||||
|
||||
Reference in New Issue
Block a user