forked from 1b-agent/opencadstudio-upstream
feat(clipboard): PASTESPEC pastes in a chosen format
PASTESPEC offers the formats on the clipboard: Objects and Block for objects copied in the application (the PASTECLIP and PASTEBLOCK paths), and Text for the system clipboard's text, placed as multi-line text in the current text style with its lines as paragraphs. Refs #645 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
4ffae00199
commit
b1d4c9bd9b
29 files changed
+242
-1
No files matched your search
@@ -3619,6 +3619,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE حدد نقطة الإدراج:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC حدد نقطة الإدراج:
|
||||
.pastespec-paste-as = PASTESPEC لصق كـ [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Посочи точка на вмъкване:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Задайте точка на вмъкване:
|
||||
.pastespec-paste-as = PASTESPEC Поставяне като [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3604,6 +3604,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Zadejte bod vložení:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Zadejte bod vložení:
|
||||
.pastespec-paste-as = PASTESPEC Vložit jako [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Einführstelle angeben:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Einfügepunkt angeben:
|
||||
.pastespec-paste-as = PASTESPEC Einfügen als [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Ορίστε σημείο εισαγωγής:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Καθορίστε σημείο εισαγωγής:
|
||||
.pastespec-paste-as = PASTESPEC Επικόλληση ως [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Specify insertion point:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Specify insertion point:
|
||||
.pastespec-paste-as = PASTESPEC Paste as [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Especifique el punto de inserción:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Precise el punto de inserción:
|
||||
.pastespec-paste-as = PASTESPEC Pegar como [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Määritä lisäyskohta:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Määritä lisäyspiste:
|
||||
.pastespec-paste-as = PASTESPEC Liitä muodossa [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Spécifier le point d'insertion:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Spécifiez le point d’insertion :
|
||||
.pastespec-paste-as = PASTESPEC Coller comme [Objects/Block/Text] :
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3595,6 +3595,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE निर्दिष्ट सम्मिलन बिंदु:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC सम्मिलन बिंदु निर्दिष्ट करें:
|
||||
.pastespec-paste-as = PASTESPEC इस रूप में चिपकाएँ [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3605,6 +3605,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Beszúrási pont megadása:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Adja meg a beszúrási pontot:
|
||||
.pastespec-paste-as = PASTESPEC Beillesztés mint [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF-lépték: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Adja meg a beszúrási pontot:
|
||||
.pdfui-no-pdf-underlays = Nem található PDF-alávetítés.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Specificare il punto di inserimento:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Specificare il punto di inserimento:
|
||||
.pastespec-paste-as = PASTESPEC Incolla come [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3597,6 +3597,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE 挿入点を指定:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC 挿入点を指定:
|
||||
.pastespec-paste-as = PASTESPEC 貼り付け形式 [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE 삽입점 지정:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC 삽입점 지정:
|
||||
.pastespec-paste-as = PASTESPEC 붙여넣기 형식 [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3608,6 +3608,8 @@ annotate =
|
||||
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC ກຳນົດຈຸດແຊກ:
|
||||
.pastespec-paste-as = PASTESPEC ວາງເປັນ [Objects/Block/Text]:
|
||||
.xref-unresolved-external-references = XREF ການອ້າງອີງພາຍນອກທີ່ບໍ່ພົບ: __ocs_fmt_0__ — ລາກໄຟລ໌ DWG/DXF ທີ່ອ້າງອີງມາວາງໃສ່ໜ້າເພື່ອລົງທະບຽນ, ຈາກນັ້ນເປີດແບບແຕ້ມນີ້ຄືນ ຫຼື ເອີ້ນໃຊ້ XRELOAD.
|
||||
.pdfui-pdf-scale = ມາດຕາສ່ວນ PDF: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = ກໍານົດຈຸດແຊກ:
|
||||
|
||||
@@ -3605,6 +3605,8 @@ annotate =
|
||||
.dimradius-select-arc-circle-or-polyline-arc = DIMRADIUS Selecteer een boog, cirkel of polylijnboog:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Geef invoegpunt op:
|
||||
.pastespec-paste-as = PASTESPEC Plakken als [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Określ punkt wstawienia:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Określ punkt wstawienia:
|
||||
.pastespec-paste-as = PASTESPEC Wklej jako [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3607,6 +3607,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Especifique o ponto de inserção:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Especifique o ponto de inserção:
|
||||
.pastespec-paste-as = PASTESPEC Colar como [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3608,6 +3608,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Укажите точку вставки:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Укажите точку вставки:
|
||||
.pastespec-paste-as = PASTESPEC Вставить как [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3580,6 +3580,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE Ekleme noktasını belirtin:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC Ekleme noktasını belirtin:
|
||||
.pastespec-paste-as = PASTESPEC Şu biçimde yapıştır [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF ölçeği: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Ekleme noktasını belirtin:
|
||||
.pdfui-no-pdf-underlays = PDF altlığı bulunamadı.
|
||||
|
||||
@@ -3594,6 +3594,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE 指定插入点:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC 指定插入点:
|
||||
.pastespec-paste-as = PASTESPEC 粘贴为 [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -3606,6 +3606,8 @@ annotate =
|
||||
.tolerance-specify-insertion-point = TOLERANCE 指定插入點:
|
||||
|
||||
insert =
|
||||
.pastespec-specify-insertion-point = PASTESPEC 指定插入點:
|
||||
.pastespec-paste-as = PASTESPEC 貼上為 [Objects/Block/Text]:
|
||||
.pdfui-pdf-scale = PDF scale: __ocs_fmt_0__:1
|
||||
.pdfui-specify-insertion-point = Specify insertion point:
|
||||
.pdfui-no-pdf-underlays = No PDF underlays found.
|
||||
|
||||
@@ -95,6 +95,23 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
/// PASTESPEC with the formats on hand: the copied objects, and `text`
|
||||
/// from the system clipboard once it has been read.
|
||||
pub(in crate::app) fn paste_special_command(
|
||||
&self,
|
||||
i: usize,
|
||||
text: Option<&str>,
|
||||
) -> Box<dyn CadCommand> {
|
||||
let document = &self.tabs[i].scene.document;
|
||||
let defaults = crate::scene::creation_style::current_text_defaults(document);
|
||||
Box::new(crate::modules::draw::clipboard::pastespec::PasteSpecCommand::new(
|
||||
!self.clipboard.is_empty(),
|
||||
text,
|
||||
defaults.style_name,
|
||||
defaults.height,
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) fn dispatch_blocks(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
|
||||
match cmd {
|
||||
// ── BASE — drawing insertion base point ───────────────────────
|
||||
@@ -284,6 +301,19 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
// PASTESPEC — offer the copied objects now; the system clipboard's
|
||||
// text joins the formats once read (Message::PasteSpecial).
|
||||
"PASTESPEC" => {
|
||||
let command = self.paste_special_command(i, None);
|
||||
let started = self.start_count_command(i, command);
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let read = Task::perform(crate::sys::read_clipboard_text(), Message::PasteSpecial);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let read = iced::clipboard::read_text()
|
||||
.map(|result| Message::PasteSpecial(result.ok().map(|text| (*text).clone())));
|
||||
return Some(Task::batch([started, read]));
|
||||
}
|
||||
|
||||
// PASTEORIG — paste at the entities' original coordinates (no pick).
|
||||
"PASTEORIG" => {
|
||||
if self.clipboard.is_empty() {
|
||||
|
||||
@@ -188,7 +188,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
fn start_count_command(&mut self, i: usize, command: Box<dyn CadCommand>) -> Task<Message> {
|
||||
pub(in crate::app) fn start_count_command(&mut self, i: usize, command: Box<dyn CadCommand>) -> Task<Message> {
|
||||
self.reset_command_start_state(i);
|
||||
self.command_line.push_info(&command.prompt());
|
||||
self.tabs[i].active_cmd = Some(command);
|
||||
|
||||
@@ -2360,6 +2360,8 @@ pub enum Message {
|
||||
PasteShortcut,
|
||||
/// Which text input held focus when `PasteShortcut` arrived.
|
||||
PasteShortcutResolved(PasteFocus),
|
||||
/// Completion of the system text clipboard read PASTESPEC starts.
|
||||
PasteSpecial(Option<String>),
|
||||
/// Completion of a system text clipboard read requested by PASTECLIP.
|
||||
SystemClipboardPaste(SystemClipboardText),
|
||||
/// Web: completion of the clipboard-image read the paste fallback starts
|
||||
|
||||
@@ -6815,6 +6815,32 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
Message::PasteSpecial(text) => {
|
||||
let i = self.active_tab;
|
||||
let waiting = self.tabs[i]
|
||||
.active_cmd
|
||||
.as_ref()
|
||||
.is_some_and(|command| command.name() == "PASTESPEC");
|
||||
if !waiting {
|
||||
return Task::none();
|
||||
}
|
||||
match text.filter(|text| !text.trim().is_empty()) {
|
||||
Some(text) => {
|
||||
// Same prompt, one more option: swap without echoing it.
|
||||
self.tabs[i].active_cmd = Some(self.paste_special_command(i, Some(&text)));
|
||||
self.push_ucs_to_cmd(i);
|
||||
Task::none()
|
||||
}
|
||||
None if self.clipboard.is_empty() => {
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.command_line
|
||||
.push_error(crate::tr!("clipboard", "no-supported-content").as_ref());
|
||||
Task::none()
|
||||
}
|
||||
None => Task::none(),
|
||||
}
|
||||
}
|
||||
|
||||
Message::SystemClipboardPaste(result) => {
|
||||
use super::SystemClipboardText as Text;
|
||||
|
||||
|
||||
@@ -2380,6 +2380,8 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static
|
||||
"PAPER" => Some(("ui", "paper")),
|
||||
"PAPER: double-click viewport to enter MSPACE\nMODEL: click to switch to Model Space" => Some(("ui", "paper-double-click-viewport-to-enter-mspace-mo")),
|
||||
"PASTEBLOCK: clipboard is empty." => Some(("insert", "pasteblock-clipboard-is-empty")),
|
||||
"PASTESPEC Paste as [Objects/Block/Text]:" => Some(("insert", "pastespec-paste-as")),
|
||||
"PASTESPEC Specify insertion point:" => Some(("insert", "pastespec-specify-insertion-point")),
|
||||
"PASTEBLOCK: {e}" => Some(("insert", "pasteblock-e")),
|
||||
"PASTECLIP Pick insertion point:" => Some(("clipboard", "pasteclip-pick-insertion-point")),
|
||||
"PASTEORIG: clipboard is empty." => Some(("insert", "pasteorig-clipboard-is-empty")),
|
||||
|
||||
@@ -2,3 +2,4 @@ pub mod copy_base;
|
||||
pub mod copy_clip;
|
||||
pub mod cut;
|
||||
pub mod paste;
|
||||
pub mod pastespec;
|
||||
@@ -0,0 +1,136 @@
|
||||
// PASTESPEC — paste the clipboard in a chosen format: the copied objects, the
|
||||
// copied objects as a block, or the system clipboard's text as multi-line text.
|
||||
|
||||
use crate::t;
|
||||
use codec::entities::mtext::AttachmentPoint;
|
||||
use codec::entities::MText;
|
||||
use codec::types::Vector3;
|
||||
use codec::EntityType;
|
||||
use glam::DVec3;
|
||||
|
||||
use crate::command::{CadCommand, CmdOption, CmdResult, WorkingPlane};
|
||||
|
||||
pub struct PasteSpecCommand {
|
||||
/// Objects copied inside the application are waiting on the clipboard.
|
||||
objects: bool,
|
||||
/// The system clipboard's text, already escaped for MTEXT.
|
||||
text: Option<String>,
|
||||
style: String,
|
||||
height: f64,
|
||||
placing_text: bool,
|
||||
plane: WorkingPlane,
|
||||
}
|
||||
|
||||
impl PasteSpecCommand {
|
||||
pub fn new(objects: bool, text: Option<&str>, style: String, height: f64) -> Self {
|
||||
Self {
|
||||
objects,
|
||||
text: text.map(mtext_value),
|
||||
style,
|
||||
height,
|
||||
placing_text: false,
|
||||
plane: WorkingPlane::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Plain text as an MTEXT value: control characters escaped, lines as
|
||||
/// paragraphs.
|
||||
fn mtext_value(text: &str) -> String {
|
||||
text.trim_end_matches(['\r', '\n'])
|
||||
.replace('\\', "\\\\")
|
||||
.replace('{', "\\{")
|
||||
.replace('}', "\\}")
|
||||
.replace("\r\n", "\\P")
|
||||
.replace(['\r', '\n'], "\\P")
|
||||
}
|
||||
|
||||
impl CadCommand for PasteSpecCommand {
|
||||
fn name(&self) -> &'static str {
|
||||
"PASTESPEC"
|
||||
}
|
||||
|
||||
fn set_working_plane(&mut self, plane: WorkingPlane) {
|
||||
self.plane = plane;
|
||||
}
|
||||
|
||||
fn prompt(&self) -> String {
|
||||
if self.placing_text {
|
||||
t!("PASTESPEC Specify insertion point:").into_owned()
|
||||
} else {
|
||||
t!("PASTESPEC Paste as [Objects/Block/Text]:").into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self) -> Vec<CmdOption> {
|
||||
if self.placing_text {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut options = Vec::new();
|
||||
if self.objects {
|
||||
options.push(CmdOption::new("Objects", "O"));
|
||||
options.push(CmdOption::new("Block", "B"));
|
||||
}
|
||||
if self.text.is_some() {
|
||||
options.push(CmdOption::new("Text", "T"));
|
||||
}
|
||||
options
|
||||
}
|
||||
|
||||
fn wants_text_input(&self) -> bool {
|
||||
!self.placing_text
|
||||
}
|
||||
|
||||
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
||||
if self.placing_text {
|
||||
return None;
|
||||
}
|
||||
match text.trim().trim_start_matches('_').to_ascii_uppercase().as_str() {
|
||||
"O" | "OBJECTS" if self.objects => Some(CmdResult::Dispatch("PASTECLIP".into())),
|
||||
"B" | "BLOCK" if self.objects => Some(CmdResult::Dispatch("PASTEBLOCK".into())),
|
||||
"T" | "TEXT" if self.text.is_some() => {
|
||||
self.placing_text = true;
|
||||
Some(CmdResult::NeedPoint)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
||||
let Some(value) = self.text.clone().filter(|_| self.placing_text) else {
|
||||
return CmdResult::NeedPoint;
|
||||
};
|
||||
let p = self.plane.to_local(pt);
|
||||
let mut mtext = MText::new();
|
||||
mtext.value = value;
|
||||
mtext.insertion_point = Vector3::new(p.x, p.y, p.z);
|
||||
mtext.height = self.height;
|
||||
mtext.style = self.style.clone();
|
||||
mtext.attachment_point = AttachmentPoint::TopLeft;
|
||||
mtext.rectangle_width = 0.0;
|
||||
CmdResult::CommitAndExit(self.plane.place_entity(EntityType::MText(mtext)))
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> CmdResult {
|
||||
if self.placing_text {
|
||||
return CmdResult::NeedPoint;
|
||||
}
|
||||
// Enter takes the first format offered.
|
||||
let first = self.options().first().map(|o| o.keyword.clone());
|
||||
first
|
||||
.and_then(|keyword| self.on_text_input(&keyword))
|
||||
.unwrap_or(CmdResult::Cancel)
|
||||
}
|
||||
}
|
||||
|
||||
inventory::submit!(crate::command::CommandRegistration { names: &["PASTESPEC"] });
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::mtext_value;
|
||||
|
||||
#[test]
|
||||
fn plain_text_becomes_escaped_paragraphs() {
|
||||
assert_eq!(mtext_value("a{b}\\c\r\nline 2\n"), "a\\{b\\}\\\\c\\Pline 2");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user