From ae73bbc8bd3991931f32ac88430d1a8f401e05e6 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 5 Nov 2026 11:29:28 +0100 Subject: [PATCH] Include selected sheet in multi-sheet export filenames --- crates/rundown-converter/src/gui.rs | 86 ++++++++++++++++++++++++++--- docs/rundown-converter.md | 6 ++ 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/crates/rundown-converter/src/gui.rs b/crates/rundown-converter/src/gui.rs index f88b3a3..84924ee 100644 --- a/crates/rundown-converter/src/gui.rs +++ b/crates/rundown-converter/src/gui.rs @@ -291,16 +291,57 @@ impl App { self.tables.clear(); self.invalidate(); } + fn default_output(&self) -> String { + let input = PathBuf::from(&self.input); + if self.sheets.len() > 1 && !self.sheet.is_empty() { + let sheet: String = self + .sheet + .chars() + .map(|c| { + if c.is_control() || r#"/\:*?"<>|"#.contains(c) { + '_' + } else { + c + } + }) + .collect(); + let sheet = sheet.trim_matches([' ', '.']); + let sheet = if sheet.is_empty() { "sheet" } else { sheet }; + let stem = input.file_stem().unwrap_or_default().to_string_lossy(); + input + .with_file_name(format!( + "{stem} - {sheet}.{}", + self.export_choice.extension() + )) + .to_string_lossy() + .into_owned() + } else { + input + .with_extension(self.export_choice.extension()) + .to_string_lossy() + .into_owned() + } + } + + fn select_sheet(&mut self, sheet: String) { + let automatic = self.output == self.default_output(); + self.sheet = sheet; + if automatic { + self.output = self.default_output(); + } + self.profile = "{}".into(); + self.profile_path = None; + self.invalidate(); + self.status = "Ready to analyze selected sheet".into(); + } + fn change_export_choice(&mut self, choice: ExportChoice) { if self.export_choice == choice { return; } self.export_choice = choice; if !self.input.is_empty() { - self.output = PathBuf::from(&self.input) - .with_extension(choice.extension()) - .to_string_lossy() - .into(); + self.output = self.default_output(); } } fn begin(&mut self) -> mpsc::Sender { @@ -466,12 +507,16 @@ impl App { self.status = s; } Update::Sheets(s) => { + let automatic = self.output == self.default_output(); self.rx = None; self.sheets = s.iter().map(|t| t.name.clone()).collect(); self.tables = s; if self.sheets.len() == 1 { self.sheet = self.sheets[0].clone(); } + if automatic { + self.output = self.default_output(); + } self.status = if self.sheets.len() > 1 { format!( "Choose one of {} workbook sheets to continue", @@ -1078,11 +1123,10 @@ impl App { }) .show_ui(ui, |ui| { for s in self.sheets.clone() { - if ui.selectable_value(&mut self.sheet, s.clone(), s).changed() { - self.profile = "{}".into(); - self.profile_path = None; - self.invalidate(); - self.status = "Ready to analyze selected sheet".into(); + if ui.selectable_label(self.sheet == s, &s).clicked() + && self.sheet != s + { + self.select_sheet(s); } } }); @@ -1690,6 +1734,30 @@ mod tests { assert!(app.rx.is_none()); } + #[test] + fn multi_sheet_export_names_follow_selection_and_keep_custom_paths() { + let mut app = App::default(); + app.set_input(PathBuf::from("/tmp/show.v2.xlsx")); + app.sheets = vec!["Morning".into(), "Après-midi".into()]; + app.select_sheet("Morning".into()); + assert_eq!(app.output, "/tmp/show.v2 - Morning.ontime.json"); + app.select_sheet("Après-midi".into()); + assert_eq!(app.output, "/tmp/show.v2 - Après-midi.ontime.json"); + app.change_export_choice(ExportChoice::OntimeXlsx); + assert_eq!(app.output, "/tmp/show.v2 - Après-midi.ontime.xlsx"); + app.change_export_choice(ExportChoice::NeutralJson); + assert_eq!(app.output, "/tmp/show.v2 - Après-midi.neutral.json"); + app.select_sheet("Unsafe/Name: ".into()); + assert_eq!(app.output, "/tmp/show.v2 - Unsafe_Name_.neutral.json"); + app.output = "/tmp/custom.json".into(); + app.select_sheet("Morning".into()); + assert_eq!(app.output, "/tmp/custom.json"); + app.set_input(PathBuf::from("/tmp/single.xlsx")); + app.sheets = vec!["Only sheet".into()]; + app.select_sheet("Only sheet".into()); + assert_eq!(app.output, "/tmp/single.ontime.json"); + } + #[test] fn multiple_sheets_focus_the_picker_and_explain_blocked_analysis() { let mut app = App::default(); diff --git a/docs/rundown-converter.md b/docs/rundown-converter.md index debe53c..cba4a54 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -317,6 +317,12 @@ use Ontime's Partial Load when you want to keep an existing project's settings. ## Output choice +For multi-sheet workbooks, the default GUI filename includes the selected sheet: +`show - Main stage.ontime.json` (or `.ontime.xlsx` / `.neutral.json`). Switching +sheets updates the suggested name, while a manually chosen output path is kept. +Single-sheet filenames remain unchanged. Characters unsafe in filenames are +replaced with underscores. + After saving, the GUI opens Results with a green **Export successful** panel, the saved path, and Open / Open output folder / Copy path actions. A confirmation with the filename remains in the bottom bar when switching tabs. Starting another