checkpoint
This commit is contained in:
parent
3e7509a9c7
commit
e64aee2b31
76
src/main.rs
76
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
#![feature(iter_map_windows)]
|
#![feature(iter_map_windows)]
|
||||||
use iced::{
|
use iced::{
|
||||||
clipboard, widget::{self, column, combo_box, row, text_input}, Element, Task
|
Element, Task, clipboard,
|
||||||
|
widget::{self, button, column, combo_box, row, scrollable, text, text_input},
|
||||||
};
|
};
|
||||||
use std::{env, fs, path::PathBuf};
|
use std::{env, fs, path::PathBuf};
|
||||||
use texts::*;
|
use texts::*;
|
||||||
@ -24,7 +25,7 @@ fn main() -> iced::Result {
|
|||||||
// ) {
|
// ) {
|
||||||
// println!("{}", f);
|
// println!("{}", f);
|
||||||
// }
|
// }
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +42,8 @@ enum Message {
|
|||||||
Clear,
|
Clear,
|
||||||
WordSearchInput(String),
|
WordSearchInput(String),
|
||||||
SubmitWordSearch,
|
SubmitWordSearch,
|
||||||
|
QuickSearch(String),
|
||||||
|
AddColRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
@ -49,9 +52,12 @@ struct State {
|
|||||||
bible_selected: Option<bible::Bible>,
|
bible_selected: Option<bible::Bible>,
|
||||||
|
|
||||||
bible_search: String,
|
bible_search: String,
|
||||||
body: Option<String>,
|
scripture_body: Option<String>,
|
||||||
|
|
||||||
word_search: String,
|
word_search: String,
|
||||||
|
word_search_results: Option<Vec<String>>,
|
||||||
|
|
||||||
|
cols: usize,
|
||||||
}
|
}
|
||||||
impl Default for State {
|
impl Default for State {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -83,9 +89,12 @@ impl Default for State {
|
|||||||
bible_selected: None,
|
bible_selected: None,
|
||||||
|
|
||||||
bible_search: String::new(),
|
bible_search: String::new(),
|
||||||
body: None,
|
scripture_body: None,
|
||||||
|
|
||||||
word_search: String::new(),
|
word_search: String::new(),
|
||||||
|
word_search_results: None,
|
||||||
|
|
||||||
|
cols: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +102,7 @@ impl Default for State {
|
|||||||
impl State {
|
impl State {
|
||||||
fn update(&mut self, msg: Message) -> Task<Message> {
|
fn update(&mut self, msg: Message) -> Task<Message> {
|
||||||
match msg {
|
match msg {
|
||||||
|
Message::AddColRight => self.cols += 1,
|
||||||
Message::BibleSelected(file) => {
|
Message::BibleSelected(file) => {
|
||||||
if let Ok(contents) = fs::read_to_string(&file) {
|
if let Ok(contents) = fs::read_to_string(&file) {
|
||||||
if let Ok(bible) = quick_xml::de::from_str::<bible::Bible>(&contents) {
|
if let Ok(bible) = quick_xml::de::from_str::<bible::Bible>(&contents) {
|
||||||
@ -105,6 +115,10 @@ impl State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::QuickSearch(s) => {
|
||||||
|
self.bible_search = s;
|
||||||
|
return self.update(Message::BibleSearchSubmit);
|
||||||
|
}
|
||||||
Message::BibleSearchInput(query) => self.bible_search = query,
|
Message::BibleSearchInput(query) => self.bible_search = query,
|
||||||
Message::WordSearchInput(query) => self.word_search = query,
|
Message::WordSearchInput(query) => self.word_search = query,
|
||||||
Message::BibleSearchSubmit => {
|
Message::BibleSearchSubmit => {
|
||||||
@ -115,20 +129,25 @@ impl State {
|
|||||||
if let (Some(book), Some(chap_and_ver), Some(bible)) =
|
if let (Some(book), Some(chap_and_ver), Some(bible)) =
|
||||||
(book, location, &self.bible_selected)
|
(book, location, &self.bible_selected)
|
||||||
{
|
{
|
||||||
self.body = bible::get(book, chap_and_ver, vec![bible]);
|
self.scripture_body = bible::get(book, chap_and_ver, vec![bible]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::SubmitWordSearch => {
|
Message::SubmitWordSearch => {
|
||||||
println!("todo: search for {}", self.word_search);
|
if let Some(bible) = &self.bible_selected {
|
||||||
|
let res = bible::search_for_word(&self.word_search, bible);
|
||||||
|
self.word_search_results = Some(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Message::CopyText => {
|
Message::CopyText => {
|
||||||
if let Some(text) = &self.body {
|
if let Some(text) = &self.scripture_body {
|
||||||
return clipboard::write::<Message>(parse(text));
|
return clipboard::write::<Message>(parse(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Clear => {
|
Message::Clear => {
|
||||||
self.body = None;
|
self.scripture_body = None;
|
||||||
|
self.word_search_results = None;
|
||||||
self.bible_search = String::new();
|
self.bible_search = String::new();
|
||||||
|
self.word_search = String::new();
|
||||||
return text_input::focus("bible-search");
|
return text_input::focus("bible-search");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -136,20 +155,23 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
let msg = if let Some(body) = self.body.clone() {
|
let body = if let Some(body) = self.scripture_body.clone() {
|
||||||
parse(&body)
|
parse(&body)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
scrollable(row((0..self.cols).map(|_| {
|
||||||
|
row![
|
||||||
|
button("-"),
|
||||||
column![
|
column![
|
||||||
widget::combo_box(
|
combo_box(
|
||||||
&self.files,
|
&self.files,
|
||||||
"Select Bible",
|
"Select Bible",
|
||||||
self.selected_file.as_ref(),
|
self.selected_file.as_ref(),
|
||||||
Message::BibleSelected
|
Message::BibleSelected
|
||||||
),
|
),
|
||||||
widget::text_input("Search query, ie: Gen 1:1", &self.bible_search)
|
text_input("Search query, ie: Gen 1:1", &self.bible_search)
|
||||||
.on_input(Message::BibleSearchInput)
|
.on_input(Message::BibleSearchInput)
|
||||||
.on_submit(Message::BibleSearchSubmit)
|
.on_submit(Message::BibleSearchSubmit)
|
||||||
.id("bible-search"),
|
.id("bible-search"),
|
||||||
@ -158,12 +180,33 @@ impl State {
|
|||||||
.on_submit(Message::SubmitWordSearch)
|
.on_submit(Message::SubmitWordSearch)
|
||||||
.id("word-search"),
|
.id("word-search"),
|
||||||
row![
|
row![
|
||||||
widget::button("Copy").on_press(Message::CopyText),
|
button("Clear All").on_press(Message::Clear),
|
||||||
widget::button("Clear").on_press(Message::Clear),
|
button("Copy Scripture").on_press(Message::CopyText),
|
||||||
],
|
],
|
||||||
widget::text(msg),
|
row![
|
||||||
|
scrollable(column(
|
||||||
|
self.word_search_results
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(Vec::new())
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| button(text(i.clone()))
|
||||||
|
.on_press_with(move || Message::QuickSearch(i.to_owned()))
|
||||||
|
.into())
|
||||||
|
)),
|
||||||
|
scrollable(text(body.clone()))
|
||||||
|
],
|
||||||
|
],
|
||||||
|
button(text("+").center())
|
||||||
|
.height(iced::Length::FillPortion(1))
|
||||||
|
.on_press(Message::AddColRight)
|
||||||
]
|
]
|
||||||
.into()
|
.into()
|
||||||
|
})))
|
||||||
|
.direction(scrollable::Direction::Both {
|
||||||
|
vertical: scrollable::Scrollbar::new(),
|
||||||
|
horizontal: scrollable::Scrollbar::new(),
|
||||||
|
})
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,12 +281,11 @@ fn parse(input: &str) -> String {
|
|||||||
to_remove.reverse();
|
to_remove.reverse();
|
||||||
let mut modified = input.to_owned();
|
let mut modified = input.to_owned();
|
||||||
|
|
||||||
for (s,e) in to_remove {
|
for (s, e) in to_remove {
|
||||||
let front = modified[..s].to_string();
|
let front = modified[..s].to_string();
|
||||||
let back = modified[e+1..].to_string();
|
let back = modified[e + 1..].to_string();
|
||||||
modified = front + &back;
|
modified = front + &back;
|
||||||
}
|
}
|
||||||
|
|
||||||
modified
|
modified
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
|
|||||||
"Joshua",
|
"Joshua",
|
||||||
"Judges",
|
"Judges",
|
||||||
"Ruth",
|
"Ruth",
|
||||||
"1 Samuel",
|
"1-Samuel",
|
||||||
"2 Samuel",
|
"2-Samuel",
|
||||||
"1 Kings",
|
"1-Kings",
|
||||||
"2 Kings",
|
"2-Kings",
|
||||||
"1 Chronicles",
|
"1-Chronicles",
|
||||||
"2 Chronicles",
|
"2-Chronicles",
|
||||||
"Ezra",
|
"Ezra",
|
||||||
"Nehemiah",
|
"Nehemiah",
|
||||||
"Esther",
|
"Esther",
|
||||||
@ -25,7 +25,7 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
|
|||||||
"Psalms",
|
"Psalms",
|
||||||
"Proverbs",
|
"Proverbs",
|
||||||
"Ecclesiastes",
|
"Ecclesiastes",
|
||||||
"Song of Solomon",
|
"Song-of-Solomon",
|
||||||
"Isaiah",
|
"Isaiah",
|
||||||
"Jeremiah",
|
"Jeremiah",
|
||||||
"Lamentations",
|
"Lamentations",
|
||||||
@ -49,31 +49,43 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
|
|||||||
"John",
|
"John",
|
||||||
"Acts",
|
"Acts",
|
||||||
"Romans",
|
"Romans",
|
||||||
"1 Corinthians",
|
"1-Corinthians",
|
||||||
"2 Corinthians",
|
"2-Corinthians",
|
||||||
"Galations",
|
"Galations",
|
||||||
"Ephesians",
|
"Ephesians",
|
||||||
"Philippians",
|
"Philippians",
|
||||||
"Colossians",
|
"Colossians",
|
||||||
"1 Thessalonians",
|
"1-Thessalonians",
|
||||||
"2 Thessalonians",
|
"2-Thessalonians",
|
||||||
"1 Timothy",
|
"1-Timothy",
|
||||||
"2 Timothy",
|
"2-Timothy",
|
||||||
"Titus",
|
"Titus",
|
||||||
"Philemon",
|
"Philemon",
|
||||||
"Hebrews",
|
"Hebrews",
|
||||||
"James",
|
"James",
|
||||||
"1 Peter",
|
"1-Peter",
|
||||||
"2 Peter",
|
"2-Peter",
|
||||||
"1 John",
|
"1-John",
|
||||||
"2 John",
|
"2-John",
|
||||||
"3 John",
|
"3-John",
|
||||||
"Jude",
|
"Jude",
|
||||||
"Revelation",
|
"Revelation",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn search_for_word(word: &str, from_files: &Bible) -> Vec<String> {
|
pub fn search_for_word(word: &str, from_files: &Bible) -> Vec<String> {
|
||||||
todo!()
|
let mut found = Vec::new();
|
||||||
|
for test in &from_files.testaments {
|
||||||
|
for book in &test.books {
|
||||||
|
for chapter in &book.chapters {
|
||||||
|
for verse in &chapter.verses {
|
||||||
|
if verse.text.contains(word) {
|
||||||
|
found.push(format!("{} {}:{}", BOOKS_IN_ORDER[book.number-1], chapter.number, verse.number));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String> {
|
pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String> {
|
||||||
@ -92,7 +104,14 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
|
|||||||
let res = BOOKS_IN_ORDER
|
let res = BOOKS_IN_ORDER
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, lbook)| lbook.replace(" ", "").to_lowercase().starts_with(&book.trim().to_lowercase()))
|
.filter(|(_, lbook)| lbook
|
||||||
|
.to_lowercase()
|
||||||
|
.starts_with(&book
|
||||||
|
.trim()
|
||||||
|
.replace(" ", "-")
|
||||||
|
.to_lowercase()
|
||||||
|
)
|
||||||
|
)
|
||||||
.collect::<Vec<(usize, &&str)>>();
|
.collect::<Vec<(usize, &&str)>>();
|
||||||
|
|
||||||
let (book_idx, book_name) = match res.len() {
|
let (book_idx, book_name) = match res.len() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user