use crate::oxml::writer::XmlWriter;
pub const SECTION_EXT_URI: &str = "{521415D9-36F7-43E2-AB2F-B90AF26B5E64}";
#[derive(Clone, Debug, Default)]
pub struct Section {
pub name: String,
pub slide_ids: Vec<u32>,
}
impl Section {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
slide_ids: Vec::new(),
}
}
pub fn push(&mut self, id: u32) {
self.slide_ids.push(id);
}
pub fn write_xml(&self, w: &mut XmlWriter) {
let attrs: Vec<(&str, &str)> = vec![("name", self.name.as_str())];
w.open_with("p14:section", &attrs);
if !self.slide_ids.is_empty() {
w.open("p14:sldIdLst");
for id in &self.slide_ids {
let id_s = id.to_string();
w.empty_with("p14:sldId", &[("id", id_s.as_str())]);
}
w.close("p14:sldIdLst");
}
w.close("p14:section");
}
}
#[derive(Clone, Debug, Default)]
pub struct SectionList {
pub items: Vec<Section>,
}
impl SectionList {
pub fn new() -> Self {
Self::default()
}
pub fn len(&self) -> usize {
self.items.len()
}
pub fn is_empty(&self) -> bool {
self.items.is_empty()
}
pub fn push(&mut self, section: Section) {
self.items.push(section);
}
pub fn section_name_of(&self, slide_id: u32) -> Option<&str> {
for s in &self.items {
if s.slide_ids.contains(&slide_id) {
return Some(s.name.as_str());
}
}
None
}
pub fn write_xml(&self) -> String {
if self.is_empty() {
return String::new();
}
let mut w = XmlWriter::new();
w.open("p:extLst");
let ext_attrs: Vec<(&str, &str)> = vec![("uri", SECTION_EXT_URI)];
w.open_with("p:ext", &ext_attrs);
w.open("p14:sectionLst");
for s in &self.items {
s.write_xml(&mut w);
}
w.close("p14:sectionLst");
w.close("p:ext");
w.close("p:extLst");
w.into_string()
}
}