FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
UI.9: no move or float leaves the frame tree empty
aiongg0169eba9f931
diff --git a/crates/ui-egui/src/dock_ui.rs b/crates/ui-egui/src/dock_ui.rsindex 50d39d17b..beb62fe0d 100644--- a/crates/ui-egui/src/dock_ui.rs+++ b/crates/ui-egui/src/dock_ui.rs@@ -94,18 +94,12 @@ fn alias(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: &Value)Ok(json!({"panel": panel.id()}))}-/// Keep one docked destination available for dragging floating panels back into the workspace.-fn check_last_docked(layout: &Layout<PanelKind>, action: &Action<PanelKind>) -> Result<(), String> {- let panel = match action {- Action::Float { panel, .. } => Some(panel),- Action::Move { panel, anchor, .. } if layout.floating.iter().any(|window| window.contains(anchor)) => Some(panel),- _ => None,- };- if let Some(panel) = panel {- let docked = Layout { root: layout.root.clone(), floating: vec![] };- if docked.contains(panel) && docked.panels().len() <= 1 {- return Err("the last docked panel must remain in the workspace".into());- }+/// Keep one docked destination available for dragging floating panels back into the workspace:+/// no move or float may leave the frame tree empty. Closing the last docked panel stays allowed.+fn check_last_docked(before: &Layout<PanelKind>, action: &Action<PanelKind>, after: &Layout<PanelKind>) -> Result<(), String> {+ let closing = matches!(action, Action::Close { .. } | Action::CloseGroup { .. } | Action::CloseWindow { .. } | Action::CloseOthers { .. });+ if !closing && before.root.is_some() && after.root.is_none() {+ return Err("the last docked panel must remain in the workspace".into());}Ok(())}@@ -149,8 +143,9 @@ impl FilmcraftApp {closed_floating.push((panel, window.rect));}}- check_last_docked(&layout, &action)?;- layout.apply(action).map_err(|error| error.to_string())?;+ let before = layout.clone();+ layout.apply(action.clone()).map_err(|error| error.to_string())?;+ check_last_docked(&before, &action, &layout)?;}self.ui.dock = layout;self.ui.closed_floating = closed_floating;diff --git a/crates/ui-egui/tests/shared_docking_ui.rs b/crates/ui-egui/tests/shared_docking_ui.rsindex ce0dbd444..a8e2e43cd 100644--- a/crates/ui-egui/tests/shared_docking_ui.rs+++ b/crates/ui-egui/tests/shared_docking_ui.rs@@ -685,3 +685,22 @@ fn clicking_the_active_sequence_tab_focuses_the_timeline() {click(&mut h, &format!("timeline.tab.{active}"));assert_eq!(h.state().ui.focused, PanelKind::Timeline);}++/// No move or float may empty the frame tree, whichever unit it moves.+#[test]+fn the_last_docked_group_cannot_float_away() {+ let mut app = FilmcraftApp::new(Session::default());+ app.ui.dock = root(tabs(&[PanelKind::Project, PanelKind::Info], 0));+ let ctx = egui::Context::default();+ let before = app.ui.dock.clone();+ let float = craft_ui::docking::Target::Float { rect: Some([20.0, 20.0, 300.0, 200.0]) };+ for action in [Action::MoveGroup { panel: PanelKind::Project, to: float.clone() }, Action::MoveColumn { panel: PanelKind::Project, to: float.clone() }] {+ let _ = menus::invoke(&mut app, &ctx, "window.dockAction", json!({ "action": action }));+ assert_eq!(app.ui.dock, before);+ }+ assert!(menus::invoke(&mut app, &ctx, "window.panel.float", json!({"panel": "Project", "group": true})).is_err());+ assert_eq!(app.ui.dock, before);+ // one panel of the group may float; the other stays docked+ menus::invoke(&mut app, &ctx, "window.panel.float", json!({"panel": "Info"})).unwrap();+ assert!(app.ui.dock.docked(PanelKind::Project) && !app.ui.dock.docked(PanelKind::Info));+}