diff options
| author | lukeflo | 2024-11-17 22:21:18 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-17 22:21:18 +0100 |
| commit | 558712ac6741c28777f69b93ccb6b4a5e0d4ff22 (patch) | |
| tree | f785b2952f14855f4cdad34869ca61863bdc6202 | |
| parent | 585e45708e2a69c7531e94723d681de7f20ea7d1 (diff) | |
| download | bibiman-558712ac6741c28777f69b93ccb6b4a5e0d4ff22.tar.gz bibiman-558712ac6741c28777f69b93ccb6b4a5e0d4ff22.zip | |
implement warning message popup
| -rw-r--r-- | src/app.rs | 29 | ||||
| -rw-r--r-- | src/tui/popup.rs | 11 | ||||
| -rw-r--r-- | src/tui/ui.rs | 25 |
3 files changed, 44 insertions, 21 deletions
@@ -70,12 +70,13 @@ impl App { // Event::Key(key_event) => handle_key_events(key_event, self, &mut tui)?, // Event::Mouse(_) => {} Event::Key(key_event) => { - if let Some(PopupKind::Message) = self.bibiman.popup_area.popup_kind { + // Automatically close message popups on next keypress + if let Some(PopupKind::MessageConfirm) = self.bibiman.popup_area.popup_kind { + self.bibiman.close_popup() + } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind + { self.bibiman.close_popup() } - // else if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { - // self.bibiman.go_back() - // } let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) } else { @@ -270,6 +271,7 @@ impl App { self.bibiman.popup_area.popup_message( "Yanked citekey to clipboard: ", citekey, // self.bibiman.get_selected_citekey(), + true, ); } } @@ -299,22 +301,15 @@ impl App { self.bibiman.former_area = Some(FormerArea::EntryArea); self.bibiman.current_area = CurrentArea::PopupArea; self.bibiman.popup_area.popup_state.select(Some(0)) + } else { + self.bibiman.popup_area.popup_message( + "Selected entry has no connected ressources: ", + &entry.citekey, + false, + ) } } } - // match ressource { - // OpenRessource::Pdf => { - // if let CurrentArea::EntryArea = self.bibiman.current_area { - // self.bibiman.open_connected_file()?; - // } - // } - // OpenRessource::WebLink => { - // if let CurrentArea::EntryArea = self.bibiman.current_area { - // self.bibiman.open_doi_url()?; - // } - // } - // OpenRessource::Note => {} - // }, CmdAction::ShowHelp => { self.bibiman.show_help(); } diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 94df9b9..4cde704 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -26,7 +26,8 @@ use crate::{MAIN_BLUE_COLOR_INDEX, MAIN_PURPLE_COLOR_INDEX}; #[derive(Debug)] pub enum PopupKind { Help, - Message, + MessageConfirm, + MessageError, Selection, } @@ -100,13 +101,17 @@ impl PopupArea { Text::from(helptext) } - pub fn popup_message(&mut self, message: &str, object: &str) { + pub fn popup_message(&mut self, message: &str, object: &str, msg_confirm: bool) { if object.is_empty() { self.popup_message = message.to_owned(); } else { self.popup_message = message.to_owned() + object; //format!("{} \"{}\"", message, object); } - self.popup_kind = Some(PopupKind::Message); + if msg_confirm { + self.popup_kind = Some(PopupKind::MessageConfirm); + } else { + self.popup_kind = Some(PopupKind::MessageError) + } self.is_popup = true; } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 0534761..af94be4 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -195,7 +195,7 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(par, popup_area) } - Some(PopupKind::Message) => { + Some(PopupKind::MessageConfirm) => { let area = frame.area(); let block = Block::bordered() @@ -218,6 +218,29 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { frame.render_widget(Clear, popup_area); frame.render_widget(&content, popup_area) } + Some(PopupKind::MessageError) => { + let area = frame.area(); + + let block = Block::bordered() + .title_top(" Warning ".bold().fg(Color::Red)) + .border_style(Style::new().fg(Color::Red)) + .style(POPUP_HELP_BOX); + + let content = Paragraph::new(app.bibiman.popup_area.popup_message.clone()) + .block(block) + .style(Style::new().fg(Color::Red)); + + // Calculate popup size. Width is number of string chars plus 2 for border + let popup_area = popup_area( + area, + (app.bibiman.popup_area.popup_message.chars().count() + 2) as u16, + 3, + ); + + // Clear area and draw popup + frame.render_widget(Clear, popup_area); + frame.render_widget(&content, popup_area) + } Some(PopupKind::Selection) => { let list_items: Vec<ListItem> = app .bibiman |
