diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-09 21:11:14 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-09 21:11:14 +0200 |
| commit | 4f0b65f5eab1875edd3d4f547952e49bbc79a54d (patch) | |
| tree | bdd7f82b3c924ce64e2d96f312b3ffd1e86ce7b9 /src/gui/mod.rs | |
| parent | afa9d5b588a9f8dcd0e38f0ffd28977d2ae9b60a (diff) | |
add file status and export button
Diffstat (limited to 'src/gui/mod.rs')
| -rw-r--r-- | src/gui/mod.rs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 52cf8a7..6f88923 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,8 +1,9 @@ +use std::fs::File; +use std::io::Write; use std::thread; use std::time::Duration; - use iced::theme::Theme; -use iced::widget::{text, scrollable, container, column, button, text_input, progress_bar}; +use iced::widget::{text, row, scrollable, container, column, button, text_input, progress_bar}; use iced::{window, Length}; use iced::{Application, Element}; use iced::{Command, Settings}; @@ -72,7 +73,8 @@ enum Message { GeneratingUpdate(GenProgress), InputChanged(String), SearchSubmit, - SearchFinished(Vec<SearchResult>) + SearchFinished(Vec<SearchResult>), + ExportResults } async fn load_file() -> Index { @@ -206,6 +208,17 @@ impl Application for App { state.results = results; Command::none() } + Message::ExportResults => { + let file = rfd::FileDialog::new().set_title("Export to File").add_filter("Raw Text", &["txt"]).save_file(); + if file.is_some() { + let file = file.unwrap(); + let mut file = File::create(file).unwrap(); + for result in state.results.iter() { + writeln!(file, "{}", result.path).ok(); + } + } + Command::none() + } _ => { Command::none() } @@ -239,7 +252,7 @@ impl Application for App { progress_bar(0.0..=100.0, state.progress as f32) ].spacing(10).align_items(iced::Alignment::Center) } - App::Search(State { input_value, results, ..}) => { + App::Search(State { input_value, index, results, ..}) => { let res : Element<Message> = if results.is_empty() { column![text("There are no results")].spacing(10).into() } else { @@ -248,12 +261,19 @@ impl Application for App { }; column![ - text_input("Search", input_value) - .id(SEARCH_ID.clone()) - .on_submit(Message::SearchSubmit) - .on_input(Message::InputChanged) - .padding(5), - scrollable(res).width(Length::Fill) + row![ + text_input("Search", input_value) + .id(SEARCH_ID.clone()) + .on_submit(Message::SearchSubmit) + .on_input(Message::InputChanged) + .padding(10), + text(format!("{} files", index.num_files())) + ].align_items(iced::Alignment::Center).spacing(10), + scrollable(res).width(Length::Fill).height(Length::Fill), + row![ + text(format!("{} results", results.len())).width(Length::Fill), + button("export results").on_press(Message::ExportResults) + ].align_items(iced::Alignment::End).spacing(10) ].spacing(10) } }).center_x() |