aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukeflo2024-11-16 18:32:55 +0100
committerlukeflo2024-11-16 18:32:55 +0100
commit13bb655e3d63cf9e324ca055720d2fdb65e6b76e (patch)
tree07b29fb168d4633e25acdf2d93935bd3765b8d96
parent9c2fef5c1481d852b69ea342a38fec3eb6337524 (diff)
downloadbibiman-13bb655e3d63cf9e324ca055720d2fdb65e6b76e.tar.gz
bibiman-13bb655e3d63cf9e324ca055720d2fdb65e6b76e.zip
selection popup fundament
-rw-r--r--src/app.rs57
-rw-r--r--src/bibiman.rs12
-rw-r--r--src/tui/commands.rs21
-rw-r--r--src/tui/popup.rs10
-rw-r--r--src/tui/ui.rs37
5 files changed, 92 insertions, 45 deletions
diff --git a/src/app.rs b/src/app.rs
index 33baf2d..7141ead 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -15,32 +15,33 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
-use crate::bibiman::CurrentArea;
+use crate::bibiman::{CurrentArea, FormerArea};
// use super::Event;
use crate::cliargs::CLIArgs;
-use crate::tui::commands::{InputCmdAction, OpenRessource};
+use crate::tui::commands::InputCmdAction;
use crate::tui::popup::PopupKind;
use crate::tui::{self, Tui};
use crate::{bibiman::Bibiman, tui::commands::CmdAction};
use color_eyre::eyre::{Ok, Result};
+use color_eyre::owo_colors::colors::css::LemonChiffon;
use tui::Event;
use tui_input::backend::crossterm::EventHandler;
use tui_input::Input;
// Application.
#[derive(Debug)]
-pub struct App<'a> {
+pub struct App {
// Is the application running?
pub running: bool,
// bibimain
- pub bibiman: Bibiman<'a>,
+ pub bibiman: Bibiman,
// Input mode
pub input: Input,
// Input mode bool
pub input_mode: bool,
}
-impl App<'_> {
+impl App {
// Constructs a new instance of [`App`].
pub fn new(args: CLIArgs) -> Result<Self> {
// Self::default()
@@ -207,6 +208,8 @@ impl App<'_> {
if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
self.bibiman.popup_area.popup_scroll_pos = 0;
self.bibiman.close_popup()
+ } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind {
+ self.bibiman.close_popup()
}
} else {
self.bibiman.reset_current_list();
@@ -218,6 +221,9 @@ impl App<'_> {
} else if let CurrentArea::PopupArea = self.bibiman.current_area {
if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind {
self.bibiman.close_popup();
+ } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind {
+ // run command to open file/Url
+ self.bibiman.close_popup()
}
}
}
@@ -248,19 +254,40 @@ impl App<'_> {
self.bibiman.run_editor(tui)?;
}
}
- CmdAction::Open(ressource) => match ressource {
- OpenRessource::Pdf => {
- if let CurrentArea::EntryArea = self.bibiman.current_area {
- self.bibiman.open_connected_file()?;
+ CmdAction::Open => {
+ if let CurrentArea::EntryArea = self.bibiman.current_area {
+ let idx = self
+ .bibiman
+ .entry_table
+ .entry_table_state
+ .selected()
+ .unwrap();
+ let entry = self.bibiman.entry_table.entry_table_items[idx].clone();
+ let mut items = vec![];
+ if entry.doi_url.is_some() {
+ items.push(entry.doi_url.unwrap())
}
- }
- OpenRessource::WebLink => {
- if let CurrentArea::EntryArea = self.bibiman.current_area {
- self.bibiman.open_doi_url()?;
+ if entry.filepath.is_some() {
+ items.push(entry.filepath.unwrap())
}
+ self.bibiman.popup_area.popup_selection(items);
+ self.bibiman.former_area = Some(FormerArea::EntryArea);
+ self.bibiman.current_area = CurrentArea::PopupArea
}
- OpenRessource::Note => {}
- },
+ }
+ // 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/bibiman.rs b/src/bibiman.rs
index 0993b76..767dec1 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -54,7 +54,7 @@ pub enum FormerArea {
// Application.
#[derive(Debug)]
-pub struct Bibiman<'a> {
+pub struct Bibiman {
// main bib file
pub main_bibfile: PathBuf,
// main bibliography
@@ -72,10 +72,10 @@ pub struct Bibiman<'a> {
// mode for popup window
pub former_area: Option<FormerArea>,
// active popup
- pub popup_area: PopupArea<'a>,
+ pub popup_area: PopupArea,
}
-impl Bibiman<'_> {
+impl Bibiman {
// Constructs a new instance of [`App`].
pub fn new(args: CLIArgs) -> Result<Self> {
let main_bibfile = args.bibfilearg;
@@ -185,7 +185,7 @@ impl Bibiman<'_> {
}
}
-impl Bibiman<'_> {
+impl Bibiman {
// Entry Table commands
/// Select next entry in Table holding the bibliographic entries.
@@ -453,7 +453,7 @@ impl Bibiman<'_> {
}
}
-impl Bibiman<'_> {
+impl Bibiman {
// Tag List commands
// Movement
@@ -556,7 +556,7 @@ impl Bibiman<'_> {
}
}
-impl Bibiman<'_> {
+impl Bibiman {
// Search Area
// Enter the search area
diff --git a/src/tui/commands.rs b/src/tui/commands.rs
index a9566d0..a3049ee 100644
--- a/src/tui/commands.rs
+++ b/src/tui/commands.rs
@@ -20,13 +20,13 @@ use ratatui::crossterm::event::{
};
use tui_input::Input;
-// Possible ressources to open
-#[derive(Debug, PartialEq, Eq)]
-pub enum OpenRessource {
- Pdf,
- WebLink,
- Note,
-}
+// // Possible ressources to open
+// #[derive(Debug, PartialEq, Eq)]
+// pub enum OpenRessource {
+// Pdf,
+// WebLink,
+// Note,
+// }
/// Application command.
#[derive(Debug, PartialEq, Eq)]
@@ -62,7 +62,7 @@ pub enum CmdAction {
// Edit file
EditFile,
// Open linked ressource
- Open(OpenRessource),
+ Open,
// Input command.
Input(InputCmdAction),
// Hexdump command.
@@ -109,7 +109,8 @@ impl From<KeyEvent> for CmdAction {
if key_event.modifiers == KeyModifiers::CONTROL {
Self::SelectPrevRow(5)
} else {
- Self::Open(OpenRessource::WebLink)
+ Self::Nothing
+ // Self::Open(OpenRessource::WebLink)
}
}
// Scroll info/preview area
@@ -142,7 +143,7 @@ impl From<KeyEvent> for CmdAction {
// Reset lists/tables
KeyCode::Esc => Self::Reset,
// Open linked ressource
- KeyCode::Char('o') => Self::Open(OpenRessource::Pdf),
+ KeyCode::Char('o') => Self::Open,
// KeyCode::Char('u') => Self::Open(OpenRessource::WebLink),
// Edit currently selected entry
KeyCode::Char('e') => Self::EditFile,
diff --git a/src/tui/popup.rs b/src/tui/popup.rs
index e15ed13..94df9b9 100644
--- a/src/tui/popup.rs
+++ b/src/tui/popup.rs
@@ -31,16 +31,16 @@ pub enum PopupKind {
}
#[derive(Debug, Default)]
-pub struct PopupArea<'a> {
+pub struct PopupArea {
pub is_popup: bool,
pub popup_kind: Option<PopupKind>,
pub popup_message: String,
pub popup_scroll_pos: u16,
- pub popup_list: Vec<&'a str>,
+ pub popup_list: Vec<String>,
pub popup_state: ListState,
}
-impl PopupArea<'_> {
+impl PopupArea {
pub fn popup_help<'a>() -> Text<'a> {
let help = [
("General", "first"),
@@ -110,10 +110,10 @@ impl PopupArea<'_> {
self.is_popup = true;
}
- pub fn popup_selection(&mut self, items: Vec<&'static str>) {
+ pub fn popup_selection(&mut self, items: Vec<String>) {
self.popup_list = items;
self.popup_kind = Some(PopupKind::Selection);
- self.is_popup = true
+ self.is_popup = true;
}
pub fn popup_scroll_down(&mut self) {
diff --git a/src/tui/ui.rs b/src/tui/ui.rs
index 6971fcb..daeba7f 100644
--- a/src/tui/ui.rs
+++ b/src/tui/ui.rs
@@ -163,7 +163,8 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) {
match app.bibiman.popup_area.popup_kind {
Some(PopupKind::Help) => {
let block = Block::bordered()
- .title_top(" Keybindings (j,k|↓,↑)".bold())
+ .title_top(" Keybindings ".bold())
+ .title_bottom(" (j,k|↓,↑) ".bold())
.title_alignment(Alignment::Center)
.style(POPUP_HELP_BOX)
.border_set(symbols::border::THICK)
@@ -218,16 +219,34 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) {
frame.render_widget(&content, popup_area)
}
Some(PopupKind::Selection) => {
- // let list_items: Vec<ListItem> = app
- // .bibiman
- // .popup_area
- // .popup_list
- // .iter()
- // .map(|item| ListItem::from(item.to_owned()))
- // .collect();
+ let list_items: Vec<ListItem> = app
+ .bibiman
+ .popup_area
+ .popup_list
+ .iter()
+ .map(|item| ListItem::from(item.to_owned()))
+ .collect();
+
+ let block = Block::bordered()
+ .title_top(" Open ".bold())
+ .title_bottom(" (j,k|↓,↑) ".bold())
+ .title_alignment(Alignment::Center)
+ .style(POPUP_HELP_BOX)
+ .border_set(symbols::border::THICK)
+ .border_style(Style::new().fg(MAIN_PURPLE));
+
+ let list = List::new(list_items)
+ .block(block)
+ .highlight_style(SELECTION_SELECTED_ROW_STYLE);
- // let list = List::new(list_items).highlight_style(SELECTION_SELECTED_ROW_STYLE);
+ app.bibiman.popup_area.popup_state.select(Some(0));
+ let popup_width = frame.area().width / 2;
+ let popup_heigth = list.len() + 2;
+ let popup_area = popup_area(frame.area(), popup_width, popup_heigth as u16);
+
+ frame.render_widget(Clear, popup_area);
+ frame.render_stateful_widget(list, popup_area, &mut app.bibiman.popup_area.popup_state)
// let sized_list = SizedWrapper {
// inner: list.clone(),
// width: (frame.area().width / 2) as usize,