forked from 1b-agent/opencadstudio-upstream
Route every text-bearing entity to an in-place editor instead of the command line: a plain text box for single-line text (Text, attributes, dimension override, tolerance) and the rich MText editor for MText / MultiLeader. A Leader resolves to the entity it annotates. - TEXT places a plain text box at the click; double-click edits in place. - DDEDIT and double-click on any text entity open the matching editor. - MLEADER places the leader then opens the MText editor on its content. - LEADER follows the classic flow: points, Enter, then a linked empty MText annotation opens in the editor; the leader's annotation_handle links the pair so they edit/erase as a unit. Adds shared field read/write helpers and a begin_text_edit router, plus CommitAndEditText / CommitManyAndEditText results that commit an entity and open its editor (commit_entity now returns the new handle). Co-Authored-By: Claude Opus 4.8 <[email protected]>
69 lines
1.6 KiB
Rust
69 lines
1.6 KiB
Rust
use crate::command::{CadCommand, CmdResult};
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
|
use crate::scene::wire_model::WireModel;
|
|
use glam::Vec3;
|
|
|
|
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/text.svg"));
|
|
|
|
pub fn tool() -> ToolDef {
|
|
ToolDef {
|
|
id: "TEXT",
|
|
label: "Text",
|
|
icon: ICON,
|
|
event: ModuleEvent::Command("TEXT".to_string()),
|
|
}
|
|
}
|
|
|
|
enum Step {
|
|
InsertPoint,
|
|
}
|
|
|
|
pub struct TextCommand {
|
|
step: Step,
|
|
}
|
|
|
|
impl TextCommand {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
step: Step::InsertPoint,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl CadCommand for TextCommand {
|
|
fn name(&self) -> &'static str {
|
|
"TEXT"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
match &self.step {
|
|
Step::InsertPoint => "TEXT Specify insertion point:".into(),
|
|
}
|
|
}
|
|
|
|
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
|
// Hand off to the in-place plain-text editor anchored at the click.
|
|
CmdResult::OpenTextEditor {
|
|
pos: pt,
|
|
handle: None,
|
|
initial: String::new(),
|
|
height: 0.25,
|
|
}
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
fn on_escape(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_mouse_move(&mut self, _pt: Vec3) -> Option<WireModel> {
|
|
None
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["DT", "T", "TEXT"] }); // TextCommand
|