From 4f0b65f5eab1875edd3d4f547952e49bbc79a54d Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sun, 9 Jul 2023 21:11:14 +0200 Subject: add file status and export button --- src/gui/mod.rs | 40 ++++++++++++++++++++++++++++++---------- src/index.rs | 4 ++++ 2 files changed, 34 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) + SearchFinished(Vec), + 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 = 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() diff --git a/src/index.rs b/src/index.rs index 36f0ae2..98a174b 100644 --- a/src/index.rs +++ b/src/index.rs @@ -284,4 +284,8 @@ impl Index { file.flush().ok(); }); } + + pub fn num_files(&self) -> usize { + self.filecache.len() + } } -- cgit v1.2.3-70-g09d2