mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 08:11:41 +00:00
Links: the request to show the selected image applies only in its own document
The Control bar label's request to scroll the Links panel to the selected image now carries the document it was made in. A draw of another document drops it and leaves the Show filter as it is, and every draw that reads the request clears it, including one with an empty list.
This commit is contained in:
@@ -89,7 +89,8 @@ fn set_options(ctx: &egui::Context, f: impl FnOnce(&mut Options)) {
|
||||
/// thumbnail size and DCS option keep their settings.
|
||||
pub(crate) fn show_selected_image(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let first = selected_images(app).first().copied();
|
||||
set_pstate(ctx, "links-scroll-to", first);
|
||||
let request = app.session.active().map(|st| st.uid).zip(first);
|
||||
set_pstate(ctx, "links-scroll-to", request);
|
||||
// The list drawn next is read after this request, so a row a file change has just brought
|
||||
// into the Show filter is there to scroll to.
|
||||
let mut c: std::sync::Arc<Cache> = pstate(ctx, "links-cache");
|
||||
@@ -602,9 +603,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
widgets::dim_label(ui, tl!("No document"));
|
||||
return;
|
||||
};
|
||||
// A Show filter that leaves out the row `show_selected_image` asks for goes back to Show All,
|
||||
// decided from the rows this frame draws and scrolls through.
|
||||
let scroll_to: Option<u64> = pstate(ui.ctx(), "links-scroll-to");
|
||||
// The row that `show_selected_image` asks for, used by this draw only and only in the document
|
||||
// it was asked in. A Show filter that leaves the row out goes back to Show All, decided from the
|
||||
// rows this frame draws and scrolls through.
|
||||
let request: Option<(u64, u64)> = pstate(ui.ctx(), "links-scroll-to");
|
||||
if request.is_some() {
|
||||
set_pstate::<Option<(u64, u64)>>(ui.ctx(), "links-scroll-to", None);
|
||||
}
|
||||
let uid = app.session.active().map(|st| st.uid);
|
||||
let scroll_to = request.filter(|(doc, _)| Some(*doc) == uid).map(|(_, id)| id);
|
||||
let listed = |cache: &Cache, id: u64| cache.list["links"].as_array().is_some_and(|rows| rows.iter().any(|r| r["id"].as_u64() == Some(id)));
|
||||
if scroll_to.filter(|id| o.show != "all" && !listed(&cache, *id)).is_some() {
|
||||
set_options(ui.ctx(), |o| o.show = "all");
|
||||
@@ -630,10 +637,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
super::empty_state(ui, "link", tl!("No images"), detail);
|
||||
return;
|
||||
}
|
||||
// The row that `show_selected_image` asks the list to scroll to, once.
|
||||
if scroll_to.is_some() {
|
||||
set_pstate::<Option<u64>>(ui.ctx(), "links-scroll-to", None);
|
||||
}
|
||||
egui::ScrollArea::vertical().max_height(260.0).auto_shrink([false, true]).show(ui, |ui| {
|
||||
let h = o.thumb.max(16.0) + 6.0;
|
||||
for r in rows {
|
||||
|
||||
@@ -263,7 +263,29 @@ fn opening_the_panel_on_the_selected_image_decides_the_filter_from_the_drawn_row
|
||||
super::links::show_selected_image(&mut app, &ctx);
|
||||
std::fs::write(dir.0.join("linked.png"), bytes).unwrap();
|
||||
assert_eq!(drawn(&mut app, 2.0), 2, "the restored image's row and its Link Info are drawn");
|
||||
assert_eq!(super::pstate::<Option<u64>>(&ctx, "links-scroll-to"), None, "the scroll request is used on the row");
|
||||
assert_eq!(super::pstate::<Option<(u64, u64)>>(&ctx, "links-scroll-to"), None, "the scroll request is used on the row");
|
||||
}
|
||||
|
||||
/// A request to show the selected image applies only in the document it was made in: drawn for
|
||||
/// another document, the panel keeps its Show filter and drops the request.
|
||||
#[test]
|
||||
fn opening_the_panel_on_the_selected_image_leaves_another_document_alone() {
|
||||
let dir = Folder::new("show-selected-other-doc");
|
||||
let (mut app, linked, _) = app(&dir);
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let text = |app: &mut VectorcraftApp, time: f64| {
|
||||
let raw = egui::RawInput { time: Some(time), ..Default::default() };
|
||||
let texts = super::tests_appearance::frame_raw(&ctx, app, raw, super::links::show);
|
||||
texts.into_iter().map(|(t, _)| t).collect::<Vec<_>>().join("\n")
|
||||
};
|
||||
app.run("select.set", json!({"ids": [linked]})).unwrap();
|
||||
click_menu_item(&mut app, &ctx, "Show Missing", 1.0);
|
||||
super::links::show_selected_image(&mut app, &ctx);
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let other = text(&mut app, 2.0);
|
||||
assert!(other.contains("Nothing matches the Show filter."), "the other document keeps Show Missing: {other}");
|
||||
assert_eq!(super::pstate::<Option<(u64, u64)>>(&ctx, "links-scroll-to"), None, "the request is dropped");
|
||||
}
|
||||
|
||||
/// A frame that fetches nothing keeps the stored rows and Link Info as they are, without a copy; the
|
||||
|
||||
Reference in New Issue
Block a user