From 2594cf34dcf2f04f398dab7b6ecae364eb4c7d17 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 4 Jul 2025 13:56:55 +0200 Subject: impl `PopupItem` enum, adapt ui: include colors --- src/tui/popup.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/tui/popup.rs') diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 93b01c3..da44744 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -40,13 +40,23 @@ pub enum PopupKind { YankItem, } +#[derive(Debug)] +pub enum PopupItem { + Bibfile, + Entryfile, + Notefile, + Link, + Default, + None, +} + #[derive(Debug, Default)] pub struct PopupArea { pub is_popup: bool, pub popup_kind: Option, pub popup_message: String, pub popup_scroll_pos: u16, - pub popup_list: Vec<(String, String)>, + pub popup_list: Vec<(String, String, PopupItem)>, pub popup_state: ListState, pub popup_sel_item: String, // pub add_entry_input: String, @@ -116,8 +126,8 @@ impl PopupArea { /// Opens a popup with a selectable list /// - /// The list items are passed as argument of the kind `Vec<(String, String)>`. - pub fn popup_selection(&mut self, items: Vec<(String, String)>) { + /// The list items are passed as argument of the kind `Vec<(String, String, PopupItem)>`. + pub fn popup_selection(&mut self, items: Vec<(String, String, PopupItem)>) { self.popup_list = items; // self.popup_kind = Some(PopupKind::SelectRes); self.is_popup = true; -- cgit v1.2.3 From 5ebecf2ea9d0fb9c57b264d7cd1c6e92b36d30e8 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 4 Jul 2025 14:41:47 +0200 Subject: `PopupItem::Citekey` impl --- src/app.rs | 8 ++++---- src/config.rs | 4 ++++ src/tui/popup.rs | 1 + src/tui/ui.rs | 28 ++++++++++++++++------------ 4 files changed, 25 insertions(+), 16 deletions(-) (limited to 'src/tui/popup.rs') diff --git a/src/app.rs b/src/app.rs index d645dbe..d475328 100644 --- a/src/app.rs +++ b/src/app.rs @@ -314,7 +314,7 @@ impl App { let mut items = vec![( "Citekey: ".to_string(), entry.citekey.clone(), - PopupItem::Default, + PopupItem::Citekey, )]; if entry.doi_url.is_some() { items.push(( @@ -365,7 +365,7 @@ impl App { { if entry.doi_url.is_some() { items.push(( - "Weblink (DOI/URL): ".into(), + format!("{} ", cfg.general.link_symbol.clone().trim()), entry.doi_url.unwrap().clone(), PopupItem::Link, )) @@ -373,7 +373,7 @@ impl App { if entry.filepath.is_some() { entry.filepath.unwrap().iter().for_each(|p| { items.push(( - "File (PDF/EPUB): ".into(), + format!("{} ", cfg.general.file_symbol.clone().trim()), // p.clone().into_string().unwrap(), if entry.file_field && cfg.general.file_prefix.is_some() { cfg.general @@ -394,7 +394,7 @@ impl App { if entry.notes.is_some() { entry.notes.unwrap().iter().for_each(|n| { items.push(( - "Note: ".into(), + format!("{} ", cfg.general.note_symbol.clone().trim()), n.clone().into_string().unwrap(), PopupItem::Notefile, )); diff --git a/src/config.rs b/src/config.rs index 278f4b1..1f6c619 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,6 +81,7 @@ const DEFAULT_CONFIG: &str = r##" # confirm_color = "47" # warn_color = "124" # bar_bg_color = "234" +# popup_fg_color = "43" # popup_bg_color = "234" # selected_row_bg_color = "237" # note_color = "123" @@ -125,6 +126,7 @@ pub struct Colors { pub confirm_color: Color, pub warn_color: Color, pub bar_bg_color: Color, + pub popup_fg_color: Color, pub popup_bg_color: Color, pub selected_row_bg_color: Color, pub note_color: Color, @@ -211,6 +213,7 @@ impl BibiConfig { confirm_color: Color::Indexed(47), warn_color: Color::Indexed(124), bar_bg_color: Color::Indexed(235), + popup_fg_color: Color::Indexed(43), popup_bg_color: Color::Indexed(234), selected_row_bg_color: Color::Indexed(237), note_color: Color::Indexed(123), @@ -231,6 +234,7 @@ impl BibiConfig { keyword_color: Color::Indexed(58), info_color: Color::Indexed(57), bar_bg_color: Color::Indexed(144), + popup_fg_color: Color::Indexed(43), popup_bg_color: Color::Indexed(187), confirm_color: Color::Indexed(22), warn_color: Color::Indexed(124), diff --git a/src/tui/popup.rs b/src/tui/popup.rs index da44744..4aaa2c1 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -45,6 +45,7 @@ pub enum PopupItem { Bibfile, Entryfile, Notefile, + Citekey, Link, Default, None, diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 2c30154..0a34e51 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -281,18 +281,22 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .iter() .map( |(mes, obj, i)| { - let style = match i { - PopupItem::Bibfile => Style::new().fg(cfg.colors.entry_color), - PopupItem::Entryfile => Style::new().fg(cfg.colors.file_color), - PopupItem::Notefile => Style::new().fg(cfg.colors.note_color), - PopupItem::Link => Style::new().fg(cfg.colors.link_color), - PopupItem::Default => Style::new(), - PopupItem::None => Style::new(), + let style: Color = match i { + PopupItem::Bibfile => cfg.colors.entry_color, + PopupItem::Citekey => cfg.colors.entry_color, + PopupItem::Entryfile => cfg.colors.file_color, + PopupItem::Notefile => cfg.colors.note_color, + PopupItem::Link => cfg.colors.link_color, + PopupItem::Default => cfg.colors.main_text_color, + PopupItem::None => cfg.colors.main_text_color, }; - ListItem::from(Line::from(vec![ - Span::styled(mes, style.bold()), - Span::raw(obj), - ])) + ListItem::from( + Line::from(vec![ + Span::styled(mes, Style::new().bold()), + Span::raw(obj), + ]) + .fg(style), + ) }, // ListItem::from(mes.to_owned() + obj) ) .collect(); @@ -325,7 +329,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { .bg(cfg.colors.popup_bg_color), ) .border_set(symbols::border::THICK) - .border_style(Style::new().fg(cfg.colors.keyword_color)); + .border_style(Style::new().fg(cfg.colors.popup_fg_color)); let list = List::new(list_items).block(block).highlight_style( Style::new() -- cgit v1.2.3 From 80c04702012cb1a43711d559e8ffbe9e250b1a57 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sat, 5 Jul 2025 20:21:52 +0200 Subject: first steps for create new note --- src/app.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/bibiman.rs | 4 ++++ src/tui/commands.rs | 2 ++ src/tui/popup.rs | 2 ++ 4 files changed, 67 insertions(+), 3 deletions(-) (limited to 'src/tui/popup.rs') diff --git a/src/app.rs b/src/app.rs index d475328..14cc864 100644 --- a/src/app.rs +++ b/src/app.rs @@ -365,7 +365,7 @@ impl App { { if entry.doi_url.is_some() { items.push(( - format!("{} ", cfg.general.link_symbol.clone().trim()), + "Link: ".into(), entry.doi_url.unwrap().clone(), PopupItem::Link, )) @@ -373,7 +373,7 @@ impl App { if entry.filepath.is_some() { entry.filepath.unwrap().iter().for_each(|p| { items.push(( - format!("{} ", cfg.general.file_symbol.clone().trim()), + "File: ".into(), // p.clone().into_string().unwrap(), if entry.file_field && cfg.general.file_prefix.is_some() { cfg.general @@ -394,7 +394,7 @@ impl App { if entry.notes.is_some() { entry.notes.unwrap().iter().for_each(|n| { items.push(( - format!("{} ", cfg.general.note_symbol.clone().trim()), + "Note: ".into(), n.clone().into_string().unwrap(), PopupItem::Notefile, )); @@ -419,6 +419,62 @@ impl App { self.bibiman.add_entry(); } } + CmdAction::CreateNote => { + if let CurrentArea::EntryArea = self.bibiman.current_area { + if cfg.general.note_path.is_some() + && cfg.general.note_extensions.is_some() + && self.bibiman.entry_table.entry_table_items[self + .bibiman + .entry_table + .entry_table_state + .selected() + .unwrap()] + .notes + .is_none() + { + let mut items = vec![]; + for ex in cfg.general.note_extensions.as_ref().unwrap() { + items.push(( + self.bibiman.entry_table.entry_table_items[self + .bibiman + .entry_table + .entry_table_state + .selected() + .unwrap()] + .citekey() + .to_string(), + ex.clone(), + PopupItem::Notefile, + )); + } + self.bibiman + .open_popup(PopupKind::CreateNote, None, None, Some(items)); + } else if cfg.general.note_path.is_some() + && self.bibiman.entry_table.entry_table_items[self + .bibiman + .entry_table + .entry_table_state + .selected() + .unwrap()] + .notes + .is_some() + { + self.bibiman.open_popup( + PopupKind::MessageError, + Some("Selected entry already has a connected note"), + None, + None, + )?; + } else { + self.bibiman.open_popup( + PopupKind::MessageError, + Some("No note path found. Set it in config file."), + None, + None, + )?; + } + } + } CmdAction::ShowHelp => { self.bibiman.open_popup(PopupKind::Help, None, None, None)?; } diff --git a/src/bibiman.rs b/src/bibiman.rs index 6aec1fb..c92b869 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -740,6 +740,10 @@ impl Bibiman { Ok(()) } + pub fn create_note(&mut self, cfg: &BibiConfig) -> Result<()> { + Ok(()) + } + pub fn open_connected_res(&mut self, cfg: &BibiConfig, tui: &mut Tui) -> Result<()> { // Index of selected entry let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); diff --git a/src/tui/commands.rs b/src/tui/commands.rs index 08ee677..47d2802 100644 --- a/src/tui/commands.rs +++ b/src/tui/commands.rs @@ -73,6 +73,8 @@ pub enum CmdAction { ShowHelp, // Add new entry AddEntry, + // Create note + CreateNote, // Do nothing. Nothing, } diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 4aaa2c1..46e4792 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -38,6 +38,8 @@ pub enum PopupKind { AddEntry, /// select an item of the current entry to yank to clipboard YankItem, + /// Create a new note, select extension + CreateNote, } #[derive(Debug)] -- cgit v1.2.3