forked from 1b-agent/opencadstudio-upstream
Automation: ribbon tab and dropdown actions; _PDFIMPORTFILE takes a path
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28853cd32e
commit
c9426a5d6d
3 files changed
+38
No files matched your search
@@ -669,6 +669,17 @@ impl OpenCADStudio {
|
|||||||
"_PDFIMPORTFILE" => {
|
"_PDFIMPORTFILE" => {
|
||||||
return Some(Task::done(Message::PdfImportPick));
|
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" => {
|
"PDFCLIP" | "CLIP" => {
|
||||||
use crate::command::CadCommand;
|
use crate::command::CadCommand;
|
||||||
let command = crate::modules::insert::pdf_clip::PdfClipCommand::new(cmd == "CLIP");
|
let command = crate::modules::insert::pdf_clip::PdfClipCommand::new(cmd == "CLIP");
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ pub(super) const NAMES: &[&str] = &[
|
|||||||
"pdf_dialog_ok",
|
"pdf_dialog_ok",
|
||||||
"pdf_layer_toggle",
|
"pdf_layer_toggle",
|
||||||
"pdf_page_select",
|
"pdf_page_select",
|
||||||
|
"ribbon_tab",
|
||||||
|
"ribbon_dropdown",
|
||||||
"close_document",
|
"close_document",
|
||||||
"toggle_properties",
|
"toggle_properties",
|
||||||
"toggle_layers",
|
"toggle_layers",
|
||||||
@@ -683,6 +685,16 @@ impl OpenCADStudio {
|
|||||||
state.selected = pages;
|
state.selected = pages;
|
||||||
return Ok(Task::none());
|
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" => {
|
"pdf_dialog_ok" => {
|
||||||
use crate::ui::window::pdf_dialogs::PdfDialogMsg;
|
use crate::ui::window::pdf_dialogs::PdfDialogMsg;
|
||||||
Message::PdfDialog(match self.active_modal {
|
Message::PdfDialog(match self.active_modal {
|
||||||
|
|||||||
@@ -180,6 +180,21 @@ impl Ribbon {
|
|||||||
self.underlay_ctx.as_mut()
|
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) {
|
pub fn select_underlay_tab(&mut self) {
|
||||||
if self.underlay_ctx.is_some() {
|
if self.underlay_ctx.is_some() {
|
||||||
self.underlay_tab_active = true;
|
self.underlay_tab_active = true;
|
||||||
|
|||||||
Reference in new issue
Block a user