Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Parameter import and image pickers offer their own file types (#3216) (#3314)

phanoobb5edd98bc92a
diff --git a/crates/ui-egui/src/file_picker.rs b/crates/ui-egui/src/file_picker.rs
index 2c081346b5..c0f31508e9 100644
--- a/crates/ui-egui/src/file_picker.rs
+++ b/crates/ui-egui/src/file_picker.rs
@@ -365,4 +365,27 @@ mod tests {
finish(&mut h.app, &answer, None);
assert!(h.app.tool.is_none(), "cancelling does not resume the old placement");
}
+
+ /// #3216: pickers for files that aren't designs list the files' own types. On macOS a type
+ /// no filter names can't be picked: CSV parameters were greyed out.
+ #[test]
+ fn parameter_import_and_canvas_images_ask_for_their_file_types() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ let asked: Rc<RefCell<Vec<Vec<String>>>> = Rc::default();
+ let log = asked.clone();
+ h.app.services.pick_open = Some(Box::new(move |types: &[&str]| {
+ log.borrow_mut().push(types.iter().map(|t| t.to_string()).collect());
+ Box::pin(std::future::ready(None))
+ }));
+ crate::params_dialog::open(&mut h.app);
+ h.frames(2);
+ h.step(&json!({"widget": "Import…"})).unwrap();
+ h.frames(2);
+ h.app.params = None;
+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
+ h.app.start("canvas.insert");
+ h.frames(2);
+ assert_eq!(*asked.borrow(), [vec!["csv", "json"], vec!["png", "jpg", "jpeg"]]);
+ }
}
diff --git a/crates/ui-egui/src/params_dialog.rs b/crates/ui-egui/src/params_dialog.rs
index 91c1119d13..8294c794b3 100644
--- a/crates/ui-egui/src/params_dialog.rs
+++ b/crates/ui-egui/src/params_dialog.rs
@@ -17,6 +17,10 @@ use serde_json::{Value, json};
use crate::SolveApp;
use crate::ui_kit::{self, Column};
+/// What Import reads. The picker must list them: on macOS, files of a type no filter names
+/// can't be picked (#3216).
+pub(crate) const IMPORT_TYPES: &[&str] = &["csv", "json"];
+
const UNITS: [&str; 9] = ["mm", "cm", "m", "in", "ft", "deg", "rad", "", "um"];
/// Dialog state (what is being typed; the parameters themselves live in the document).
@@ -239,7 +243,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
.on_hover_text(crate::i18n::tr_label("CSV or JSON: updates existing parameters, adds new ones"))
.clicked()
{
- app.pick_open_command("parameters.import", json!({}), &[]);
+ app.pick_open_command("parameters.import", json!({}), IMPORT_TYPES);
}
for (label, ext) in [("Export CSV…", "csv"), ("Export JSON…", "json")] {
if ui_kit::icon_label_button(ui, label, "export_tray", true, false).clicked() {