From 8f3095f777e0fd7c4b17761d20ec73a4ef925e0b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 16:32:27 +0100 Subject: [PATCH] Add paste layer values to the layer context menu --- crates/midra-layout/src/gui.rs | 71 ++++++++++++++++++++++++++++++ crates/midra-layout/src/menu_ui.rs | 8 +--- docs/midra-layout.md | 3 +- docs/midralayout/changelog.md | 2 + 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index c6ce581..452a1e3 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -562,6 +562,15 @@ impl Editor { .map(|i| FormatDraft::new(&self.layout, i)); } } + fn request_layer_paste(ctx: &egui::Context) { + ctx.memory_mut(|m| { + if let Some(id) = m.focused() { + m.surrender_focus(id); + } + }); + ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaste); + } + fn open_paste(&mut self, text: String) { let targets = self.layout.selected_indices(); let mut p = Paste { @@ -1723,6 +1732,14 @@ impl Editor { self.copy(ui.ctx()); ui.close_menu(); } + if ui + .button("Paste layer values") + .on_hover_text("Read the clipboard and review which values and layers to apply.") + .clicked() + { + ui.close_menu(); + Self::request_layer_paste(ui.ctx()); + } if ui.button("Lock selected layers").clicked() { for &i in &selected { self.layout.set_locked(i, true); @@ -5454,6 +5471,60 @@ mod tests { app.edit_content = false; assert_eq!(app.content_hit(covered, origin, 1.0), None); } + #[test] + fn context_paste_requests_clipboard_and_reviews_values_before_applying() { + let mut app = Editor::default(); + let ctx = egui::Context::default(); + let before = app.layout.layers().clone(); + let output = frame(&mut app, &ctx, vec![]); + let pos = layer_rects(&output)[0].center(); + let secondary = |pressed| egui::Event::PointerButton { + pos, + button: egui::PointerButton::Secondary, + pressed, + modifiers: egui::Modifiers::NONE, + }; + frame( + &mut app, + &ctx, + vec![egui::Event::PointerMoved(pos), secondary(true)], + ); + frame(&mut app, &ctx, vec![secondary(false)]); + let output = frame(&mut app, &ctx, vec![]); + let pos = output + .shapes + .iter() + .find_map(|s| match &s.shape { + egui::Shape::Text(t) if t.galley.text() == "Paste layer values" => { + Some(t.pos + t.galley.size() / 2.) + } + _ => None, + }) + .expect("context paste action"); + frame( + &mut app, + &ctx, + vec![egui::Event::PointerMoved(pos), mouse(pos, true)], + ); + let output = frame(&mut app, &ctx, vec![mouse(pos, false)]); + assert!(output.viewport_output.values().any(|v| { + v.commands + .iter() + .any(|c| matches!(c, egui::ViewportCommand::RequestPaste)) + })); + frame( + &mut app, + &ctx, + vec![egui::Event::Paste( + include_str!("../tests/fixtures/drawio-rectangle.txt").into(), + )], + ); + let paste = app.paste.as_ref().expect("paste mapping review"); + assert!(paste.error.is_empty()); + assert_eq!(paste.shapes.len(), 1); + assert_eq!(*app.layout.layers(), before); + } + #[test] fn import_menu_requests_clipboard_and_opens_layer_review() { let mut app = Editor::default(); diff --git a/crates/midra-layout/src/menu_ui.rs b/crates/midra-layout/src/menu_ui.rs index 35716eb..0c57ee2 100644 --- a/crates/midra-layout/src/menu_ui.rs +++ b/crates/midra-layout/src/menu_ui.rs @@ -60,13 +60,7 @@ impl Editor { .clicked() { ui.close_menu(); - ui.ctx().memory_mut(|m| { - if let Some(id) = m.focused() { - m.surrender_focus(id); - } - }); - ui.ctx() - .send_viewport_cmd(egui::ViewportCommand::RequestPaste); + Self::request_layer_paste(ui.ctx()); } ui.separator(); ui.weak("Screen reference"); diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 981135f..154183b 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -208,7 +208,8 @@ clipboard testing against a running draw.io instance remains to be done. can be toggled on paste. This is not a native WebRCS clipboard payload. Right-click a layer for **Source properties**, **Layer properties**, **Crop properties**, -**Adjust layer crop**, alignment, copying values, and lock/hide actions. Right-clicking a layer +**Adjust layer crop**, alignment, **Copy layer values**, **Paste layer values**, and lock/hide actions. +Paste reads the clipboard and opens the existing value/mapping review before applying changes. Right-clicking a layer already in a selection keeps the whole selection and offers **Resize together**. Right-clicking an unselected layer selects it first. Locked/hidden layers remain protected; use the layer list to unlock/show them. Right-click empty canvas for diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index daa695d..1afca36 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Add Paste layer values beside Copy layer values in the layer context menu, using the existing clipboard import and mapping review before applying changes. + - Make Source an advanced, opt-in section with explanations of input aspect correction and pre-layer input crop. Show the linked device input's actual WebRCS aspect/crop controls separately from the local geometry model. Stage only edited fields, include them in scoped sends only while enabled, and pulse input crop updates. The opt-in and staged device edits are session-only and clear on disconnect, address/project change or uncheck. Verified field names/ranges against the connected Eikos WebRCS; regression tests use mock devices, without hardware writes. - Add a Mapping properties tab and right-click entry with selectable Midra screen/layer links and Unmap. Unmapped layers are excluded from linked sends/loads; link edits are local, saved with projects and undoable. Move the separate editor input identity selector into Mapping.