Skip to content

Commit 4de6cb8

Browse files
committed
Refactor modules and fix word-wrap control rebinding
1 parent 367a904 commit 4de6cb8

37 files changed

+295
-290
lines changed

src/config.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use base64::{
1313
use sha1::{Digest, Sha1};
1414
use wxdragon::config::{Config, ConfigStyle};
1515

16+
use crate::types::DocumentListItem;
17+
1618
const CONFIG_VERSION_LEGACY: i64 = 0;
1719
const CONFIG_VERSION_1: i64 = 1;
1820
const CONFIG_VERSION_2: i64 = 2;
@@ -828,12 +830,8 @@ impl Drop for ConfigManager {
828830
}
829831
}
830832

831-
pub fn get_sorted_document_list(
832-
config: &ConfigManager,
833-
open_paths: &[String],
834-
filter: &str,
835-
) -> Vec<crate::ui_types::DocumentListItem> {
836-
use crate::ui_types::{DocumentListItem, DocumentListStatus};
833+
pub fn get_sorted_document_list(config: &ConfigManager, open_paths: &[String], filter: &str) -> Vec<DocumentListItem> {
834+
use crate::types::{DocumentListItem, DocumentListStatus};
837835

838836
let recent_docs = config.get_recent_documents();
839837
let all_docs = config.get_all_documents();

src/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use bitflags::bitflags;
44

5-
use crate::utils::text::{display_len, is_space_like};
5+
use crate::text::{display_len, is_space_like};
66

77
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
88
#[repr(i32)]
File renamed without changes.

src/html_to_text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bitflags::bitflags;
44
use ego_tree::NodeRef;
55
use scraper::{ElementRef, Html, Node, node};
66

7-
use crate::utils::text::{collapse_whitespace, display_len, format_list_item, remove_soft_hyphens, trim_string};
7+
use crate::text::{collapse_whitespace, display_len, format_list_item, remove_soft_hyphens, trim_string};
88

99
bitflags! {
1010
#[derive(Default, Clone, Copy)]

src/ipc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{env, path::{Path, PathBuf}};
1+
use std::{
2+
env,
3+
path::{Path, PathBuf},
4+
};
25

36
pub const IPC_SERVICE: &str = "4242";
47
pub const IPC_TOPIC_OPEN_FILE: &str = "open_file";

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
mod config;
55
mod document;
6+
mod encoding;
67
mod html_to_text;
78
mod ipc;
89
mod parser;
910
mod reader_core;
1011
mod session;
12+
mod text;
1113
mod translation_manager;
14+
mod types;
1215
mod ui;
13-
mod ui_types;
1416
mod update;
15-
mod utils;
1617
mod version;
1718
mod xml_to_text;
19+
mod zip;
1820

1921
use ui::PaperbackApp;
2022
use wxdragon::prelude::{Appearance, SystemOptions, set_appearance};

src/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ pub mod html;
1515
pub mod markdown;
1616
pub mod odp;
1717
pub mod odt;
18+
pub mod ooxml;
19+
pub mod path;
1820
pub mod pdf;
1921
pub mod pptx;
2022
pub mod rtf;
2123
pub mod text;
22-
pub mod utils;
24+
pub mod toc;
25+
pub mod xml;
2326

2427
pub const PASSWORD_REQUIRED_ERROR_PREFIX: &str = "[password_required]";
2528

src/parser/chm.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ use scraper::{ElementRef, Html, Selector};
66

77
use crate::{
88
document::{Document, DocumentBuffer, Marker, MarkerType, ParserContext, ParserFlags, TocItem},
9+
encoding::convert_to_utf8,
910
html_to_text::{HtmlSourceMode, HtmlToText},
10-
parser::{
11-
Parser,
12-
utils::{extract_title_from_path, heading_level_to_marker_type},
13-
},
14-
utils::encoding::convert_to_utf8,
11+
parser::{Parser, path::extract_title_from_path, toc::heading_level_to_marker_type},
1512
};
1613

1714
pub struct ChmParser;

src/parser/docx.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use crate::{
99
html_to_text::HeadingInfo,
1010
parser::{
1111
Parser,
12-
utils::{
13-
build_toc_from_buffer, collect_ooxml_run_text, extract_title_from_path, find_child_element,
14-
heading_level_to_marker_type, read_ooxml_relationships,
15-
},
12+
ooxml::{collect_ooxml_run_text, read_ooxml_relationships},
13+
path::extract_title_from_path,
14+
toc::{build_toc_from_buffer, heading_level_to_marker_type},
15+
xml::find_child_element,
1616
},
17-
utils::zip::read_zip_entry_by_name,
17+
zip::read_zip_entry_by_name,
1818
};
1919

2020
pub struct DocxParser;

src/parser/epub.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ use crate::{
1414
html_to_text::{
1515
HeadingInfo, HtmlSourceMode, HtmlToText, LinkInfo, ListInfo, ListItemInfo, SeparatorInfo, TableInfo,
1616
},
17-
parser::{
18-
Parser,
19-
utils::{extract_title_from_path, heading_level_to_marker_type},
20-
},
21-
utils::{
22-
text::{collapse_whitespace, trim_string, url_decode},
23-
zip::read_zip_entry_by_name,
24-
},
17+
parser::{Parser, path::extract_title_from_path, toc::heading_level_to_marker_type},
18+
text::{collapse_whitespace, trim_string, url_decode},
2519
xml_to_text::XmlToText,
20+
zip::read_zip_entry_by_name,
2621
};
2722

2823
struct SectionContent {

0 commit comments

Comments
 (0)