style: apply cargo fmt across workspace

This commit is contained in:
Karim Jerbi committed 2026-10-11 03:14:29 +01:00
1 parent 85710e5454
commit 9cf9ff2c5c
531 files changed
+57740 -33906

No files matched your search

+146 -98
View File
@@ -91,9 +91,9 @@ fn reorder_insertion_index(from: usize, to: usize, after: bool, len: usize) -> O
(insertion != from).then_some(insertion)
}
mod blocks_palette;
mod command;
mod context_menu;
mod blocks_palette;
mod dialog;
mod dynamic;
mod file;
@@ -352,7 +352,8 @@ impl OpenCADStudio {
2 => "ATTMODE2",
_ => "ATTMODE1",
};
self.ribbon.set_dropdown_current("ATTMODE_DROPDOWN", attmode);
self.ribbon
.set_dropdown_current("ATTMODE_DROPDOWN", attmode);
}
fn update_message(&mut self, msg: Message) -> Task<Message> {
@@ -382,8 +383,7 @@ impl OpenCADStudio {
{
// Esc backs out of a pending ALIASEDIT draft first, mirroring
// the shortcut editor's capture cancel; the next Esc closes.
if self.active_modal == Some(super::ModalKind::Aliases) && self.alias_pending_add
{
if self.active_modal == Some(super::ModalKind::Aliases) && self.alias_pending_add {
return self.update(Message::AliasEditorDraftCancel);
}
if self.active_modal == Some(super::ModalKind::BlockDefinition) {
@@ -445,9 +445,12 @@ impl OpenCADStudio {
// a mouse move included — without allocating.
#[cfg(not(target_arch = "wasm32"))]
let active_command = |app: &Self| -> Option<(u64, Option<&'static str>)> {
app.tabs
.get(app.active_tab)
.map(|tab| (tab.id, tab.active_cmd.as_ref().map(|command| command.name())))
app.tabs.get(app.active_tab).map(|tab| {
(
tab.id,
tab.active_cmd.as_ref().map(|command| command.name()),
)
})
};
#[cfg(not(target_arch = "wasm32"))]
let command_before = active_command(self);
@@ -564,9 +567,8 @@ impl OpenCADStudio {
Message::SpaceMouseWake => self.on_spacemouse_wake(),
Message::TrackpadPinch(magnification) => self.on_pinch_zoom(magnification),
Message::SpaceMouseFrame(time) => {
self.spacemouse.frame(
time.saturating_duration_since(self.start).as_secs_f64() * 1000.,
);
self.spacemouse
.frame(time.saturating_duration_since(self.start).as_secs_f64() * 1000.);
Task::none()
}
Message::SpaceMouseFocus(id, focused) => {
@@ -618,9 +620,8 @@ impl OpenCADStudio {
if response["ok"] == false {
let code = response["code"].as_str().unwrap_or("failed");
let detail = response["error"].as_str().unwrap_or("");
self.command_line.push_error(&format!(
"automation {op}: {code} — {detail}"
));
self.command_line
.push_error(&format!("automation {op}: {code} — {detail}"));
} else if matches!(
response["status"].as_str(),
Some("completed" | "cancelled" | "waiting_input")
@@ -966,7 +967,8 @@ impl OpenCADStudio {
.scene
.selection
.borrow_mut()
.menu.open_at = None;
.menu
.open_at = None;
// Same guard as typed MTP/M2P: point step, not entity pick.
let i = self.active_tab;
let allowed = self.tabs[i].active_cmd.as_ref().is_some_and(|c| {
@@ -1226,19 +1228,23 @@ impl OpenCADStudio {
Task::none()
}
Message::ImageEmbedPick => {
Task::perform(crate::io::pick_embedded_image_file(), Message::ImageEmbedPickResult)
}
Message::ImageEmbedPick => Task::perform(
crate::io::pick_embedded_image_file(),
Message::ImageEmbedPickResult,
),
Message::ImageEmbedPickResult(Ok(image)) => {
use crate::command::CadCommand;
use crate::modules::draw::draw::raster_image::ImageCommand;
self.command_line.push_output(crate::tf!(
"IMAGEEMBED \"{name}\": {w}×{h} px (embedded)",
name = image.name.as_str(),
w = image.pixel_width,
h = image.pixel_height,
).as_ref());
self.command_line.push_output(
crate::tf!(
"IMAGEEMBED \"{name}\": {w}×{h} px (embedded)",
name = image.name.as_str(),
w = image.pixel_width,
h = image.pixel_height,
)
.as_ref(),
);
let cmd = ImageCommand::new_embedded(image);
let i = self.active_tab;
self.command_line.push_info(&cmd.prompt());
@@ -1325,10 +1331,13 @@ impl OpenCADStudio {
.insert(crate::io::font_repo::font_key(name));
}
for (name, path) in &pairs {
self.command_line.push_output(crate::tf!(
"FONT Downloaded {name} → {path}",
path = path.display()
).as_ref());
self.command_line.push_output(
crate::tf!(
"FONT Downloaded {name} → {path}",
path = path.display()
)
.as_ref(),
);
}
if !unavailable.is_empty() {
self.command_line.push_info(crate::tf!(
@@ -1344,14 +1353,16 @@ impl OpenCADStudio {
if let Some(path) = path {
return Task::done(Message::OpenExternal(path));
}
self.command_line.push_info(crate::t!(
"Save and reopen the drawing to apply the new fonts."
).as_ref());
self.command_line.push_info(
crate::t!("Save and reopen the drawing to apply the new fonts.")
.as_ref(),
);
}
Err(e) => {
// Keep the prompt open: the user can correct a custom
// source or retry a transient network failure.
self.command_line.push_error(crate::tf!("Font download failed: {e}").as_ref());
self.command_line
.push_error(crate::tf!("Font download failed: {e}").as_ref());
}
}
Task::none()
@@ -1889,9 +1900,9 @@ impl OpenCADStudio {
self.refresh_layer_panel();
self.sync_ribbon_styles();
}
Err(error) => self.command_line.push_error(
error["error"].as_str().unwrap_or("template"),
),
Err(error) => self
.command_line
.push_error(error["error"].as_str().unwrap_or("template")),
}
}
Task::none()
@@ -2170,8 +2181,7 @@ impl OpenCADStudio {
(false, Vec::new(), String::new(), Vec::new())
};
self.command_line
.set_contextual_suggestions(suggestions);
self.command_line.set_contextual_suggestions(suggestions);
if should_update {
self.command_line.set_step_options(opts);
@@ -2602,7 +2612,8 @@ impl OpenCADStudio {
use crate::app::config::DockSide;
use crate::ui::dock::PanelId;
if self.dock.location(PanelId::ExternalReferences).is_none() {
self.dock.dock(PanelId::ExternalReferences, DockSide::Right, usize::MAX);
self.dock
.dock(PanelId::ExternalReferences, DockSide::Right, usize::MAX);
}
self.dock_expanded = Some(PanelId::ExternalReferences);
self.refresh_xref_manager();
@@ -2740,16 +2751,13 @@ impl OpenCADStudio {
};
let new_raw = path.to_string_lossy().into_owned();
self.push_undo_snapshot(i, "XREF-PATH");
match crate::io::xref::set_ref_path(
&mut self.tabs[i].scene.document,
key,
&new_raw,
) {
match crate::io::xref::set_ref_path(&mut self.tabs[i].scene.document, key, &new_raw)
{
Ok(name) => {
self.command_line.push_output(crate::tf!(
"XREF: Path set for \"{}\" — Reload to apply.",
name
).as_ref());
self.command_line.push_output(
crate::tf!("XREF: Path set for \"{}\" — Reload to apply.", name)
.as_ref(),
);
self.post_ref_op(i);
}
Err(msg) => self.command_line.push_error(msg.as_str()),
@@ -2759,7 +2767,8 @@ impl OpenCADStudio {
}
Message::XrefPathPickResult(Err(e)) => {
if e != "Cancelled" {
self.command_line.push_error(crate::tf!("XREF: {e}").as_ref());
self.command_line
.push_error(crate::tf!("XREF: {e}").as_ref());
}
Task::none()
}
@@ -2785,9 +2794,13 @@ impl OpenCADStudio {
if let Some(found) = entry.found_at.clone() {
let is_dwg = found.to_ascii_lowercase().ends_with(".dwg")
|| found.to_ascii_lowercase().ends_with(".dxf");
self.command_line.push_output(crate::tf!("XOPEN: opening \"{}\".", found).as_ref());
self.command_line.push_output(
crate::tf!("XOPEN: opening \"{}\".", found).as_ref(),
);
if is_dwg {
return self.update(Message::OpenRecent(std::path::PathBuf::from(found)));
return self.update(Message::OpenRecent(
std::path::PathBuf::from(found),
));
} else {
#[cfg(not(target_arch = "wasm32"))]
let _ = open::that_detached(&found);
@@ -2827,7 +2840,10 @@ impl OpenCADStudio {
|| "XREF Path Find ".to_string(),
|entry| {
let saved = &entry.saved_path;
if let Some(parent) = std::path::Path::new(saved).parent().and_then(|p| p.to_str()) {
if let Some(parent) = std::path::Path::new(saved)
.parent()
.and_then(|p| p.to_str())
{
if !parent.is_empty() {
format!("XREF Path Find \"{}\" ", parent)
} else {
@@ -3171,20 +3187,15 @@ impl OpenCADStudio {
super::LayerStateProperty::Frozen => codec::LayerStateMask::FROZEN,
super::LayerStateProperty::Locked => codec::LayerStateMask::LOCKED,
super::LayerStateProperty::Plot => codec::LayerStateMask::PLOT,
super::LayerStateProperty::NewViewport => {
codec::LayerStateMask::NEW_VIEWPORT
}
super::LayerStateProperty::NewViewport => codec::LayerStateMask::NEW_VIEWPORT,
super::LayerStateProperty::Color => codec::LayerStateMask::COLOR,
super::LayerStateProperty::LineType => codec::LayerStateMask::LINE_TYPE,
super::LayerStateProperty::LineWeight => codec::LayerStateMask::LINE_WEIGHT,
super::LayerStateProperty::PlotStyle => codec::LayerStateMask::PLOT_STYLE,
super::LayerStateProperty::Transparency => {
codec::LayerStateMask::TRANSPARENCY
}
super::LayerStateProperty::Transparency => codec::LayerStateMask::TRANSPARENCY,
};
if let Some(state) = self.layer_state_edit_draft.as_mut() {
state.mask =
codec::LayerStateMask::from_bits(state.mask.bits() ^ flag.bits());
state.mask = codec::LayerStateMask::from_bits(state.mask.bits() ^ flag.bits());
}
Task::none()
}
@@ -3806,7 +3817,8 @@ impl OpenCADStudio {
.scene
.selection
.borrow_mut()
.input.last_move_pos = Some(p);
.input
.last_move_pos = Some(p);
return Task::none();
}
self.focus_model_pane(idx);
@@ -3903,7 +3915,8 @@ impl OpenCADStudio {
let was_click = !sel.input.right_dragging;
// How long the button was held, for the time-sensitive mode.
let held_ms = sel
.input.right_press_time
.input
.right_press_time
.map_or(0, |t| t.elapsed().as_millis() as i32);
sel.input.right_down = false;
sel.input.right_press_pos = None;
@@ -4095,7 +4108,8 @@ impl OpenCADStudio {
.scene
.selection
.borrow()
.input.last_move_pos
.input
.last_move_pos
.unwrap_or(self.cursor_pos);
self.update_grip_hover(i, p);
Task::none()
@@ -4490,7 +4504,9 @@ impl OpenCADStudio {
continue;
};
let current = (
crate::scene::pe_url_of(entity).unwrap_or_default().to_owned(),
crate::scene::pe_url_of(entity)
.unwrap_or_default()
.to_owned(),
crate::scene::pe_url_description_of(entity)
.unwrap_or_default()
.to_owned(),
@@ -4602,18 +4618,16 @@ impl OpenCADStudio {
return Task::none();
};
if self.tabs[i].scene.is_layer_locked(entity) {
self.command_line.push_info(
crate::t!("The object is on a locked layer.").as_ref(),
);
self.command_line
.push_info(crate::t!("The object is on a locked layer.").as_ref());
return Task::none();
}
if let Some(sh) = self.tabs[i].scene.scale_handle_ensuring(&name) {
self.push_undo_snapshot(i, "OBJECTSCALE");
let doc = &mut self.tabs[i].scene.document;
let is_member =
crate::scene::annotative::object_scale_memberships(doc, entity)
.iter()
.any(|(_, h)| *h == sh);
let is_member = crate::scene::annotative::object_scale_memberships(doc, entity)
.iter()
.any(|(_, h)| *h == sh);
if is_member {
crate::scene::annotative::remove_annotation_context_for_scale(
doc, entity, sh,
@@ -4625,9 +4639,8 @@ impl OpenCADStudio {
self.invalidate_property_targets(i, &[entity]);
self.refresh_properties();
} else {
self.command_line.push_info(
crate::tf!("Unknown annotation scale '{name}'.").as_ref(),
);
self.command_line
.push_info(crate::tf!("Unknown annotation scale '{name}'.").as_ref());
}
Task::none()
}
@@ -4953,7 +4966,9 @@ impl OpenCADStudio {
self.tabs[i].scene.bump_geometry();
self.refresh_properties();
crate::entities::common::set_unit_context(
crate::entities::common::UnitContext::from_header(&self.tabs[i].scene.document.header),
crate::entities::common::UnitContext::from_header(
&self.tabs[i].scene.document.header,
),
);
Task::none()
}
@@ -5112,12 +5127,14 @@ impl OpenCADStudio {
};
let name = state.name.trim().to_string();
if name.is_empty() {
state.error_message = Some(crate::t!("Block name cannot be empty.").into_owned());
state.error_message =
Some(crate::t!("Block name cannot be empty.").into_owned());
return Task::none();
}
if let Some(_ch) = state.invalid_name_char() {
state.error_message = Some(
crate::t!("Block name cannot contain: \\ / : * ? \" < > | = `").into_owned(),
crate::t!("Block name cannot contain: \\ / : * ? \" < > | = `")
.into_owned(),
);
return Task::none();
}
@@ -5128,13 +5145,21 @@ impl OpenCADStudio {
}
if !state.objects_specify_onscreen && state.selected_handles.is_empty() {
state.error_message = Some(
crate::t!("No objects selected. You must select objects to define a block.")
.into_owned(),
crate::t!(
"No objects selected. You must select objects to define a block."
)
.into_owned(),
);
return Task::none();
}
let i = self.active_tab;
if self.tabs[i].scene.document.block_records.get(&name).is_some() {
if self.tabs[i]
.scene
.document
.block_records
.get(&name)
.is_some()
{
state.confirm_redefine = Some(name);
return Task::none();
}
@@ -5160,12 +5185,16 @@ impl OpenCADStudio {
let current_path = std::path::Path::new(&state.file_path);
let file_stem = current_path.file_stem().and_then(|s| s.to_str());
let is_default_or_block = file_stem == Some("new_block")
|| state.existing_blocks.iter().any(|b| Some(b.as_str()) == file_stem);
|| state
.existing_blocks
.iter()
.any(|b| Some(b.as_str()) == file_stem);
if is_default_or_block {
let new_file_name = format!("{}.dwg", trimmed);
if let Some(parent) = current_path.parent() {
if !parent.as_os_str().is_empty() {
state.file_path = parent.join(new_file_name).to_string_lossy().to_string();
state.file_path =
parent.join(new_file_name).to_string_lossy().to_string();
} else {
state.file_path = new_file_name;
}
@@ -5286,12 +5315,19 @@ impl OpenCADStudio {
WblockSourceMode::Block => {
let name = state.block_name.trim();
if name.is_empty() {
state.error_message =
Some(crate::t!("Please select or enter a block name.").into_owned());
state.error_message = Some(
crate::t!("Please select or enter a block name.").into_owned(),
);
return Task::none();
}
let i = self.active_tab;
if self.tabs[i].scene.document.block_records.get(name).is_none() {
if self.tabs[i]
.scene
.document
.block_records
.get(name)
.is_none()
{
state.error_message = Some(
crate::tf!("Block \"{}\" does not exist in drawing.", name)
.into_owned(),
@@ -5416,10 +5452,7 @@ impl OpenCADStudio {
}
WblockSourceMode::Objects => {
crate::modules::insert::wblock::extract_entities_to_doc_with_base(
&document,
&handles,
base_point,
unit,
&document, &handles, base_point, unit,
)
.map_err(|e| e.to_string())?
}
@@ -5478,7 +5511,9 @@ impl OpenCADStudio {
self.tabs[i].scene.bump_geometry();
self.refresh_properties();
crate::entities::common::set_unit_context(
crate::entities::common::UnitContext::from_header(&self.tabs[i].scene.document.header),
crate::entities::common::UnitContext::from_header(
&self.tabs[i].scene.document.header,
),
);
let label = crate::modules::draw::units::linear_format_label(code);
self.command_line
@@ -5808,8 +5843,7 @@ impl OpenCADStudio {
Task::none()
}
Message::AutoConstrainReset => {
self.auto_constrain_settings =
super::settings::AutoConstrainSettings::default();
self.auto_constrain_settings = super::settings::AutoConstrainSettings::default();
self.auto_constrain_selected_row = 0;
self.auto_constrain_distance_input =
format!("{}", self.auto_constrain_settings.distance_tolerance);
@@ -5848,8 +5882,7 @@ impl OpenCADStudio {
self.auto_constrain_settings.distance_tolerance = distance;
self.auto_constrain_settings.angle_tolerance_deg = angle;
self.auto_constrain_settings.sanitize();
self.auto_constrain_saved =
Some(self.auto_constrain_settings.clone());
self.auto_constrain_saved = Some(self.auto_constrain_settings.clone());
self.persist_settings_if_changed();
if matches!(action, Message::AutoConstrainOk) {
self.close_active_modal();
@@ -6917,7 +6950,8 @@ impl OpenCADStudio {
};
let Some((sx, sy, sz)) = scales else { return };
let eq = (sx - sy).abs() < 1e-12 && (sx - sz).abs() < 1e-12;
let checked = eq && !app.tabs[i].props_asym_scale.contains(&handle.value());
let checked =
eq && !app.tabs[i].props_asym_scale.contains(&handle.value());
if checked {
app.tabs[i].props_asym_scale.insert(handle.value());
} else {
@@ -8728,7 +8762,9 @@ impl OpenCADStudio {
Message::CloseModal => {
// The Invalid Area dialog's ✕ undoes the boundary change, as its Cancel does.
if self.active_modal == Some(super::ModalKind::CountInvalidArea) {
return self.update(Message::Count(crate::ui::window::count_palette::CountMsg::InvalidUndo));
return self.update(Message::Count(
crate::ui::window::count_palette::CountMsg::InvalidUndo,
));
}
if self.active_modal == Some(super::ModalKind::SheetSet) {
self.close_sheet_set_dialog();
@@ -8745,7 +8781,11 @@ impl OpenCADStudio {
self.attdef_dialog = None;
let editing = self.attdef_edit.take().is_some();
self.close_active_modal();
return if editing { self.post_editor_closed(false) } else { Task::none() };
return if editing {
self.post_editor_closed(false)
} else {
Task::none()
};
}
// Cancelling the section settings drops the waiting extraction.
if self.active_modal == Some(super::ModalKind::PcSection) {
@@ -11269,7 +11309,10 @@ mod dock_visibility_tests {
}
app.clean_screen = true;
for id in ALL {
assert!(!app.dock_panel_visible(id), "{id:?} must hide on clean screen");
assert!(
!app.dock_panel_visible(id),
"{id:?} must hide on clean screen"
);
}
}
@@ -11430,7 +11473,9 @@ mod free_text_entry_tests {
app.clipboard = vec![codec::EntityType::Line(codec::entities::Line::default())];
// A dialog field pasted natively: no command-line text, no PASTECLIP.
let _ = app.update(Message::PasteShortcutResolved(crate::app::PasteFocus::Field));
let _ = app.update(Message::PasteShortcutResolved(
crate::app::PasteFocus::Field,
));
assert_eq!(app.command_line.input, "EXISTING");
assert!(app.tabs[0].active_cmd.is_none());
}
@@ -11449,7 +11494,10 @@ mod free_text_entry_tests {
// Copied objects paste even though the command line holds focus.
app.clipboard = vec![codec::EntityType::Line(codec::entities::Line::default())];
let _ = app.update(Message::PasteShortcutResolved(PasteFocus::CommandLine));
assert!(app.tabs[0].active_cmd.as_ref().is_some_and(|cmd| cmd.name() == "PASTECLIP"));
assert!(app.tabs[0]
.active_cmd
.as_ref()
.is_some_and(|cmd| cmd.name() == "PASTECLIP"));
}
}