checkpoint
This commit is contained in:
		
							
								
								
									
										72
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,6 +1,7 @@
 | 
			
		||||
#![feature(iter_map_windows)]
 | 
			
		||||
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 texts::*;
 | 
			
		||||
@@ -24,7 +25,7 @@ fn main() -> iced::Result {
 | 
			
		||||
            // ) {
 | 
			
		||||
            //   println!("{}", f);
 | 
			
		||||
            // }
 | 
			
		||||
            return Ok(())
 | 
			
		||||
            return Ok(());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -41,6 +42,8 @@ enum Message {
 | 
			
		||||
    Clear,
 | 
			
		||||
    WordSearchInput(String),
 | 
			
		||||
    SubmitWordSearch,
 | 
			
		||||
    QuickSearch(String),
 | 
			
		||||
    AddColRight,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct State {
 | 
			
		||||
@@ -49,9 +52,12 @@ struct State {
 | 
			
		||||
    bible_selected: Option<bible::Bible>,
 | 
			
		||||
 | 
			
		||||
    bible_search: String,
 | 
			
		||||
    body: Option<String>,
 | 
			
		||||
    scripture_body: Option<String>,
 | 
			
		||||
 | 
			
		||||
    word_search: String,
 | 
			
		||||
    word_search_results: Option<Vec<String>>,
 | 
			
		||||
 | 
			
		||||
    cols: usize,
 | 
			
		||||
}
 | 
			
		||||
impl Default for State {
 | 
			
		||||
    fn default() -> Self {
 | 
			
		||||
@@ -83,9 +89,12 @@ impl Default for State {
 | 
			
		||||
            bible_selected: None,
 | 
			
		||||
 | 
			
		||||
            bible_search: String::new(),
 | 
			
		||||
            body: None,
 | 
			
		||||
            scripture_body: None,
 | 
			
		||||
 | 
			
		||||
            word_search: String::new(),
 | 
			
		||||
            word_search_results: None,
 | 
			
		||||
 | 
			
		||||
            cols: 1,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -93,6 +102,7 @@ impl Default for State {
 | 
			
		||||
impl State {
 | 
			
		||||
    fn update(&mut self, msg: Message) -> Task<Message> {
 | 
			
		||||
        match msg {
 | 
			
		||||
            Message::AddColRight => self.cols += 1,
 | 
			
		||||
            Message::BibleSelected(file) => {
 | 
			
		||||
                if let Ok(contents) = fs::read_to_string(&file) {
 | 
			
		||||
                    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::WordSearchInput(query) => self.word_search = query,
 | 
			
		||||
            Message::BibleSearchSubmit => {
 | 
			
		||||
@@ -115,20 +129,25 @@ impl State {
 | 
			
		||||
                if let (Some(book), Some(chap_and_ver), Some(bible)) =
 | 
			
		||||
                    (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 => {
 | 
			
		||||
                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 => {
 | 
			
		||||
                if let Some(text) = &self.body {
 | 
			
		||||
                if let Some(text) = &self.scripture_body {
 | 
			
		||||
                    return clipboard::write::<Message>(parse(text));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            Message::Clear => {
 | 
			
		||||
                self.body = None;
 | 
			
		||||
                self.scripture_body = None;
 | 
			
		||||
                self.word_search_results = None;
 | 
			
		||||
                self.bible_search = String::new();
 | 
			
		||||
                self.word_search = String::new();
 | 
			
		||||
                return text_input::focus("bible-search");
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
@@ -136,20 +155,23 @@ impl State {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        } else {
 | 
			
		||||
            String::new()
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        scrollable(row((0..self.cols).map(|_| {
 | 
			
		||||
            row![
 | 
			
		||||
                button("-"),
 | 
			
		||||
                column![
 | 
			
		||||
            widget::combo_box(
 | 
			
		||||
                    combo_box(
 | 
			
		||||
                        &self.files,
 | 
			
		||||
                        "Select Bible",
 | 
			
		||||
                        self.selected_file.as_ref(),
 | 
			
		||||
                        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_submit(Message::BibleSearchSubmit)
 | 
			
		||||
                        .id("bible-search"),
 | 
			
		||||
@@ -158,12 +180,33 @@ impl State {
 | 
			
		||||
                        .on_submit(Message::SubmitWordSearch)
 | 
			
		||||
                        .id("word-search"),
 | 
			
		||||
                    row![
 | 
			
		||||
                widget::button("Copy").on_press(Message::CopyText),
 | 
			
		||||
                widget::button("Clear").on_press(Message::Clear),
 | 
			
		||||
                        button("Clear All").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()
 | 
			
		||||
        })))
 | 
			
		||||
        .direction(scrollable::Direction::Both {
 | 
			
		||||
            vertical: scrollable::Scrollbar::new(),
 | 
			
		||||
            horizontal: scrollable::Scrollbar::new(),
 | 
			
		||||
        })
 | 
			
		||||
        .into()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -246,4 +289,3 @@ fn parse(input: &str) -> String {
 | 
			
		||||
 | 
			
		||||
    modified
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,12 +12,12 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
 | 
			
		||||
    "Joshua",
 | 
			
		||||
    "Judges",
 | 
			
		||||
    "Ruth",
 | 
			
		||||
    "1 Samuel",
 | 
			
		||||
    "2 Samuel",
 | 
			
		||||
    "1 Kings",
 | 
			
		||||
    "2 Kings",
 | 
			
		||||
    "1 Chronicles",
 | 
			
		||||
    "2 Chronicles",
 | 
			
		||||
    "1-Samuel",
 | 
			
		||||
    "2-Samuel",
 | 
			
		||||
    "1-Kings",
 | 
			
		||||
    "2-Kings",
 | 
			
		||||
    "1-Chronicles",
 | 
			
		||||
    "2-Chronicles",
 | 
			
		||||
    "Ezra",
 | 
			
		||||
    "Nehemiah",
 | 
			
		||||
    "Esther",
 | 
			
		||||
@@ -25,7 +25,7 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
 | 
			
		||||
    "Psalms",
 | 
			
		||||
    "Proverbs",
 | 
			
		||||
    "Ecclesiastes",
 | 
			
		||||
    "Song of Solomon",
 | 
			
		||||
    "Song-of-Solomon",
 | 
			
		||||
    "Isaiah",
 | 
			
		||||
    "Jeremiah",
 | 
			
		||||
    "Lamentations",
 | 
			
		||||
@@ -49,31 +49,43 @@ pub const BOOKS_IN_ORDER: [&str; 66] = [
 | 
			
		||||
    "John",
 | 
			
		||||
    "Acts",
 | 
			
		||||
    "Romans",
 | 
			
		||||
    "1 Corinthians",
 | 
			
		||||
    "2 Corinthians",
 | 
			
		||||
    "1-Corinthians",
 | 
			
		||||
    "2-Corinthians",
 | 
			
		||||
    "Galations",
 | 
			
		||||
    "Ephesians",
 | 
			
		||||
    "Philippians",
 | 
			
		||||
    "Colossians",
 | 
			
		||||
    "1 Thessalonians",
 | 
			
		||||
    "2 Thessalonians",
 | 
			
		||||
    "1 Timothy",
 | 
			
		||||
    "2 Timothy",
 | 
			
		||||
    "1-Thessalonians",
 | 
			
		||||
    "2-Thessalonians",
 | 
			
		||||
    "1-Timothy",
 | 
			
		||||
    "2-Timothy",
 | 
			
		||||
    "Titus",
 | 
			
		||||
    "Philemon",
 | 
			
		||||
    "Hebrews",
 | 
			
		||||
    "James",
 | 
			
		||||
    "1 Peter",
 | 
			
		||||
    "2 Peter",
 | 
			
		||||
    "1 John",
 | 
			
		||||
    "2 John",
 | 
			
		||||
    "3 John",
 | 
			
		||||
    "1-Peter",
 | 
			
		||||
    "2-Peter",
 | 
			
		||||
    "1-John",
 | 
			
		||||
    "2-John",
 | 
			
		||||
    "3-John",
 | 
			
		||||
    "Jude",
 | 
			
		||||
    "Revelation",
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
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> {
 | 
			
		||||
@@ -92,7 +104,14 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
 | 
			
		||||
    let res = BOOKS_IN_ORDER
 | 
			
		||||
        .iter()
 | 
			
		||||
        .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)>>();
 | 
			
		||||
 | 
			
		||||
    let (book_idx, book_name) = match res.len() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user