aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-07-09 21:11:14 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2023-07-09 21:11:14 +0200
commit4f0b65f5eab1875edd3d4f547952e49bbc79a54d (patch)
treebdd7f82b3c924ce64e2d96f312b3ffd1e86ce7b9 /src
parentafa9d5b588a9f8dcd0e38f0ffd28977d2ae9b60a (diff)
add file status and export button
Diffstat (limited to 'src')
-rw-r--r--src/gui/mod.rs40
-rw-r--r--src/index.rs4
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<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()
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()
+ }
}