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 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-17 10:22:08 +03:00
1 parent 844069b4ef
commit 50825b6346
8 files changed
+107 -7

No files matched your search

+6
View File
@@ -1,6 +1,12 @@
use crate::plugin::host::HostSession;
pub fn handle(host: &mut HostSession<'_>, cmd: &str) -> bool {
// "DP_IMPORT <path>" arrives from ModuleEvent::PluginFileDialog with the
// path in its original case (the command line is bypassed).
if let Some(path) = cmd.strip_prefix("DP_IMPORT ") {
host.push_info(&format!("demo_plugin imported: {path}"));
return true;
}
match cmd {
"DP_HELLO" => {
host.push_info("Hello from demo_plugin (plugin host OK).");
+22 -7
View File
@@ -8,7 +8,7 @@ pub mod register;
use crate::modules::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
inventory::submit!(crate::command::CommandRegistration {
names: &["DP_HELLO"]
names: &["DP_HELLO", "DP_IMPORT"]
});
pub struct DemoPluginModule;
@@ -25,12 +25,27 @@ impl CadModule for DemoPluginModule {
fn ribbon_groups(&self) -> Vec<RibbonGroup> {
vec![RibbonGroup {
title: "Smoke",
tools: vec![RibbonItem::LargeTool(ToolDef {
id: "DP_HELLO",
label: "Hello",
icon: IconKind::Glyph("★"),
event: ModuleEvent::Command("DP_HELLO".to_string()),
})],
tools: vec![
RibbonItem::LargeTool(ToolDef {
id: "DP_HELLO",
label: "Hello",
icon: IconKind::Glyph("★"),
event: ModuleEvent::Command("DP_HELLO".to_string()),
}),
// Exercises ModuleEvent::PluginFileDialog: the host opens a
// native picker and dispatches "DP_IMPORT <path>" back here.
RibbonItem::LargeTool(ToolDef {
id: "DP_IMPORT",
label: "Import",
icon: IconKind::Glyph("📂"),
event: ModuleEvent::PluginFileDialog {
command: "DP_IMPORT".to_string(),
title: "Import Demo File".to_string(),
filter_name: "Text".to_string(),
extensions: vec!["txt".to_string(), "csv".to_string()],
},
}),
],
}]
}
}