From 7513fa7b11c21c6efcff7babd8df24590f01bfa3 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 21 Nov 2026 23:52:34 -0500 Subject: [PATCH 1/4] fix(plugins): mark cut diagnostic names and tidy panel notices A panel diagnostic name cut at MAX_TREE_ID now ends in an ellipsis and keeps its ".label" suffix. Panel notices say "update object(s)" and "field(s)", which they cover. Docs on apply, Dropped, KINDS and PanelItemDecl::command match the code again; ParamDecl says it also describes command form fields. The session's two error-output drains share one helper, and uninstall asks settings::file for the settings path. --- crates/plugins/src/lib.rs | 2 +- crates/plugins/src/manifest.rs | 3 +- crates/plugins/src/panel.rs | 59 +++++++++++++++++++++++++++------- crates/plugins/src/session.rs | 56 ++++++++++++++++++-------------- crates/plugins/src/settings.rs | 10 ++++++ crates/plugins/src/store.rs | 2 +- crates/plugins/src/tests.rs | 4 ++- 7 files changed, 96 insertions(+), 40 deletions(-) diff --git a/crates/plugins/src/lib.rs b/crates/plugins/src/lib.rs index 6d7524960b..520529122a 100644 --- a/crates/plugins/src/lib.rs +++ b/crates/plugins/src/lib.rs @@ -461,7 +461,7 @@ fn call_with_timeout( ) -> Result { // A command's settings requests are answered here, by this plugin's own id, however it runs. // A tool gets none: it runs off the UI thread, in models and on copies, and its output must - // not depend on what was saved (it makes no host requests). + // not depend on what was saved (its settings requests are refused). let mut scoped; let host: &mut dyn Host = if tool { host diff --git a/crates/plugins/src/manifest.rs b/crates/plugins/src/manifest.rs index 12304cab41..34f1382710 100644 --- a/crates/plugins/src/manifest.rs +++ b/crates/plugins/src/manifest.rs @@ -225,7 +225,8 @@ fn no_params() -> String { "{}".into() } -/// A tool parameter: the Tools pane turns its kind into a widget. +/// A tool parameter, or a field of a command's dialog (`commands[].form`): the Tools pane and the +/// dialog turn its kind into a widget. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ParamDecl { diff --git a/crates/plugins/src/panel.rs b/crates/plugins/src/panel.rs index 0c6fcee2f9..5a8f0ffaa6 100644 --- a/crates/plugins/src/panel.rs +++ b/crates/plugins/src/panel.rs @@ -39,7 +39,6 @@ pub const MAX_FORM_FIELD_ID: usize = 64; pub const MAX_FORM_CHOICES: usize = 256; /// The most options a dropdown (`choice`) holds. pub const MAX_CHOICES: usize = 1_000; -/// The widget kinds. /// Whether a kind takes its value from a list of `options`: a dropdown, or a tab row, which is the /// same thing drawn as a row of labels instead of a menu. They differ only in how they look, so /// everything from `options` to the value they keep is shared. @@ -48,6 +47,7 @@ pub fn picks_an_option(kind: &str) -> bool { matches!(kind, "choice" | "tabs") } +/// The widget kinds. pub const KINDS: &[&str] = &["text", "checkbox", "slider", "button", "tree", "form", "choice", "tabs", "date", "range", "pick"]; /// What a pick asks for on the map: a point (the default) or a box. pub const PICK_SHAPES: &[&str] = &["point", "box"]; @@ -93,6 +93,7 @@ pub struct PanelItemDecl { /// A text's first contents, until the plugin sets them. #[serde(default)] pub text: String, + /// The command it runs: a button's when clicked; a checkbox's when ticked or cleared; a /// slider's or a range's when let go (or stepped); a tree's or a dropdown's when a node or an /// option is chosen; a form's when one of its fields changes; a date's when a date is picked; /// a pick's when the place is picked on the map. Optional for all but buttons, whose values @@ -352,10 +353,24 @@ fn clip(s: &str, n: usize) -> String { s.chars().take(n).collect() } -/// A bounded, single-line name for a diagnostic, without terminal control characters. +/// A bounded, single-line name for a diagnostic, without terminal control characters: one longer +/// than [`MAX_TREE_ID`] ends in `…` to show it was cut. fn diagnostic_name(s: &str) -> String { - s.chars() - .take(MAX_TREE_ID) + diagnostic_cut(s, MAX_TREE_ID) +} + +/// A diagnostic name of a widget id and a suffix (`.label`): the id is cut, not the suffix. +fn diagnostic_suffixed(id: &str, suffix: &str) -> String { + let room = MAX_TREE_ID.saturating_sub(suffix.chars().count()).max(1); + format!("{}{suffix}", diagnostic_cut(id, room)) +} + +/// `s` as [`diagnostic_name`] makes it, at most `n` characters with the last a `…` when cut. +fn diagnostic_cut(s: &str, n: usize) -> String { + let cut = s.chars().count() > n; + let mut out: String = s + .chars() + .take(if cut { n.saturating_sub(1) } else { n }) .map(|c| { if c.is_control() || matches!(c,'\u{061c}'|'\u{200e}'|'\u{200f}'|'\u{2028}'..='\u{202e}'|'\u{2066}'..='\u{2069}') { ' ' @@ -363,7 +378,11 @@ fn diagnostic_name(s: &str) -> String { c } }) - .collect() + .collect(); + if cut { + out.push('…'); + } + out } /// A whole number from an integer or a float with no fraction (JSON from other languages). @@ -489,7 +508,9 @@ const MAX_NAMED: usize = 10; /// Counts and bounded name samples for what a panel update left out or changed. `values`, /// `fields`, `clipped` and `label_fields` retain at most ten names, each at most 200 characters. -/// The unlisted counters retain the remaining totals; `labels` is the full clipped-label count. +/// The unlisted counters retain the remaining totals; `labels` is the full clipped-label count; +/// `cut` holds each tree cut at [`MAX_TREE_NODES`] (its id and the nodes it was given), and the +/// notice names the first ten. /// Use `notice()` for the complete counts and sampled locations. #[derive(Clone, Debug, Default, PartialEq)] pub struct Dropped { @@ -513,7 +534,7 @@ impl Dropped { fn clip_label(&mut self, id: &str) { self.labels = self.labels.saturating_add(1); if self.label_fields.len() < MAX_NAMED { - self.label_fields.push(diagnostic_name(&format!("{id}.label"))); + self.label_fields.push(diagnostic_suffixed(id, ".label")); } } /// Count every field, retaining only a bounded sample for diagnostics. @@ -546,7 +567,7 @@ impl Dropped { pub fn notice(&self) -> Option { let mut parts = Vec::new(); if self.malformed > 0 { - parts.push(format!("{} panel object(s) not taken: expected an object", self.malformed)); + parts.push(format!("{} update object(s) not taken: expected an object", self.malformed)); } if self.labels > 0 { let names = self.label_fields.iter().map(|name| diagnostic_name(name)).collect::>().join(", "); @@ -555,8 +576,8 @@ impl Dropped { parts.push(format!("{} label(s) clipped to {MAX_STATE_LABEL} characters{location}", self.labels)); } for (ids, unlisted, what) in [ - (&self.fields, self.unlisted_fields, "item field(s) not taken (unknown, inapplicable, wrong type or invalid bounds)"), - (&self.clipped, self.unlisted_clipped, "item field(s) clipped or truncated"), + (&self.fields, self.unlisted_fields, "field(s) not taken (unknown, inapplicable, wrong type or invalid bounds)"), + (&self.clipped, self.unlisted_clipped, "field(s) clipped or truncated"), ( &self.adjusted, 0, @@ -1102,11 +1123,12 @@ impl PanelState { /// Takes in a plugin's answer about its panel: `{"values": {...}, "items": {"id": {...}}}`. /// An item may set `label` (`null` for the declared one), `text`, `enabled`, `visible`, for a /// slider or a range `min`, `max` and `labels`, for a tree `nodes`, for a dropdown `options`, - /// and for a form `fields`. Unknown ids and fields, and values of the wrong type, are ignored; + /// and for a form `fields`. Unknown ids and fields, and values of the wrong type, aren't taken; /// texts are clipped, sliders' values kept within their ends, a tree's chosen node among its /// nodes, and a form's value to its fields (a field the plugin no longer gives is dropped; a /// new one starts at its default). A pick's value can only be cleared (`null`): the place is - /// the user's to pick. Returns the values, options and nodes left out. + /// the user's to pick. Everything not taken, clipped, adjusted or cut is counted and named in + /// the returned [`Dropped`], whose `notice` reports it. pub fn apply(&mut self, decl: &PanelDecl, update: &Value) -> Dropped { let mut dropped = Dropped::default(); if !update.is_object() { @@ -1336,6 +1358,19 @@ impl PanelState { mod tests { use super::*; + #[test] + fn a_cut_diagnostic_name_ends_in_an_ellipsis_and_keeps_its_suffix() { + let id = "w".repeat(300); + let name = diagnostic_name(&id); + assert_eq!(name.chars().count(), MAX_TREE_ID); + assert!(name.ends_with('…'), "{name}"); + let label = diagnostic_suffixed(&id, ".label"); + assert_eq!(label.chars().count(), MAX_TREE_ID); + assert!(label.ends_with("….label"), "{label}"); + assert_eq!(diagnostic_name("short"), "short"); + assert_eq!(diagnostic_suffixed("short", ".label"), "short.label"); + } + fn form_decl() -> PanelDecl { PanelDecl { title: "Test".into(), diff --git a/crates/plugins/src/session.rs b/crates/plugins/src/session.rs index c633e13f1a..2302b8b025 100644 --- a/crates/plugins/src/session.rs +++ b/crates/plugins/src/session.rs @@ -81,17 +81,22 @@ struct Running { impl Running { /// Whether one more line may be logged now; says once when lines stop being logged. fn may_log(&mut self) -> bool { - if self.logged.0.elapsed() > LOG_WINDOW { - self.logged = (Instant::now(), 0); - } - self.logged.1 += 1; - if self.logged.1 == MAX_LOGGED + 1 { - log::info!("{}: more output than {MAX_LOGGED} lines a minute; the rest isn't logged", self.plugin); - } - self.logged.1 <= MAX_LOGGED + may_log(&mut self.logged, &self.plugin) } } +/// [`Running::may_log`] over the fields it reads, for code that holds other fields borrowed. +fn may_log(logged: &mut (Instant, usize), plugin: &str) -> bool { + if logged.0.elapsed() > LOG_WINDOW { + *logged = (Instant::now(), 0); + } + logged.1 += 1; + if logged.1 == MAX_LOGGED + 1 { + log::info!("{plugin}: more output than {MAX_LOGGED} lines a minute; the rest isn't logged"); + } + logged.1 <= MAX_LOGGED +} + static RUNNING: Mutex> = Mutex::new(Vec::new()); /// How programs found ended by a command (not by [`poll`]) ended: for the app to say ([`take_ended`]). static ENDED: Mutex> = Mutex::new(Vec::new()); @@ -229,30 +234,33 @@ fn shut(mut r: Running, grace: Duration) -> (Option, bool, Option = lines; - if dropped > 0 && r.may_log() { - log::info!("plugin {}: {dropped} earlier lines of its error output weren't kept", r.program); - } - for line in lines.into_iter().filter(|l| !l.trim().is_empty()) { - if r.may_log() { - log::info!("plugin {}: {line}", r.program); - } - r.last_stderr = Some(line); + let Running { errs, program, logged, plugin, last_stderr, .. } = r; + if let Some(line) = take_errors(errs, program, || may_log(logged, plugin)) { + *last_stderr = Some(line); } } /// Logs what is left of a program's error output; returns its last line. fn drain_errors(errs: &Kept, program: &str) -> Option { - let (lines, dropped) = errs.lock().map(|mut k| (k.lines.drain(..).collect(), std::mem::take(&mut k.dropped))).unwrap_or_default(); - let lines: Vec = lines; - if dropped > 0 { + take_errors(errs, program, || true) +} + +/// Takes the error output `errs` holds, logging each line (and how many earlier ones weren't +/// kept) while `may_log` allows; returns the last line that isn't blank. +fn take_errors(errs: &Kept, program: &str, mut may_log: impl FnMut() -> bool) -> Option { + let (lines, dropped): (Vec, usize) = + errs.lock().map(|mut k| (k.lines.drain(..).collect(), std::mem::take(&mut k.dropped))).unwrap_or_default(); + if dropped > 0 && may_log() { log::info!("plugin {program}: {dropped} earlier lines of its error output weren't kept"); } - for line in lines.iter().filter(|l| !l.trim().is_empty()) { - log::info!("plugin {program}: {line}"); + let mut last = None; + for line in lines.into_iter().filter(|l| !l.trim().is_empty()) { + if may_log() { + log::info!("plugin {program}: {line}"); + } + last = Some(line); } - lines.into_iter().rev().find(|l| !l.trim().is_empty()) + last } /// Stops `plugin`'s program, if it's running. diff --git a/crates/plugins/src/settings.rs b/crates/plugins/src/settings.rs index da36db099f..d9726108b0 100644 --- a/crates/plugins/src/settings.rs +++ b/crates/plugins/src/settings.rs @@ -237,6 +237,12 @@ impl Host for Scoped<'_> { #[cfg(not(target_arch = "wasm32"))] use native::{remove_saved, with_backing}; +/// The file a plugin's settings are saved in, when there is a plugins folder. +#[cfg(not(target_arch = "wasm32"))] +pub fn file(id: &str) -> Option { + native::file(id) +} + #[cfg(not(target_arch = "wasm32"))] mod native { use std::path::{Path, PathBuf}; @@ -302,6 +308,10 @@ mod native { f(&Dir(&dir)) } + pub(super) fn file(id: &str) -> Option { + dir().map(|d| Dir(&d).file(id)) + } + /// Without a plugins folder nothing could have been saved: there is nothing to erase. pub(super) fn remove_saved(id: &str) -> Result<(), String> { let Some(dir) = dir() else { return Ok(()) }; diff --git a/crates/plugins/src/store.rs b/crates/plugins/src/store.rs index cfc85ca541..20660a85dc 100644 --- a/crates/plugins/src/store.rs +++ b/crates/plugins/src/store.rs @@ -381,7 +381,7 @@ pub fn uninstall(id: &str) -> Result<(), String> { // tried again from here (it is gone), so a step that fails now says where they are when they // stay (a later install of the id would find them). let erase = is_package || package.is_none(); - let file = dir().map(|d| d.join("settings").join(format!("{id}.json"))); + let file = crate::settings::file(id); let kept = |e: String| match file.as_ref().filter(|f| erase && f.exists()) { Some(f) => format!("{e} (the plugin was uninstalled; its saved settings were kept: remove {} by hand)", f.display()), None => e, diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 45a611305c..bf48b29c72 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -2567,8 +2567,10 @@ fn panel_diagnostic_field_samples_are_bounded_and_counts_are_complete() { let report = state.apply(&decl, &json!({"items":fields})); assert!(report.fields.len() <= 10); assert!(report.fields.iter().all(|name| name.chars().count() <= 200)); + // A name cut to fit says so. + assert!(report.fields.iter().all(|name| name.ends_with('…')), "{:?}", report.fields); let notice = report.notice().unwrap(); - assert!(notice.contains("1000 item field(s)"), "{notice}"); + assert!(notice.contains("1000 field(s)"), "{notice}"); assert!(notice.len() < 7000); } From f84cfedbab511d10d528225c47d8003dd10de8a8 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 21 Nov 2026 23:52:34 -0500 Subject: [PATCH 2/4] docs(tiles,geom): match docs to code; share the full-turn rule Tiles docs on the revision lock, reload validation, a source's origin and kept() say what the code does. The STAC parsers that drop refused and omitted counts are test-only now. Geom exports is_full_turn_step, which the analysis unwrap uses instead of its own 360 - 1e-4, and the ring_pole_turns doc names the tolerance. The no-coordinates raster hint names the Imagery extension. --- crates/analysis/src/tools.rs | 4 ++-- crates/data/src/raster/mod.rs | 2 +- crates/geom/src/lib.rs | 16 ++++++++++++---- crates/tiles/src/arcgis_auth.rs | 4 ++-- crates/tiles/src/cache.rs | 4 +++- crates/tiles/src/pmtiles.rs | 4 ++++ crates/tiles/src/stac/catalog.rs | 18 ++++++++---------- crates/tiles/src/style.rs | 9 ++++++--- 8 files changed, 38 insertions(+), 23 deletions(-) diff --git a/crates/analysis/src/tools.rs b/crates/analysis/src/tools.rs index 357c227ea7..d4fca036cb 100644 --- a/crates/analysis/src/tools.rs +++ b/crates/analysis/src/tools.rs @@ -5511,8 +5511,8 @@ fn ground_area_perimeter(g: &Geometry) -> (f64, f64) { for c in &mut ring.0 { let step = c.x - previous; previous = c.x; - // Within 1e-4° of a full turn, as `wgs84_ring_perimeter_area_m2` takes it. - if step.abs() >= 360.0 - 1e-4 && step.is_finite() { + // A full turn as `wgs84_ring_perimeter_area_m2` takes it. + if rustgis_geom::is_full_turn_step(step) { longitude += step; full_turn = true; } else { diff --git a/crates/data/src/raster/mod.rs b/crates/data/src/raster/mod.rs index bde73f7d2f..2126a7f2e7 100644 --- a/crates/data/src/raster/mod.rs +++ b/crates/data/src/raster/mod.rs @@ -1049,7 +1049,7 @@ impl Raster { if self.georeferenced { Ok(()) } else { - Err(format!("{} has no coordinates: georeference it first (raster.georeference)", self.name)) + Err(format!("{} has no coordinates: georeference it first (raster.georeference, with the Imagery extension on)", self.name)) } } diff --git a/crates/geom/src/lib.rs b/crates/geom/src/lib.rs index 5dd5ec3199..d07b2e23b1 100644 --- a/crates/geom/src/lib.rs +++ b/crates/geom/src/lib.rs @@ -478,19 +478,19 @@ pub fn ring_area_is_ambiguous(ring: &[Coord]) -> bool { } /// How many times a lon/lat ring that never reaches a pole winds around one: each step of -/// longitude taken the short way round (within ±180°; an edge of exactly a whole turn as [`ring_lon_steps`] -/// reads it), summed, in whole turns. A ring cut at ±180° and closed along the pole, the form +/// longitude taken the short way round (within ±180°; an edge of a whole turn, within [`NEAR_DEG`] +/// (about 11 m), as [`ring_lon_steps`] reads it), summed, in whole turns. A ring cut at ±180° and closed along the pole, the form /// RustGIS takes for a polygon around a pole, reaches the pole and gives 0; so does any ring whose /// steps cancel. A loop such as a parallel written all the way round (`[0, 80]`, `[30, 80]`, …, /// `[330, 80]`) gives ±1, and the analysis plane, which reads longitude and latitude as x and y, /// sees it as a line with no area. 0 for a ring with fewer than three vertices, a coordinate that -/// isn't finite or lies past ±90° of latitude, or a vertex at a pole. +/// isn't finite or lies past ±90° of latitude, or a vertex at a pole (within [`NEAR_DEG`]). /// /// Only the coordinates are read, as longitude and latitude, as the analysis tools that read areas /// in the plane take a layer's (a layer with a coordinate system is read into them): a ring whose x /// and y were never degrees (a layer with no coordinate system, in small units, taken for degrees) /// can wind too, but only with an edge more than 180 long in x, and the steps decide it, taken the -/// short way but for an edge of exactly 360, which may be a full turn as above (`[0, 0]`, +/// short way but for an edge of 360 (within [`NEAR_DEG`]), which may be a full turn as above (`[0, 0]`, /// `[360, 0]`, `[360, 10]`, `[240, 10]`, `[120, 10]`, `[0, 10]` keeps its first edge as one, and /// gives 0). /// The triangle `[0, 0]`, `[300, 0]`, `[150, 80]` steps -60°, -150° and -150°, so it gives -1 @@ -592,6 +592,14 @@ fn wgs84_parallel_m(lat_deg: f64, dlon_deg: f64) -> f64 { /// decimals or more keeps its full turns. const NEAR_DEG: f64 = 1e-4; +/// Whether a step of longitude (degrees) is a full turn, within [`NEAR_DEG`]: an edge along a +/// parallel or the pole written from -180° to 180°, which the area and winding measures here keep +/// as written. Code that unwraps longitudes must agree with them, so it asks this. +#[must_use] +pub fn is_full_turn_step(step: f64) -> bool { + step.is_finite() && step.abs() >= 360.0 - NEAR_DEG +} + /// Whether a latitude is at a pole, within [`NEAR_DEG`]. fn at_pole(lat: f64) -> bool { lat.is_finite() && lat.abs() >= 90.0 - NEAR_DEG diff --git a/crates/tiles/src/arcgis_auth.rs b/crates/tiles/src/arcgis_auth.rs index f4bfeb6b5c..cac39da8bc 100644 --- a/crates/tiles/src/arcgis_auth.rs +++ b/crates/tiles/src/arcgis_auth.rs @@ -752,8 +752,8 @@ pub fn signed_in(portal: &str) -> Option { } /// Whether a sign-in kept still gives a token: one that renews itself or hasn't expired. A sign-in -/// past its expiry with nothing to renew it is kept, but no request uses it; a token given with an -/// address covers its server only and isn't counted. +/// past its expiry with nothing to renew it stays in memory but isn't counted (no request uses +/// it); a token given with an address covers its server only and isn't counted either. pub fn kept() -> bool { let now = now_secs(); sessions().iter().any(|s| s.signed_in_at(now)) diff --git a/crates/tiles/src/cache.rs b/crates/tiles/src/cache.rs index befd53b4ff..eb1296c7f3 100644 --- a/crates/tiles/src/cache.rs +++ b/crates/tiles/src/cache.rs @@ -250,7 +250,9 @@ static IN_FLIGHT: AtomicUsize = AtomicUsize::new(0); static SIGNED_OUT: AtomicU64 = AtomicU64::new(0); /// Source revisions are locked before any retained cache. Publication and reload share this -/// lock; callbacks and I/O must always run after releasing it. +/// lock. [`if_archive_current`] runs its `f` while holding it (`land`, `keep` and +/// `remember_info` run there), so such a callback must not do I/O or call back into code that +/// takes this lock; any other I/O runs after releasing it. fn archive_epochs() -> &'static Mutex> { static E: std::sync::LazyLock>> = std::sync::LazyLock::new(Mutex::default); &E diff --git a/crates/tiles/src/pmtiles.rs b/crates/tiles/src/pmtiles.rs index ddd78f3348..afc009c054 100644 --- a/crates/tiles/src/pmtiles.rs +++ b/crates/tiles/src/pmtiles.rs @@ -907,6 +907,10 @@ struct DirectorySummary { } /// An unfinished range encountered again is a cycle; completed ranges cost no further I/O or budget. +/// +/// Reload and repair validate more strictly than an ordinary open: a tile run past +/// `data_length` is refused even when the header gives 0 (where [`find`] reads it), and so is any +/// entry over [`MAX_BYTES`], where the reader fails only that tile. #[cfg(not(target_arch = "wasm32"))] fn validate_directories( archive: &str, diff --git a/crates/tiles/src/stac/catalog.rs b/crates/tiles/src/stac/catalog.rs index 8eb81da692..808d238043 100644 --- a/crates/tiles/src/stac/catalog.rs +++ b/crates/tiles/src/stac/catalog.rs @@ -56,14 +56,11 @@ pub fn label_of(url: &str) -> String { } /// The children (`child` links) of a catalog's document fetched from `from`: web addresses only, -/// sorted by title. -pub fn parse_children(bytes: &[u8], from: &str) -> Result, String> { - parse_children_from_origin(bytes, &crate::address::Origin::named(from)) -} - -/// Like [`parse_children`], carrying the observed post-redirect [`crate::address::Origin`] and reach. -pub fn parse_children_from_origin(bytes: &[u8], origin: &crate::address::Origin) -> Result, String> { - parse_children_noted(bytes, origin).map(|listing| listing.links) +/// sorted by title. For tests: it drops the counts of links refused or left out, which code that +/// lists children reports through [`parse_children_noted`]. +#[cfg(test)] +pub(crate) fn parse_children(bytes: &[u8], from: &str) -> Result, String> { + parse_children_noted(bytes, &crate::address::Origin::named(from)).map(|listing| listing.links) } /// A bounded link listing and the counted reasons it is incomplete. @@ -87,8 +84,9 @@ pub fn parse_children_noted(bytes: &[u8], origin: &crate::address::Origin) -> Re } /// The items (`item` links) of a catalog's or collection's document fetched from `from`: web -/// addresses only, in the order the document gives them. -pub fn parse_item_links(bytes: &[u8], from: &str) -> Result, String> { +/// addresses only, in the order the document gives them. For tests, as [`parse_children`]. +#[cfg(test)] +pub(crate) fn parse_item_links(bytes: &[u8], from: &str) -> Result, String> { parse_item_links_noted(bytes, &crate::address::Origin::named(from)).map(|listing| listing.links) } diff --git a/crates/tiles/src/style.rs b/crates/tiles/src/style.rs index f7bfbf6e2f..6089a6bd4c 100644 --- a/crates/tiles/src/style.rs +++ b/crates/tiles/src/style.rs @@ -1283,7 +1283,8 @@ impl StyleView { pub enum Source { Vector { tiles: Vec, - /// Runtime provenance of the tile templates; `None` for a user-selected template. + /// Runtime provenance of the tile templates: `None` for a template given directly; + /// templates from a TileJSON keep that document's origin, even when the user picked it. from: Option, url: Option, min_zoom: u8, @@ -1292,7 +1293,8 @@ pub enum Source { }, Raster { tiles: Vec, - /// Runtime provenance of the tile templates; `None` for a user-selected template. + /// Runtime provenance of the tile templates: `None` for a template given directly; + /// templates from a TileJSON keep that document's origin, even when the user picked it. from: Option, url: Option, tile_size: u32, @@ -1303,7 +1305,8 @@ pub enum Source { /// Elevation tiles, for `hillshade` and `color-relief` layers. RasterDem { tiles: Vec, - /// Runtime provenance of the tile templates; `None` for a user-selected template. + /// Runtime provenance of the tile templates: `None` for a template given directly; + /// templates from a TileJSON keep that document's origin, even when the user picked it. from: Option, url: Option, tile_size: u32, From 96c8375885eec96eb423d66cb6aae5628d0243ec Mon Sep 17 00:00:00 2001 From: giswqs Date: Sat, 21 Nov 2026 23:52:34 -0500 Subject: [PATCH 3/4] fix(ui): release quality pass fixes in the app and engine - A read left with no name is called by its own command, not "Run Model". - Column Statistics' Copy keeps one line per statistic when a text value holds a tab or line break. - A HEIC or AVIF picture names its format in the pop-up. - Settings errors no longer repeat "could not save preferences". - Plugin withdrawals are one warning with a count. - The GeoLibre panel links only the pinned release. - Shared constants for window keys and connection test messages, one listed() helper, the Model Builder's field filter from panes::takes_field, i18n for the plugin dialog's title and required marks, a clipped echo, stale comments and dead code. --- apps/rustgis-mobile/README.md | 5 +++-- apps/rustgis/src/main.rs | 12 +++++------ crates/engine/src/cmd/exports.rs | 9 ++------- crates/engine/src/cmd/plugins.rs | 8 ++++---- crates/engine/src/lib.rs | 12 ++++++----- crates/engine/src/policy/downloads.rs | 6 +++++- crates/engine/src/policy/mod.rs | 1 + crates/engine/src/prefs.rs | 21 +++++++++---------- crates/engine/src/service_logins.rs | 6 ++++-- crates/ui-egui/src/connectionui.rs | 8 ++------ crates/ui-egui/src/cubesui.rs | 13 +++++------- crates/ui-egui/src/layerprops.rs | 2 +- crates/ui-egui/src/layoutview.rs | 2 +- crates/ui-egui/src/lib.rs | 13 +++++++----- crates/ui-egui/src/modelbuilder.rs | 27 +++++++++++-------------- crates/ui-egui/src/panes.rs | 15 ++++++++++---- crates/ui-egui/src/plugindialog.rs | 8 ++++++-- crates/ui-egui/src/pluginpanel.rs | 1 - crates/ui-egui/src/pluginsui.rs | 11 +++++----- crates/ui-egui/src/popupmedia.rs | 29 ++++++++++++++++++++++++++- crates/ui-egui/src/readjob.rs | 25 +++++++++++++++++++---- crates/ui-egui/src/ribbon.rs | 2 +- crates/ui-egui/src/scriptcomplete.rs | 3 ++- crates/ui-egui/src/table.rs | 21 +++++++++++++++++-- crates/ui-egui/src/widgets.rs | 9 +++------ 25 files changed, 167 insertions(+), 102 deletions(-) diff --git a/apps/rustgis-mobile/README.md b/apps/rustgis-mobile/README.md index 0f41b242d8..cb1d1e4a37 100644 --- a/apps/rustgis-mobile/README.md +++ b/apps/rustgis-mobile/README.md @@ -87,8 +87,9 @@ Rust calls Java and never the other way: each frame the app collects what happen A phone starts in the touch interface: the map, a bar of four large buttons under it (Layers, Add Data, Capture, More) and sheets that rise over the map. The Layers sheet shows and hides layers, zooms to one and makes one the active layer; the More sheet has Full Extent, the project, undo -and redo, and **Use the Desktop Interface**, which brings back the ribbon and panes until the app -is started again. +and redo, and **Use the Desktop Interface**, which brings back the ribbon and panes; **Touch +Interface**, on the View tab (or Use the Touch Interface in Command Search), returns to the phone's +interface. **Capture** adds a feature to one of the map's point, line or polygon layers. A cross marks the middle of the map: the map is moved under it, and the sheet's fields are filled in (one for each diff --git a/apps/rustgis/src/main.rs b/apps/rustgis/src/main.rs index c911001e79..a899bf24b4 100644 --- a/apps/rustgis/src/main.rs +++ b/apps/rustgis/src/main.rs @@ -931,11 +931,11 @@ mod tests { } assert!(!ctx.has_requested_repaint(), "clean preferences keep the window idle"); // A full disk: said once, not for every setting that follows. - prefs::saved(Err("could not save preferences: no space left".into())); - prefs::saved(Err("could not save preferences: no space left".into())); + prefs::saved(Err("no space left".into())); + prefs::saved(Err("no space left".into())); frame(); assert!(ctx.has_requested_repaint(), "the pending failure requests its delivery frame"); - assert_eq!(prefs::take_notices(), [Notice::NotSaved("could not save preferences: no space left".into())]); + assert_eq!(prefs::take_notices(), [Notice::NotSaved("no space left".into())]); for _ in 0..4 { frame(); } @@ -949,8 +949,8 @@ mod tests { assert!(prefs::take_notices().is_empty(), "equivalent recovery outcomes stay quiet"); // Once a save works, the next failure is news again. prefs::saved(Ok(None)); - prefs::saved(Err("could not save preferences: read-only".into())); - assert_eq!(prefs::take_notices(), [Notice::NotSaved("could not save preferences: read-only".into())]); + prefs::saved(Err("read-only".into())); + assert_eq!(prefs::take_notices(), [Notice::NotSaved("read-only".into())]); prefs::saved(Ok(None)); // A malformed file set aside says where it went. let bad = std::path::PathBuf::from("prefs.json.bad"); @@ -959,7 +959,7 @@ mod tests { let text = prefs::text(&Notice::SetAside(bad)); assert!(text.contains("prefs.json.bad"), "{text}"); // Both a failed replacement and an unconfirmed final flush give an accurate notice. - for error in ["could not save preferences: read-only", "preferences were replaced, but their durability could not be confirmed"] { + for error in ["read-only", "preferences were replaced, but their durability could not be confirmed"] { let text = prefs::text(&Notice::NotSaved(error.into())); assert!(text.contains("Settings could not be saved reliably") && text.contains(error), "{text}"); assert!(!text.contains("changes last only until"), "{text}"); diff --git a/crates/engine/src/cmd/exports.rs b/crates/engine/src/cmd/exports.rs index d3305aebd2..4fb7210d75 100644 --- a/crates/engine/src/cmd/exports.rs +++ b/crates/engine/src/cmd/exports.rs @@ -179,18 +179,13 @@ pub(crate) fn drawn( } } if written.is_ok() { - let listed = |v: &[String]| { - let more = v.len().saturating_sub(10); - let shown = v.iter().take(10).cloned().collect::>().join("; "); - if more > 0 { format!("{shown}; and {more} more") } else { shown } - }; let warn = rustgis_data::diagnostics::Severity::Warning; if unplaced > 0 { notices.push(( warn, format!( "{path}: {unplaced} feature(s) have a place that can't be given in longitude/latitude, drawn without it ({})", - listed(&partly) + crate::listed(&partly) ), )); } @@ -200,7 +195,7 @@ pub(crate) fn drawn( format!( "{path}: {} layer(s) aren't drawn, as their system can't be given in longitude/latitude: {}", undrawn.len(), - listed(&undrawn) + crate::listed(&undrawn) ), )); } diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index 1dd5ea35b6..4bcc64d936 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -287,10 +287,10 @@ fn fetch_registry(s: &mut Session, url: &str) -> Result Ok(Vec::new()), }; match applied { - Ok(pulled) if !pulled.is_empty() => s.notify( - format!("{} plugin(s) were withdrawn from the plugin registry and turned off: {}", pulled.len(), pulled.join(", ")), - true, - ), + // A warning, not an error: the list was read and the withdrawal applied as asked. + Ok(pulled) if !pulled.is_empty() => { + s.warn(format!("{} plugin(s) were withdrawn from the plugin registry and turned off: {}", pulled.len(), pulled.join(", "))) + } Ok(_) => {} Err(e) => s.warn(format!("{blocklist}: {e}; the last blocklist read, if any, stays in force")), } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 5a2f420f50..73d7b89717 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -394,6 +394,13 @@ fn clip(s: &str, n: usize) -> String { /// stays well within what a notice keeps. const NAMES_SAID: usize = 5; +/// The first ten of `v` for a notice, separated by `; `, then how many more. +pub(crate) fn listed(v: &[String]) -> String { + let more = v.len().saturating_sub(10); + let shown = v.iter().take(10).cloned().collect::>().join("; "); + if more > 0 { format!("{shown}; and {more} more") } else { shown } +} + /// Layer names for a notice: the first [`NAMES_SAID`], each clipped, and how many more. fn names_said(names: &[String]) -> String { let shown: Vec = names.iter().take(NAMES_SAID).map(|n| clip(n, 80)).collect(); @@ -3229,11 +3236,6 @@ impl Session { } // Layers gone are forgotten, so the map stays as small as the project. self.unplaced_checked.retain(|id, _| seen.contains(id)); - let listed = |v: &[String]| { - let more = v.len().saturating_sub(10); - let shown = v.iter().take(10).cloned().collect::>().join("; "); - if more > 0 { format!("{shown}; and {more} more") } else { shown } - }; if features > 0 { let text = format!( "{features} feature(s) have a place that can't be given in longitude/latitude: the map and the globe draw them without it, and labels' lines, block diagrams and terrain water leave them out ({})", diff --git a/crates/engine/src/policy/downloads.rs b/crates/engine/src/policy/downloads.rs index 7b4c8ccb5c..26d42c7422 100644 --- a/crates/engine/src/policy/downloads.rs +++ b/crates/engine/src/policy/downloads.rs @@ -10,10 +10,14 @@ use std::{ }, }; +/// The keys of a window the app reads off the frame (`"window"`, #1330): the app copies these +/// from the request, and a landed window holding any other key is refused. +pub const WINDOW_KEYS: [&str; 3] = ["bbox", "cellSize", "cog"]; + /// What a window the app read off the frame says it read (`"window"`, #1330) is what its request /// asked for: a box, and its cell size and `"cog"` if the request gave them, nothing else. fn asked_window(asked: &Value, window: &Value) -> bool { - const KEYS: [&str; 3] = ["bbox", "cellSize", "cog"]; + const KEYS: [&str; 3] = WINDOW_KEYS; let given = |k: &str| asked.get(k).filter(|v| !v.is_null()); given("bbox").is_some() && window.as_object().is_some_and(|w| w.keys().all(|k| KEYS.contains(&k.as_str())) && KEYS.iter().all(|k| given(k) == w.get(*k))) diff --git a/crates/engine/src/policy/mod.rs b/crates/engine/src/policy/mod.rs index 384f5e7101..a9899074cd 100644 --- a/crates/engine/src/policy/mod.rs +++ b/crates/engine/src/policy/mod.rs @@ -5,6 +5,7 @@ mod decide; mod dispatch; pub(crate) mod downloads; +pub use downloads::WINDOW_KEYS; mod effects; pub mod handler; mod plan; diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 9816eefd77..55503003f8 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -91,17 +91,13 @@ fn write_at_with_bytes( map.insert(key.to_string(), Value::String(value.to_string())); let text = serde_json::to_vec(&map).map_err(|_| "could not serialize preferences")?; let dir = path.parent().ok_or("the settings folder isn't available")?; - std::fs::create_dir_all(dir).and_then(|_| rustgis_data::io::replace_atomic(path, &text)).map_err(|error| match &set_aside { - Some(backup) => format!("could not save preferences: {error}; malformed preferences were kept at {}", backup.display()), - None => format!("could not save preferences: {error}"), - })?; - sync(path).map_err(|error| match &set_aside { - Some(backup) => format!( - "preferences were replaced, but their durability could not be confirmed: {error}; malformed preferences were kept at {}", - backup.display() - ), - None => format!("preferences were replaced, but their durability could not be confirmed: {error}"), - })?; + // The app wraps these in "Settings could not be saved reliably (…)", so they don't repeat it. + let kept = |message: String| match &set_aside { + Some(backup) => format!("{message}; malformed preferences were kept at {}", backup.display()), + None => message, + }; + std::fs::create_dir_all(dir).and_then(|_| rustgis_data::io::replace_atomic(path, &text)).map_err(|error| kept(error.to_string()))?; + sync(path).map_err(|error| kept(format!("preferences were replaced, but their durability could not be confirmed: {error}")))?; Ok(set_aside) } @@ -181,7 +177,8 @@ fn sync_directory(path: &Path) -> std::io::Result<()> { } /// Returns the open copy when its bytes match, so the caller can confirm its durability. -/// Symlink paths and read errors do not establish a match; sync failures remain distinct. +/// Symlink paths and read errors do not establish a match. This doesn't sync: the caller confirms +/// durability on the returned file. fn same_contents(source: &[u8], target: &Path) -> std::io::Result> { if !std::fs::symlink_metadata(target)?.file_type().is_file() { return Ok(None); diff --git a/crates/engine/src/service_logins.rs b/crates/engine/src/service_logins.rs index d7d9408503..6083e74f60 100644 --- a/crates/engine/src/service_logins.rs +++ b/crates/engine/src/service_logins.rs @@ -72,6 +72,10 @@ pub const CHOOSE_CONNECTION: &str = "Several saved connections match this addres pub const NO_SUCH_CONNECTION: &str = "No saved web-service connection with this id."; /// A request's `connection` that isn't text. pub const CONNECTION_TEXT: &str = "connection must be a saved web-service connection id (text)"; +/// A form-test probe given an unusable connection definition. +pub const BAD_DEFINITION: &str = "The service test requires a valid web-service connection and login."; +/// A form-test probe given an address that isn't plain and at the connection's origin. +pub const BAD_ADDRESS: &str = "The service test requires a credential-free HTTP or HTTPS address at the connection's origin."; /// The commands that add layers from a service, and so may record the connection they came from /// (their `connection` parameter, or the connection whose login their address is read with). pub const ADD_COMMANDS: &[&str] = &[ @@ -323,8 +327,6 @@ impl Drop for TemporaryProbe { /// `url` is the address returned by the existing anonymous `connection.test` probe. Only a /// plain, credential-free address at the cleaned definition's exact origin may carry it. pub fn temporary_probe(c: &Connection, secret: &str, insecure: bool, url: &str) -> Result<(String, TemporaryProbe), String> { - const BAD_DEFINITION: &str = "The service test requires a valid web-service connection and login."; - const BAD_ADDRESS: &str = "The service test requires a credential-free HTTP or HTTPS address at the connection's origin."; if !c.id.is_empty() || !is_service(c) { return Err(BAD_DEFINITION.into()); } diff --git a/crates/ui-egui/src/connectionui.rs b/crates/ui-egui/src/connectionui.rs index 126ea67c72..b240b56245 100644 --- a/crates/ui-egui/src/connectionui.rs +++ b/crates/ui-egui/src/connectionui.rs @@ -151,12 +151,8 @@ pub(crate) fn translated(e: &str) -> String { web::NOT_THIS_SESSION => tl!("This request's login does not belong to this session."), web::CHOOSE_CONNECTION => tl!("Several saved connections match this address. Choose a connection explicitly."), web::NO_SUCH_CONNECTION => tl!("No saved web-service connection with this id."), - "The service test requires a valid web-service connection and login." => { - tl!("The service test requires a valid web-service connection and login.") - } - "The service test requires a credential-free HTTP or HTTPS address at the connection's origin." => { - tl!("The service test requires a credential-free HTTP or HTTPS address at the connection's origin.") - } + web::BAD_DEFINITION => tl!("The service test requires a valid web-service connection and login."), + web::BAD_ADDRESS => tl!("The service test requires a credential-free HTTP or HTTPS address at the connection's origin."), web::CONNECTION_TEXT => tl!("connection must be a saved web-service connection id (text)"), other => other, } diff --git a/crates/ui-egui/src/cubesui.rs b/crates/ui-egui/src/cubesui.rs index 8f40dec426..21d3b69fc6 100644 --- a/crates/ui-egui/src/cubesui.rs +++ b/crates/ui-egui/src/cubesui.rs @@ -112,7 +112,7 @@ pub fn pane(app: &mut RustGisApp, ui: &mut egui::Ui) { ui.separator(); let title = ui.label(egui::RichText::new(e.name.as_str()).strong()); // A JAXA Earth collection's licence is read once its entry comes into view. - let shown = ui.is_rect_visible(title.rect); + let visible = ui.is_rect_visible(title.rect); ui.label(egui::RichText::new(format!("{} · {} · {} · {}", e.provider, period(e), e.step, e.resolution)).small()); let source = match &e.source { Source::Stac { collection, asset } => format!("STAC {collection} · {asset}"), @@ -157,7 +157,7 @@ pub fn pane(app: &mut RustGisApp, ui: &mut egui::Ui) { } ui.hyperlink_to(tl!("About"), e.about.as_str()); if !e.credit.is_empty() { - licence_link(ui, e, shown); + licence_link(ui, e, visible); } }); } @@ -217,9 +217,9 @@ fn jaxa_line(ui: &mut egui::Ui, t: &crate::theme::Tokens) { } } -/// A JAXA Earth cube's licence: its collection's own once read (asked for when `shown`), JAXA's +/// A JAXA Earth cube's licence: its collection's own once read (asked for when `visible`), JAXA's /// terms when it can't be. -fn licence_link(ui: &mut egui::Ui, e: &Entry, shown: bool) { +fn licence_link(ui: &mut egui::Ui, e: &Entry, visible: bool) { match jaxa::licence(&e.url) { Some(Ok(l)) => { let tip = l.title.clone().unwrap_or_else(|| l.url.clone()); @@ -231,14 +231,11 @@ fn licence_link(ui: &mut egui::Ui, e: &Entry, shown: bool) { } None => { // Not in tests, which read nothing from the web. - #[cfg(not(test))] - if shown { + if visible && !cfg!(test) { jaxa::fetch_licence(&e.url); // As for the catalog: look again until the licence is read. ui.ctx().request_repaint_after(std::time::Duration::from_millis(250)); } - #[cfg(test)] - let _ = shown; ui.label(egui::RichText::new(tl!("Licence…")).small().weak()); } } diff --git a/crates/ui-egui/src/layerprops.rs b/crates/ui-egui/src/layerprops.rs index b6263836af..5f199d19d3 100644 --- a/crates/ui-egui/src/layerprops.rs +++ b/crates/ui-egui/src/layerprops.rs @@ -218,7 +218,7 @@ fn name_key(instance: u64) -> egui::Id { } /// The most characters `layer.rename` takes of a name: the box takes no more (a longer paste is -/// cut to fit, and a note under the box says so), so the command refuses none. +/// cut to fit, and a note under the box says so), so a name typed here is never refused. const NAME_LIMIT: usize = rustgis_engine::cmd::layer::MAX_LAYER_NAME; /// The layer's name, renamed (`layer.rename`) when the box is left (a click elsewhere, another diff --git a/crates/ui-egui/src/layoutview.rs b/crates/ui-egui/src/layoutview.rs index 49e5a1b9cd..38446aa2a2 100644 --- a/crates/ui-egui/src/layoutview.rs +++ b/crates/ui-egui/src/layoutview.rs @@ -1398,7 +1398,6 @@ fn text_field( None } -/// A map frame's grid options; `set` sends the changed ones (`false` removes the grid). /// An outline in a map frame's properties (its extent indicator, its border): the command key its /// changes go under, its width's drag id, and its colour and width (points) within `range`. struct Outline { @@ -1445,6 +1444,7 @@ fn outline_rows( }); } +/// A map frame's grid options; `set` sends the changed ones (`false` removes the grid). fn grid_properties(app: &mut RustGisApp, ui: &mut Ui, grid: Option<&Grid>, id: u32, set: &dyn Fn(&mut RustGisApp, Value)) { let mut on = grid.is_some(); if ui.checkbox(&mut on, tl!("Show grid")).changed() { diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 3e383aadd9..87625f4eac 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1475,7 +1475,10 @@ impl RustGisApp { Some(Value::Number(_) | Value::String(_)) => {} // Not taken for the active layer: with replaceTable that would overwrite a table. Some(other) => { - return Err(crate::i18n::fmt("\"layer\" must be a layer's id or name, not {value}", &[("value", &other.to_string())])); + return Err(crate::i18n::fmt( + "\"layer\" must be a layer's id or name, not {value}", + &[("value", &crate::theme::clip(&other.to_string()))], + )); } } let id = self.session.layer_id(p)?; @@ -2386,8 +2389,8 @@ impl RustGisApp { return Err(tl!("this build saves projects with Save As").into()); } let stem: String = stem.chars().take(200).collect(); - // Not an undoable edit: saving names the project, as `project.saveAs` does, once the - // browser takes the file. + // Not an undoable edit: saving names the project, as `project.saveAs` does. The name + // stays set while the download is offered, and goes back if the download fails. let construction_notes = self.session.construction_output_notes()?; let old = std::mem::replace(&mut self.session.project.name, stem.clone()); let (text, report) = match self.session.project.saved_text(None) { @@ -6073,7 +6076,7 @@ impl RustGisApp { })?; // What a task needs to read it again, as the download itself can't be (`record_step`). let mut window = json!({}); - for k in ["bbox", "cellSize", "cog"] { + for k in rustgis_engine::policy::WINDOW_KEYS { if let Some(v) = p.get(k).filter(|v| !v.is_null()) { window[k] = v.clone(); } @@ -8698,7 +8701,7 @@ mod download_service_tests { assert!(!app.session.notices.iter().any(|n| n.text.contains("Download offered"))); assert!(!app.download("archive.pmtiles", vec![1, 2, 3])); assert!(app.session.notices.iter().any(|n| n.error && n.text.contains("browser rejected download"))); - assert!(!app.session.notices.iter().any(|n| n.text.contains("Downloaded"))); + assert!(!app.session.notices.iter().any(|n| n.text.contains("Download offered"))); } /// The web download encodes the filtered rows and reports the count once the bytes are accepted. diff --git a/crates/ui-egui/src/modelbuilder.rs b/crates/ui-egui/src/modelbuilder.rs index 291869b55f..a39d5a0b53 100644 --- a/crates/ui-egui/src/modelbuilder.rs +++ b/crates/ui-egui/src/modelbuilder.rs @@ -1408,16 +1408,16 @@ fn source_input(app: &RustGisApp, n: &ModelNode, input: &str) -> Option } } -/// Fields of a known model input. Numeric parameters refer strictly to a standalone table ID; +/// The dataset of a known model input, whose fields its field parameters offer. Numeric parameters refer strictly to a standalone table ID; /// a wire takes precedence, and tool-produced schemas remain unknown until execution. -fn input_fields<'a>(app: &'a RustGisApp, n: &ModelNode, input: &str) -> Option<&'a [rustgis_engine::data::Field]> { +fn input_dataset<'a>(app: &'a RustGisApp, n: &ModelNode, input: &str) -> Option<&'a rustgis_engine::data::Dataset> { if !app.mb.graph.edges.iter().any(|e| e.to == n.id && e.to_port == input) && let Some(id) = n.params.get(input).and_then(Value::as_u64) { - return app.session.project.table(u32::try_from(id).ok()?).map(|t| t.dataset.fields.as_slice()); + return app.session.project.table(u32::try_from(id).ok()?).map(|t| &t.dataset); } let name = source_input(app, n, input)?; - crate::panes::input_dataset(&app.session, &name).map(|d| d.fields.as_slice()) + crate::panes::input_dataset(&app.session, &name) } fn tool_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, i: usize, n: &ModelNode) { @@ -1502,7 +1502,7 @@ fn tool_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, i: usize, n: &Mo continue; } if let Some(input) = crate::fieldlists::input(p.kind) { - let fields = input_fields(app, n, input); + let fields = input_dataset(app, n, input).map(|d| d.fields.as_slice()); let edit = ui.push_id(("mb_list", &n.id, p.name), |ui| crate::fieldlists::show(ui, p.kind, &cur, fields)).inner; if edit.checkpoint { app.mb.edit(); @@ -1518,17 +1518,14 @@ fn tool_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, i: usize, n: &Mo let fields: Vec<&str> = if matches!(p.kind, ParamKind::Field | ParamKind::FieldNames | ParamKind::NumericField | ParamKind::CoordinateField) { crate::panes::layer_for_param(spec, p.name) - .and_then(|input| input_fields(app, n, input.name)) - .map(|fields| { - // As the Tools pane offers them (`panes::takes_field`). - fields + .and_then(|input| input_dataset(app, n, input.name)) + .map(|d| { + // As the Tools pane offers them. + d.fields .iter() - .filter(|f| match p.kind { - ParamKind::NumericField => f.ty.is_numeric(), - ParamKind::FieldNames => !f.name.contains([',', ';']), - _ => true, - }) - .map(|f| f.name.as_str()) + .enumerate() + .filter(|(i, _)| crate::panes::takes_field(p.kind, d, *i)) + .map(|(_, f)| f.name.as_str()) .collect() }) .unwrap_or_default() diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index fa9e138008..aa741da5eb 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -1950,8 +1950,9 @@ fn disk_note(app: &RustGisApp, layer: Option<&Layer>, tile: Option) -> Op /// The note after a layer's name, its details and tint, as [`disk_note`] gives them. A layer read /// whole from a Shapefile or GeoJSON file it publishes to (`source.publish`) also says whether it -/// holds edits the file lacks (`syncmark`), and its file's changes point to Publish to Source, -/// which refuses to overwrite them, rather than Reload Data, which can't read it again. +/// holds edits the file lacks (`syncmark`). A change on disk with no edits points to adding the +/// file again (and Source File State), not Reload Data, which can't read it again; with edits, +/// Publish to Source refuses to overwrite the change and Export Features keeps them. pub(crate) fn layer_note(app: &mut RustGisApp, l: &Layer, ctx: &egui::Context) -> Option<(String, String, Option)> { #[cfg(not(target_arch = "wasm32"))] { @@ -3406,7 +3407,9 @@ fn geolibre_card(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { ui.label(egui::RichText::new(e).size(11.0).color(t.red)); } } - let download = status["download"].as_str().unwrap_or("https://github.com/opengeos/geolibre-rust/releases/latest").to_string(); + // The pinned release's page, as `gp::geolibre_status` gives it; none, no link (never the latest + // release, which may be one this version can't run). + let download = status["download"].as_str().map(str::to_string); ui.add_space(6.0); egui::Frame::NONE.stroke(Stroke::new(1.0, t.border)).corner_radius(CornerRadius::same(6)).inner_margin(egui::Margin::same(10)).show( ui, @@ -3459,7 +3462,11 @@ fn geolibre_card(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { ui.add_space(2.0); ui.horizontal_wrapped(|ui| { ui.label(egui::RichText::new(tl!("Or")).size(11.0).color(t.text_dim)); - ui.add(egui::Hyperlink::from_label_and_url(tl!("Download the GeoLibre runner"), download).open_in_new_tab(true)); + if let Some(download) = &download { + ui.add( + egui::Hyperlink::from_label_and_url(tl!("Download the GeoLibre runner"), download).open_in_new_tab(true), + ); + } #[cfg(not(target_arch = "wasm32"))] if ui.small_button(tl!("Locate…")).clicked() && let Some(path) = diff --git a/crates/ui-egui/src/plugindialog.rs b/crates/ui-egui/src/plugindialog.rs index b201fc7ff1..b03a44c5b1 100644 --- a/crates/ui-egui/src/plugindialog.rs +++ b/crates/ui-egui/src/plugindialog.rs @@ -263,7 +263,10 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { let fields = c.form.iter().any(|f| !is_tabs(f)); let mut open = true; - let title = format!("{} › {}", m.translate(&lang, &m.name), m.translate(&lang, &c.label).replace('\n', " ")); + let title = crate::i18n::fmt( + "{plugin} › {command}", + &[("plugin", m.translate(&lang, &m.name)), ("command", &m.translate(&lang, &c.label).replace('\n', " "))], + ); egui::Window::new(title) .id(egui::Id::unique(("plugin_form", &d.plugin, &d.command))) .open(&mut open) @@ -295,7 +298,8 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { let mut layer: Option = None; for f in c.form.iter().filter(|f| !is_tabs(f)) { let text = m.translate(&lang, &f.label); - let mut label = ui.label(if f.required { format!("{text} *") } else { text.to_string() }); + let mut label = + ui.label(if f.required { crate::i18n::fmt("{label} *", &[("label", text)]) } else { text.to_string() }); if !f.help.is_empty() { label = label.on_hover_text(m.translate(&lang, &f.help)); } diff --git a/crates/ui-egui/src/pluginpanel.rs b/crates/ui-egui/src/pluginpanel.rs index affc4c97c4..753f9b6e21 100644 --- a/crates/ui-egui/src/pluginpanel.rs +++ b/crates/ui-egui/src/pluginpanel.rs @@ -1015,7 +1015,6 @@ fn tabs(app: &mut RustGisApp, ui: &mut Ui, pid: &str, item: &PanelItemDecl, stat }); }); ui.add_space(2.0); - let _ = t; if let Some(n) = pick { send(app, pid, item, json!(n)); } diff --git a/crates/ui-egui/src/pluginsui.rs b/crates/ui-egui/src/pluginsui.rs index 583353111a..19d6b679fa 100644 --- a/crates/ui-egui/src/pluginsui.rs +++ b/crates/ui-egui/src/pluginsui.rs @@ -723,11 +723,12 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { )); Vec::new() }); - for name in pulled { - app.session.notify( - crate::i18n::fmt("{name} was withdrawn from the plugin registry and has been turned off.", &[("name", &name)]), - true, - ); + // One warning for them all, with a count: the withdrawal was applied as asked. + if !pulled.is_empty() { + app.session.warn(crate::i18n::fmt( + "{n} plugin(s) were withdrawn from the plugin registry and turned off: {names}", + &[("n", &pulled.len().to_string()), ("names", &pulled.join(", "))], + )); } } // Another registry may have no blocklist (it blocks nothing); the hosted one always diff --git a/crates/ui-egui/src/popupmedia.rs b/crates/ui-egui/src/popupmedia.rs index 39f0027c42..531a8b41f8 100644 --- a/crates/ui-egui/src/popupmedia.rs +++ b/crates/ui-egui/src/popupmedia.rs @@ -333,13 +333,29 @@ fn header(bytes: &[u8]) -> Result>, Fa const SHOWN: [image::ImageFormat; 4] = [image::ImageFormat::Png, image::ImageFormat::Jpeg, image::ImageFormat::WebP, image::ImageFormat::Gif]; +/// A HEIC or AVIF picture (common from phones), by the brand of its ISO-BMFF `ftyp` box, which +/// `image` doesn't recognise without those decoders: such a picture says its format rather than +/// that it isn't a picture. +fn heif_brand(bytes: &[u8]) -> Option<&'static str> { + if bytes.get(4..8) != Some(b"ftyp".as_slice()) { + return None; + } + match bytes.get(8..12)? { + b"heic" | b"heix" | b"mif1" | b"msf1" => Some("HEIC"), + b"avif" | b"avis" => Some("AVIF"), + _ => None, + } +} + /// Decodes a fetched picture for the pop-up: refused when it isn't one, or is in a format outside /// [`SHOWN`], or when its header says it is larger than [`crate::mapview::decode_picture`] takes /// (before anything is decoded, so a small file can't unpack into a huge picture), and kept at /// most [`MAX_SIDE`] pixels a side. pub(crate) fn decode(bytes: &[u8]) -> Result { let header = header(bytes)?; - let Some(format) = header.format() else { return Err(Failure::NotPicture) }; + let Some(format) = header.format() else { + return Err(heif_brand(bytes).map_or(Failure::NotPicture, |f| Failure::Unsupported(f.into()))); + }; // A picture in another format says so, rather than that it isn't one. if !SHOWN.contains(&format) { return Err(Failure::Unsupported(format!("{format:?}").to_uppercase())); @@ -560,6 +576,17 @@ mod tests { let mut tiff = b"II*\0".to_vec(); tiff.resize(64, 0); assert_eq!(decode(&tiff), Err(Failure::Unsupported("TIFF".into()))); + // A phone's HEIC or AVIF photo names its format, by its `ftyp` brand. + let ftyp = |brand: &[u8]| { + let mut box_ = b"\0\0\0\x18ftyp".to_vec(); + box_.extend_from_slice(brand); + box_.resize(64, 0); + box_ + }; + assert_eq!(decode(&ftyp(b"heic")), Err(Failure::Unsupported("HEIC".into()))); + assert_eq!(decode(&ftyp(b"mif1")), Err(Failure::Unsupported("HEIC".into()))); + assert_eq!(decode(&ftyp(b"avif")), Err(Failure::Unsupported("AVIF".into()))); + assert_eq!(decode(&ftyp(b"isom")), Err(Failure::NotPicture)); // A GIF is shown (a 1 × 1 one). let gif = b"GIF89a\x01\0\x01\0\x80\0\0\0\0\0\xff\xff\xff!\xf9\x04\x01\0\0\0\0,\0\0\0\0\x01\0\x01\0\0\x02\x02D\x01\0;"; assert_eq!(decode(gif).unwrap().dimensions(), (1, 1)); diff --git a/crates/ui-egui/src/readjob.rs b/crates/ui-egui/src/readjob.rs index 1def825991..894ef2ee12 100644 --- a/crates/ui-egui/src/readjob.rs +++ b/crates/ui-egui/src/readjob.rs @@ -242,7 +242,6 @@ fn run_presented( return Ok(json!({"reading": instance})); } let archive = matches!(command, "map.reloadTiles" | "map.repairTiles").then(|| reads::archive_target(&app.session, &p)).flatten(); - let mut p = p; if let Some((i, _)) = &archive && let Some(params) = p.as_object_mut() { @@ -393,17 +392,24 @@ fn leave(app: &mut RustGisApp, left: &mut Vec<(String, Gone)>, asked: &Asked, wh left.push((what, why)); } -/// What a command asked for is called in a notice: a script, or an unnamed model, by the -/// command's name. +/// What a command asked for is called in a notice: a script, an unnamed model or anything else +/// that gives no name, by the command's name. fn called<'a>(command: &str, what: &'a str) -> &'a str { match (what.is_empty(), command) { (false, _) => what, (true, "script.run") => tl_raw!("Run Script"), + (true, "model.run") => tl_raw!("Run Model"), (true, "topology.validate") => tl_raw!("Error Inspector"), (true, "table.statistics") => tl_raw!("Column Statistics"), (true, "layer.sizeBy") => tl_raw!("Size by Field"), (true, "service.add") => tl_raw!("Add Service Layer"), - (true, _) => tl_raw!("Run Model"), + (true, "service.layers") => tl_raw!("List Service Layers"), + (true, "edit.previewShapeConversion") => tl_raw!("Preview Shape Conversion"), + (true, "raster.imageGrid") => tl_raw!("Original Image Grid"), + (true, "source.syncState") => tl_raw!("Source File State"), + (true, "map.reloadTiles") => tl_raw!("Reload Tile Archive"), + (true, "map.repairTiles") => tl_raw!("Repair Tile Archive"), + (true, _) => tl_raw!("A background read"), } } @@ -788,6 +794,17 @@ mod tests { } } + #[test] + fn a_read_without_a_name_is_called_by_its_own_command() { + assert_eq!(called("model.run", "Flood"), "Flood"); + assert_eq!(called("model.run", ""), "Run Model"); + assert_eq!(called("service.layers", ""), "List Service Layers"); + for command in ["edit.previewShapeConversion", "raster.imageGrid", "source.syncState", "map.reloadTiles", "map.repairTiles"] { + assert_ne!(called(command, ""), "Run Model", "{command}"); + } + assert_eq!(called("layer.loadAll", ""), "A background read"); + } + #[test] fn annotation_grid_cancel_preserves_unrelated_waiting_reads() { annotation_grid_cancel_case(false); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 989eae4ac6..1ffeba31d5 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1895,7 +1895,7 @@ fn graticule_menu(ui: &mut Ui, app: &mut RustGisApp) { } } ui.separator(); - // Under the layers, filled ones hide the lines; over them, only the labels are on top. + // Under the layers, filled ones hide the lines; over them, the lines show on every layer. let mut on_top = app.session.map().graticule_on_top; if ui .checkbox(&mut on_top, tl!("Draw on top of layers")) diff --git a/crates/ui-egui/src/scriptcomplete.rs b/crates/ui-egui/src/scriptcomplete.rs index dd76f0c608..0034014f0b 100644 --- a/crates/ui-egui/src/scriptcomplete.rs +++ b/crates/ui-egui/src/scriptcomplete.rs @@ -862,7 +862,8 @@ fn step_value(script: &str, at: usize, session: &rustgis_engine::Session) -> Opt /// What a `gp.run` line's tool takes for the value being typed in its `"params"` (#788), by the /// kind of the tool's parameter of that key, as the tool's form offers it (`takes_layer`, /// `takes_field`): the layers of its kind, then the tables for one that takes any layer; the -/// fields it takes of the layer or table the tool's first layer parameter names (before or after +/// fields it takes of the layer or table named by the parameter whose fields it lists (the +/// input `fieldlists::input` gives for its kind, else `panes::layer_for_param`, before or after /// it); or its choices. None for another kind: a number, a bool, a path, a text, several layers in /// one string. fn tool_value(script: &str, at: usize, session: &rustgis_engine::Session) -> Option { diff --git a/crates/ui-egui/src/table.rs b/crates/ui-egui/src/table.rs index 6c26aaac5d..d413721370 100644 --- a/crates/ui-egui/src/table.rs +++ b/crates/ui-egui/src/table.rs @@ -827,8 +827,7 @@ fn statistics_window(app: &mut RustGisApp, ctx: &egui::Context) { ui.add_space(4.0); if ui.button(tl!("Copy")).clicked() { // The values as the answer holds them, not as the window rounds them, for a spreadsheet. - let text: Vec = lines.iter().map(|(n, _, full)| format!("{n}\t{full}")).collect(); - ui.ctx().copy_text(text.join("\n")); + ui.ctx().copy_text(stats_tsv(&lines)); } }); if !open { @@ -836,6 +835,14 @@ fn statistics_window(app: &mut RustGisApp, ctx: &egui::Context) { } } +/// The statistics as tab-separated lines, one per statistic: a tab or line break inside a name +/// or value (a text column's minimum, say) becomes a space so it can't split the pasted table. +fn stats_tsv(lines: &[(String, String, String)]) -> String { + let cell = |s: &str| s.replace(['\t', '\r', '\n'], " "); + let text: Vec = lines.iter().map(|(n, _, full)| format!("{}\t{}", cell(n), cell(full))).collect(); + text.join("\n") +} + /// The window's first line: the layer and the field. fn stats_title(answer: &Value) -> String { let text = |k: &str| answer.get(k).and_then(Value::as_str).unwrap_or_default().to_string(); @@ -1558,6 +1565,16 @@ mod tests { assert_eq!(of("Mean"), Some(("0.123457".to_string(), "0.1234567".to_string()))); } + #[test] + fn a_tab_or_line_break_in_a_text_value_keeps_one_copied_line_per_statistic() { + let text = json!({"kind": "text", "count": 2, "nulls": 0, "distinct": 2, "min": "a\tb", "max": "c\r\nd"}); + let lines = stats_lines(&text); + let copied = stats_tsv(&lines); + assert_eq!(copied.lines().count(), lines.len()); + assert!(copied.lines().all(|l| l.matches('\t').count() == 1), "{copied}"); + assert!(copied.contains("a b") && copied.contains("c d"), "{copied}"); + } + #[test] fn whole_numbers_past_2_53_and_a_capped_distinct_count_are_shown_as_they_are() { assert_eq!(fmt_whole(9_007_199_254_740_993), "9,007,199,254,740,993"); diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index c524b57db1..91945e5656 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -155,8 +155,8 @@ pub(crate) struct Tab { /// A row of tabs drawn as the ribbon's: the chosen one open onto the pane below with its accent /// bar, a base line and a hover fill; as the pane narrows, each tab drops its icon, then its name /// (the icon alone, its hover text — or its name — on hover). `current` becomes the chosen tab's -/// value; returns whether it changed. -pub(crate) fn tabs(ui: &mut Ui, t: &Tokens, id: egui::Id, current: &mut T, tabs: &[Tab]) -> bool { +/// value. +pub(crate) fn tabs(ui: &mut Ui, t: &Tokens, id: egui::Id, current: &mut T, tabs: &[Tab]) { let font = |on: bool| if on { semibold(12.5) } else { regular(12.5) }; let (pad, icon, gap, h) = (8.0, 16.0, 5.0, 30.0); // Measured in the chosen tab's font, so the tabs don't move as another is chosen. @@ -176,7 +176,6 @@ pub(crate) fn tabs(ui: &mut Ui, t: &Tokens, id: egui::Id, c let base = row.max.y - 0.5; ui.painter().hline(row.x_range(), base, Stroke::new(1.0, t.border)); let mut x = row.min.x; - let mut changed = false; for (tab, w) in tabs.iter().zip(text) { let shown = tl!(tab.label); let on = tab.value == *current; @@ -217,12 +216,10 @@ pub(crate) fn tabs(ui: &mut Ui, t: &Tokens, id: egui::Id, c resp = resp.on_hover_text(tl!(hover)); } } - if resp.clicked() && *current != tab.value { + if resp.clicked() { *current = tab.value; - changed = true; } } - changed } /// The shortcut of a command run without parameters (`⌘S` on a Mac, as egui reads the keys, From a408d686db20986373dfde93bf55d7d6d1eed728 Mon Sep 17 00:00:00 2001 From: giswqs Date: Sun, 22 Nov 2026 00:26:25 -0500 Subject: [PATCH 4/4] Address review feedback - GeoLibre card: "Or" shows only when a download link or Locate follows it (the browser has neither). - Pop-up pictures: the generic mif1/msf1 brands say HEIF, not HEIC. --- crates/ui-egui/src/panes.rs | 6 +++++- crates/ui-egui/src/popupmedia.rs | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index aa741da5eb..bb6fe7e405 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -3461,7 +3461,11 @@ fn geolibre_card(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } ui.add_space(2.0); ui.horizontal_wrapped(|ui| { - ui.label(egui::RichText::new(tl!("Or")).size(11.0).color(t.text_dim)); + // "Or" only when something follows it: the browser has no download link + // and no Locate…. + if download.is_some() || cfg!(not(target_arch = "wasm32")) { + ui.label(egui::RichText::new(tl!("Or")).size(11.0).color(t.text_dim)); + } if let Some(download) = &download { ui.add( egui::Hyperlink::from_label_and_url(tl!("Download the GeoLibre runner"), download).open_in_new_tab(true), diff --git a/crates/ui-egui/src/popupmedia.rs b/crates/ui-egui/src/popupmedia.rs index 531a8b41f8..39cf91b242 100644 --- a/crates/ui-egui/src/popupmedia.rs +++ b/crates/ui-egui/src/popupmedia.rs @@ -333,7 +333,7 @@ fn header(bytes: &[u8]) -> Result>, Fa const SHOWN: [image::ImageFormat; 4] = [image::ImageFormat::Png, image::ImageFormat::Jpeg, image::ImageFormat::WebP, image::ImageFormat::Gif]; -/// A HEIC or AVIF picture (common from phones), by the brand of its ISO-BMFF `ftyp` box, which +/// A HEIC, HEIF or AVIF picture (common from phones), by the brand of its ISO-BMFF `ftyp` box, which /// `image` doesn't recognise without those decoders: such a picture says its format rather than /// that it isn't a picture. fn heif_brand(bytes: &[u8]) -> Option<&'static str> { @@ -341,7 +341,9 @@ fn heif_brand(bytes: &[u8]) -> Option<&'static str> { return None; } match bytes.get(8..12)? { - b"heic" | b"heix" | b"mif1" | b"msf1" => Some("HEIC"), + b"heic" | b"heix" => Some("HEIC"), + // The generic HEIF brands, whose pictures need not be HEVC-coded. + b"mif1" | b"msf1" => Some("HEIF"), b"avif" | b"avis" => Some("AVIF"), _ => None, } @@ -584,7 +586,7 @@ mod tests { box_ }; assert_eq!(decode(&ftyp(b"heic")), Err(Failure::Unsupported("HEIC".into()))); - assert_eq!(decode(&ftyp(b"mif1")), Err(Failure::Unsupported("HEIC".into()))); + assert_eq!(decode(&ftyp(b"mif1")), Err(Failure::Unsupported("HEIF".into()))); assert_eq!(decode(&ftyp(b"avif")), Err(Failure::Unsupported("AVIF".into()))); assert_eq!(decode(&ftyp(b"isom")), Err(Failure::NotPicture)); // A GIF is shown (a 1 × 1 one).