Restore saved Midra screen links in export configuration

This commit is contained in:
Dandaedre 2026-11-13 18:56:20 +01:00
parent 2e46ec0b58
commit 1be695b847
5 changed files with 79 additions and 8 deletions

View File

@ -256,6 +256,21 @@ impl Editor {
}
}
}
pub(super) fn open_midra_export(&mut self) {
if let Some(snapshot) = &self.device.snapshot
&& let Some(index) = self.layout.selected_indices().iter().find_map(|&i| {
let link = self.layout.layer_info(i).midra_link.as_ref()?;
snapshot
.screens
.iter()
.position(|screen| screen.id == link.screen)
})
{
self.device.screen = index;
}
self.device.prepare_send = true;
self.device.open = true;
}
pub(super) fn midra_apply_button(&mut self, ui: &mut egui::Ui) {
if ui.add_enabled(
self.device.online() && self.device.pending.is_none(),
@ -264,8 +279,7 @@ impl Editor {
.on_hover_text("Choose layers, destination links and export settings, then click Send mapped layers.")
.on_disabled_hover_text("Connect to Midra and wait for any transfer to finish.")
.clicked() {
self.device.prepare_send = true;
self.device.open = true;
self.open_midra_export();
ui.close_menu();
}
}
@ -534,7 +548,7 @@ fn send_review(
.selected_text(if target.is_empty() {
"Choose Midra layer".into()
} else {
format!("Midra layer {target}")
format!("Screen {} · Layer {target}", screen.id)
})
.show_ui(ui, |ui| {
ui.selectable_value(target, String::new(), "Choose Midra layer");
@ -542,7 +556,7 @@ fn send_review(
ui.selectable_value(
target,
layer.id.clone(),
format!("Layer {}", layer.id),
format!("Screen {} · Layer {}", screen.id, layer.id),
);
}
});
@ -696,6 +710,41 @@ mod tests {
}
}
#[test]
fn saved_screen_distinguishes_same_numbered_layers_and_restores_picker() {
let mut app = Editor::default();
let mut snapshot = linked_test_snapshot();
let mut second = snapshot.screens[0].clone();
second.id = "2".into();
second.layers[0].geometry.x += 200.0;
snapshot.screens.push(second);
let mut links = Vec::new();
for i in 0..2 {
let link = midra_layout::MidraLink {
screen: (i + 1).to_string(),
layer: "1".into(),
};
app.layout.set_midra_link(i, Some(link.clone())).unwrap();
links.push((app.layout.layer_info(i).id, link));
}
load_linked_layers(&mut app.layout, &snapshot, &links).unwrap();
assert_eq!(
app.layout.layers()[0],
snapshot.screens[0].layers[0].geometry
);
assert_eq!(
app.layout.layers()[1],
snapshot.screens[1].layers[0].geometry
);
assert_ne!(app.layout.layers()[0], app.layout.layers()[1]);
app.device.snapshot = Some(snapshot);
for i in [1, 0] {
app.layout.select(Some(i));
app.open_midra_export();
assert_eq!(app.device.screen, i);
assert!(app.device.pending.is_none());
}
}
#[test]
fn linked_load_is_atomic_undoable_and_keeps_links() {
let snapshot = linked_test_snapshot();
let mut layout = midra_layout::Layout::default();

View File

@ -134,8 +134,7 @@ impl Editor {
)
.clicked()
{
self.device.prepare_send = true;
self.device.open = true;
self.open_midra_export();
ui.close_menu();
}
ui.menu_button("Export", |ui| self.export_menu(ui));
@ -145,8 +144,7 @@ impl Editor {
self.midra_send_button(ui);
self.midra_load_button(ui, true);
if ui.button("Configure Midra export…").clicked() {
self.device.prepare_send = true;
self.device.open = true;
self.open_midra_export();
ui.close_menu();
}
ui.separator();

View File

@ -200,6 +200,11 @@ fn persistent_midra_links_roundtrip_migrate_and_undo() {
screen: "2".into(),
layer: "1".into(),
};
let first_link = MidraLink {
screen: "1".into(),
layer: "1".into(),
};
layout.set_midra_link(0, Some(first_link.clone())).unwrap();
layout.set_midra_link(1, Some(link.clone())).unwrap();
layout.select(None);
let project = Project::from_layout(&layout);
@ -207,6 +212,7 @@ fn persistent_midra_links_roundtrip_migrate_and_undo() {
.unwrap()
.layout()
.unwrap();
assert_eq!(restored.layer_info(0).midra_link, Some(first_link));
assert_eq!(restored.layer_info(1).midra_link, Some(link.clone()));
layout.undo();
assert!(layout.layer_info(1).midra_link.is_none());

View File

@ -173,3 +173,12 @@ with every schema or semantic change, including additive fields under the strict
unknown-field policy. Never silently interpret a future version as a supported version.
Midra links belong to layer identity and survive selection changes, refresh, rename, reorder and project round trips. Link edits support Undo/Redo. New layers and older projects start unlinked. Links refer to the currently connected device; Preview/Program and sizing remain session choices, and Program permission remains an application preference. Duplicate destinations can be stored, but a send containing duplicates is rejected before any writes. Unavailable screens/layers are reported without deleting the saved links. SVG exports geometry only and omits links.
Midra destinations are identified by the pair **screen ID + layer ID**: Screen 1
Layer 1 and Screen 2 Layer 1 are distinct links. Both IDs are already persisted
in project version 5; no schema change is needed. Opening **Apply changes…** or
**Configure Midra export…** restores the first selected layer's available linked
screen. Destination choices display both IDs. Browsing another screen does not
retarget existing links; choosing a destination there explicitly replaces that
layer's saved link. Direct send/load actions use each layer's saved screen,
independently of the screen currently displayed in the configuration window.

View File

@ -643,3 +643,12 @@ geometry, and hidden or locked editor destinations reject the complete import
without changing the document. Unlock/show destinations before loading. Results
appear in the transfer window or the load button's status tooltip. No project or
settings schema changes are involved.
Midra destinations are identified by the pair **screen ID + layer ID**: Screen 1
Layer 1 and Screen 2 Layer 1 are distinct links. Both IDs are already persisted
in project version 5; no schema change is needed. Opening **Apply changes…** or
**Configure Midra export…** restores the first selected layer's available linked
screen. Destination choices display both IDs. Browsing another screen does not
retarget existing links; choosing a destination there explicitly replaces that
layer's saved link. Direct send/load actions use each layer's saved screen,
independently of the screen currently displayed in the configuration window.