diff options
| author | lukeflo | 2024-10-01 22:07:22 +0200 |
|---|---|---|
| committer | lukeflo | 2024-10-01 22:07:22 +0200 |
| commit | c78ae222ea75d36f4aef6e274d2c986e37462276 (patch) | |
| tree | 06ddb27b79db1d497bb63da5c0681a76e601e135 /src | |
| parent | 4ce74dc8ab23e2b72c3f5d3310ec088fa2610ad9 (diff) | |
| download | bibiman-c78ae222ea75d36f4aef6e274d2c986e37462276.tar.gz bibiman-c78ae222ea75d36f4aef6e274d2c986e37462276.zip | |
finish single functions, remove old code
Diffstat (limited to 'src')
| -rw-r--r-- | src/frontend/app.rs | 127 | ||||
| -rw-r--r-- | src/frontend/handler.rs | 49 |
2 files changed, 68 insertions, 108 deletions
diff --git a/src/frontend/app.rs b/src/frontend/app.rs index eeb2d4c..72d1020 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -263,6 +263,41 @@ impl App { // } } + pub fn reset_current_list(&mut self) { + if let CurrentArea::EntryArea = self.current_area { + self.entry_table = + EntryTable::from_iter(self.biblio_data.entry_list.bibentries.clone()); + if self.search_struct.inner_search { + self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()) + } + } else if let CurrentArea::TagArea = self.current_area { + self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()); + self.tag_list.tag_list_state.select(Some(0)) + } + self.former_area = None + } + + // Yank the passed string to system clipboard + pub fn yank_text(selection: &str) { + let mut clipboard = Clipboard::new().unwrap(); + let yanked_text = selection.to_string(); + clipboard.set_text(yanked_text).unwrap(); + } + + pub fn scroll_info_down(&mut self) { + self.scroll_info = self.scroll_info + 1; + } + + pub fn scroll_info_up(&mut self) { + if self.scroll_info == 0 { + {} + } else { + self.scroll_info = self.scroll_info - 1; + } + } + + // Search Area + // Enter the search area pub fn enter_search_area(&mut self) { if let CurrentArea::EntryArea = self.current_area { @@ -292,43 +327,51 @@ impl App { pub fn break_search(&mut self) { if let Some(FormerArea::EntryArea) = self.former_area { self.current_area = CurrentArea::EntryArea; - self.reset_entry_table(); } else if let Some(FormerArea::TagArea) = self.former_area { self.current_area = CurrentArea::TagArea; - self.reset_taglist(); self.tag_list.tag_list_state.select(Some(0)) } + self.reset_current_list(); self.former_area = None; // If search is canceled, reset default status of struct self.search_struct.search_string.clear(); } - // Yank the passed string to system clipboard - pub fn yank_text(selection: &str) { - let mut clipboard = Clipboard::new().unwrap(); - let yanked_text = selection.to_string(); - clipboard.set_text(yanked_text).unwrap(); - } - - pub fn scroll_info_down(&mut self) { - self.scroll_info = self.scroll_info + 1; + // Search entry list + pub fn search_entries(&mut self) { + let orig_list = { + if self.search_struct.inner_search { + let orig_list = &self.search_struct.filtered_entry_list; + orig_list + } else { + let orig_list = &self.biblio_data.entry_list.bibentries; + orig_list + } + }; + let filtered_list = + BibiSearch::search_entry_list(&mut self.search_struct.search_string, orig_list.clone()); + //search::search_entry_list(&self.search_string, orig_list.clone()); + self.entry_table = EntryTable::from_iter(filtered_list) } - pub fn scroll_info_up(&mut self) { - if self.scroll_info == 0 { - {} - } else { - self.scroll_info = self.scroll_info - 1; + // Remove last char from search pattern and filter list immidiately + pub fn search_pattern_pop(&mut self) { + self.search_struct.search_string.pop(); + if let Some(FormerArea::EntryArea) = self.former_area { + self.search_entries(); + } else if let Some(FormerArea::TagArea) = self.former_area { + self.search_tags(); } } - pub fn select_none(&mut self) { - match self.current_area { - CurrentArea::EntryArea => self.entry_table.entry_table_state.select(None), - CurrentArea::TagArea => self.tag_list.tag_list_state.select(None), - _ => {} + // Add current char to search pattern and filter list immidiatley + pub fn search_pattern_push(&mut self, search_pattern: char) { + self.search_struct.search_string.push(search_pattern); + if let Some(FormerArea::EntryArea) = self.former_area { + self.search_entries(); + } else if let Some(FormerArea::TagArea) = self.former_area { + self.search_tags(); } - // self.tag_list.tag_list_state.select(None); } // Tag List commands @@ -363,10 +406,6 @@ impl App { self.tag_list = TagList::from_iter(filtered_list) } - pub fn reset_taglist(&mut self) { - self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()) - } - // Filter the entry list by tags // If already inside a filtered tag or entry list, apply the filtering // to the already filtered list only @@ -417,40 +456,4 @@ impl App { let citekey = &self.entry_table.entry_table_items[idx].citekey; citekey } - - // Reset Entry Table to initial state - pub fn reset_entry_table(&mut self) { - self.entry_table = EntryTable::from_iter(self.biblio_data.entry_list.bibentries.clone()) - } - - pub fn reset_current_list(&mut self) { - if let CurrentArea::EntryArea = self.current_area { - self.entry_table = - EntryTable::from_iter(self.biblio_data.entry_list.bibentries.clone()); - if self.search_struct.inner_search { - self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()) - } - } else if let CurrentArea::TagArea = self.current_area { - self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()); - self.tag_list.tag_list_state.select(Some(0)) - } - self.former_area = None - } - - // Search entry list - pub fn search_entries(&mut self) { - let orig_list = { - if self.search_struct.inner_search { - let orig_list = &self.search_struct.filtered_entry_list; - orig_list - } else { - let orig_list = &self.biblio_data.entry_list.bibentries; - orig_list - } - }; - let filtered_list = - BibiSearch::search_entry_list(&mut self.search_struct.search_string, orig_list.clone()); - //search::search_entry_list(&self.search_string, orig_list.clone()); - self.entry_table = EntryTable::from_iter(filtered_list) - } } diff --git a/src/frontend/handler.rs b/src/frontend/handler.rs index 5c7519a..ad899e2 100644 --- a/src/frontend/handler.rs +++ b/src/frontend/handler.rs @@ -15,10 +15,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// -use crate::{ - backend::search::BibiSearch, - frontend::app::{App, AppResult}, -}; +use crate::frontend::app::{App, AppResult}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use super::app::{CurrentArea, FormerArea}; @@ -62,8 +59,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.select_last_tag(); } KeyCode::Char('/') => { - // app.former_area = Some(FormerArea::TagArea); - // app.current_area = CurrentArea::SearchArea; app.enter_search_area(); } KeyCode::Char('f') | KeyCode::Char('F') => { @@ -76,13 +71,9 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { } KeyCode::Esc => { app.reset_current_list(); - // app.reset_taglist(); } KeyCode::Enter => { app.filter_for_tags(); - // app.toggle_area(); - // app.reset_taglist(); - // app.former_area = Some(FormerArea::TagArea); } _ => {} }, @@ -104,11 +95,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { App::yank_text(&app.get_selected_citekey()); } KeyCode::Char('/') => { - // if let Some(FormerArea::TagArea) = app.former_area { - // app.search_struct.inner_search = true; - // } - // app.former_area = Some(FormerArea::EntryArea); - // app.current_area = CurrentArea::SearchArea; app.enter_search_area(); } KeyCode::Char('f') | KeyCode::Char('F') => { @@ -120,11 +106,6 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.toggle_area(); } KeyCode::Esc => { - // app.reset_entry_table(); - // if app.search_struct.inner_search { - // app.reset_taglist(); - // } - // app.former_area = None; app.reset_current_list(); } _ => {} @@ -132,40 +113,16 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // Keycodes for the search area (rendered in footer) CurrentArea::SearchArea => match key_event.code { KeyCode::Esc => { - // app.toggle_area(); - // if let Some(FormerArea::EntryArea) = app.former_area { - // app.reset_entry_table(); - // } else if let Some(FormerArea::TagArea) = app.former_area { - // app.reset_taglist(); - // } - // app.former_area = None; - // // If search is canceled, reset default status of struct - // BibiSearch::default(); app.break_search(); } KeyCode::Enter => { - // TODO: run function for filtering the list - // app.toggle_area(); - // app.former_area = Some(FormerArea::SearchArea); - // // app.search_string.clear(); - // app.search_struct.search_string.clear(); app.confirm_search(); } KeyCode::Backspace => { - app.search_struct.search_string.pop(); - if let Some(FormerArea::EntryArea) = app.former_area { - app.search_entries(); - } else if let Some(FormerArea::TagArea) = app.former_area { - app.search_tags(); - } + app.search_pattern_pop(); } KeyCode::Char(search_pattern) => { - app.search_struct.search_string.push(search_pattern); - if let Some(FormerArea::EntryArea) = app.former_area { - app.search_entries(); - } else if let Some(FormerArea::TagArea) = app.former_area { - app.search_tags(); - } + app.search_pattern_push(search_pattern); } _ => {} }, |
