aboutsummaryrefslogtreecommitdiff
path: root/src/bibiman.rs
diff options
context:
space:
mode:
authorlukeflo2025-07-05 22:29:18 +0200
committerlukeflo2025-07-05 22:29:18 +0200
commit2990df627ff54f01bafdcab767c0a73198e9e6cc (patch)
tree8bdb05d9d4502bff9c3240958b8915df6026acda /src/bibiman.rs
parent80c04702012cb1a43711d559e8ffbe9e250b1a57 (diff)
downloadbibiman-2990df627ff54f01bafdcab767c0a73198e9e6cc.tar.gz
bibiman-2990df627ff54f01bafdcab767c0a73198e9e6cc.zip
create note function impl
Diffstat (limited to 'src/bibiman.rs')
-rw-r--r--src/bibiman.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs
index c92b869..71ac831 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -238,6 +238,18 @@ impl Bibiman {
))
}
}
+ PopupKind::CreateNote => {
+ if items.is_some() {
+ self.popup_area.popup_kind = Some(PopupKind::CreateNote);
+ self.popup_area.popup_selection(items.unwrap());
+ self.popup_area.popup_state.select(Some(0));
+ Ok(())
+ } else {
+ Err(Error::msg(
+ "No Vec<(String, String)> passed as argument to generate the items list",
+ ))
+ }
+ }
}
}
@@ -741,6 +753,27 @@ impl Bibiman {
}
pub fn create_note(&mut self, cfg: &BibiConfig) -> Result<()> {
+ // Index of selected entry
+ let entry_idx = self.entry_table.entry_table_state.selected().unwrap();
+ let citekey = self.entry_table.entry_table_items[entry_idx].citekey();
+
+ // Index of selected popup field
+ let popup_idx = self.popup_area.popup_state.selected().unwrap();
+ let ext = self.popup_area.popup_list[popup_idx].1.clone();
+
+ let basename = PathBuf::from(citekey).with_extension(ext);
+ let path = cfg.general.note_path.as_ref().unwrap();
+
+ let new_file = path.join(basename);
+
+ let new_file = if new_file.starts_with("~") {
+ expand_home(&new_file)
+ } else {
+ new_file
+ };
+
+ File::create_new(new_file).unwrap();
+ self.close_popup();
Ok(())
}