use group layers instead of linked tracks
This commit is contained in:
@@ -101,6 +101,9 @@ impl Action for AddClipInstanceAction {
|
||||
AnyLayer::Effect(_) => {
|
||||
return Err("Cannot add clip instances to effect layers".to_string());
|
||||
}
|
||||
AnyLayer::Group(_) => {
|
||||
return Err("Cannot add clip instances directly to group layers".to_string());
|
||||
}
|
||||
}
|
||||
self.executed = true;
|
||||
|
||||
@@ -136,6 +139,9 @@ impl Action for AddClipInstanceAction {
|
||||
AnyLayer::Effect(_) => {
|
||||
// Effect layers don't have clip instances, nothing to rollback
|
||||
}
|
||||
AnyLayer::Group(_) => {
|
||||
// Group layers don't have clip instances, nothing to rollback
|
||||
}
|
||||
}
|
||||
self.executed = false;
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ pub struct AddLayerAction {
|
||||
/// If Some, add to this VectorClip's layers instead of root
|
||||
target_clip_id: Option<Uuid>,
|
||||
|
||||
/// If Some, add as a child of this GroupLayer instead of root
|
||||
target_group_id: Option<Uuid>,
|
||||
|
||||
/// ID of the created layer (set after execution)
|
||||
created_layer_id: Option<Uuid>,
|
||||
}
|
||||
@@ -30,6 +33,7 @@ impl AddLayerAction {
|
||||
Self {
|
||||
layer: AnyLayer::Vector(layer),
|
||||
target_clip_id: None,
|
||||
target_group_id: None,
|
||||
created_layer_id: None,
|
||||
}
|
||||
}
|
||||
@@ -43,6 +47,7 @@ impl AddLayerAction {
|
||||
Self {
|
||||
layer,
|
||||
target_clip_id: None,
|
||||
target_group_id: None,
|
||||
created_layer_id: None,
|
||||
}
|
||||
}
|
||||
@@ -53,6 +58,12 @@ impl AddLayerAction {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the target group for this action (add layer inside a group layer)
|
||||
pub fn with_target_group(mut self, group_id: Uuid) -> Self {
|
||||
self.target_group_id = Some(group_id);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the ID of the created layer (after execution)
|
||||
pub fn created_layer_id(&self) -> Option<Uuid> {
|
||||
self.created_layer_id
|
||||
@@ -61,7 +72,18 @@ impl AddLayerAction {
|
||||
|
||||
impl Action for AddLayerAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
let layer_id = if let Some(clip_id) = self.target_clip_id {
|
||||
let layer_id = if let Some(group_id) = self.target_group_id {
|
||||
// Add layer inside a group layer
|
||||
let id = self.layer.id();
|
||||
if let Some(AnyLayer::Group(g)) = document.root.children.iter_mut()
|
||||
.find(|l| l.id() == group_id)
|
||||
{
|
||||
g.add_child(self.layer.clone());
|
||||
} else {
|
||||
return Err(format!("Target group {} not found", group_id));
|
||||
}
|
||||
id
|
||||
} else if let Some(clip_id) = self.target_clip_id {
|
||||
// Add layer inside a vector clip (movie clip)
|
||||
let clip = document.vector_clips.get_mut(&clip_id)
|
||||
.ok_or_else(|| format!("Target clip {} not found", clip_id))?;
|
||||
@@ -84,7 +106,14 @@ impl Action for AddLayerAction {
|
||||
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 {
|
||||
if let Some(clip_id) = self.target_clip_id {
|
||||
if let Some(group_id) = self.target_group_id {
|
||||
// Remove from group layer
|
||||
if let Some(AnyLayer::Group(g)) = document.root.children.iter_mut()
|
||||
.find(|l| l.id() == group_id)
|
||||
{
|
||||
g.children.retain(|l| l.id() != layer_id);
|
||||
}
|
||||
} else if let Some(clip_id) = self.target_clip_id {
|
||||
// Remove from vector clip
|
||||
if let Some(clip) = document.vector_clips.get_mut(&clip_id) {
|
||||
clip.layers.roots.retain(|node| node.data.id() != layer_id);
|
||||
@@ -107,6 +136,7 @@ impl Action for AddLayerAction {
|
||||
AnyLayer::Audio(_) => "Add audio layer",
|
||||
AnyLayer::Video(_) => "Add video layer",
|
||||
AnyLayer::Effect(_) => "Add effect layer",
|
||||
AnyLayer::Group(_) => "Add group layer",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ impl Action for LoopClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
for (instance_id, _old_dur, new_dur, _old_lb, new_lb) in loops {
|
||||
@@ -57,6 +58,7 @@ impl Action for LoopClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
for (instance_id, old_dur, _new_dur, old_lb, _new_lb) in loops {
|
||||
|
||||
@@ -29,6 +29,7 @@ pub mod set_keyframe;
|
||||
pub mod group_shapes;
|
||||
pub mod convert_to_movie_clip;
|
||||
pub mod region_split;
|
||||
pub mod toggle_group_expansion;
|
||||
|
||||
pub use add_clip_instance::AddClipInstanceAction;
|
||||
pub use add_effect::AddEffectAction;
|
||||
@@ -56,3 +57,4 @@ pub use set_keyframe::SetKeyframeAction;
|
||||
pub use group_shapes::GroupAction;
|
||||
pub use convert_to_movie_clip::ConvertToMovieClipAction;
|
||||
pub use region_split::RegionSplitAction;
|
||||
pub use toggle_group_expansion::ToggleGroupExpansionAction;
|
||||
|
||||
@@ -56,6 +56,7 @@ impl Action for MoveClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
};
|
||||
|
||||
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
|
||||
@@ -93,6 +94,7 @@ impl Action for MoveClipInstancesAction {
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Vector(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
};
|
||||
|
||||
let group: Vec<(Uuid, f64, f64)> = moves.iter().filter_map(|(id, old_start, _)| {
|
||||
@@ -126,6 +128,7 @@ impl Action for MoveClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
// Update timeline_start for each clip instance
|
||||
@@ -151,6 +154,7 @@ impl Action for MoveClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
// Restore original timeline_start for each clip instance
|
||||
|
||||
@@ -44,6 +44,7 @@ impl Action for RemoveClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
// Find and remove the instance, saving it for rollback
|
||||
@@ -68,6 +69,7 @@ impl Action for RemoveClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
clip_instances.push(instance);
|
||||
|
||||
@@ -112,6 +112,7 @@ impl Action for SplitClipInstanceAction {
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => return Err("Cannot split clip instances on group layers".to_string()),
|
||||
};
|
||||
|
||||
let instance = clip_instances
|
||||
@@ -228,6 +229,9 @@ impl Action for SplitClipInstanceAction {
|
||||
}
|
||||
el.clip_instances.push(right_instance);
|
||||
}
|
||||
AnyLayer::Group(_) => {
|
||||
return Err("Cannot split clip instances on group layers".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
self.executed = true;
|
||||
@@ -283,6 +287,9 @@ impl Action for SplitClipInstanceAction {
|
||||
inst.timeline_duration = self.original_timeline_duration;
|
||||
}
|
||||
}
|
||||
AnyLayer::Group(_) => {
|
||||
// Group layers don't have clip instances, nothing to rollback
|
||||
}
|
||||
}
|
||||
|
||||
self.executed = false;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//! Toggle group layer expansion state (collapsed/expanded in timeline)
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::document::Document;
|
||||
use crate::layer::AnyLayer;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Action that toggles a group layer's expanded/collapsed state
|
||||
pub struct ToggleGroupExpansionAction {
|
||||
group_id: Uuid,
|
||||
new_expanded: bool,
|
||||
old_expanded: Option<bool>,
|
||||
}
|
||||
|
||||
impl ToggleGroupExpansionAction {
|
||||
pub fn new(group_id: Uuid, expanded: bool) -> Self {
|
||||
Self {
|
||||
group_id,
|
||||
new_expanded: expanded,
|
||||
old_expanded: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for ToggleGroupExpansionAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
if let Some(AnyLayer::Group(g)) = document
|
||||
.root
|
||||
.children
|
||||
.iter_mut()
|
||||
.find(|l| l.id() == self.group_id)
|
||||
{
|
||||
self.old_expanded = Some(g.expanded);
|
||||
g.expanded = self.new_expanded;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Group layer {} not found", self.group_id))
|
||||
}
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
if let Some(old) = self.old_expanded {
|
||||
if let Some(AnyLayer::Group(g)) = document
|
||||
.root
|
||||
.children
|
||||
.iter_mut()
|
||||
.find(|l| l.id() == self.group_id)
|
||||
{
|
||||
g.expanded = old;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn description(&self) -> String {
|
||||
if self.new_expanded {
|
||||
"Expand group".to_string()
|
||||
} else {
|
||||
"Collapse group".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,7 @@ impl Action for TransformClipInstancesAction {
|
||||
}
|
||||
}
|
||||
AnyLayer::Effect(_) => {}
|
||||
AnyLayer::Group(_) => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -136,6 +137,7 @@ impl Action for TransformClipInstancesAction {
|
||||
}
|
||||
}
|
||||
AnyLayer::Effect(_) => {}
|
||||
AnyLayer::Group(_) => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
};
|
||||
|
||||
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
|
||||
@@ -134,6 +135,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
};
|
||||
|
||||
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
|
||||
@@ -176,6 +178,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Vector(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
};
|
||||
|
||||
let instance = clip_instances.iter()
|
||||
@@ -267,6 +270,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
// Apply trims
|
||||
@@ -305,6 +309,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) => continue,
|
||||
};
|
||||
|
||||
// Restore original trim values
|
||||
|
||||
Reference in New Issue
Block a user