fix: File > Import > Variable Data Sets opens a file picker (#8816)

This commit is contained in:
MarekSpodBiedry committed 2026-10-23 17:37:40 +02:00
1 parent e6d6fb45a4
commit cddef0c6cc
2 files changed
+24

No files matched your search

+12
View File
@@ -1472,3 +1472,15 @@ fn save_a_copy_appends_copy_unless_the_preference_says_not_to() {
);
}
}
#[test]
fn import_variable_data_sets_menu_asks_for_a_csv_and_imports_it() {
let (mut app, open, _) = app();
let ctx = egui::Context::default();
assert_eq!(crate::menus::invoke(&mut app, &ctx, "file.import.variableDataSets", json!({})).unwrap(), json!({"fileDialog": "open"}));
app.poll_file_dialog(&ctx, None);
assert!(matches!(open.borrow().as_slice(), [(FileDialogRequest::Open { multiple: false, extensions: Some(e), .. }, _)] if e == &["csv", "txt"]));
answer(&open, Some(FileDialogAnswer::Contents("sets.csv".into(), b"headline\nHello\nWorld\n".to_vec())));
app.poll_file_dialog(&ctx, None);
assert_eq!(app.session.active().map(|d| d.doc.variables.data_sets.len()), Some(2));
}
+12
View File
@@ -228,6 +228,18 @@ pub(crate) fn invoke_unguarded(app: &mut PhotocraftApp, ctx: &egui::Context, id:
"file.import.videoFramesToLayers" if params.get("path").and_then(Value::as_str).is_none() => {
app.ask_folder(|app, path| app.run("file.import.videoFramesToLayers", json!({"path": path})).map_err(|e| e.to_string()))
}
// File > Import > Variable Data Sets… asks for the CSV (#8816); with a `path` the engine reads it itself.
"file.import.variableDataSets" if params.get("path").and_then(Value::as_str).is_none() => {
let doc = app.active_doc_id()?;
let params = params.clone();
app.pick_file_bytes_filtered(&["csv", "txt"], move |app, _name, bytes| {
app.refocus(doc)?;
let text = String::from_utf8_lossy(&bytes).into_owned();
let r = photocraft_engine::import_data_sets_text(&mut app.session, &text, &params).map_err(|e| e.to_string());
app.sync_views();
r
})
}
"file.save" => {
// Writes back only to a layered file that holds the whole document; anything else
// goes through Save As, so the original is never overwritten with less (#3806).