Initial Commit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
Generated
+5407
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "pdfsearcher"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
native-dialog = "0.7.0"
|
||||||
|
pdf-extract = "0.7.7"
|
||||||
|
rust_search = "2.1.0"
|
||||||
|
slint = "1.6.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
slint-build = "1.6"
|
||||||
|
winresource = "0.1.17"
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
use {
|
||||||
|
std::{
|
||||||
|
env,
|
||||||
|
io,
|
||||||
|
},
|
||||||
|
winresource::WindowsResource,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let config: slint_build::CompilerConfiguration =
|
||||||
|
slint_build::CompilerConfiguration::new()
|
||||||
|
.with_style("cosmic-dark".into());
|
||||||
|
slint_build::compile_with_config("ui/template.slint", config).unwrap();
|
||||||
|
if env::var_os("CARGO_CFG_WINDOWS").is_some() {
|
||||||
|
WindowsResource::new()
|
||||||
|
// This path can be absolute, or relative to your crate root.
|
||||||
|
.set_icon("assets/pdf.ico")
|
||||||
|
.set("FileVersion", "1.0.0")
|
||||||
|
.set("FileDescription", "PDF Searcher")
|
||||||
|
.set("ProductName", "PDF Searcher")
|
||||||
|
.set("ProductVersion", "1.0.0")
|
||||||
|
.set("LegalCopyright", "Copyright © 2024")
|
||||||
|
.compile()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#![windows_subsystem = "windows"]
|
||||||
|
slint::include_modules!();
|
||||||
|
slint::slint!();
|
||||||
|
use native_dialog::FileDialog;
|
||||||
|
use pdf_extract::extract_text;
|
||||||
|
use rust_search::SearchBuilder;
|
||||||
|
|
||||||
|
static mut FILEPATH: String = String::new();
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let app: App = App::new().unwrap();
|
||||||
|
let _weak = app.as_weak();
|
||||||
|
app.on_fileexplorer(move || {
|
||||||
|
let opendialog: Option<std::path::PathBuf> = FileDialog::new()
|
||||||
|
.set_location("~/Downloads")
|
||||||
|
.add_filter("PDF", &["pdf"])
|
||||||
|
.show_open_single_dir()
|
||||||
|
.unwrap();
|
||||||
|
match opendialog {
|
||||||
|
Some(_) => {
|
||||||
|
let filepath: std::path::PathBuf = opendialog.unwrap();
|
||||||
|
unsafe {
|
||||||
|
FILEPATH = filepath.into_os_string().into_string().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None {} => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
app.on_search({
|
||||||
|
let handle: slint::Weak<App> = app.as_weak();
|
||||||
|
move || {
|
||||||
|
let weak: App = handle.unwrap();
|
||||||
|
let mut fileresults: String = String::new();
|
||||||
|
let binding = weak.get_texttosearch();
|
||||||
|
let texttosearch: &str = binding.as_str();
|
||||||
|
unsafe {
|
||||||
|
let search: Vec<String> = SearchBuilder::default()
|
||||||
|
.location(FILEPATH.clone())
|
||||||
|
.ext("pdf")
|
||||||
|
.build()
|
||||||
|
.collect();
|
||||||
|
for file in search {
|
||||||
|
let text = extract_text(&file).expect("Unable to read PDF");
|
||||||
|
if text.contains(texttosearch) {
|
||||||
|
fileresults = fileresults + "Found: " + &file + "\n\n";
|
||||||
|
weak.set_results((&fileresults).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
app.run().unwrap();
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { CheckBox, Button, LineEdit, ProgressIndicator, TextEdit, Spinner, AboutSlint } from "std-widgets.slint";
|
||||||
|
|
||||||
|
export component App inherits Window {
|
||||||
|
width: 715px;
|
||||||
|
height: 400px;
|
||||||
|
title: @tr("PDF Searcher");
|
||||||
|
icon: @image-url("../assets/pdf.png");
|
||||||
|
callback fileexplorer();
|
||||||
|
callback search();
|
||||||
|
in-out property <string> texttosearch;
|
||||||
|
in-out property <string> results;
|
||||||
|
Button {
|
||||||
|
text: "Open Directory";
|
||||||
|
x: 471px;
|
||||||
|
y: 15px;
|
||||||
|
clicked => {
|
||||||
|
root.fileexplorer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LineEdit {
|
||||||
|
x: 125px;
|
||||||
|
y: 15px;
|
||||||
|
input-type: text;
|
||||||
|
read-only: false;
|
||||||
|
text <=> texttosearch;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "String to Search: ";
|
||||||
|
x: 25px;
|
||||||
|
y: 23px;
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: "Search";
|
||||||
|
x: 309px;
|
||||||
|
y: 15px;
|
||||||
|
clicked => {
|
||||||
|
root.search();
|
||||||
|
spinner.visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "Found Items:";
|
||||||
|
x: 33px;
|
||||||
|
y: 57px;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEdit {
|
||||||
|
width: 546px;
|
||||||
|
height: 303px;
|
||||||
|
x: 27px;
|
||||||
|
y: 80px;
|
||||||
|
read-only: true;
|
||||||
|
text <=> results;
|
||||||
|
}
|
||||||
|
|
||||||
|
spinner := Spinner {
|
||||||
|
x: 403px;
|
||||||
|
y: 46px;
|
||||||
|
indeterminate: true;
|
||||||
|
visible: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AboutSlint {
|
||||||
|
width: 110px;
|
||||||
|
height: 42px;
|
||||||
|
x: 594px;
|
||||||
|
y: 284px;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user