diff --git a/locales/ar-SA/opencadstudio.ftl b/locales/ar-SA/opencadstudio.ftl index 41b5274fd..d3afe0afa 100644 --- a/locales/ar-SA/opencadstudio.ftl +++ b/locales/ar-SA/opencadstudio.ftl @@ -3586,6 +3586,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/bg-BG/opencadstudio.ftl b/locales/bg-BG/opencadstudio.ftl index afa5f27c6..7d3e0ce5d 100644 --- a/locales/bg-BG/opencadstudio.ftl +++ b/locales/bg-BG/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/cs-CZ/opencadstudio.ftl b/locales/cs-CZ/opencadstudio.ftl index 28a81eef9..3633cd515 100644 --- a/locales/cs-CZ/opencadstudio.ftl +++ b/locales/cs-CZ/opencadstudio.ftl @@ -3571,6 +3571,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/de-DE/opencadstudio.ftl b/locales/de-DE/opencadstudio.ftl index 49aa5435e..5f06c5e29 100644 --- a/locales/de-DE/opencadstudio.ftl +++ b/locales/de-DE/opencadstudio.ftl @@ -3574,6 +3574,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/el-GR/opencadstudio.ftl b/locales/el-GR/opencadstudio.ftl index 42807d01d..80ee77915 100644 --- a/locales/el-GR/opencadstudio.ftl +++ b/locales/el-GR/opencadstudio.ftl @@ -3574,6 +3574,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/en-US/opencadstudio.ftl b/locales/en-US/opencadstudio.ftl index 25797df8f..4706965fb 100644 --- a/locales/en-US/opencadstudio.ftl +++ b/locales/en-US/opencadstudio.ftl @@ -3575,6 +3575,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/es-ES/opencadstudio.ftl b/locales/es-ES/opencadstudio.ftl index 88b5c13fd..1ce5f4834 100644 --- a/locales/es-ES/opencadstudio.ftl +++ b/locales/es-ES/opencadstudio.ftl @@ -3574,6 +3574,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/fi-FI/opencadstudio.ftl b/locales/fi-FI/opencadstudio.ftl index 3cd366010..97cee839e 100644 --- a/locales/fi-FI/opencadstudio.ftl +++ b/locales/fi-FI/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/fr-FR/opencadstudio.ftl b/locales/fr-FR/opencadstudio.ftl index 7e0219344..c3ae35108 100644 --- a/locales/fr-FR/opencadstudio.ftl +++ b/locales/fr-FR/opencadstudio.ftl @@ -3574,6 +3574,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/hi-IN/opencadstudio.ftl b/locales/hi-IN/opencadstudio.ftl index cd2b00dbb..2844c23a7 100644 --- a/locales/hi-IN/opencadstudio.ftl +++ b/locales/hi-IN/opencadstudio.ftl @@ -3562,6 +3562,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/hu-HU/opencadstudio.ftl b/locales/hu-HU/opencadstudio.ftl index f39afb99b..3fc5da1ad 100644 --- a/locales/hu-HU/opencadstudio.ftl +++ b/locales/hu-HU/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/it-IT/opencadstudio.ftl b/locales/it-IT/opencadstudio.ftl index 332b99767..fa7f97aa2 100644 --- a/locales/it-IT/opencadstudio.ftl +++ b/locales/it-IT/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/ja-JP/opencadstudio.ftl b/locales/ja-JP/opencadstudio.ftl index 6ef6bebc1..571cf1255 100644 --- a/locales/ja-JP/opencadstudio.ftl +++ b/locales/ja-JP/opencadstudio.ftl @@ -3564,6 +3564,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/ko-KR/opencadstudio.ftl b/locales/ko-KR/opencadstudio.ftl index fa5d64017..0bea09964 100644 --- a/locales/ko-KR/opencadstudio.ftl +++ b/locales/ko-KR/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/nl-NL/opencadstudio.ftl b/locales/nl-NL/opencadstudio.ftl index 5ec3e222e..0f98e0ac8 100644 --- a/locales/nl-NL/opencadstudio.ftl +++ b/locales/nl-NL/opencadstudio.ftl @@ -3572,6 +3572,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/pl-PL/opencadstudio.ftl b/locales/pl-PL/opencadstudio.ftl index b518cae38..ded45105b 100644 --- a/locales/pl-PL/opencadstudio.ftl +++ b/locales/pl-PL/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/pt-BR/opencadstudio.ftl b/locales/pt-BR/opencadstudio.ftl index 4c3a95027..94641aebb 100644 --- a/locales/pt-BR/opencadstudio.ftl +++ b/locales/pt-BR/opencadstudio.ftl @@ -3574,6 +3574,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/ru-RU/opencadstudio.ftl b/locales/ru-RU/opencadstudio.ftl index a5fb82176..2fe909619 100644 --- a/locales/ru-RU/opencadstudio.ftl +++ b/locales/ru-RU/opencadstudio.ftl @@ -3575,6 +3575,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/tr-TR/opencadstudio.ftl b/locales/tr-TR/opencadstudio.ftl index 86a7aee2f..50d6a6f5b 100644 --- a/locales/tr-TR/opencadstudio.ftl +++ b/locales/tr-TR/opencadstudio.ftl @@ -3548,6 +3548,12 @@ insert = .refui-requires-int-90 = -90 ile 90 arasında bir tam sayı gerekir. .refui-xref-fading = Xref soldurma .refui-edit-reference = Referansı Düzenle + .refui-edit-reference-in-place = + Yerinde Referansı + Düzenle + .refui-open-reference = + Referansı + Aç .refui-snap-to-underlays-off = Altlıklara Yakala Kapalı .refui-snap-to-underlays-on = Altlıklara Yakala Açık .refui-snap-to-underlays = Altlıklara Yakala @@ -4501,7 +4507,7 @@ properties = .extended-lighting = Gelişmiş Aydınlatma .extents-max = En Büyük Sınırlar .extents-min = En Küçük Sınırlar - .external-reference = Dış Referans + .external-reference = Harici Referans .face = Yüz .face-count = Yüz sayısı .falloff-angle = Düşüş Açısı diff --git a/locales/zh-CN/opencadstudio.ftl b/locales/zh-CN/opencadstudio.ftl index 1f508ef20..0d784ed0b 100644 --- a/locales/zh-CN/opencadstudio.ftl +++ b/locales/zh-CN/opencadstudio.ftl @@ -3561,6 +3561,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/locales/zh-TW/opencadstudio.ftl b/locales/zh-TW/opencadstudio.ftl index ff52f4561..17f2ea56c 100644 --- a/locales/zh-TW/opencadstudio.ftl +++ b/locales/zh-TW/opencadstudio.ftl @@ -3573,6 +3573,12 @@ insert = .refui-requires-int-90 = Requires an integer between -90 and 90. .refui-xref-fading = Xref fading .refui-edit-reference = Edit Reference + .refui-edit-reference-in-place = + Edit Reference + In-Place + .refui-open-reference = + Open + Reference .refui-snap-to-underlays-off = Snap to Underlays OFF .refui-snap-to-underlays-on = Snap to Underlays ON .refui-snap-to-underlays = Snap to Underlays diff --git a/src/app/commands/pdf_underlay.rs b/src/app/commands/pdf_underlay.rs index 976990c30..3a4606199 100644 --- a/src/app/commands/pdf_underlay.rs +++ b/src/app/commands/pdf_underlay.rs @@ -20,9 +20,31 @@ impl OpenCADStudio { out } - /// Show the tab while only PDF underlays are selected. + /// The selected xrefs, or nothing when anything else is selected. + pub(in crate::app) fn selected_xrefs(&self, i: usize) -> Vec { + let doc = &self.tabs[i].scene.document; + let mut out = Vec::new(); + for (handle, entity) in self.tabs[i].scene.selected_entities() { + let xref = match entity { + codec::EntityType::Insert(ins) => doc + .block_records + .get(&ins.block_name) + .is_some_and(|br| br.flags.is_xref || br.flags.is_xref_overlay), + _ => false, + }; + if !xref { + return Vec::new(); + } + out.push(handle); + } + out + } + + /// Show the PDF Underlay tab while only PDF underlays are selected, the + /// External Reference tab while only xrefs are. pub(in crate::app) fn sync_underlay_tab(&mut self) { let i = self.active_tab; + let xref = !self.tabs[i].is_start && !self.selected_xrefs(i).is_empty(); let context = if self.tabs[i].is_start { None } else { @@ -36,7 +58,7 @@ impl OpenCADStudio { ) }) }; - self.ribbon.set_underlay_context(context); + self.ribbon.set_underlay_context(context, xref); } /// One undo step that edits every selected PDF underlay. @@ -127,6 +149,41 @@ impl OpenCADStudio { self.tabs[i].scene.reseed_underlays(); self.sync_underlay_tab(); } + // External Reference tab: the selected xrefs. + "_XREFEDIT" | "_XREFOPEN" => { + let Some(&handle) = self.selected_xrefs(i).first() else { + return Some(Task::none()); + }; + self.tabs[i].scene.deselect_all(); + self.tabs[i].scene.select_entity(handle, true); + let command = if cmd == "_XREFEDIT" { "REFEDIT" } else { "XOPEN" }; + return Some(self.dispatch_command(command)); + } + "_XREFCLIP" => { + use crate::command::CadCommand; + let inserts = self.selected_xrefs(i); + if inserts.is_empty() { + return Some(Task::none()); + } + let clipped = inserts.iter().any(|h| { + crate::scene::pick::xclip::filter_handle(&self.tabs[i].scene.document, *h).is_some() + }); + let (command, first) = + crate::modules::insert::xclip::XclipCommand::start_new_boundary(inserts, clipped); + if let crate::command::CmdResult::ReportMeasurement(text) = first { + for line in text.lines() { + self.command_line.push_output(line); + } + } + self.command_line.push_info(&command.prompt()); + self.tabs[i].active_cmd = Some(Box::new(command)); + } + "_XREFUNCLIP" => { + let inserts = self.selected_xrefs(i); + if !inserts.is_empty() { + self.apply_xclip(i, inserts, crate::modules::insert::xclip::XclipAction::Delete); + } + } "_PDFULUNCLIP" => { self.edit_selected_underlays(i, "PDFCLIP", |u| { u.clip_boundary_vertices.clear(); diff --git a/src/locale_catalog.rs b/src/locale_catalog.rs index 87b1740ff..0ba970977 100644 --- a/src/locale_catalog.rs +++ b/src/locale_catalog.rs @@ -2950,6 +2950,8 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static "Snap to Underlays ON" => Some(("insert", "refui-snap-to-underlays-on")), "Snap to Underlays OFF" => Some(("insert", "refui-snap-to-underlays-off")), "Edit Reference" => Some(("insert", "refui-edit-reference")), + "Edit Reference\nIn-Place" => Some(("insert", "refui-edit-reference-in-place")), + "Open\nReference" => Some(("insert", "refui-open-reference")), "Xref fading" => Some(("insert", "refui-xref-fading")), "Requires an integer between -90 and 90." => Some(("insert", "refui-requires-int-90")), "Underlay" => Some(("properties", "underlay")), diff --git a/src/modules/insert/xclip.rs b/src/modules/insert/xclip.rs index f1ea06b28..8c14c01cb 100644 --- a/src/modules/insert/xclip.rs +++ b/src/modules/insert/xclip.rs @@ -103,6 +103,15 @@ impl XclipCommand { } } + /// A new boundary for block references already chosen (the External + /// Reference tab's Create Clipping Boundary): the New boundary branch at + /// once. Returns the command and the result of its first step. + pub fn start_new_boundary(inserts: Vec, clipped: bool) -> (Self, CmdResult) { + let mut command = Self::for_inserts(inserts, clipped); + let first = command.option("N"); + (command, first) + } + fn act(&self, action: XclipAction) -> CmdResult { CmdResult::XClip { inserts: self.inserts.clone(), diff --git a/src/ui/ribbon/mod.rs b/src/ui/ribbon/mod.rs index 0fd851d09..d1bc827c4 100644 --- a/src/ui/ribbon/mod.rs +++ b/src/ui/ribbon/mod.rs @@ -109,6 +109,8 @@ pub struct Ribbon { underlay_ctx: Option, /// The contextual underlay tab is the one shown. underlay_tab_active: bool, + /// Only xrefs are selected: the External Reference tab is offered. + xref_ctx: bool, /// XDWGFADECTL as the Reference slide-out shows it (negative = off). pub xref_fade: i32, } @@ -206,6 +208,7 @@ impl Ribbon { collapse_tight: Arc::new(AtomicBool::new(false)), underlay_ctx: None, underlay_tab_active: false, + xref_ctx: false, xref_fade: 50, } } @@ -589,8 +592,8 @@ impl Ribbon { ); let mut tab_items = tab_items; - if self.underlay_ctx.is_some() { - tab_items.push(underlay_tab_button(self.underlay_tab_shown())); + if let Some(title) = self.contextual_tab() { + tab_items.push(underlay_tab_button(title, self.underlay_tab_shown())); } // Tabs may squeeze their gaps to fit before wrapping: from the normal 6px @@ -1627,9 +1630,9 @@ mod tests { } } -/// The contextual underlay tab's button: framed in the accent colour. -fn underlay_tab_button<'a>(active: bool) -> Element<'a, Message> { - let btn = button(text(t!("PDF Underlay")).size(12)) +/// The contextual tab's button: framed in the accent colour. +fn underlay_tab_button<'a>(title: &'static str, active: bool) -> Element<'a, Message> { + let btn = button(text(t!(title)).size(12)) .on_press(Message::RibbonSelectUnderlayTab) .style(move |theme: &Theme, status| { let palette = theme.palette(); diff --git a/src/ui/ribbon/underlay_tab.rs b/src/ui/ribbon/underlay_tab.rs index ec36772c3..485e21342 100644 --- a/src/ui/ribbon/underlay_tab.rs +++ b/src/ui/ribbon/underlay_tab.rs @@ -1,5 +1,6 @@ -//! The contextual "PDF Underlay" tab: shown and brought forward while only -//! PDF underlays are selected, gone when the selection changes. +//! The contextual tabs: "PDF Underlay" while only PDF underlays are +//! selected, "External Reference" while only xrefs are; shown and brought +//! forward with the selection, gone when it changes. use iced::widget::{column, row, slider, text, text_input}; use iced::{Element, Length}; @@ -112,6 +113,47 @@ fn groups() -> &'static [RibbonGroup] { }) } +/// The External Reference tab: edit or open the reference, clip it, and the +/// External References palette. +fn xref_groups() -> &'static [RibbonGroup] { + static GROUPS: std::sync::OnceLock> = std::sync::OnceLock::new(); + const CLIP: &[u8] = include_bytes!("../../../assets/icons/xclip.svg"); + GROUPS.get_or_init(|| { + vec![ + RibbonGroup { + title: "Edit", + tools: vec![ + RibbonItem::LargeTool(tool( + "_XREFEDIT", + "Edit Reference\nIn-Place", + include_bytes!("../../../assets/icons/edit_block.svg"), + )), + RibbonItem::LargeTool(tool( + "_XREFOPEN", + "Open\nReference", + crate::ui::icons::FOLDER_OPEN, + )), + ], + }, + RibbonGroup { + title: "Clipping", + tools: vec![ + RibbonItem::LargeTool(tool("_XREFCLIP", "Create Clipping\nBoundary", CLIP)), + RibbonItem::LargeTool(tool("_XREFUNCLIP", "Remove\nClipping", CLIP)), + ], + }, + RibbonGroup { + title: "Options", + tools: vec![RibbonItem::LargeTool(tool( + "EXTERNALREFERENCES", + "External\nReferences", + crate::ui::icons::FOLDER_OPEN, + ))], + }, + ] + }) +} + /// Contrast / Fade: a label, a 0–100 slider and the value box. fn adjust_rows<'a>(ctx: &'a UnderlayContext) -> Element<'a, Message> { let line = |label: &'static str, @@ -156,15 +198,16 @@ fn adjust_rows<'a>(ctx: &'a UnderlayContext) -> Element<'a, Message> { } impl Ribbon { - /// Show the tab for the selected underlay, or drop it (`None`). A tab - /// that appears comes to the front; one that goes returns the tab that - /// was active before it. - pub fn set_underlay_context(&mut self, context: Option) { - match (&self.underlay_ctx, &context) { - (None, Some(_)) => self.underlay_tab_active = true, - (Some(_), None) => self.underlay_tab_active = false, - _ => {} + /// Show the tab for the selected underlay (`context`) or the selected + /// xrefs (`xref`), or drop it. A tab that appears comes to the front; + /// one that goes returns the tab that was active before it. + pub fn set_underlay_context(&mut self, context: Option, xref: bool) { + let before = (self.underlay_ctx.is_some(), self.xref_ctx); + let after = (context.is_some(), xref); + if before != after { + self.underlay_tab_active = after.0 || after.1; } + self.xref_ctx = xref; // A value being typed survives a refresh that leaves the value as is. let mut context = context; if let (Some(old), Some(new)) = (&self.underlay_ctx, &mut context) { @@ -180,9 +223,10 @@ impl Ribbon { self.underlay_ctx.as_mut() } - /// Select a tab by its module id; "pdf_underlay" is the contextual tab. + /// Select a tab by its module id; "pdf_underlay" and "xref" are the + /// contextual tabs. pub fn select_by_id(&mut self, id: &str) -> bool { - if id == "pdf_underlay" { + if (id == "pdf_underlay" && self.underlay_ctx.is_some()) || (id == "xref" && self.xref_ctx) { self.select_underlay_tab(); return self.underlay_tab_active; } @@ -196,13 +240,22 @@ impl Ribbon { } pub fn select_underlay_tab(&mut self) { - if self.underlay_ctx.is_some() { + if self.contextual_tab().is_some() { self.underlay_tab_active = true; } } pub(super) fn underlay_tab_shown(&self) -> bool { - self.underlay_tab_active && self.underlay_ctx.is_some() + self.underlay_tab_active && self.contextual_tab().is_some() + } + + /// The contextual tab's title, while one is offered. + pub(super) fn contextual_tab(&self) -> Option<&'static str> { + if self.xref_ctx { + Some("External Reference") + } else { + self.underlay_ctx.as_ref().map(|_| "PDF Underlay") + } } pub(super) fn underlay_panels<'a>( @@ -210,6 +263,12 @@ impl Ribbon { ts: widgets::ToggleState, style_ctx: &StyleContext<'_>, ) -> Vec> { + if self.xref_ctx { + return xref_groups() + .iter() + .map(|g| self.panel(g, ts, style_ctx, &|_| Vec::new())) + .collect(); + } let Some(ctx) = self.underlay_ctx.as_ref() else { return Vec::new(); };