feat(alias): centralize command aliases in user-editable ocad.pgp (#286/#288)

Command aliases (L→LINE, CC→COPYCLIP) were scattered across dispatch match
arms and CommandRegistration name arrays. Move them all into a single
user-editable file:

- assets/ocad.pgp: shipped default alias table (ALIAS,*COMMAND format),
  embedded and copied to config/ocad.pgp on first launch; only that user
  copy is read after. AA→AREA default closes #286.
- resolve_alias() rewrites the leading command token at the top of
  dispatch_command_inner, so aliases resolve for every path (families,
  plugins, Repeat menu). Args after the first space are untouched.
- Autocomplete hides alias keys and, when the whole input is an alias,
  surfaces its target command as the top (highlighted) suggestion so the
  highlight matches what Enter runs (AA→AREA, L→LINE).
- ALIASEDIT opens a new editor modal (add/edit/delete rows) with an Apply
  button; Apply persists to ocad.pgp, closing discards unapplied edits.
- Strip alias tokens from all 8 dispatch match-arm files and 71 module
  CommandRegistration arrays, keeping canonical/synonym/distinct-command
  names. ocad.pgp is now the sole source: deleting or remapping an alias
  there takes effect. CUI stays on the keyboard-shortcut panel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-07-10 12:39:22 +03:00
1 parent f5b8a7d993
commit 91ba9f7699
69 files changed
+767 -164

No files matched your search

+159
View File
@@ -0,0 +1,159 @@
//! Command aliases — short abbreviations typed at the command line that expand
//! to a full command (e.g. `L` → `LINE`). The alias table is the single source
//! of truth: it is loaded from a user-editable `aliases.pgp` file at startup and
//! consulted before every command dispatch (see `resolve_alias`), so users can
//! add, remap, or delete aliases without touching the app.
//!
//! File format mirrors the long-standing plain-text `.pgp` convention so it is
//! familiar and hand-editable, stored as `ocad.pgp`:
//!
//! ```text
//! ; lines beginning with a semicolon are comments
//! L, *LINE
//! CC, *COPYCLIP
//! ```
//!
//! An alias is the token left of the comma; the command is the token right of
//! it, with an optional leading `*`. Both are matched case-insensitively and
//! stored uppercased. Stored next to the other per-user config under
//! `crate::config::config_dir()`, so no serialization crate is pulled in.
use super::OpenCADStudio;
use rustc_hash::FxHashMap;
use std::path::PathBuf;
/// The shipped default alias file, embedded at compile time. Its aliases live in
/// `assets/ocad.pgp` — not in Rust — so the defaults are just data in the same
/// format the user edits. On first launch this text is written verbatim to the
/// user's config folder (comments and all) as the starting `ocad.pgp`; only that
/// user copy is read thereafter. This embedded copy is the first-run seed /
/// factory default.
const DEFAULT_ALIASES_PGP: &str = include_str!("../../assets/ocad.pgp");
/// Path to the user's alias file, `<config>/ocad.pgp`. `None` when the platform
/// config base can't be resolved (headless, no `HOME`, wasm).
fn alias_file_path() -> Option<PathBuf> {
Some(crate::config::config_dir()?.join("ocad.pgp"))
}
/// Parse `.pgp` text into an `alias → command` map, both uppercased. Skips blank
/// lines and `;` comments; tolerates a leading `*` on the command and arbitrary
/// whitespace padding.
fn parse_pgp(body: &str) -> FxHashMap<String, String> {
let mut map = FxHashMap::default();
for line in body.lines() {
let line = line.trim();
if line.is_empty() || line.starts_with(';') {
continue;
}
let Some((alias, cmd)) = line.split_once(',') else {
continue;
};
let alias = alias.trim().to_uppercase();
let cmd = cmd.trim().trim_start_matches('*').trim().to_uppercase();
if alias.is_empty() || cmd.is_empty() {
continue;
}
map.insert(alias, cmd);
}
map
}
/// Serialize an `alias → command` map to `.pgp` text with a header and aligned
/// columns, sorted by alias for a stable, diffable file.
pub(super) fn to_pgp(map: &FxHashMap<String, String>) -> String {
let mut rows: Vec<(&String, &String)> = map.iter().collect();
rows.sort_by(|a, b| a.0.cmp(b.0));
let mut out = String::from(
"; OpenCADStudio command aliases.\n\
; Format: ALIAS,*COMMAND (lines starting with ';' are comments)\n\
; Edit here or via the ALIASEDIT command. One alias per line.\n\n",
);
for (alias, cmd) in rows {
out.push_str(&format!("{:<10}*{}\n", format!("{alias},"), cmd));
}
out
}
/// The built-in defaults, parsed from the embedded `.pgp`. Used when no user
/// file exists yet (or can't be reached, e.g. wasm).
fn default_map() -> FxHashMap<String, String> {
parse_pgp(DEFAULT_ALIASES_PGP)
}
/// Load the alias table at boot. Reads the user's `aliases.pgp`; if it is
/// missing, writes the shipped default file verbatim (preserving its comments
/// and layout) so the user has a well-formatted starting point to edit, then
/// parses it. Falls back to the embedded defaults when the file can't be read
/// or written (read-only home, wasm — where it silently no-ops).
pub(super) fn load_aliases() -> FxHashMap<String, String> {
match alias_file_path() {
Some(path) => match std::fs::read_to_string(&path) {
Ok(body) => parse_pgp(&body),
Err(_) => {
// No file yet — copy the shipped default file, best-effort.
if let Some(dir) = path.parent() {
let _ = std::fs::create_dir_all(dir);
}
let _ = std::fs::write(&path, DEFAULT_ALIASES_PGP);
default_map()
}
},
None => default_map(),
}
}
/// Persist the alias table to `aliases.pgp`. Best-effort; returns `Ok` (no-op)
/// when there is no config dir (wasm/headless).
pub(super) fn save_map(map: &FxHashMap<String, String>) -> std::io::Result<()> {
let Some(path) = alias_file_path() else {
return Ok(());
};
if let Some(dir) = path.parent() {
std::fs::create_dir_all(dir)?;
}
std::fs::write(path, to_pgp(map))
}
impl OpenCADStudio {
/// Rewrite the leading command token through the alias table, leaving any
/// arguments after the first whitespace untouched. Returns `None` when the
/// verb is not an alias, so the caller passes the original string through
/// unchanged. Keyed uppercase so lowercase aliases from scripts/plugins
/// (which bypass the command line's verb-uppercasing) still resolve.
pub(super) fn resolve_alias(&self, cmd: &str) -> Option<String> {
if self.command_aliases.is_empty() {
return None;
}
let (verb, rest) = match cmd.split_once(char::is_whitespace) {
Some((v, r)) => (v, Some(r)),
None => (cmd, None),
};
let canon = self.command_aliases.get(&verb.to_uppercase())?;
Some(match rest {
Some(r) => format!("{canon} {r}"),
None => canon.clone(),
})
}
/// Replace the alias table (from the editor), persist it, and mirror it into
/// the command line so autocomplete reflects the edits immediately.
pub(super) fn set_command_aliases(&mut self, map: FxHashMap<String, String>) {
let _ = save_map(&map);
self.command_line.command_aliases = map.clone();
self.command_aliases = map;
}
/// Commit the alias-editor working rows to the table (Apply button): build a
/// map from the rows, dropping incomplete ones, and persist + sync. Leaves
/// the editor open so the user can keep editing.
pub(super) fn apply_alias_editor_rows(&mut self) {
let map: FxHashMap<String, String> = self
.alias_editor_rows
.iter()
.filter(|(a, c)| !a.trim().is_empty() && !c.trim().is_empty())
.map(|(a, c)| (a.trim().to_string(), c.trim().to_string()))
.collect();
self.set_command_aliases(map);
}
}
+6 -6
View File
@@ -53,7 +53,7 @@ impl OpenCADStudio {
}
}
"COPYCLIP" | "CC" => {
"COPYCLIP" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -142,7 +142,7 @@ impl OpenCADStudio {
}
}
"CUTCLIP" | "CX" => {
"CUTCLIP" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -179,7 +179,7 @@ impl OpenCADStudio {
}
}
"PASTECLIP" | "PC" => {
"PASTECLIP" => {
if self.clipboard.is_empty() {
self.command_line.push_error("Clipboard is empty.");
} else {
@@ -386,7 +386,7 @@ impl OpenCADStudio {
// ADCENTER / CONTENTBROWSER — report the drawing's named content
// (blocks and layers) from the command line in place of the browser
// panel.
"ADCENTER" | "CONTENTBROWSER" | "ADC" => {
"ADCENTER" | "CONTENTBROWSER" => {
let blocks = self.tabs[i].scene.custom_block_names();
let layers: Vec<String> = self.tabs[i]
.scene
@@ -476,7 +476,7 @@ impl OpenCADStudio {
}
}
"XATTACH" | "XA" => {
"XATTACH" => {
// Launch the file picker; XAttachPickResult will start the command.
return Some(Task::done(Message::XAttachPick));
}
@@ -498,7 +498,7 @@ impl OpenCADStudio {
}
}
"XREF" | "XR" => {
"XREF" => {
// List all xref blocks in the current drawing.
let xrefs: Vec<String> = self.tabs[i]
.scene
+29 -29
View File
@@ -3,42 +3,42 @@ use super::*;
impl OpenCADStudio {
pub(super) fn dispatch_dim(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
match cmd {
"DIMALIGNED" | "DAL" => {
"DIMALIGNED" => {
use crate::modules::annotate::aligned_dim::AlignedDimensionCommand;
let cmd = AlignedDimensionCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMDIAMETER" | "DDI" => {
"DIMDIAMETER" => {
use crate::modules::annotate::diameter_dim::DiameterDimensionCommand;
let cmd = DiameterDimensionCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMLINEAR" | "DLI" => {
"DIMLINEAR" => {
use crate::modules::annotate::linear_dim::LinearDimensionCommand;
let new_cmd = LinearDimensionCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMRADIUS" | "DRA" => {
"DIMRADIUS" => {
use crate::modules::annotate::radius_dim::RadiusDimensionCommand;
let new_cmd = RadiusDimensionCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMANGULAR" | "DAN" => {
"DIMANGULAR" => {
use crate::modules::annotate::angular_dim::AngularDimensionCommand;
let new_cmd = AngularDimensionCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMORDINATE" | "DOR" => {
"DIMORDINATE" => {
use crate::modules::annotate::ordinate_dim::OrdinateDimCommand;
let new_cmd = OrdinateDimCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -47,7 +47,7 @@ impl OpenCADStudio {
// LEADER draws a leader line with an annotation; QLEADER is the same
// quick leader-plus-annotation operation.
"LEADER" | "LE" | "QLEADER" | "QL" => {
"LEADER" | "QLEADER" => {
use crate::modules::annotate::leader_cmd::LeaderCommand;
let new_cmd = LeaderCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -400,14 +400,14 @@ impl OpenCADStudio {
));
}
"MLEADER" | "MLD" => {
"MLEADER" => {
use crate::modules::annotate::mleader_cmd::MLeaderCommand;
let new_cmd = MLeaderCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"TOLERANCE" | "TOL" => {
"TOLERANCE" => {
use crate::modules::annotate::tolerance_cmd::ToleranceCommand;
let cmd = ToleranceCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -421,7 +421,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMCONTINUE" | "DCO" => {
"DIMCONTINUE" => {
use crate::modules::annotate::dim_continue::DimContinueCommand;
let cmd = if let Some((p1, p2, dp, rot, trot)) =
find_last_linear_dim(&self.tabs[i].scene)
@@ -434,7 +434,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMBASELINE" | "DBA" => {
"DIMBASELINE" => {
use crate::modules::annotate::dim_baseline::DimBaselineCommand;
let cmd = if let Some((p1, p2, dp, rot, trot)) =
find_last_linear_dim(&self.tabs[i].scene)
@@ -548,7 +548,7 @@ impl OpenCADStudio {
return Some(Task::none());
}
"DIMEDIT" | "DED" => {
"DIMEDIT" => {
use crate::modules::annotate::dimedit::DimEditCommand;
let cmd = DimEditCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -562,7 +562,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMBREAK" | "DBR" => {
"DIMBREAK" => {
use crate::modules::annotate::dimbreak::DimBreakCommand;
let cmd = DimBreakCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -576,35 +576,35 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIMJOGLINE" | "DJL" => {
"DIMJOGLINE" => {
use crate::modules::annotate::dimjogline::DimJogLineCommand;
let cmd = DimJogLineCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MLEADERADD" | "MLA" => {
"MLEADERADD" => {
use crate::modules::annotate::mleader_edit::MLeaderAddCommand;
let cmd = MLeaderAddCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MLEADERREMOVE" | "MLR" => {
"MLEADERREMOVE" => {
use crate::modules::annotate::mleader_edit::MLeaderRemoveCommand;
let cmd = MLeaderRemoveCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MLEADERALIGN" | "MLAL" => {
"MLEADERALIGN" => {
use crate::modules::annotate::mleader_edit::MLeaderAlignCommand;
let cmd = MLeaderAlignCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MLEADERCOLLECT" | "MLC" => {
"MLEADERCOLLECT" => {
use crate::modules::annotate::mleader_edit::MLeaderCollectCommand;
let cmd = MLeaderCollectCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -647,14 +647,14 @@ impl OpenCADStudio {
}
}
"PLOTWINDOW" | "PW" => {
"PLOTWINDOW" => {
use crate::modules::view::plot_window::PlotWindowCommand;
let cmd = PlotWindowCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"QUICKPRINT" | "QP" => {
"QUICKPRINT" => {
use crate::modules::view::quick_print::QuickPrintCommand;
let cmd = QuickPrintCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -671,7 +671,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"STRETCH" | "SS" => {
"STRETCH" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -692,7 +692,7 @@ impl OpenCADStudio {
}
}
"FILLET" | "F" => {
"FILLET" => {
use crate::modules::draw::modify::fillet::FilletCommand;
let entities: Vec<_> = self.tabs[i]
.scene
@@ -717,7 +717,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"ARRAY" | "AR" | "ARRAYRECT" => {
"ARRAY" | "ARRAYRECT" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -809,7 +809,7 @@ impl OpenCADStudio {
}
}
"CHAMFER" | "CHA" => {
"CHAMFER" => {
use crate::modules::draw::modify::fillet::ChamferCommand;
let entities: Vec<_> = self.tabs[i]
.scene
@@ -834,7 +834,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"EXPLODE" | "X" => {
"EXPLODE" => {
use crate::modules::draw::modify::explode::explode_entity;
let entities: Vec<_> = self.tabs[i].scene.selected_entities().into_iter().collect();
if entities.is_empty() {
@@ -876,7 +876,7 @@ impl OpenCADStudio {
}
}
"OFFSET" | "O" => {
"OFFSET" => {
use crate::modules::draw::modify::offset::OffsetCommand;
let all_entities: Vec<_> = self.tabs[i]
.scene
@@ -892,7 +892,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"TRIM" | "TR" => {
"TRIM" => {
use crate::modules::draw::modify::trim::TrimCommand;
let entities: Vec<_> = self.tabs[i]
.scene
@@ -930,7 +930,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"EXTEND" | "EX" => {
"EXTEND" => {
use crate::modules::draw::modify::trim::ExtendCommand;
let entities: Vec<_> = self.tabs[i]
.scene
@@ -955,7 +955,7 @@ impl OpenCADStudio {
// DIMJOGGED <DJO> — create a jogged radius dimension on the selected
// arc/circle: a standard radius dim carrying an OCS_JOGGED XData marker
// that the geometry generator renders with a foreshortened zig-zag.
"DIMJOGGED" | "DJO" | "DIMJOG" => {
"DIMJOGGED" | "DIMJOG" => {
use acadrust::entities::{Dimension, DimensionRadius};
use acadrust::types::Vector3;
use acadrust::xdata::{ExtendedDataRecord, XDataValue};
+7 -7
View File
@@ -5,7 +5,7 @@ impl OpenCADStudio {
match cmd {
// Interactive pan: left-drag pans the view until Esc. The only pan
// path when there is no middle mouse button (trackpad / web).
"PAN" | "P" => {
"PAN" => {
self.tabs[i].pan_mode = true;
self.command_line
.push_output("PAN: drag with the left mouse button. Press Esc to exit.");
@@ -126,7 +126,7 @@ impl OpenCADStudio {
}
// ── PROPERTIES — toggle Properties panel visibility ──────────────────
"PROPERTIES" | "PR" | "PROPS" => {
"PROPERTIES" | "PROPS" => {
return Some(Task::done(Message::ToggleProperties));
}
@@ -160,7 +160,7 @@ impl OpenCADStudio {
return Some(Task::done(Message::ToggleSnapPopup));
}
// UNITS — open the drawing-units picker (linear / angular format).
"UNITS" | "UN" | "DDUNITS" => {
"UNITS" | "DDUNITS" => {
return Some(Task::done(Message::ToggleUnitsPopup));
}
@@ -174,13 +174,13 @@ impl OpenCADStudio {
}
// ── TOOLPALETTES — not yet implemented ───────────────────────────────
"TOOLPALETTES" | "TP" => {
"TOOLPALETTES" => {
self.command_line
.push_info("TOOLPALETTES: Tool Palettes not yet implemented.");
}
// ── SHEETSET — not yet implemented ───────────────────────────────────
"SHEETSET" | "SSM" => {
"SHEETSET" => {
self.command_line
.push_info("SHEETSET: Sheet Set Manager not yet implemented.");
}
@@ -292,7 +292,7 @@ impl OpenCADStudio {
// PRESSPULL on a closed boundary creates a solid by extruding it to a
// height — the same operation as EXTRUDE. THICKEN turns a closed planar
// profile into a solid of the given thickness, which is also an extrude.
"EXTRUDE" | "EXT" | "PRESSPULL" | "THICKEN" => {
"EXTRUDE" | "PRESSPULL" | "THICKEN" => {
use crate::modules::insert::solid3d_cmds::ExtrudeCommand;
// If a single entity is already selected, skip the pick step.
let selected: Vec<_> = self.tabs[i].scene.selected_entities().into_iter().collect();
@@ -311,7 +311,7 @@ impl OpenCADStudio {
}
// ── REVOLVE ────────────────────────────────────────────────────
"REVOLVE" | "REV" => {
"REVOLVE" => {
use crate::modules::insert::solid3d_cmds::RevolveCommand;
let color = self.tabs[i].scene.layer_color(&self.tabs[i].active_layer);
let cmd = RevolveCommand::new(color);
+27 -27
View File
@@ -4,14 +4,14 @@ impl OpenCADStudio {
pub(super) fn dispatch_draw(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
match cmd {
// ── Draw commands ──────────────────────────────────────────────
"LINE" | "L" => {
"LINE" => {
use crate::modules::draw::draw::line::LineCommand;
let new_cmd = LineCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"MLINE" | "ML" => {
"MLINE" => {
use crate::modules::draw::draw::mline::MlineCommand;
let style = self.tabs[i].scene.document.header.multiline_style.clone();
let cmd_obj = MlineCommand::with_style(style);
@@ -184,14 +184,14 @@ impl OpenCADStudio {
}
}
"DONUT" | "DO" => {
"DONUT" => {
use crate::modules::draw::draw::donut::DonutCommand;
let cmd = DonutCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"CIRCLE" | "C" => {
"CIRCLE" => {
use crate::modules::draw::draw::circle::CircleCommand;
let new_cmd = CircleCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -232,7 +232,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"ARC" | "A" => {
"ARC" => {
use crate::modules::draw::draw::arc::ArcCommand;
let new_cmd = ArcCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -318,7 +318,7 @@ impl OpenCADStudio {
}
}
"RECT" | "RECTANG" | "REC" => {
"RECT" | "RECTANG" => {
use crate::modules::draw::draw::shapes::RectCommand;
let new_cmd = RectCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -348,7 +348,7 @@ impl OpenCADStudio {
}
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"POLY" | "POLYGON" | "POL" => {
"POLY" | "POLYGON" => {
use crate::modules::draw::draw::shapes::PolyCommand;
let new_cmd = PolyCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -367,7 +367,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"PLINE" | "PL" => {
"PLINE" => {
use crate::modules::draw::draw::polyline::PlineCommand;
let new_cmd = PlineCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -383,7 +383,7 @@ impl OpenCADStudio {
// 2D filled solid. Reached via SO / SOLID2D — the bare SOLID verb is
// currently the shaded-display toggle (token collision tracked).
"SO" | "SOLID" | "SOLID2D" => {
"SOLID" | "SOLID2D" => {
use crate::modules::draw::draw::solid2d::Solid2dCommand;
let new_cmd = Solid2dCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -411,7 +411,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DIMCENTER" | "DCE" | "CENTERMARK" => {
"DIMCENTER" | "CENTERMARK" => {
use crate::modules::draw::draw::dimcenter::DimCenterCommand;
let new_cmd = DimCenterCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -432,7 +432,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"MEASUREGEOM" | "MEA" => {
"MEASUREGEOM" => {
use crate::modules::draw::inquiry::measuregeom::MeasureGeomCommand;
let new_cmd = MeasureGeomCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -442,7 +442,7 @@ impl OpenCADStudio {
// ── Modify commands ────────────────────────────────────────────
// MOVE works from picked points, so it already relocates entities
// in 3D; 3DMOVE is the same operation.
"MOVE" | "M" | "3DMOVE" => {
"MOVE" | "3DMOVE" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -463,7 +463,7 @@ impl OpenCADStudio {
}
}
"COPY" | "CO" => {
"COPY" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -484,7 +484,7 @@ impl OpenCADStudio {
}
}
"ROTATE" | "RO" => {
"ROTATE" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -539,7 +539,7 @@ impl OpenCADStudio {
}
}
"POINT" | "PO" => {
"POINT" => {
use crate::modules::draw::draw::point::PointCommand;
let new_cmd = PointCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -553,14 +553,14 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"XLINE" | "XL" | "CONSTRUCTIONLINE" => {
"XLINE" | "CONSTRUCTIONLINE" => {
use crate::modules::draw::draw::ray::XLineCommand;
let new_cmd = XLineCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"HATCH" | "H" => {
"HATCH" => {
use crate::modules::draw::draw::hatch::HatchCommand;
let outlines = self.tabs[i].scene.closed_outlines();
let new_cmd = HatchCommand::new(outlines);
@@ -568,7 +568,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"HATCHEDIT" | "HE" => {
"HATCHEDIT" => {
use crate::modules::draw::draw::hatchedit::HatcheditCommand;
// If a single hatch is already selected, skip the pick step.
let sel = self.tabs[i].scene.selected_entities();
@@ -610,7 +610,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"ELLIPSE" | "EL" => {
"ELLIPSE" => {
use crate::modules::draw::draw::ellipse::EllipseCommand;
let new_cmd = EllipseCommand::new();
self.command_line.push_info(&new_cmd.prompt());
@@ -631,14 +631,14 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"SPLINE" | "SPL" => {
"SPLINE" => {
use crate::modules::draw::draw::spline::SplineCommand;
let new_cmd = SplineCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"SCALE" | "SC" => {
"SCALE" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -659,7 +659,7 @@ impl OpenCADStudio {
}
}
"MIRROR" | "MI" => {
"MIRROR" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -682,7 +682,7 @@ impl OpenCADStudio {
}
}
"ERASE" | "E" => {
"ERASE" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -727,7 +727,7 @@ impl OpenCADStudio {
}
// INTERFERE — non-destructive intersect: solid from the overlap.
"INTERFERE" | "INF" => {
"INTERFERE" => {
return Some(self.solid_interfere());
}
@@ -963,14 +963,14 @@ impl OpenCADStudio {
}
// ── Annotate commands ──────────────────────────────────────────
"TEXT" | "T" | "DT" => {
"TEXT" => {
use crate::modules::annotate::text::TextCommand;
let new_cmd = TextCommand::new();
self.command_line.push_info(&new_cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
}
"DDEDIT" | "ED" => {
"DDEDIT" => {
use crate::modules::annotate::ddedit::DdeditCommand;
// A single text entity already selected opens its in-place
// editor directly; otherwise prompt for a pick.
@@ -994,7 +994,7 @@ impl OpenCADStudio {
}
}
"MTEXT" | "MT" => {
"MTEXT" => {
use crate::modules::annotate::mtext::MTextCommand;
let new_cmd = MTextCommand::new();
self.command_line.push_info(&new_cmd.prompt());
+3 -3
View File
@@ -70,7 +70,7 @@ impl OpenCADStudio {
}
}
}
"UNDO" | "U" => return Some(Task::done(Message::Undo)),
"UNDO" => return Some(Task::done(Message::Undo)),
"REDO" => return Some(Task::done(Message::Redo)),
// OOPS — restore the objects removed by the most recent ERASE,
// without undoing any work done since.
@@ -92,7 +92,7 @@ impl OpenCADStudio {
}
}
"CLEAR" | "CLR" => return Some(Task::done(Message::ClearScene)),
"WIREFRAME" | "VW" => return Some(Task::done(Message::SetWireframe(true))),
"WIREFRAME" => return Some(Task::done(Message::SetWireframe(true))),
// Visual-style commands. OCS renders either a wireframe or a shaded
// view; the named styles map onto the closest of the two and the
// chosen style is reported so the mapping is explicit. (`SOLID` is
@@ -309,7 +309,7 @@ impl OpenCADStudio {
"ORTHO" => return Some(Task::done(Message::ToggleOrtho)),
"PARALLEL" => return Some(Task::done(Message::SetProjection(true))),
"PERSP" => return Some(Task::done(Message::SetProjection(false))),
"LAYERS" | "LA" => return Some(Task::done(Message::ToggleLayers)),
"LAYERS" => return Some(Task::done(Message::ToggleLayers)),
// SCRIPT <path> — run a command script: each non-blank, non-comment
// line is fed through the same command path the `--script` startup
+16 -16
View File
@@ -3,13 +3,13 @@ use super::*;
impl OpenCADStudio {
pub(super) fn dispatch_inquiry(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
match cmd {
"3DORBIT" | "3O" => {
"3DORBIT" => {
self.command_line
.push_info("3D Orbit: drag with right mouse button.");
}
// ── Selection utilities ───────────────────────────────────────
"SELECTALL" | "SA" => {
"SELECTALL" => {
use crate::scene::Scene;
let handles: Vec<acadrust::Handle> = self.tabs[i]
.scene
@@ -28,7 +28,7 @@ impl OpenCADStudio {
self.refresh_properties();
}
"DESELECT" | "DE" | "DESELALL" => {
"DESELECT" | "DESELALL" => {
self.tabs[i].scene.deselect_all();
self.command_line.push_output("Deselected.");
self.refresh_properties();
@@ -49,7 +49,7 @@ impl OpenCADStudio {
// QSELECT builds a selection set by object type / property; FILTER is
// the same criteria-based selection.
"QSELECT" | "QS" | "FILTER" | "FI" => {
"QSELECT" | "FILTER" => {
return Some(Task::done(Message::QSelectOpen));
}
@@ -75,7 +75,7 @@ impl OpenCADStudio {
}
// ── LIST — entity info ────────────────────────────────────────
"LIST" | "LI" => {
"LIST" => {
let selected: Vec<_> = self.tabs[i].scene.selected_entities();
if selected.is_empty() {
self.command_line
@@ -218,35 +218,35 @@ impl OpenCADStudio {
}
// ── Break / Join ─────────────────────────────────────────────────
"JOIN" | "J" => {
"JOIN" => {
use crate::modules::draw::modify::join::JoinCommand;
let cmd = JoinCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"BREAK" | "BR" => {
"BREAK" => {
use crate::modules::draw::modify::break_cmd::BreakInteractiveCommand;
let cmd = BreakInteractiveCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"BREAKATPOINT" | "BAP" => {
"BREAKATPOINT" => {
use crate::modules::draw::modify::break_cmd::BreakAtPointCommand;
let cmd = BreakAtPointCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"PEDIT" | "PE" => {
"PEDIT" => {
use crate::modules::draw::modify::pedit::PeditCommand;
let cmd_obj = PeditCommand::new();
self.command_line.push_info(&cmd_obj.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd_obj));
}
"SPLINEDIT" | "SPE" => {
"SPLINEDIT" => {
use crate::modules::draw::modify::splinedit::SplineditCommand;
let cmd_obj = SplineditCommand::new();
self.command_line.push_info(&cmd_obj.prompt());
@@ -257,7 +257,7 @@ impl OpenCADStudio {
// If a single block with attributes is already selected it opens on
// that block; otherwise the pick command runs and the editor opens
// once a block is chosen (see `command_driver`).
"ATTEDIT" | "ATE" => {
"ATTEDIT" => {
let selected_attr_insert = {
let sel = self.tabs[i].scene.selected_entities();
if sel.len() == 1 {
@@ -547,28 +547,28 @@ impl OpenCADStudio {
.push_output("REFCLOSE: Changes discarded.");
}
"ALIGN" | "AL" => {
"ALIGN" => {
use crate::modules::draw::modify::align::AlignCommand;
let cmd = AlignCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"LENGTHEN" | "LEN" => {
"LENGTHEN" => {
use crate::modules::draw::modify::lengthen::LengthenCommand;
let cmd = LengthenCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"DIVIDE" | "DIV" => {
"DIVIDE" => {
use crate::modules::draw::inquiry::divide::DivideCommand;
let cmd = DivideCommand::new();
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MEASURE" | "ME" => {
"MEASURE" => {
use crate::modules::draw::inquiry::divide::MeasureCommand;
let cmd = MeasureCommand::new();
self.command_line.push_info(&cmd.prompt());
@@ -576,7 +576,7 @@ impl OpenCADStudio {
}
// ── Inquiry ──────────────────────────────────────────────────────
"DIST" | "DI" => {
"DIST" => {
use crate::modules::draw::inquiry::dist::DistCommand;
let cmd = DistCommand::new();
self.command_line.push_info(&cmd.prompt());
+3 -3
View File
@@ -510,7 +510,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"MATCHPROP" | "MA" => {
"MATCHPROP" => {
use crate::modules::draw::properties::match_prop::MatchPropCommand;
self.tabs[i].scene.deselect_all();
let cmd = MatchPropCommand::new();
@@ -518,7 +518,7 @@ impl OpenCADStudio {
self.tabs[i].active_cmd = Some(Box::new(cmd));
}
"GROUP" | "G" => {
"GROUP" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
@@ -540,7 +540,7 @@ impl OpenCADStudio {
}
}
"UNGROUP" | "UG" => {
"UNGROUP" => {
let handles: Vec<_> = self.tabs[i]
.scene
.selected_entities()
+7
View File
@@ -59,6 +59,12 @@ impl OpenCADStudio {
fn dispatch_command_inner(&mut self, cmd: &str, allow_suggest: bool) -> Task<Message> {
let i = self.active_tab;
// Expand a command alias ("L" → "LINE") on the leading token before any
// routing, so every path below (Start-tab gate, plugins, all dispatch
// families, the Repeat menu) sees the canonical command. Arguments after
// the first space are left untouched. A non-alias passes through as-is.
let resolved = self.resolve_alias(cmd);
let cmd = resolved.as_deref().unwrap_or(cmd);
// Starting a command closes any open ribbon dropdown (e.g. a style
// combo left open) so it does not stay stuck behind the new tool.
self.ribbon.close_dropdown();
@@ -151,6 +157,7 @@ impl OpenCADStudio {
if let Some(top) = crate::ui::command_line::ranked_matches(
cmd,
&self.command_line.dynamic_commands,
&self.command_line.command_aliases,
)
.into_iter()
.next()
+12 -7
View File
@@ -208,10 +208,15 @@ impl OpenCADStudio {
self.command_line.push_info("Opening release notes...");
}
// ── CUI / ALIASEDIT — customization entry points ───────────────
// Command-alias and key-binding editing lives in the keyboard
// shortcuts panel, so route the customization verbs there.
"CUI" | "ALIASEDIT" => {
// ── ALIASEDIT — command-alias editor ───────────────────────────
// Opens the command-alias table editor (ocad.pgp). Keyboard
// key-bindings are edited separately via CUI (below).
"ALIASEDIT" => {
return Some(Task::done(Message::AliasEditorOpen));
}
// ── CUI — keyboard shortcut / key-binding editor ───────────────
"CUI" => {
return Some(Task::done(Message::ShortcutsPanelOpen));
}
@@ -380,7 +385,7 @@ impl OpenCADStudio {
}
// ── Layout / viewport ──────────────────────────────────────────
"MVIEW" | "MV" => {
"MVIEW" => {
if self.tabs[i].scene.current_layout == "Model" {
self.command_line
.push_error("MVIEW: switch to a paper space layout first.");
@@ -393,7 +398,7 @@ impl OpenCADStudio {
}
// ── MSPACE / PSPACE ───────────────────────────────────────────
"MS" | "MSPACE" => {
"MSPACE" => {
return Some(Task::done(Message::MspaceCommand));
}
"PSPACE" => {
@@ -970,7 +975,7 @@ impl OpenCADStudio {
}
// HIDE — hidden-line view of the active viewport.
"HIDE" | "HI" => {
"HIDE" => {
return Some(Task::done(Message::SetRenderMode(
acadrust::entities::ViewportRenderMode::HiddenLine,
)));
+35
View File
@@ -1,3 +1,4 @@
mod alias;
#[cfg(not(target_arch = "wasm32"))]
mod automation;
#[cfg(not(target_arch = "wasm32"))]
@@ -629,6 +630,16 @@ pub(super) struct OpenCADStudio {
/// User-defined function-key overrides: "F3" → command string.
shortcut_overrides: rustc_hash::FxHashMap<String, String>,
// ── Command Aliases ───────────────────────────────────────────────────
/// Command-line aliases: uppercase abbreviation → uppercase command
/// ("L" → "LINE"). Loaded from `ocad.pgp` at boot and consulted before
/// every dispatch (`resolve_alias`); user-editable via ALIASEDIT. See
/// [`alias`].
command_aliases: rustc_hash::FxHashMap<String, String>,
/// Working buffer for the ALIASEDIT modal: `(alias, command)` rows being
/// edited. Seeded from `command_aliases` on open, committed back on close.
alias_editor_rows: Vec<(String, String)>,
// ── Layout Manager Panel ──────────────────────────────────────────────
layout_manager_selected: String,
layout_manager_rename_buf: String,
@@ -1081,6 +1092,7 @@ pub enum ModalKind {
PointStyle,
AttributeEditor,
LayerDeleteWarning,
Aliases,
}
/// Identifies a DimStyle field that can be edited in the dialog.
@@ -1628,6 +1640,21 @@ pub enum Message {
ShortcutsPanelOpen,
#[allow(dead_code)]
ShortcutsPanelClose,
// ── Command Alias Editor (ALIASEDIT) ────────────────────────────────
/// Open the command-alias editor modal, seeding rows from the alias table.
AliasEditorOpen,
/// Live edit of the alias or command in row `idx`.
AliasEditorInput {
idx: usize,
field: crate::ui::window::alias_editor::AliasField,
value: String,
},
/// Append a blank alias row.
AliasEditorAdd,
/// Remove alias row `idx`.
AliasEditorRemove(usize),
/// Commit the edited rows to the alias table (Apply button); stays open.
AliasEditorApply,
// ── About window ────────────────────────────────────────────────────
AboutOpen,
/// Close whatever in-canvas modal dialog is open (Plan B).
@@ -2187,6 +2214,9 @@ impl OpenCADStudio {
active_theme: Theme::Dark,
// Keyboard shortcuts
shortcut_overrides: rustc_hash::FxHashMap::default(),
// Command aliases (populated from ocad.pgp just after construction)
command_aliases: rustc_hash::FxHashMap::default(),
alias_editor_rows: Vec::new(),
// Layout Manager
layout_manager_selected: "Model".to_string(),
layout_manager_rename_buf: String::new(),
@@ -2328,6 +2358,11 @@ impl OpenCADStudio {
if let Some(s) = settings::UserSettings::load() {
app.apply_settings(&s);
}
// Load command aliases from ocad.pgp (writes the shipped default file
// on first launch). The hide-set keeps aliases out of autocomplete while
// their target command still shows.
app.command_aliases = alias::load_aliases();
app.command_line.command_aliases = app.command_aliases.clone();
// Load external plugin packages from the plugins folder once, then fold
// their ribbon tabs into the ribbon. Skipped under test/wasm.
#[cfg(all(not(target_arch = "wasm32"), not(test)))]
+52
View File
@@ -118,6 +118,12 @@ impl OpenCADStudio {
self.attr_editor_selected = 0;
self.attr_editor_tab = crate::ui::window::attribute_editor::AttrTab::Attribute;
}
// Closing (✕) discards edits made since the last Apply — matching the
// style editors. Committing happens only through the Apply button.
Some(Aliases) => {
self.alias_editor_rows.clear();
self.ribbon.deactivate_tool_if("ALIASEDIT");
}
_ => {}
}
self.active_modal = None;
@@ -2631,6 +2637,52 @@ impl OpenCADStudio {
Task::none()
}
// ── Command Alias Editor (ALIASEDIT) ──────────────────────────────
Message::AliasEditorOpen => {
// Seed the working buffer from the current table, sorted by alias
// so the list is stable and diffable.
let mut rows: Vec<(String, String)> = self
.command_aliases
.iter()
.map(|(a, c)| (a.clone(), c.clone()))
.collect();
rows.sort_by(|a, b| a.0.cmp(&b.0));
self.alias_editor_rows = rows;
self.active_modal = Some(super::ModalKind::Aliases);
Task::none()
}
Message::AliasEditorInput { idx, field, value } => {
use crate::ui::window::alias_editor::AliasField;
// Aliases and commands are stored uppercase; uppercasing as the
// user types keeps display and the committed table consistent.
let value = value.to_uppercase();
if let Some(rowdata) = self.alias_editor_rows.get_mut(idx) {
match field {
AliasField::Alias => rowdata.0 = value,
AliasField::Command => rowdata.1 = value,
}
}
Task::none()
}
Message::AliasEditorAdd => {
self.alias_editor_rows.push((String::new(), String::new()));
Task::none()
}
Message::AliasEditorRemove(idx) => {
if idx < self.alias_editor_rows.len() {
self.alias_editor_rows.remove(idx);
}
Task::none()
}
Message::AliasEditorApply => {
self.apply_alias_editor_rows();
self.command_line.push_info(&format!(
"{} alias(es) applied.",
self.command_aliases.len()
));
Task::none()
}
// ── About window ──────────────────────────────────────────────
Message::AboutOpen => {
self.active_modal = Some(super::ModalKind::About);
+1
View File
@@ -1495,6 +1495,7 @@ impl OpenCADStudio {
PointStyle => (360, 470),
AttributeEditor => (640, 500),
LayerDeleteWarning => (440, 200),
Aliases => (480, 520),
};
Some((w as f32 + EXTRA_W, h as f32 + EXTRA_H))
}
+3
View File
@@ -21,6 +21,9 @@ impl OpenCADStudio {
super::super::ModalKind::Shortcuts => {
sized(crate::ui::window::shortcuts::view_window(&self.shortcut_overrides), 720, 520)
}
super::super::ModalKind::Aliases => {
sized(crate::ui::window::alias_editor::view_window(&self.alias_editor_rows), 480, 520)
}
super::super::ModalKind::PluginManager => sized(
crate::ui::window::plugin_manager::view_window(
&self.disabled_plugins,