diff options
| author | lukeflo | 2025-05-26 17:11:55 +0200 |
|---|---|---|
| committer | lukeflo | 2025-05-26 17:11:55 +0200 |
| commit | 5ab55a263a5ae9cc5cbadf52f6000621e2552f85 (patch) | |
| tree | fa0ed3addcafbf3a1d9479c71d4a3e5cb8a312c9 /src/app.rs | |
| parent | c0dcbcd18a3fba111885fd0eaf8ef18f71cf693a (diff) | |
| download | bibiman-5ab55a263a5ae9cc5cbadf52f6000621e2552f85.tar.gz bibiman-5ab55a263a5ae9cc5cbadf52f6000621e2552f85.zip | |
first steps in rewriting popups
Diffstat (limited to 'src/app.rs')
| -rw-r--r-- | src/app.rs | 73 |
1 files changed, 51 insertions, 22 deletions
@@ -300,18 +300,24 @@ impl App { .selected() .unwrap(); let entry = self.bibiman.entry_table.entry_table_items[idx].clone(); - let mut items = vec!["Citekey".to_owned()]; + let mut items = vec![("Citekey: ".to_string(), entry.citekey.clone())]; if entry.doi_url.is_some() { - items.push("Weblink".to_owned()) + items.push(("Weblink: ".into(), entry.doi_url.unwrap().clone())) } if entry.filepath.is_some() { - items.push("Filepath".to_owned()) + items.push(( + "Filepath: ".into(), + entry.filepath.unwrap()[0].clone().into_string().unwrap(), + )) } - self.bibiman.popup_area.popup_kind = Some(PopupKind::YankItem); - self.bibiman.popup_area.popup_selection(items); - self.bibiman.former_area = Some(FormerArea::EntryArea); - self.bibiman.current_area = CurrentArea::PopupArea; - self.bibiman.popup_area.popup_state.select(Some(0)); + + // self.bibiman.popup_area.popup_kind = Some(PopupKind::YankItem); + // self.bibiman.popup_area.popup_selection(items); + // self.bibiman.former_area = Some(FormerArea::EntryArea); + // self.bibiman.current_area = CurrentArea::PopupArea; + // self.bibiman.popup_area.popup_state.select(Some(0)); + self.bibiman + .open_popup(PopupKind::YankItem, None, None, Some(items)); } } CmdAction::EditFile => { @@ -328,25 +334,40 @@ impl App { .selected() .unwrap(); let entry = self.bibiman.entry_table.entry_table_items[idx].clone(); + let mut items: Vec<(String, String)> = vec![]; if entry.filepath.is_some() || entry.doi_url.is_some() { - let mut items = vec![]; if entry.doi_url.is_some() { - items.push("Weblink (DOI/URL)".to_owned()) + items.push(( + "Weblink (DOI/URL): ".into(), + entry.doi_url.unwrap().clone(), + )) } if entry.filepath.is_some() { - items.push("File (PDF/EPUB)".to_owned()) + items.push(( + "File (PDF/EPUB): ".into(), + entry.filepath.unwrap()[0].clone().into_string().unwrap(), + )) } - self.bibiman.popup_area.popup_kind = Some(PopupKind::OpenRes); - self.bibiman.popup_area.popup_selection(items); - self.bibiman.former_area = Some(FormerArea::EntryArea); - self.bibiman.current_area = CurrentArea::PopupArea; - self.bibiman.popup_area.popup_state.select(Some(0)) + // self.bibiman.popup_area.popup_kind = Some(PopupKind::OpenRes); + // self.bibiman.popup_area.popup_selection(items); + // self.bibiman.former_area = Some(FormerArea::EntryArea); + // self.bibiman.current_area = CurrentArea::PopupArea; + // self.bibiman.popup_area.popup_state.select(Some(0)) + + self.bibiman + .open_popup(PopupKind::OpenRes, None, None, Some(items)); } else { - self.bibiman.popup_area.popup_message( - "Selected entry has no connected ressources: ", - &entry.citekey, - false, - ) + self.bibiman.open_popup( + PopupKind::MessageError, + Some("Selected entry has no connected ressources: "), + Some(&entry.citekey), + None, + ); + // self.bibiman.popup_area.popup_message( + // "Selected entry has no connected ressources: ", + // &entry.citekey, + // false, + // ) } } } @@ -357,7 +378,7 @@ impl App { } } CmdAction::ShowHelp => { - self.bibiman.show_help(); + self.bibiman.open_popup(PopupKind::Help, None, None, None); } CmdAction::Exit => { self.quit(); @@ -430,6 +451,14 @@ pub fn expand_home(path: &PathBuf) -> PathBuf { } } +/// Convert `Vec<(&str, &str)` to `Vec<(String, String)` +pub fn convert_to_owned_vec(mut items: Vec<(&str, &str)>) -> Vec<(String, String)> { + items + .iter_mut() + .map(|(msg, obj)| (msg.to_string(), obj.to_string())) + .collect() +} + #[cfg(test)] mod test { use super::*; |
