From 1317e5a6e21d995f8c06c50b5f61dfeb2c9c47a8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 16 May 2021 00:09:02 +0100 Subject: [PATCH] otter: Show bundle in library information Signed-off-by: Ian Jackson --- src/bundles.rs | 3 +++ src/shapelib.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/bundles.rs b/src/bundles.rs index ce970a5e..e2f27f4b 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -574,6 +574,7 @@ fn parse_bundle(id: Id, instance: &InstanceName, file: File, eh: EH, catalogue_data: String, svg_dir: &'l String, need_svgs: Vec, + id: &'l Id, } impl shapelib::LibrarySource for LibraryInBundle<'_> { @@ -582,6 +583,7 @@ fn parse_bundle(id: Id, instance: &InstanceName, file: File, eh: EH, fn note_svg(&mut self, basename: &GoodItemName) { self.need_svgs.push(basename.clone()) } + fn bundle(&self) -> Option { Some(*self.id) } } for (progress_count, LibScanned { libname, dir_inzip, inzip }) @@ -600,6 +602,7 @@ fn parse_bundle(id: Id, instance: &InstanceName, file: File, eh: EH, catalogue_data: catalogue_data, svg_dir: &svg_dir, need_svgs: Vec::new(), + id: &id, }; let contents = shapelib::load_catalogue(&libname, &mut src) .map_err(|e| LE::badlib(&libname, &e))?; diff --git a/src/shapelib.rs b/src/shapelib.rs index 48de1858..1322ea55 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -38,6 +38,7 @@ pub trait OutlineDefn: Debug + Sync + Send + 'static { pub struct Contents { libname: String, dirname: String, + bundle: Option, items: HashMap, ItemData>, } @@ -247,11 +248,15 @@ impl Display for ItemEnquiryData { #[derive(Debug,Clone,Serialize,Deserialize,Eq,PartialEq,Ord,PartialOrd)] pub struct LibraryEnquiryData { + pub bundle: Option, pub libname: String, } impl Display for LibraryEnquiryData { #[throws(fmt::Error)] fn fmt(&self, f: &mut Formatter) { + if let Some(id) = self.bundle.as_ref() { + write!(f, "[{}] ", id)?; + } if self.libname.chars().all(|c| { c.is_alphanumeric() || c=='-' || c=='_' || c=='.' }) { @@ -589,6 +594,7 @@ impl Contents { pub fn enquiry(&self) -> LibraryEnquiryData { LibraryEnquiryData { libname: self.libname.clone(), + bundle: self.bundle, } } @@ -686,6 +692,7 @@ pub trait LibrarySource { fn catalogue_data(&self) -> &str; fn svg_dir(&self) -> String; fn note_svg(&mut self, _basename: &GoodItemName) { } + fn bundle(&self) -> Option; } struct BuiltinLibrary<'l> { @@ -696,12 +703,14 @@ struct BuiltinLibrary<'l> { impl LibrarySource for BuiltinLibrary<'_> { fn catalogue_data(&self) -> &str { self.catalogue_data } fn svg_dir(&self) -> String { self.dirname.to_string() } + fn bundle(&self) -> Option { None } } #[throws(LibraryLoadError)] pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource) -> Contents { let toplevel: toml::Value = src.catalogue_data().parse()?; let mut l = Contents { + bundle: src.bundle(), libname: libname.to_string(), items: HashMap::new(), dirname: src.svg_dir(), -- 2.30.2