Type-as-you-go suggestion popup above the input that filters known command names by substring (so `LEADER` surfaces both LEADER and MLEADER). Up / Down navigates the list, Enter dispatches the highlighted entry, clicking a row dispatches directly. Esc on a non-empty input clears the buffer instead of escalating to command-cancel. The name corpus comes from `inventory::submit!` blocks placed next to each `CadCommand` impl rather than a hand-maintained static list. Adding a new interactive command means dropping one `inventory::submit!` line in its own module file — the autocomplete picks it up at the next compile. 98 submissions seeded across 60 module files; `command::all_registered_command_names()` flattens them at runtime. One-shot dispatch arms in `app/commands.rs` (NEW, OPEN, SAVE, UNDO, …) don't have a `CadCommand` impl and are therefore absent from autocomplete by design. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
85 lines
2.5 KiB
Rust
85 lines
2.5 KiB
Rust
// Match Layer tool — ribbon definition + CadCommand implementation.
|
|
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
|
|
|
pub fn tool() -> ToolDef {
|
|
ToolDef {
|
|
id: "LAYMATCH",
|
|
label: "Match Layer",
|
|
icon: IconKind::Svg(include_bytes!(
|
|
"../../../../assets/icons/layers/laymatch.svg"
|
|
)),
|
|
event: ModuleEvent::Command("LAYMATCH".to_string()),
|
|
}
|
|
}
|
|
|
|
// ── CadCommand implementation ─────────────────────────────────────────────
|
|
|
|
use acadrust::Handle;
|
|
use glam::Vec3;
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
use crate::scene::wire_model::WireModel;
|
|
|
|
pub struct LayMatchCommand {
|
|
dest_handles: Vec<Handle>,
|
|
}
|
|
|
|
impl LayMatchCommand {
|
|
pub fn new(dest: Vec<Handle>) -> Self {
|
|
Self { dest_handles: dest }
|
|
}
|
|
}
|
|
|
|
impl CadCommand for LayMatchCommand {
|
|
fn name(&self) -> &'static str {
|
|
"LAYMATCH"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
if self.dest_handles.is_empty() {
|
|
"LAYMATCH Select objects to change layer:".into()
|
|
} else {
|
|
"LAYMATCH Select source object to match layer from:".into()
|
|
}
|
|
}
|
|
|
|
fn is_selection_gathering(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn on_selection_complete(&mut self, handles: Vec<Handle>) -> CmdResult {
|
|
if handles.is_empty() {
|
|
return CmdResult::NeedPoint;
|
|
}
|
|
if self.dest_handles.is_empty() {
|
|
// Phase 1 complete — store destinations, move to phase 2.
|
|
self.dest_handles = handles;
|
|
CmdResult::NeedPoint
|
|
} else {
|
|
// Phase 2 complete — first handle is the source object.
|
|
let src = handles[0];
|
|
CmdResult::MatchEntityLayer {
|
|
dest: std::mem::take(&mut self.dest_handles),
|
|
src,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn on_point(&mut self, _pt: Vec3) -> CmdResult {
|
|
CmdResult::NeedPoint
|
|
}
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
fn on_escape(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
fn on_hover_entity(&mut self, _handle: Handle, _pt: Vec3) -> Vec<WireModel> {
|
|
vec![]
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["LAYMATCH", "LAYMCH"] }); // LayMatchCommand
|