feat(plugin): ModuleEvent::PluginFileDialog for native file import
Add-ons had no way to request a file picker — only the host's own Open dialog. PluginFileDialog lets a plugin tool ask the host to open a native picker; on selection the host dispatches "<command> <path>" back to the plugin with original case preserved (bypassing the command-line upper-casing that mangles case-sensitive paths on Linux/macOS). The demo plugin gains an Import tool exercising it. Part of the #100 extensibility epic (surfaced in #106). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
844069b4ef
commit
50825b6346
8 changed files with 107 additions and 7 deletions
|
|
@ -1027,6 +1027,42 @@ impl OpenCADStudio {
|
|||
ModuleEvent::ToggleLayers => {
|
||||
return Task::done(Message::ToggleLayers);
|
||||
}
|
||||
ModuleEvent::PluginFileDialog {
|
||||
command,
|
||||
title,
|
||||
filter_name,
|
||||
extensions,
|
||||
} => {
|
||||
return Task::perform(
|
||||
async move {
|
||||
let exts: Vec<&str> =
|
||||
extensions.iter().map(|s| s.as_str()).collect();
|
||||
let path = rfd::AsyncFileDialog::new()
|
||||
.set_title(title)
|
||||
.add_filter(filter_name, &exts)
|
||||
.add_filter("All Files", &["*"])
|
||||
.pick_file()
|
||||
.await
|
||||
.map(|h| crate::sys::handle_path(&h));
|
||||
(command, path)
|
||||
},
|
||||
|(command, path)| Message::PluginFileDialogResult { command, path },
|
||||
);
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::PluginFileDialogResult { command, path } => {
|
||||
if let Some(path) = path {
|
||||
// Dispatch "<command> <path>" with original case intact —
|
||||
// the command line would upper-case the whole string and
|
||||
// mangle case-sensitive paths on Linux/macOS.
|
||||
let line = format!("{} {}", command, path.to_string_lossy());
|
||||
let i = self.active_tab;
|
||||
if !crate::plugin::try_dispatch(self, i, &line) {
|
||||
self.command_line
|
||||
.push_error(&format!("No plugin handled: {command}"));
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue