FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Let a bin be cleared from its context menu, the trash button, the panel menu and Delete (#587)
MarekSpodBiedryb5965dc5683f
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex d5437e972..527c3184e 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1258,8 +1258,16 @@ impl FilmcraftApp {if self.ui.focused == PanelKind::Project && matches!(id.as_str(), "edit.selectAll" | "edit.deselectAll") {id = id.replacen("edit.", "project.", 1);}+ // Clear in the Project panel removes the selected bin when no item is selected (#587).+ let clear = if self.ui.focused == PanelKind::Project && id == "project.delete" {+ crate::panels::project_views::clear_params(&self.session.state.project_selection, self.ui.project_panel.selected_bin)+ } else {+ None+ };// Mark In/Out in the Source monitor when it has focus.- let params = if self.ui.focused == PanelKind::Source+ let params = if let Some(p) = clear {+ p+ } else if self.ui.focused == PanelKind::Source&& (matches!(id.as_str(), "markers.markIn" | "markers.markOut" | "markers.clearInOut")|| id.starts_with("markers.markSplit")|| id.starts_with("markers.goToSplit"))diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rsindex 09b040694..e859f539d 100644--- a/crates/ui-egui/src/panels/project.rs+++ b/crates/ui-egui/src/panels/project.rs@@ -609,7 +609,10 @@ fn footer(app: &mut FilmcraftApp, ui: &mut egui::Ui, bar: Rect, v: &View, actionlet parent = (v.bin != app.session.project.root.id).then_some(v.bin.0);actions.push(("file.newBin".into(), json!({"name": "New Bin", "parent": parent})));}- "project.delete" if app.session.state.project_selection.is_empty() => app.ui.status = tl!("Select items to clear").into(),+ "project.delete" => match crate::panels::project_views::clear_params(&app.session.state.project_selection, app.ui.project_panel.selected_bin) {+ Some(p) => actions.push((id.into(), p)),+ None => app.ui.status = tl!("Select items to clear").into(),+ },_ => actions.push((id.into(), json!({}))),}}@@ -673,6 +676,7 @@ pub fn panel_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui) -> bool {let inst = shown_inst(app);let v = view_of(app, inst);let has_sel = !app.session.state.project_selection.is_empty() || app.ui.project_panel.selected_bin.is_some();+ let clear = crate::panels::project_views::clear_params(&app.session.state.project_selection, app.ui.project_panel.selected_bin);let has_project_path = app.session.path.is_some();let sc = |id: &str| app.session.shortcuts.primary(id);let (s_close, s_save, s_bin, s_find) = (sc("file.closeProject"), sc("file.save"), sc("file.newBin"), sc("edit.find"));@@ -712,8 +716,8 @@ pub fn panel_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui) -> bool {if item(ui, "rename", tl!("Rename"), has_sel, None) {actions.push(("projectPanel.rename".into(), json!({})));}- if item(ui, "delete", tl!("Delete"), !app.session.state.project_selection.is_empty(), Some("Backspace")) {- actions.push(("project.delete".into(), json!({})));+ if item(ui, "delete", tl!("Delete"), clear.is_some(), Some("Backspace")) {+ actions.push(("project.delete".into(), clear.unwrap_or_default()));}ui.separator();if item(ui, "automateToSequence", tl!("Automate to Sequence…"), !app.session.state.project_selection.is_empty(), None) {diff --git a/crates/ui-egui/src/panels/project_views.rs b/crates/ui-egui/src/panels/project_views.rsindex 7a54afaea..fbfe6922e 100644--- a/crates/ui-egui/src/panels/project_views.rs+++ b/crates/ui-egui/src/panels/project_views.rs@@ -314,6 +314,20 @@ fn bin_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui, v: &View, bin: u64, actioactions.push(("file.newBin".into(), json!({"name": "New Bin", "parent": bin})));ui.close();}+ ui.separator();+ if ui.button(tl!("Clear")).clicked() {+ actions.push(("project.delete".into(), json!({"items": [bin]})));+ ui.close();+ }+}++/// Parameters for `project.delete`: the selected items, else the selected bin by id (the engine+/// deletes a named bin with everything in it). `None` when nothing is selected.+pub fn clear_params(selection: &[filmcraft_project::ItemId], selected_bin: Option<u64>) -> Option<serde_json::Value> {+ if !selection.is_empty() {+ return Some(json!({}));+ }+ selected_bin.map(|b| json!({"items": [b]}))}/// Drop project items dragged onto a bin: move them (the selection when the dragged item is in it).@@ -1033,3 +1047,17 @@ fn canvas_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui, v: &View, bin: Option<ui.separator();background_menu(app, ui, v, bin.filter(|b| *b != app.session.project.root.id.0), actions);}++#[cfg(test)]+mod clear_tests {+ use super::clear_params;+ use filmcraft_project::ItemId;+ use serde_json::json;++ #[test]+ fn clear_falls_back_to_the_selected_bin() {+ assert_eq!(clear_params(&[], Some(7)), Some(json!({"items": [7]})));+ assert_eq!(clear_params(&[ItemId(3)], Some(7)), Some(json!({})));+ assert_eq!(clear_params(&[], None), None);+ }+}