forked from 1b-agent/opencadstudio-upstream
feat(insert): add initial PDF underlay attachment
This commit is contained in:
1 parent
ac8a545669
commit
410624e4b3
5 files changed
+133
-1
No files matched your search
@@ -515,11 +515,13 @@ impl OpenCADStudio {
|
||||
self.open_attedit_dialog();
|
||||
}
|
||||
|
||||
"PDFATTACH" => {
|
||||
return Some(Task::done(Message::PdfAttachPick));
|
||||
}
|
||||
"XATTACH" => {
|
||||
// Launch the file picker; XAttachPickResult will start the command.
|
||||
return Some(Task::done(Message::XAttachPick));
|
||||
}
|
||||
|
||||
cmd if cmd == "WBLOCK" || cmd == "WB" || cmd.starts_with("WBLOCK ") => {
|
||||
let arg = cmd.splitn(2, ' ').nth(1).unwrap_or("").trim();
|
||||
if arg.is_empty() {
|
||||
|
||||
@@ -3189,6 +3189,12 @@ pub enum Message {
|
||||
ImagePick,
|
||||
/// Result of the image file picker + pixel dimension decode.
|
||||
ImagePickResult(Result<(std::path::PathBuf, u32, u32), String>),
|
||||
// ── PDF Underlay ──────────────────────────────────────────────────────
|
||||
/// Open file-picker dialog for PDFATTACH command (async).
|
||||
PdfAttachPick,
|
||||
/// Result of the PDFATTACH file picker.
|
||||
PdfAttachPickResult(Result<std::path::PathBuf, String>),
|
||||
|
||||
// ── XREF ──────────────────────────────────────────────────────────────
|
||||
/// Open file-picker dialog for XATTACH command (async).
|
||||
XAttachPick,
|
||||
|
||||
@@ -902,7 +902,60 @@ impl OpenCADStudio {
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::PdfAttachPick => Task::perform(
|
||||
async {
|
||||
let handle = crate::sys::file_dialog()
|
||||
.set_title("Select PDF Underlay")
|
||||
.add_filter("PDF Files", &["pdf", "PDF"])
|
||||
.pick_file()
|
||||
.await;
|
||||
|
||||
match handle {
|
||||
Some(h) => Ok(crate::sys::handle_path(&h)),
|
||||
None => Err("Cancelled".to_string()),
|
||||
}
|
||||
},
|
||||
Message::PdfAttachPickResult,
|
||||
),
|
||||
|
||||
Message::PdfAttachPickResult(Ok(path)) => {
|
||||
use acadrust::objects::{ObjectType, UnderlayDefinition};
|
||||
use crate::command::CadCommand;
|
||||
use crate::modules::insert::pdf_attach::PdfAttachCommand;
|
||||
|
||||
let i = self.active_tab;
|
||||
let path_str = path.to_string_lossy().into_owned();
|
||||
|
||||
let definition_handle = self.tabs[i].scene.document.allocate_handle();
|
||||
|
||||
let mut definition = UnderlayDefinition::pdf(&path_str, "1");
|
||||
definition.handle = definition_handle;
|
||||
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.document
|
||||
.objects
|
||||
.insert(
|
||||
definition_handle,
|
||||
ObjectType::UnderlayDefinition(definition),
|
||||
);
|
||||
|
||||
let cmd = PdfAttachCommand::new(definition_handle);
|
||||
|
||||
self.command_line.push_info(&cmd.prompt());
|
||||
self.tabs[i].active_cmd = Some(Box::new(cmd));
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::PdfAttachPickResult(Err(e)) => {
|
||||
if e != "Cancelled" {
|
||||
self.command_line
|
||||
.push_error(crate::tf!("PDFATTACH: {e}").as_ref());
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
Message::XAttachPick => Task::perform(
|
||||
async {
|
||||
let handle = crate::sys::file_dialog()
|
||||
|
||||
Reference in new issue
Block a user