Criteria, Item, Itemlike, SpvMembers,
pivot::{Axis3, Dimension, Group, Leaf, PivotTable, value::Value},
},
- spv::{SpvArchive, legacy_bin::LegacyBin},
+ spv::{
+ SpvArchive,
+ legacy_bin::LegacyBin,
+ read::{ReadSeek, structure::OutlineItem},
+ },
};
use std::{
collections::HashMap,
))
}
+ fn read_outline(&self) -> Result<(SpvArchive<Box<dyn ReadSeek>>, Vec<Arc<OutlineItem>>)> {
+ let mut archive = SpvArchive::open_file(&self.input, self.password.as_deref())?;
+ let outline = archive.read_outline(|w| eprintln!("{w}"))?;
+ Ok((archive, self.criteria.apply(outline.items)))
+ }
+
fn directory(self) -> Result<()> {
- for child in self.read()? {
- print_item_directory(&child, 0, self.show_member_names);
+ for child in self.read_outline()?.1 {
+ print_item_directory(&*child, 0, self.show_member_names);
}
Ok(())
}
}
fn legacy_data(self) -> Result<()> {
- let mut archive = SpvArchive::open_file(&self.input, self.password.as_deref())?;
- let outline = archive.read_outline(|w| eprintln!("{w}"))?;
- let items = self.criteria.apply(outline.items);
+ let (mut archive, items) = self.read_outline()?;
for item in items {
for item in item.iter_in_order() {
if let Some(spv_info) = item.spv_info()
}
}
-fn print_item_directory(item: &Item, level: usize, show_member_names: bool) {
+fn print_item_directory<T>(item: &T, level: usize, show_member_names: bool)
+where
+ T: Itemlike,
+{
for _ in 0..level {
print!(" ");
}
- print!("- {} {:?}", item.details.kind(), item.label());
+ print!("- {} {:?}", item.kind(), item.label());
+ /*
if let Some(table) = item.details.as_table() {
let title = table.title().display(table).to_string();
if item.label.as_ref().is_none_or(|label| label != &title) {
print!(" title {title:?}");
}
- }
- if let Some(command_name) = &item.command_name {
+ }*/
+ if let Some(command_name) = item.command_name() {
print!(" command {command_name:?}");
}
if let Some(subtype) = item.subtype()
- && item.label.as_ref().is_none_or(|label| label != &subtype)
+ && let label = item.label().as_ref()
+ && label != &subtype
{
print!(" subtype {subtype:?}");
}
- if !item.show {
- if item.details.is_heading() {
- print!(" (collapsed)");
- } else {
- print!(" (hidden)");
- }
+ if item.is_expanded() == Some(false) {
+ print!(" (collapsed");
+ }
+ if item.is_shown() == Some(false) {
+ print!(" (hidden)");
}
- if show_member_names && let Some(spv_info) = &item.spv_info {
+ if show_member_names && let Some(spv_info) = item.spv_info() {
for (index, name) in spv_info.member_names().into_iter().enumerate() {
print!(" {} {name:?}", if index == 0 { "in" } else { "and" });
}
}
println!();
- for child in item.details.children() {
- print_item_directory(&child, level + 1, show_member_names);
+ for child in item.children() {
+ print_item_directory(&**child, level + 1, show_member_names);
}
}
fn label(&self) -> Cow<'_, str>;
fn command_name(&self) -> Option<&str>;
fn subtype(&self) -> Option<String>;
- fn is_shown(&self) -> bool;
+ fn is_shown(&self) -> Option<bool>;
fn page_break_before(&self) -> bool;
fn spv_info(&self) -> Option<Cow<'_, SpvInfo>>;
fn iter_in_order(&self) -> ItemRefIterator<'_, Self>
fn is_heading(&self) -> bool {
self.kind() == ItemKind::Heading
}
+ fn is_expanded(&self) -> Option<bool>;
fn is_table(&self) -> bool {
self.kind() == ItemKind::Table
}
/// Should the item be shown?
///
- /// This always returns true for headings because their contents are always
- /// shown (although headings can be collapsed in an outline view).
- fn is_shown(&self) -> bool {
- self.details.is_heading() || self.show
+ /// This returns None for headings because their contents are always shown
+ /// (although headings can be collapsed in an outline view).
+ fn is_shown(&self) -> Option<bool> {
+ if !self.details.is_heading() {
+ Some(self.show)
+ } else {
+ None
+ }
+ }
+
+ fn is_expanded(&self) -> Option<bool> {
+ if self.details.is_heading() {
+ Some(self.show)
+ } else {
+ None
+ }
}
fn page_break_before(&self) -> bool {
where
T: Itemlike,
{
- self.filter(|item| item.is_shown())
+ self.filter(|item| item.is_shown().unwrap_or(true))
}
pub fn new(start: &'a T) -> Self {
{
pub fn new(start: Arc<T>) -> Self {
Self {
- cur: start.as_ref().is_shown().then_some(start),
+ cur: start.as_ref().is_shown().unwrap_or(true).then_some(start),
stack: Vec::new(),
include_hidden: false,
}
inner(self);
while let Some(cur) = &self.cur
- && !cur.as_ref().is_shown()
+ && !cur.as_ref().is_shown().unwrap_or(true)
{
inner(self);
}
continue;
}
if let Some(visible) = selection.visible
- && !item.is_heading()
- && visible != item.is_shown()
+ && let Some(shown) = item.is_shown()
+ && visible != shown
{
continue;
}