diff --git a/src/app/commands/blocks.rs b/src/app/commands/blocks.rs index 383fa0d1c..ee8bcab08 100644 --- a/src/app/commands/blocks.rs +++ b/src/app/commands/blocks.rs @@ -669,6 +669,17 @@ impl OpenCADStudio { "_PDFIMPORTFILE" => { return Some(Task::done(Message::PdfImportPick)); } + // A file named after it skips the picker. + cmd if cmd.starts_with("_PDFIMPORTFILE ") => { + let path = cmd["_PDFIMPORTFILE ".len()..].trim().trim_matches('"').to_string(); + match std::fs::read(&path) { + Ok(bytes) => { + crate::scene::model::pdf_raster::register_source(&path, std::sync::Arc::new(bytes)); + self.open_pdf_import_file(&path); + } + Err(_) => self.command_line.push_error(&format!("{path} not found.")), + } + } "PDFCLIP" | "CLIP" => { use crate::command::CadCommand; let command = crate::modules::insert::pdf_clip::PdfClipCommand::new(cmd == "CLIP"); diff --git a/src/app/control/actions.rs b/src/app/control/actions.rs index f461d1094..d6bdecaad 100644 --- a/src/app/control/actions.rs +++ b/src/app/control/actions.rs @@ -50,6 +50,8 @@ pub(super) const NAMES: &[&str] = &[ "pdf_dialog_ok", "pdf_layer_toggle", "pdf_page_select", + "ribbon_tab", + "ribbon_dropdown", "close_document", "toggle_properties", "toggle_layers", @@ -683,6 +685,16 @@ impl OpenCADStudio { state.selected = pages; return Ok(Task::none()); } + // Bring a ribbon tab forward by module id ("pdf_underlay" for the + // contextual underlay tab). + "ribbon_tab" => { + let id = string(req, "value")?; + if !self.ribbon.select_by_id(id) { + return Err(failure("no_tab", "No such ribbon tab")); + } + return Ok(Task::none()); + } + "ribbon_dropdown" => Message::ToggleRibbonDropdown(string(req, "value")?.into()), "pdf_dialog_ok" => { use crate::ui::window::pdf_dialogs::PdfDialogMsg; Message::PdfDialog(match self.active_modal { diff --git a/src/ui/ribbon/underlay_tab.rs b/src/ui/ribbon/underlay_tab.rs index 31a478b5f..ec36772c3 100644 --- a/src/ui/ribbon/underlay_tab.rs +++ b/src/ui/ribbon/underlay_tab.rs @@ -180,6 +180,21 @@ impl Ribbon { self.underlay_ctx.as_mut() } + /// Select a tab by its module id; "pdf_underlay" is the contextual tab. + pub fn select_by_id(&mut self, id: &str) -> bool { + if id == "pdf_underlay" { + self.select_underlay_tab(); + return self.underlay_tab_active; + } + match self.modules.iter().position(|m| m.id() == id) { + Some(index) => { + self.select(index); + true + } + None => false, + } + } + pub fn select_underlay_tab(&mut self) { if self.underlay_ctx.is_some() { self.underlay_tab_active = true;