Insert ribbon: Import panel

Import File split button (PDF Import / DGN Import / Import), Recognize
SHX Text, Recognition Settings and Combine Text; Land XML moves to the
panel slide-out and Open leaves the panel. Ribbon commands may be menu
macros (`;` answers the running command's prompt). KeyTips IF, PI, DI,
OI, PS, PT, TM; labels in every locale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-15 14:53:08 +03:00
1 parent 39c3e9af58
commit 8a87a09e30
33 files changed
+326 -41

No files matched your search

+19
View File
@@ -107,6 +107,25 @@ impl OpenCADStudio {
task
}
/// Run a ribbon command. A `;` stands for Enter, as in a menu macro: each
/// part answers the running command's prompt, or starts a command when
/// none runs (`PDFIMPORT;FILE`).
pub(super) fn dispatch_ribbon_command(&mut self, cmd: &str) -> Task<Message> {
if !cmd.contains(';') {
return self.dispatch_command(cmd);
}
let i = self.active_tab;
let mut tasks = Vec::new();
for part in cmd.split(';') {
tasks.push(if self.tabs[i].active_cmd.is_some() {
self.feed_active_cmd(part)
} else {
self.dispatch_command(part)
});
}
Task::batch(tasks)
}
/// Turn the ribbon highlight off when the command just dispatched left
/// nothing running: no interactive command, dialog or navigation mode.
/// One-shot commands (view changes, clipboard, toggles, audits…) would
+1 -1
View File
@@ -133,7 +133,7 @@ impl OpenCADStudio {
match event {
// `dispatch_command` turns a one-shot tool's highlight off
// again once nothing is left running (#355).
ModuleEvent::Command(cmd) => return self.dispatch_command(&cmd),
ModuleEvent::Command(cmd) => return self.dispatch_ribbon_command(&cmd),
ModuleEvent::OpenFileDialog => {
self.command_line
.push_info(crate::t!("Open DWG/DXF: not yet implemented.").as_ref());
+1 -1
View File
@@ -6613,7 +6613,7 @@ impl OpenCADStudio {
};
self.ribbon.select_dropdown_item(dropdown_id, face);
self.ribbon.activate_tool(cmd);
self.dispatch_command(cmd)
self.dispatch_ribbon_command(cmd)
}
Message::DeleteSelected => {
+6
View File
@@ -6085,6 +6085,12 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static
"Remote image \"{url}\" could not be fetched: the server returned HTTP {status}." => Some(("common", "remote-image-url-could-not-be-fetched-the-server-returned-http-status")),
"Remote image \"{url}\" was not loaded: it exceeds the 64 MB remote-image limit." => Some(("common", "remote-image-url-was-not-loaded-it-exceeds-the-64-mb-remote-image-limit")),
"Remote image \"{url}\" could not be fetched: the request timed out." => Some(("common", "remote-image-url-could-not-be-fetched-the-request-timed-out")),
"DGN Import" => Some(("import-panel", "dgn-import")),
"Recognize SHX Text" => Some(("import-panel", "recognize-shx")),
"Recognition Settings" => Some(("import-panel", "recognition-settings")),
"Combine Text" => Some(("import-panel", "combine-text")),
"Land XML" => Some(("import-panel", "land-xml")),
"Import File — the face runs the last one chosen" => Some(("import-panel", "import-file-header")),
_ => None,
}
}
-10
View File
@@ -1,10 +0,0 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/landxml.svg"));
pub fn tool() -> ToolDef {
ToolDef {
id: "LANDXMLIMPORT",
label: "Land\nXML",
icon: ICON,
event: ModuleEvent::Command("LANDXMLIMPORT".to_string()),
}
}
+40 -6
View File
@@ -11,10 +11,8 @@ mod design_center;
pub(crate) mod edit_block;
pub(crate) mod image_transparency;
pub(crate) mod insert_block;
mod landxml;
pub mod minsert;
mod mview_block;
mod open_obj;
pub(crate) mod pc_attach;
pub(crate) mod pc_crop;
pub(crate) mod pc_extract;
@@ -32,7 +30,9 @@ pub(crate) mod xattach;
pub(crate) mod xclip;
pub(crate) mod xref_cmd;
use crate::modules::{CadModule, IconKind, RibbonGroup, RibbonItem};
use crate::modules::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
const IMPORT_ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/import_obj.svg"));
const FRAMES_ICON: IconKind =
IconKind::Svg(include_bytes!("../../../assets/icons/underlay_frames.svg"));
@@ -144,12 +144,46 @@ impl CadModule for InsertModule {
},
],
},
// ── Import ────────────────────────────────────────────────────────
// ── Import (slide-out: Land XML) ──────────────────────────────────
RibbonGroup {
title: "Import",
tools: vec![
RibbonItem::LargeTool(open_obj::tool()),
RibbonItem::LargeTool(landxml::tool()),
// The face names and runs the last one chosen. A `;`
// answers the started command's prompt, as in a menu
// macro.
RibbonItem::LargeDropdown {
id: "IMPORT_FILE",
label: "",
icon: IMPORT_ICON,
items: vec![
("PDFIMPORT;FILE", "PDF Import", underlay_layers::ICON),
("DGNIMPORT", "DGN Import", underlay_layers::ICON),
("IMPORT", "Import…", IMPORT_ICON),
],
default: "PDFIMPORT;FILE",
},
RibbonItem::LabeledTool(ToolDef {
id: "PDFSHXTEXT",
label: "Recognize SHX Text",
icon: IconKind::Svg(include_bytes!("../../../assets/icons/text.svg")),
event: ModuleEvent::Command("PDFSHXTEXT".to_string()),
}),
RibbonItem::LabeledTool(ToolDef {
id: "PDFSHXTEXT_SETTINGS",
label: "Recognition Settings",
icon: IconKind::Svg(include_bytes!(
"../../../assets/icons/options_tool.svg"
)),
event: ModuleEvent::Command(
"PDFSHXTEXTSETTINGS 1;PDFSHXTEXT;SETTINGS".to_string(),
),
}),
RibbonItem::LargeTool(ToolDef {
id: "TXT2MTXT",
label: "Combine Text",
icon: IconKind::Svg(include_bytes!("../../../assets/icons/mtext.svg")),
event: ModuleEvent::Command("TXT2MTXT".to_string()),
}),
],
},
// ── Content ───────────────────────────────────────────────────────
-9
View File
@@ -1,9 +0,0 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub fn tool() -> ToolDef {
ToolDef {
id: "OPEN",
label: "Open",
icon: IconKind::Svg(include_bytes!("../../../assets/icons/import_obj.svg")),
event: ModuleEvent::OpenFileDialog,
}
}
+53 -13
View File
@@ -171,6 +171,14 @@ const BLOCK_DEFINITION_TOOLS: &[Tool] = &[
),
];
/// Insert > Import slide-out, its tools named beside their icons.
const IMPORT_TOOLS: &[Tool] = &[icon_tool(
"LANDXMLIMPORT",
"Land XML",
include_bytes!("../../../assets/icons/landxml.svg"),
)];
const IMPORT_PANEL_ID: &str = "import_extension";
const PANELS: &[Panel] = &[
Panel {
id: PANEL_ID,
@@ -207,6 +215,13 @@ const PANELS: &[Panel] = &[
title: "Block Definition",
tools: BLOCK_DEFINITION_TOOLS,
},
Panel {
id: IMPORT_PANEL_ID,
anchor: None,
title_id: "import_extension_title",
title: "Import",
tools: IMPORT_TOOLS,
},
];
/// Command, label and icon of every tool in the expanded Draw and Modify
@@ -415,19 +430,14 @@ fn tool_button(tool: &Tool, active: bool, panel_id: &'static str) -> Element<'st
}
}
/// The Reference slide-out: Edit Reference, and xref fading on/off with its
/// amount (XDWGFADECTL; the switch keeps the amount as a negative value).
fn reference_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Element<'a, Message> {
let width: f32 = 260.0_f32.min((win.0 - 8.0).max(120.0));
let (_, x, anchor_top) = ribbon.dd_anchor(panel.id, width, win.0);
let left = x.clamp(0.0, (win.0 - width).max(0.0));
let top = anchor_top.min((win.1 - 80.0).max(0.0));
let tool = &panel.tools[0];
let edit = button(
/// A slide-out tool as one row: its icon, then its name.
fn labeled_row(panel_id: &'static str, tool: &Tool) -> Element<'static, Message> {
let command = tool.command;
let row = button(
row![
make_icon(IconKind::Svg(tool.icon), 16.0),
keytips::label_anchor(
|| keytips::label_id(&keytips::item_anchor(panel.id, tool.command)),
move || keytips::label_id(&keytips::item_anchor(panel_id, command)),
text(t!(tool.label)).size(11),
),
]
@@ -435,13 +445,40 @@ fn reference_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Elem
.align_y(iced::Center),
)
.on_press(Message::DropdownSelectItem {
dropdown_id: panel.id,
cmd: tool.command,
dropdown_id: panel_id,
cmd: command,
})
.style(popup_row_style)
.width(Fill)
.padding([3, 6]);
let edit = keytips::anchor_with(|| keytips::item_anchor(panel.id, tool.command), edit);
keytips::anchor_with(move || keytips::item_anchor(panel_id, command), row)
}
/// The Import slide-out: its tools listed with their names.
fn import_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Element<'a, Message> {
let width: f32 = 160.0_f32.min((win.0 - 8.0).max(120.0));
let (_, x, anchor_top) = ribbon.dd_anchor(panel.id, width, win.0);
let left = x.clamp(0.0, (win.0 - width).max(0.0));
let top = anchor_top.min((win.1 - 80.0).max(0.0));
let rows = panel.tools.iter().map(|tool| labeled_row(panel.id, tool));
let body = container(column(rows).spacing(2).padding(6))
.width(width)
.style(|theme: &Theme| {
let mut style = popup_panel_style(theme);
style.border.color = theme.palette().primary.base.color;
style
});
dropdown_backdrop(position_ribbon_dropdown(body.into(), false, left, top))
}
/// The Reference slide-out: Edit Reference, and xref fading on/off with its
/// amount (XDWGFADECTL; the switch keeps the amount as a negative value).
fn reference_overlay<'a>(ribbon: &Ribbon, panel: Panel, win: (f32, f32)) -> Element<'a, Message> {
let width: f32 = 260.0_f32.min((win.0 - 8.0).max(120.0));
let (_, x, anchor_top) = ribbon.dd_anchor(panel.id, width, win.0);
let left = x.clamp(0.0, (win.0 - width).max(0.0));
let top = anchor_top.min((win.1 - 80.0).max(0.0));
let edit = labeled_row(panel.id, &panel.tools[0]);
let fade = ribbon.xref_fade;
let on = fade > 0;
let switch = button(make_icon(
@@ -495,6 +532,9 @@ pub(super) fn overlay<'a>(ribbon: &Ribbon, id: &str, win: (f32, f32)) -> Element
if panel.id == REFERENCE_PANEL_ID {
return reference_overlay(ribbon, panel, win);
}
if panel.id == IMPORT_PANEL_ID {
return import_overlay(ribbon, panel, win);
}
let tools = panel.tools;
let width = (7.0 * (CELL + GAP) - GAP + 12.0).min((win.0 - 8.0).max(CELL + 12.0));
let (_, x, anchor_top) = ribbon.dd_anchor(panel.id, width, win.0);
+7
View File
@@ -403,6 +403,13 @@ const CODES: &[(&str, &str, &str)] = &[
("insert", "UOSNAP_DROPDOWN", "SN"),
("reference_extension", "REFEDIT", "ER"),
("reference_extension", XREF_FADE, "XF"),
("insert", "IMPORT_FILE", "IF"),
("IMPORT_FILE", "PDFIMPORT;FILE", "PI"),
("IMPORT_FILE", "DGNIMPORT", "DI"),
("IMPORT_FILE", "IMPORT", "OI"),
("insert", "PDFSHXTEXT", "PS"),
("insert", "PDFSHXTEXT_SETTINGS", "PT"),
("insert", "TXT2MTXT", "TM"),
// Annotate.
("annotate", "Text", "TE"),
("annotate", "ANNOTATE_TEXT", "MT"),
+17 -1
View File
@@ -50,6 +50,11 @@ pub(crate) fn tooltip_style(theme: &Theme) -> container::Style {
widgets::tip_style(theme)
}
/// A line over the items of a split button whose face names the chosen item.
fn dropdown_header(id: &str) -> Option<&'static str> {
(id == "IMPORT_FILE").then_some("Import File — the face runs the last one chosen")
}
// ── Ribbon state ───────────────────────────────────────────────────────────
pub struct Ribbon {
@@ -1066,11 +1071,22 @@ impl Ribbon {
.iter()
.map(|(_, label, _)| t!(*label).to_string())
.collect();
let header = dropdown_header(dd_id).map(|header| t!(header).into_owned());
let mut rows = rows;
if let Some(header) = &header {
rows.insert(
0,
container(text(header.clone()).size(10).style(muted_text_style))
.padding([4, 10])
.into(),
);
}
let panel_w = crate::ui::style::common::dropdown_popup_width(
labels.iter().map(|s| s.as_str()),
11.0,
68.0,
190.0,
// A header wraps rather than widening the menu.
if header.is_some() { 240.0 } else { 190.0 },
);
let panel = container(column(rows))
+6
View File
@@ -499,6 +499,8 @@ fn tool_description(id: &str) -> Option<&'static str> {
/// A tool's tooltip: its name, its description when one is known, and the
/// command it runs.
fn tool_tip_text(label: &str, id: &str) -> String {
// A macro (`PDFIMPORT;FILE`) shows the command it starts.
let id = id.split(';').next().unwrap_or(id);
match tool_description(id) {
Some(description) => format!("{label}\n{}\n{} {id}", t!(description), t!("Command:")),
None => format!("{label}\n{} {id}", t!("Command:")),
@@ -825,6 +827,10 @@ pub(super) fn render_large_dropdown<'a>(
})
.or_else(|| items.first().map(|(_, lbl, _)| *lbl))
.unwrap_or(id);
// An empty label: the face keeps its own icon and names the chosen item.
let names_item = explicit_label == Some("");
let cur_icon = if names_item { icon } else { cur_icon };
let explicit_label = explicit_label.filter(|label| !label.is_empty());
let label = t!(explicit_label.unwrap_or(cur_label)).into_owned();
let tip_text = tool_tip_text(&t!(cur_label), last);
let arr_tip = format!("{} {}", label, t!("options"));