Compare commits
6
Commits
d8e7cbbc36
...
9917702c4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9917702c4c | ||
|
|
0332e40feb | ||
|
|
eb6c9c5084 | ||
|
|
17e06256c1 | ||
|
|
4d0788e0f5 | ||
|
|
4ca7aa7044 |
Generated
+272
@@ -24,6 +24,17 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8eb277bec05f56a0e0591f155a484cbd0f4f07ff2905051a48c72f004f7ed58"
|
||||||
|
dependencies = [
|
||||||
|
"cipher",
|
||||||
|
"cpubits",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.8.12"
|
version = "0.8.12"
|
||||||
@@ -386,6 +397,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hybrid-array",
|
"hybrid-array",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -457,6 +469,15 @@ version = "1.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bzip2"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
|
||||||
|
dependencies = [
|
||||||
|
"libbz2-rs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "calloop"
|
name = "calloop"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
@@ -595,6 +616,16 @@ dependencies = [
|
|||||||
"half",
|
"half",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.6.1"
|
version = "4.6.1"
|
||||||
@@ -668,6 +699,12 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cmov"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "codespan-reporting"
|
name = "codespan-reporting"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
@@ -730,6 +767,12 @@ dependencies = [
|
|||||||
"tiny-keccak",
|
"tiny-keccak",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "constant_time_eq"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@@ -868,6 +911,12 @@ dependencies = [
|
|||||||
"windows 0.62.2",
|
"windows 0.62.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpubits"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -980,6 +1029,15 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b29fccfdaeb0f9bd90da5759b1d0eaa2f6cfcfe90960124cfc83141ed4e111fd"
|
checksum = "b29fccfdaeb0f9bd90da5759b1d0eaa2f6cfcfe90960124cfc83141ed4e111fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ctutils"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
|
||||||
|
dependencies = [
|
||||||
|
"cmov",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cursor-icon"
|
name = "cursor-icon"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -998,6 +1056,18 @@ version = "0.3.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
|
checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deflate64"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deranged"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
@@ -1007,6 +1077,8 @@ dependencies = [
|
|||||||
"block-buffer",
|
"block-buffer",
|
||||||
"const-oid",
|
"const-oid",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
|
"ctutils",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1043,6 +1115,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
|
"block2 0.6.2",
|
||||||
|
"libc",
|
||||||
"objc2 0.6.3",
|
"objc2 0.6.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1244,6 +1318,7 @@ checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
|
"zlib-rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1717,6 +1792,15 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hmac"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -2175,6 +2259,15 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.12.0"
|
version = "2.12.0"
|
||||||
@@ -2216,8 +2309,10 @@ dependencies = [
|
|||||||
"hex",
|
"hex",
|
||||||
"iced",
|
"iced",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
"mimalloc",
|
||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"rfd",
|
||||||
"rhai",
|
"rhai",
|
||||||
"rodio",
|
"rodio",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
@@ -2225,6 +2320,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"zip",
|
||||||
"zstd",
|
"zstd",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2369,6 +2465,12 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libbz2-rs-sys"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.189"
|
version = "0.2.189"
|
||||||
@@ -2391,6 +2493,15 @@ version = "0.2.16"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libmimalloc-sys"
|
||||||
|
version = "0.1.49"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
@@ -2479,6 +2590,15 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lzma-rust2"
|
||||||
|
version = "0.16.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca93e534d1142d1d0dcca6d25fe302508a5dfb40b302802904577725ea0b695b"
|
||||||
|
dependencies = [
|
||||||
|
"sha2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mach2"
|
name = "mach2"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -2536,6 +2656,15 @@ dependencies = [
|
|||||||
"paste",
|
"paste",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mimalloc"
|
||||||
|
version = "0.1.52"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
|
||||||
|
dependencies = [
|
||||||
|
"libmimalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
version = "0.3.17"
|
version = "0.3.17"
|
||||||
@@ -2664,6 +2793,12 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-conv"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-derive"
|
name = "num-derive"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -3280,6 +3415,16 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pbkdf2"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"hmac",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
@@ -3396,6 +3541,12 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pollster"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "portable-atomic"
|
name = "portable-atomic"
|
||||||
version = "1.13.1"
|
version = "1.13.1"
|
||||||
@@ -3420,6 +3571,18 @@ dependencies = [
|
|||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "powerfmt"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppmd-rust"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "presser"
|
name = "presser"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -3779,6 +3942,33 @@ dependencies = [
|
|||||||
"zune-jpeg",
|
"zune-jpeg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rfd"
|
||||||
|
version = "0.17.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220"
|
||||||
|
dependencies = [
|
||||||
|
"block2 0.6.2",
|
||||||
|
"dispatch2",
|
||||||
|
"js-sys",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"objc2 0.6.3",
|
||||||
|
"objc2-app-kit 0.3.2",
|
||||||
|
"objc2-core-foundation",
|
||||||
|
"objc2-foundation 0.3.2",
|
||||||
|
"percent-encoding",
|
||||||
|
"pollster",
|
||||||
|
"raw-window-handle",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"wayland-backend",
|
||||||
|
"wayland-client",
|
||||||
|
"wayland-protocols",
|
||||||
|
"web-sys",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rgb"
|
name = "rgb"
|
||||||
version = "0.8.53"
|
version = "0.8.53"
|
||||||
@@ -4162,6 +4352,17 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -4743,6 +4944,26 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time"
|
||||||
|
version = "0.3.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134"
|
||||||
|
dependencies = [
|
||||||
|
"deranged",
|
||||||
|
"js-sys",
|
||||||
|
"num-conv",
|
||||||
|
"powerfmt",
|
||||||
|
"serde_core",
|
||||||
|
"time-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-core"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiny-keccak"
|
name = "tiny-keccak"
|
||||||
version = "2.0.2"
|
version = "2.0.2"
|
||||||
@@ -4997,6 +5218,12 @@ dependencies = [
|
|||||||
"core_maths",
|
"core_maths",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typed-path"
|
||||||
|
version = "0.12.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.20.0"
|
version = "1.20.0"
|
||||||
@@ -6437,12 +6664,57 @@ dependencies = [
|
|||||||
"syn 2.0.114",
|
"syn 2.0.114",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zip"
|
||||||
|
version = "8.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b"
|
||||||
|
dependencies = [
|
||||||
|
"aes",
|
||||||
|
"bzip2",
|
||||||
|
"constant_time_eq",
|
||||||
|
"crc32fast",
|
||||||
|
"deflate64",
|
||||||
|
"flate2",
|
||||||
|
"getrandom 0.4.1",
|
||||||
|
"hmac",
|
||||||
|
"indexmap",
|
||||||
|
"lzma-rust2",
|
||||||
|
"memchr",
|
||||||
|
"pbkdf2",
|
||||||
|
"ppmd-rust",
|
||||||
|
"sha1",
|
||||||
|
"time",
|
||||||
|
"typed-path",
|
||||||
|
"zeroize",
|
||||||
|
"zopfli",
|
||||||
|
"zstd",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zlib-rs"
|
||||||
|
version = "0.6.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
|
checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zopfli"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"crc32fast",
|
||||||
|
"log",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.13.3"
|
version = "0.13.3"
|
||||||
|
|||||||
+12
-5
@@ -19,6 +19,17 @@ sha2 = "0.11.0"
|
|||||||
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros"] }
|
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
zstd = "0.13.3"
|
zstd = "0.13.3"
|
||||||
|
zip = "8.6.0"
|
||||||
|
rfd = "0.17.2"
|
||||||
|
mimalloc = "0.1.52"
|
||||||
|
|
||||||
|
[profile.super-release]
|
||||||
|
inherits = "release"
|
||||||
|
codegen-units = 1
|
||||||
|
lto = true
|
||||||
|
opt-level = 3
|
||||||
|
strip = true
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.8.2"
|
criterion = "0.8.2"
|
||||||
@@ -27,8 +38,4 @@ criterion = "0.8.2"
|
|||||||
name = "split_bench" # Имя файла в benches/ без расширения
|
name = "split_bench" # Имя файла в benches/ без расширения
|
||||||
harness = false # Отключаем стандартный тестовый раннер
|
harness = false # Отключаем стандартный тестовый раннер
|
||||||
|
|
||||||
[profile.super-release]
|
|
||||||
inherits = "release"
|
|
||||||
codegen-units = 1
|
|
||||||
lto = true
|
|
||||||
opt-level = 3
|
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
use rusqlite::Connection;
|
||||||
|
use serde_json::Value;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ImportGroup {
|
||||||
|
pub id: u64,
|
||||||
|
pub name: String,
|
||||||
|
pub fields: Vec<String>,
|
||||||
|
pub length: u64,
|
||||||
|
pub mapping: HashMap<String, String>,
|
||||||
|
pub imported: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportNote {
|
||||||
|
pub tags: String,
|
||||||
|
pub fields: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_groups(connection: &Connection) -> ImportData {
|
||||||
|
let json_models: String = connection
|
||||||
|
.query_one("select models from col", (), |row| row.get(0))
|
||||||
|
.unwrap();
|
||||||
|
let raw: Value = serde_json::from_str(json_models.as_str()).unwrap();
|
||||||
|
let sets = raw.as_object().unwrap();
|
||||||
|
let mut total_data = ImportData(vec![]);
|
||||||
|
|
||||||
|
let mut count_stmt = connection
|
||||||
|
.prepare("select mid, count(id) from notes group by mid")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let counts = count_stmt
|
||||||
|
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
||||||
|
.unwrap()
|
||||||
|
.map(|x| x.unwrap())
|
||||||
|
.collect::<Vec<(i64, i64)>>();
|
||||||
|
|
||||||
|
for (_, collection) in sets {
|
||||||
|
let fields = collection["flds"]
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|x| x["name"].as_str().unwrap().to_string())
|
||||||
|
.collect();
|
||||||
|
let mut group = ImportGroup {
|
||||||
|
id: collection["id"].as_u64().unwrap(),
|
||||||
|
name: collection["name"].as_str().unwrap().to_string(),
|
||||||
|
fields,
|
||||||
|
mapping: Default::default(),
|
||||||
|
length: 0,
|
||||||
|
imported: false,
|
||||||
|
};
|
||||||
|
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
|
||||||
|
group.length = *count as u64
|
||||||
|
}
|
||||||
|
println!("{:?}", group);
|
||||||
|
total_data.0.push(group);
|
||||||
|
}
|
||||||
|
total_data
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Vec<ImportNote> {
|
||||||
|
let mut count_stmt = connection
|
||||||
|
.prepare("select tags, flds from notes where mid == ?1;")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
count_stmt.query_map((group_id as i64, ), |row| {
|
||||||
|
Ok(ImportNote {
|
||||||
|
tags: row.get(0)?,
|
||||||
|
fields: row.get::<usize, String>(1)?
|
||||||
|
.split('')
|
||||||
|
.map(|x| x.to_string())
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
}).unwrap().map(|x| x.unwrap()).collect::<Vec<ImportNote>>()
|
||||||
|
}
|
||||||
@@ -6,3 +6,4 @@ pub(crate) mod sqlite;
|
|||||||
pub(crate) mod voice;
|
pub(crate) mod voice;
|
||||||
pub(crate) mod words;
|
pub(crate) mod words;
|
||||||
pub(crate) mod web_api;
|
pub(crate) mod web_api;
|
||||||
|
pub(crate) mod import;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{WordData, WordGroup};
|
||||||
use rusqlite::Connection;
|
use rusqlite::{params, Connection};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
pub fn add_word(word: &mut WordData, connection: &Connection) {
|
||||||
let index = connection
|
let index = connection
|
||||||
.query_row(
|
.query_row(
|
||||||
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5\
|
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id",
|
||||||
) RETURNING id",
|
|
||||||
(
|
(
|
||||||
&word.key,
|
&word.key,
|
||||||
&word.value,
|
&word.value,
|
||||||
@@ -24,6 +23,40 @@ pub fn add_word(word: &mut WordData, connection: &Connection) {
|
|||||||
word.id = index;
|
word.id = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_words(words: &mut[WordData], connection: &mut Connection) {
|
||||||
|
let tx = connection.transaction().unwrap();
|
||||||
|
let count = words.len();
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut stmt = tx.prepare(
|
||||||
|
"INSERT INTO words (key, value, tags, more, group_id) VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
for word in words.iter() {
|
||||||
|
stmt.execute(params![word.key, word.value, word.tags, serde_json::to_string(&word.additional).unwrap(), word.group_id]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.commit().unwrap();
|
||||||
|
|
||||||
|
let last_index: u32 = connection
|
||||||
|
.query_one(
|
||||||
|
"SELECT seq from sqlite_sequence WHERE name == ?1",
|
||||||
|
("words".to_string(),),
|
||||||
|
|row| row.get(0),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let start_index = last_index - (count as u32) + 1;
|
||||||
|
|
||||||
|
let mut index = 0;
|
||||||
|
for id in start_index..=last_index {
|
||||||
|
words[index].id = id;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||||
if word.id == 0 {
|
if word.id == 0 {
|
||||||
add_word(word, &connection);
|
add_word(word, &connection);
|
||||||
@@ -126,7 +159,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
|||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE word_group SET name = ?1 WHERE id = ?5",
|
"UPDATE word_group SET name = ?1 WHERE id = ?2",
|
||||||
(&group.name, &group.id),
|
(&group.name, &group.id),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
|
|||||||
+103
-71
@@ -1,8 +1,9 @@
|
|||||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||||
use crate::dictionary::DictionaryMessage::*;
|
use crate::dictionary::DictionaryMessage::*;
|
||||||
use crate::dictionary_test::DictionaryQuizState;
|
use crate::dictionary_test::DictionaryQuizState;
|
||||||
|
use crate::import::ImportState;
|
||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{WordData, WordGroup};
|
||||||
use crate::navigation::Page::Word;
|
use crate::navigation::Page::{Import, Word};
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::word::WordState;
|
use crate::word::WordState;
|
||||||
@@ -14,7 +15,8 @@ use iced::widget::button::{danger, text};
|
|||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
use iced::widget::text_input::default;
|
use iced::widget::text_input::default;
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{Border, Color, Length, Shadow, Task};
|
use iced::{Border, Color, Shadow, Task};
|
||||||
|
use iced_core::Length::Fill;
|
||||||
use rand::random_range;
|
use rand::random_range;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@@ -59,6 +61,7 @@ pub enum DictionaryMessage {
|
|||||||
DeleteGroup,
|
DeleteGroup,
|
||||||
ChangeDirection,
|
ChangeDirection,
|
||||||
TrySave(usize),
|
TrySave(usize),
|
||||||
|
ToImport,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||||
@@ -97,35 +100,21 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let ToImport = message {
|
||||||
|
return Some(Import(ImportState::new(self.state.clone())));
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
let len = self.state.lock().unwrap().dictionary.len();
|
||||||
|
|
||||||
|
self.include_map = vec![false; len];
|
||||||
|
self.tag_map = Default::default();
|
||||||
|
self.update_tags();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DictionaryState {
|
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
|
||||||
let len = state.lock().unwrap().dictionary.len();
|
|
||||||
|
|
||||||
let mut result = DictionaryState {
|
|
||||||
include_map: vec![false; len],
|
|
||||||
selected_group_index: 0,
|
|
||||||
state,
|
|
||||||
tag_map: HashMap::new(),
|
|
||||||
reverse: false,
|
|
||||||
search: "".to_string(),
|
|
||||||
no_typing: true,
|
|
||||||
reverse_list: true,
|
|
||||||
auto_save_queue: HashMap::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
result.update_tags();
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
NewWord => {
|
NewWord => {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
@@ -244,16 +233,24 @@ impl DictionaryState {
|
|||||||
if self.selected_group_index == 0 {
|
if self.selected_group_index == 0 {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
|
|
||||||
if let Some(group) = state.word_groups.get(self.selected_group_index) {
|
if let Some(group) = state.word_groups.get(self.selected_group_index) {
|
||||||
|
let remove_group_id = group.id;
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
|
|
||||||
delete_group(group, connection);
|
delete_group(group, connection);
|
||||||
state.word_groups.remove(self.selected_group_index);
|
state.word_groups.remove(self.selected_group_index);
|
||||||
|
state
|
||||||
|
.dictionary
|
||||||
|
.retain(|word| word.group_id != remove_group_id);
|
||||||
self.selected_group_index = 0;
|
self.selected_group_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_tags()
|
||||||
|
}
|
||||||
ChangeDirection => {
|
ChangeDirection => {
|
||||||
self.reverse_list = !self.reverse_list;
|
self.reverse_list = !self.reverse_list;
|
||||||
}
|
}
|
||||||
@@ -267,11 +264,55 @@ impl DictionaryState {
|
|||||||
self.save_word(word_index);
|
self.save_word(word_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ToImport => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
|
back_overlay(
|
||||||
|
row![
|
||||||
|
iced::widget::column![
|
||||||
|
self.groups_panel(),
|
||||||
|
row![horizontal().width(8), self.words_list(),],
|
||||||
|
row![
|
||||||
|
button("Добавить слово").style(jl_button).on_press(NewWord),
|
||||||
|
horizontal().width(Fill),
|
||||||
|
button("Импорт").style(text).on_press(ToImport),
|
||||||
|
]
|
||||||
|
]
|
||||||
|
.spacing(5),
|
||||||
|
self.filters(),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into(),
|
||||||
|
Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DictionaryState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||||
|
let len = state.lock().unwrap().dictionary.len();
|
||||||
|
|
||||||
|
let mut result = DictionaryState {
|
||||||
|
include_map: vec![false; len],
|
||||||
|
selected_group_index: 0,
|
||||||
|
state,
|
||||||
|
tag_map: HashMap::new(),
|
||||||
|
reverse: false,
|
||||||
|
search: "".to_string(),
|
||||||
|
no_typing: true,
|
||||||
|
reverse_list: true,
|
||||||
|
auto_save_queue: HashMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
result.update_tags();
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
fn save_word(&mut self, i: usize) {
|
fn save_word(&mut self, i: usize) {
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
@@ -291,40 +332,27 @@ impl DictionaryState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
|
||||||
back_overlay(
|
|
||||||
row![
|
|
||||||
iced::widget::column![
|
|
||||||
self.groups_panel(),
|
|
||||||
row![horizontal().width(8), self.words_list(),],
|
|
||||||
button("Добавить слово").style(jl_button).on_press(NewWord),
|
|
||||||
]
|
|
||||||
.spacing(5),
|
|
||||||
self.filters(),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
let mut col = Column::new().width(Length::Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
|
|
||||||
let mut range = (0..self.include_map.len()).collect::<Vec<_>>();
|
|
||||||
let state = self.state.lock().unwrap();
|
let state = self.state.lock().unwrap();
|
||||||
let group_id = state.word_groups[self.selected_group_index].id;
|
let group_id = state.word_groups[self.selected_group_index].id;
|
||||||
let dict = &mut state.dictionary.clone();
|
|
||||||
|
|
||||||
|
let dict = &state.dictionary;
|
||||||
|
|
||||||
|
let mut index = 0;
|
||||||
|
|
||||||
|
for access_index in 0..dict.len() {
|
||||||
|
let mut i = access_index;
|
||||||
if self.reverse_list {
|
if self.reverse_list {
|
||||||
dict.reverse()
|
i = dict.len() - access_index - 1;
|
||||||
} else {
|
}
|
||||||
range = range.iter().rev().map(|x| *x).collect::<Vec<usize>>();
|
let word = &dict[i];
|
||||||
|
if word.group_id != group_id {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for word in dict {
|
|
||||||
let i = range.pop().unwrap();
|
|
||||||
if !self.search.is_empty() {
|
if !self.search.is_empty() {
|
||||||
if word.key.contains(&self.search) == false
|
if word.key.contains(&self.search) == false
|
||||||
&& word.value.contains(&self.search) == false
|
&& word.value.contains(&self.search) == false
|
||||||
@@ -334,22 +362,20 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if word.group_id != group_id {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let word_line_data = WordLineState {
|
let word_line_data = WordLineState {
|
||||||
is_included: self.include_map[i],
|
is_included: self.include_map[i],
|
||||||
key: word.key.clone(),
|
key: word.key.clone(),
|
||||||
value: word.value.clone(),
|
value: word.value.clone(),
|
||||||
tags: word.tags.clone(),
|
tags: word.tags.clone(),
|
||||||
id: word.id,
|
id: word.id,
|
||||||
index: i
|
index: i,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
|
||||||
let lazy_line = lazy(word_line_data, move |data| {
|
let lazy_line = lazy(word_line_data, move |data| {
|
||||||
let index = data.index;
|
let index = data.index;
|
||||||
let mut line = Row::new().width(Length::Fill).align_y(Center);
|
let mut line = Row::new().width(Fill).align_y(Center);
|
||||||
line = line.push(
|
line = line.push(
|
||||||
checkbox(data.is_included)
|
checkbox(data.is_included)
|
||||||
.label("")
|
.label("")
|
||||||
@@ -360,7 +386,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Слово", &data.key)
|
text_input("Слово", &data.key)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetKey(index, string))
|
.on_input(move |string| SetKey(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -372,7 +398,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Перевод", &data.value)
|
text_input("Перевод", &data.value)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetValue(index, string))
|
.on_input(move |string| SetValue(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -385,7 +411,7 @@ impl DictionaryState {
|
|||||||
line = line.push(
|
line = line.push(
|
||||||
text_input("Теги", &data.tags)
|
text_input("Теги", &data.tags)
|
||||||
.size(ACCENT_FONT_SIZE)
|
.size(ACCENT_FONT_SIZE)
|
||||||
.width(Length::Fill)
|
.width(Fill)
|
||||||
.on_input(move |string| SetTags(index, string))
|
.on_input(move |string| SetTags(index, string))
|
||||||
.on_submit(SubmitWord(index))
|
.on_submit(SubmitWord(index))
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
@@ -414,14 +440,12 @@ impl DictionaryState {
|
|||||||
line
|
line
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
col = col.push(lazy_line);
|
col = col.push(lazy_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Drawing {index} lines");
|
||||||
println!("Words rendering time: {:?}", time.elapsed());
|
println!("Words rendering time: {:?}", time.elapsed());
|
||||||
scrollable(col).height(Length::Fill).into()
|
scrollable(col).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
@@ -430,7 +454,7 @@ impl DictionaryState {
|
|||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text_input("Поиск", &self.search)
|
text_input("Поиск", &self.search)
|
||||||
.on_input(Search)
|
.on_input(Search)
|
||||||
.width(Length::Fill),
|
.width(Fill),
|
||||||
text!("Всего слов: {}", dict.len()),
|
text!("Всего слов: {}", dict.len()),
|
||||||
text!(
|
text!(
|
||||||
"Выбрано слов: {}",
|
"Выбрано слов: {}",
|
||||||
@@ -443,10 +467,10 @@ impl DictionaryState {
|
|||||||
toggler(self.reverse)
|
toggler(self.reverse)
|
||||||
.label("Обратный тест")
|
.label("Обратный тест")
|
||||||
.on_toggle(SetReverse),
|
.on_toggle(SetReverse),
|
||||||
button(text!("Тест").center().width(Length::Fill))
|
button(text!("Тест").center().width(Fill))
|
||||||
.style(cta_button)
|
.style(cta_button)
|
||||||
.on_press(Test)
|
.on_press(Test)
|
||||||
.width(Length::Fill),
|
.width(Fill),
|
||||||
]
|
]
|
||||||
.width(250)
|
.width(250)
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -454,7 +478,7 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
let mut col = Column::new().width(Length::Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
col = col.push(
|
col = col.push(
|
||||||
button("Сбросить")
|
button("Сбросить")
|
||||||
.on_press(ResetTags)
|
.on_press(ResetTags)
|
||||||
@@ -476,7 +500,7 @@ impl DictionaryState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
container(scrollable(col)).height(Length::Fill).into()
|
container(scrollable(col)).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_tags(&mut self) {
|
fn update_tags(&mut self) {
|
||||||
@@ -529,7 +553,7 @@ impl DictionaryState {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|word| (split_with_coma(word.tags.as_str()), word.group_id))
|
.map(|word| (split_with_coma(word.tags.as_str()), word.group_id))
|
||||||
.map(|(tags, word_group_id)| {
|
.map(|(tags, word_group_id)| {
|
||||||
tags.iter().all(|t| include_tags.contains(t)) && word_group_id == group_id
|
tags.iter().all(|t| include_tags.contains(t)) && tags.len() != 0 && word_group_id == group_id
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -556,7 +580,7 @@ impl DictionaryState {
|
|||||||
let group = state.word_groups[self.selected_group_index].clone();
|
let group = state.word_groups[self.selected_group_index].clone();
|
||||||
|
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
scrollable(row).width(Length::Fill).horizontal(),
|
scrollable(row).width(Fill).horizontal(),
|
||||||
row![
|
row![
|
||||||
button("⇳").on_press(ChangeDirection).style(jl_button),
|
button("⇳").on_press(ChangeDirection).style(jl_button),
|
||||||
text_input("Название группы слов", &group.name)
|
text_input("Название группы слов", &group.name)
|
||||||
@@ -564,12 +588,20 @@ impl DictionaryState {
|
|||||||
.width(250)
|
.width(250)
|
||||||
.on_submit(SaveGroup),
|
.on_submit(SaveGroup),
|
||||||
horizontal(),
|
horizontal(),
|
||||||
button("Удалить").style(danger).on_press(DeleteGroup),
|
self.group_delete_button(),
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING / 2.0)
|
.spacing(DEFAULT_SPACING / 2.0)
|
||||||
]
|
]
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn group_delete_button(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
|
if self.selected_group_index != 0 {
|
||||||
|
button("Удалить").style(danger).on_press(DeleteGroup).into()
|
||||||
|
} else {
|
||||||
|
space().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
pub fn split_with_coma(ts: &str) -> Vec<String> {
|
||||||
|
|||||||
+21
-19
@@ -44,25 +44,8 @@ impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl DictionaryQuizState {
|
fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
||||||
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
|
||||||
DictionaryQuizState {
|
|
||||||
words,
|
|
||||||
current_set: Vec::new(),
|
|
||||||
answer: "".to_string(),
|
|
||||||
view: "---".to_string(),
|
|
||||||
correct: "".to_string(),
|
|
||||||
score: Default::default(),
|
|
||||||
is_help: false,
|
|
||||||
reverse,
|
|
||||||
laps: 0,
|
|
||||||
no_typing,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: DictionaryQuizMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
AnswerChanged(c) => self.answer = c.clone(),
|
AnswerChanged(c) => self.answer = c.clone(),
|
||||||
@@ -72,7 +55,7 @@ impl DictionaryQuizState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
fn view(&self) -> Element<'_, DictionaryQuizMessage> {
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
self.laps(),
|
self.laps(),
|
||||||
@@ -119,6 +102,25 @@ impl DictionaryQuizState {
|
|||||||
.center_x(Fill)
|
.center_x(Fill)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DictionaryQuizState {
|
||||||
|
pub fn new(words: Vec<WordData>, reverse: bool, no_typing: bool) -> DictionaryQuizState {
|
||||||
|
DictionaryQuizState {
|
||||||
|
words,
|
||||||
|
current_set: Vec::new(),
|
||||||
|
answer: "".to_string(),
|
||||||
|
view: "---".to_string(),
|
||||||
|
correct: "".to_string(),
|
||||||
|
score: Default::default(),
|
||||||
|
is_help: false,
|
||||||
|
reverse,
|
||||||
|
laps: 0,
|
||||||
|
no_typing,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn submit(&mut self) {
|
fn submit(&mut self) {
|
||||||
if self.view == "---" {
|
if self.view == "---" {
|
||||||
self.show_next();
|
self.show_next();
|
||||||
|
|||||||
+19
-18
@@ -25,6 +25,25 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
|
|||||||
}
|
}
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
|
fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, HistoryMessage> {
|
||||||
|
back_overlay(
|
||||||
|
iced::widget::row![
|
||||||
|
horizontal().width(FillPortion(1)),
|
||||||
|
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
||||||
|
.height(Fill)
|
||||||
|
.width(FillPortion(5)),
|
||||||
|
horizontal().width(FillPortion(1))
|
||||||
|
]
|
||||||
|
.height(Fill)
|
||||||
|
.width(Fill)
|
||||||
|
.into(),
|
||||||
|
Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoryState {
|
impl HistoryState {
|
||||||
@@ -49,25 +68,7 @@ impl HistoryState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, _: HistoryMessage) -> Task<RootMessage> {
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, HistoryMessage> {
|
|
||||||
back_overlay(
|
|
||||||
iced::widget::row![
|
|
||||||
horizontal().width(FillPortion(1)),
|
|
||||||
scrollable(self.history_lines().padding(DEFAULT_SPACING))
|
|
||||||
.height(Fill)
|
|
||||||
.width(FillPortion(5)),
|
|
||||||
horizontal().width(FillPortion(1))
|
|
||||||
]
|
|
||||||
.height(Fill)
|
|
||||||
.width(Fill)
|
|
||||||
.into(),
|
|
||||||
Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
fn history_lines(&self) -> Column<'_, HistoryMessage> {
|
||||||
let mut column = Column::new();
|
let mut column = Column::new();
|
||||||
|
|||||||
+554
@@ -0,0 +1,554 @@
|
|||||||
|
use crate::AppState;
|
||||||
|
use crate::data_provider::import::{ImportData, ImportGroup, get_words_of_group, load_groups};
|
||||||
|
use crate::data_provider::words::{add_group, add_words};
|
||||||
|
use crate::dictionary::app_data_dir;
|
||||||
|
use crate::import::ImportMessage::*;
|
||||||
|
use crate::lang::{WordData, WordGroup};
|
||||||
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
|
use crate::styling::*;
|
||||||
|
use iced::widget::button::danger;
|
||||||
|
use iced::widget::container::success;
|
||||||
|
use iced::widget::{
|
||||||
|
Row, button, checkbox, column, container, progress_bar, row, rule, text, text_input,
|
||||||
|
};
|
||||||
|
use iced::widget::{scrollable, space};
|
||||||
|
use iced::{Element, Task};
|
||||||
|
use iced_core::Alignment::Center;
|
||||||
|
use iced_core::Length::Fill;
|
||||||
|
use iced_core::Padding;
|
||||||
|
use rfd::AsyncFileDialog;
|
||||||
|
use rusqlite::Connection;
|
||||||
|
use std::fs::{File, OpenOptions};
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tokio::task::spawn_blocking;
|
||||||
|
use zip::ZipArchive;
|
||||||
|
|
||||||
|
const DEFAULT_FIELDS: [&str; 6] = ["key", "value", "tags", "reading", "context", "description"];
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ImportState {
|
||||||
|
state: Arc<Mutex<AppState>>,
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
import_data: Option<ImportData>,
|
||||||
|
selected_index: usize,
|
||||||
|
selected_property: Option<String>,
|
||||||
|
custom_property_name: String,
|
||||||
|
skip_empty: bool,
|
||||||
|
separator: String,
|
||||||
|
progress: Option<Arc<Mutex<f32>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum ImportMessage {
|
||||||
|
Back,
|
||||||
|
SelectFile,
|
||||||
|
UpdateFile(PathBuf),
|
||||||
|
UpdateImport(ImportData),
|
||||||
|
NextGroup,
|
||||||
|
PreviousGroup,
|
||||||
|
OpenPropertyMapper(String),
|
||||||
|
EditCustomProperty(String),
|
||||||
|
SetupCustomProperty,
|
||||||
|
SetupDefaultProperty(String),
|
||||||
|
SetupDirect,
|
||||||
|
RemoveMapping(String),
|
||||||
|
SwitchSkipEmpty(bool),
|
||||||
|
EditSeparator(String),
|
||||||
|
StartImport,
|
||||||
|
NextProgress,
|
||||||
|
ImportFinished,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NavigatedPage<ImportMessage> for ImportState {
|
||||||
|
fn navigate(&self, message: &ImportMessage) -> Option<Page> {
|
||||||
|
if let Some(_) = self.progress {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Back = message {
|
||||||
|
return Some(Page::PreviousPage);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn navigated(&mut self) {}
|
||||||
|
|
||||||
|
fn update(&mut self, message: ImportMessage) -> Task<RootMessage> {
|
||||||
|
match message {
|
||||||
|
Back => {}
|
||||||
|
UpdateFile(path) => {
|
||||||
|
self.path = Some(path);
|
||||||
|
return self.load_package();
|
||||||
|
}
|
||||||
|
SelectFile => return Self::select_import_file(),
|
||||||
|
UpdateImport(import) => {
|
||||||
|
self.import_data = Some(import);
|
||||||
|
}
|
||||||
|
NextGroup => {
|
||||||
|
self.selected_index += 1;
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
PreviousGroup => {
|
||||||
|
self.selected_index -= 1;
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
OpenPropertyMapper(prop) => self.selected_property = Some(prop),
|
||||||
|
EditCustomProperty(prop_name) => self.custom_property_name = prop_name,
|
||||||
|
SetupCustomProperty => {
|
||||||
|
self.setup_mapping(self.custom_property_name.clone());
|
||||||
|
}
|
||||||
|
SetupDefaultProperty(prop_name) => {
|
||||||
|
self.setup_mapping(prop_name);
|
||||||
|
}
|
||||||
|
SetupDirect => {
|
||||||
|
self.setup_mapping(self.selected_property.clone().unwrap());
|
||||||
|
}
|
||||||
|
RemoveMapping(pro_name) => {
|
||||||
|
self.remove_mapping(pro_name);
|
||||||
|
}
|
||||||
|
SwitchSkipEmpty(skip) => {
|
||||||
|
self.skip_empty = skip;
|
||||||
|
}
|
||||||
|
EditSeparator(separator) => {
|
||||||
|
self.separator = separator.clone();
|
||||||
|
}
|
||||||
|
StartImport => {
|
||||||
|
self.progress = Some(Arc::new(Mutex::new(0.0)));
|
||||||
|
return Task::batch([self.start_import(), self.next_progress()]);
|
||||||
|
}
|
||||||
|
NextProgress => {
|
||||||
|
if self.progress.is_none() {
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
|
return self.next_progress();
|
||||||
|
}
|
||||||
|
ImportFinished => {
|
||||||
|
self.progress = None;
|
||||||
|
let group = self
|
||||||
|
.import_data.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.get_mut(self.selected_index)
|
||||||
|
.unwrap();
|
||||||
|
group.imported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<'_, ImportMessage> {
|
||||||
|
back_overlay(
|
||||||
|
{
|
||||||
|
if let Some(value) = &self.progress {
|
||||||
|
column![progress_bar(0f32..=1f32, *value.lock().unwrap()),]
|
||||||
|
.spacing(QUARTER_SPACING)
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
scrollable(
|
||||||
|
column![
|
||||||
|
row![
|
||||||
|
button("Выбрать файл").style(jl_button).on_press(SelectFile),
|
||||||
|
text!("{}", {
|
||||||
|
if let Some(path) = &self.path {
|
||||||
|
path.to_string_lossy().to_string()
|
||||||
|
} else {
|
||||||
|
"Файл не выбран".to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
.align_y(Center)
|
||||||
|
.spacing(DEFAULT_SPACING),
|
||||||
|
self.selected_group()
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING),
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportState {
|
||||||
|
fn selected_group(&self) -> Element<'_, ImportMessage> {
|
||||||
|
if let Some(data) = &self.import_data {
|
||||||
|
let group = &data.0[self.selected_index];
|
||||||
|
return column![
|
||||||
|
row![
|
||||||
|
self.back_button(),
|
||||||
|
space().width(Fill),
|
||||||
|
text!("{}", group.name.clone()),
|
||||||
|
space().width(Fill),
|
||||||
|
self.next_button()
|
||||||
|
]
|
||||||
|
.width(Fill),
|
||||||
|
text!("Количество карточек: {}", group.length),
|
||||||
|
self.property_mapper(group),
|
||||||
|
self.import_settings(),
|
||||||
|
self.import_button(group),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
space().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_button(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
if group.imported {
|
||||||
|
return container(text!("Группа слов успешно импортирована")).padding(HALF_SPACING).align_x(Center)
|
||||||
|
.style(success)
|
||||||
|
.width(Fill)
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
button("Начать импорт")
|
||||||
|
.style(cta_button)
|
||||||
|
.on_press(StartImport)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_mapper(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
column![
|
||||||
|
self.property_list(group),
|
||||||
|
rule::horizontal(2),
|
||||||
|
self.property_selector()
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_list(&self, group: &ImportGroup) -> Element<'_, ImportMessage> {
|
||||||
|
let mut row = Row::new();
|
||||||
|
for prop in &group.fields {
|
||||||
|
let primary_button_name = (*prop).clone();
|
||||||
|
if let Some(mapped) = group.mapping.get(prop.clone().as_str()) {
|
||||||
|
row = row.push(
|
||||||
|
column![
|
||||||
|
button(text!("{}", primary_button_name)),
|
||||||
|
"↕",
|
||||||
|
button(text!("{}", mapped))
|
||||||
|
.style(danger)
|
||||||
|
.on_press(RemoveMapping(mapped.as_str().to_string())),
|
||||||
|
]
|
||||||
|
.align_x(Center),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
row = row.push(
|
||||||
|
button(text!("{}", primary_button_name))
|
||||||
|
.on_press(OpenPropertyMapper(prop.clone())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scrollable(row.spacing(HALF_SPACING).padding(Padding {
|
||||||
|
top: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
bottom: DEFAULT_SPACING,
|
||||||
|
left: 0.0,
|
||||||
|
}))
|
||||||
|
.horizontal()
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn property_selector(&self) -> Element<'_, ImportMessage> {
|
||||||
|
if self.selected_property == None {
|
||||||
|
return space().into();
|
||||||
|
}
|
||||||
|
column![
|
||||||
|
self.available_properties(),
|
||||||
|
button("Добавить напрямую").on_press(SetupDirect),
|
||||||
|
row![
|
||||||
|
text_input("Пользовательское поле", &self.custom_property_name)
|
||||||
|
.on_input(EditCustomProperty),
|
||||||
|
button("Установить привязку").on_press(SetupCustomProperty)
|
||||||
|
]
|
||||||
|
.spacing(QUARTER_SPACING)
|
||||||
|
]
|
||||||
|
.spacing(HALF_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn available_properties(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut row = Row::new();
|
||||||
|
|
||||||
|
for default in DEFAULT_FIELDS {
|
||||||
|
// if group.mapping.values().any(|name| name == default) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
row = row.push(
|
||||||
|
button(text!("{default}")).on_press(SetupDefaultProperty(default.to_string())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
row.spacing(HALF_SPACING).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_settings(&self) -> Element<'_, ImportMessage> {
|
||||||
|
column![
|
||||||
|
checkbox(self.skip_empty)
|
||||||
|
.label("Пропускать пустые строки")
|
||||||
|
.on_toggle(SwitchSkipEmpty),
|
||||||
|
column![
|
||||||
|
text!("Разделитель при множественном объединении"),
|
||||||
|
text_input("", &self.separator).on_input(EditSeparator)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn back_button(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut button = button("←").style(button::text);
|
||||||
|
if self.selected_index > 0 {
|
||||||
|
button = button.on_press(PreviousGroup);
|
||||||
|
}
|
||||||
|
button.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_button(&self) -> Element<'_, ImportMessage> {
|
||||||
|
let mut button = button("→").style(button::text);
|
||||||
|
if self.selected_index < self.import_data.as_ref().unwrap().0.len() - 1 {
|
||||||
|
button = button.on_press(NextGroup);
|
||||||
|
}
|
||||||
|
button.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> ImportState {
|
||||||
|
ImportState {
|
||||||
|
state,
|
||||||
|
path: None,
|
||||||
|
import_data: None,
|
||||||
|
selected_index: 0,
|
||||||
|
selected_property: None,
|
||||||
|
custom_property_name: "".to_string(),
|
||||||
|
skip_empty: true,
|
||||||
|
separator: ", ".to_string(),
|
||||||
|
progress: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_import_file() -> Task<RootMessage> {
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
let file = AsyncFileDialog::new()
|
||||||
|
.add_filter("Anki", &["apkg"])
|
||||||
|
.pick_file()
|
||||||
|
.await;
|
||||||
|
if let Some(file) = file {
|
||||||
|
return Some(file.path().into());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
},
|
||||||
|
|result| {
|
||||||
|
if let Some(path) = result {
|
||||||
|
RootMessage::Import(UpdateFile(path))
|
||||||
|
} else {
|
||||||
|
RootMessage::None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_package(&self) -> Task<RootMessage> {
|
||||||
|
let path = self.path.clone().unwrap();
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
spawn_blocking(move || {
|
||||||
|
Self::extract_import_file(path)?;
|
||||||
|
let data = Self::read_import_file()?;
|
||||||
|
return Ok(data);
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
},
|
||||||
|
|result: Result<ImportData, ()>| {
|
||||||
|
if let Ok(import) = result {
|
||||||
|
RootMessage::Import(UpdateImport(import))
|
||||||
|
} else {
|
||||||
|
RootMessage::None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_import_file(path: PathBuf) -> Result<(), ()> {
|
||||||
|
let file = File::open(path).map_err(|_| ())?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let mut archive = ZipArchive::new(reader).map_err(|_| ())?;
|
||||||
|
let db_file = archive.by_name("collection.anki2");
|
||||||
|
if let Ok(mut file) = db_file {
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let mut temp_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&temp_file_path)
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
std::io::copy(&mut file, &mut temp_file).map_err(|_| ())?;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn read_import_file() -> Result<ImportData, ()> {
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||||
|
let data = load_groups(&connection);
|
||||||
|
Ok(data)
|
||||||
|
}
|
||||||
|
fn setup_mapping(&mut self, property_name: String) {
|
||||||
|
let group = self.import_data.as_mut().unwrap();
|
||||||
|
let group = group.0.get_mut(self.selected_index).unwrap();
|
||||||
|
group
|
||||||
|
.mapping
|
||||||
|
.insert(self.selected_property.clone().unwrap(), property_name);
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
fn remove_mapping(&mut self, property_name: String) {
|
||||||
|
let group = self.import_data.as_mut().unwrap();
|
||||||
|
let group = group.0.get_mut(self.selected_index).unwrap();
|
||||||
|
let remove_key = group
|
||||||
|
.mapping
|
||||||
|
.keys()
|
||||||
|
.find(|key| group.mapping[*key] == property_name)
|
||||||
|
.unwrap();
|
||||||
|
group.mapping.remove(remove_key.clone().as_str());
|
||||||
|
self.selected_property = None;
|
||||||
|
self.custom_property_name.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_import(&self) -> Task<RootMessage> {
|
||||||
|
let state = self.state.clone();
|
||||||
|
let separator = self.separator.clone();
|
||||||
|
let skip_empty = self.skip_empty;
|
||||||
|
let group = self.import_data.as_ref().unwrap().0[self.selected_index].clone();
|
||||||
|
let progress = self.progress.clone().unwrap();
|
||||||
|
println!("{}", group.name);
|
||||||
|
Task::perform(
|
||||||
|
async move {
|
||||||
|
spawn_blocking(move || {
|
||||||
|
let temp_file_path = app_data_dir().join("import");
|
||||||
|
let connection = Connection::open(&temp_file_path).map_err(|_| ())?;
|
||||||
|
let import_list = get_words_of_group(&connection, group.id);
|
||||||
|
let mut words_list = Vec::with_capacity(import_list.len());
|
||||||
|
|
||||||
|
let map_indices = Self::get_mapping_indices(&group);
|
||||||
|
let mut group_entity = WordGroup {
|
||||||
|
id: 0,
|
||||||
|
name: group.name.clone(),
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let state = state.lock().unwrap();
|
||||||
|
add_group(&mut group_entity, &state.connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
let group_id = group_entity.id;
|
||||||
|
for import in import_list {
|
||||||
|
let mut word = WordData::new();
|
||||||
|
|
||||||
|
word.tags = import.tags.trim().replace(" ", ", ");
|
||||||
|
word.group_id = group_id.clone();
|
||||||
|
for (dest, indices) in &map_indices {
|
||||||
|
let collected_string = Self::collect_strings(
|
||||||
|
&import.fields,
|
||||||
|
&indices,
|
||||||
|
&separator,
|
||||||
|
skip_empty,
|
||||||
|
);
|
||||||
|
match dest.as_str() {
|
||||||
|
"key" => {
|
||||||
|
word.key = collected_string;
|
||||||
|
}
|
||||||
|
"value" => {
|
||||||
|
word.value = collected_string;
|
||||||
|
}
|
||||||
|
"tags" => {
|
||||||
|
word.tags = collected_string;
|
||||||
|
}
|
||||||
|
&_ => {
|
||||||
|
word.additional.insert((*dest).clone(), collected_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{word:?}");
|
||||||
|
words_list.push(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut state = state.lock().unwrap();
|
||||||
|
let connection = &mut state.connection;
|
||||||
|
let mut index = 0;
|
||||||
|
let total_len = words_list.len() as f32 / 256.0;
|
||||||
|
for word in &mut words_list.chunks_mut(256) {
|
||||||
|
add_words(word, connection);
|
||||||
|
index += 1;
|
||||||
|
let mut progress = progress.lock().unwrap();
|
||||||
|
*progress = index as f32 / total_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.dictionary.append(&mut words_list);
|
||||||
|
state.word_groups.push(group_entity);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
},
|
||||||
|
|_: Result<(), ()>| RootMessage::Import(ImportFinished),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_mapping_indices(group: &ImportGroup) -> Vec<(String, Vec<usize>)> {
|
||||||
|
let mut final_props = group.mapping.values().cloned().collect::<Vec<_>>();
|
||||||
|
final_props.sort();
|
||||||
|
final_props.dedup();
|
||||||
|
let mut result = final_props
|
||||||
|
.iter()
|
||||||
|
.map(|name| (name.clone(), Vec::<usize>::with_capacity(1)))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
for key in group.mapping.keys() {
|
||||||
|
let endpoint = group.mapping.get(key).unwrap();
|
||||||
|
let property_index = group.fields.iter().position(|f| f == key).unwrap();
|
||||||
|
let group_index = result
|
||||||
|
.iter()
|
||||||
|
.position(|(name, _)| name == endpoint)
|
||||||
|
.unwrap();
|
||||||
|
result.get_mut(group_index).unwrap().1.push(property_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_strings(
|
||||||
|
properties: &Vec<String>,
|
||||||
|
indices: &Vec<usize>,
|
||||||
|
separator: &str,
|
||||||
|
skip_empty: bool,
|
||||||
|
) -> String {
|
||||||
|
let mut working_words = Vec::with_capacity(indices.len());
|
||||||
|
for i in 0..indices.len() {
|
||||||
|
let index = indices[i];
|
||||||
|
let str = properties.get(index).unwrap();
|
||||||
|
if skip_empty && str.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
working_words.push(str.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
working_words.join(separator)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_progress(&self) -> Task<RootMessage> {
|
||||||
|
Task::perform(
|
||||||
|
async {
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||||
|
},
|
||||||
|
|_| RootMessage::Import(NextProgress),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-11
@@ -15,6 +15,7 @@ mod sync;
|
|||||||
mod word;
|
mod word;
|
||||||
mod writing;
|
mod writing;
|
||||||
mod repetition_settings;
|
mod repetition_settings;
|
||||||
|
pub mod import;
|
||||||
|
|
||||||
use crate::data_provider::card_sets::load_sets;
|
use crate::data_provider::card_sets::load_sets;
|
||||||
use crate::data_provider::settings::get_setting;
|
use crate::data_provider::settings::get_setting;
|
||||||
@@ -33,20 +34,16 @@ use iced_core::Size;
|
|||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use iced_core::window::settings::PlatformSpecific;
|
use iced_core::window::settings::PlatformSpecific;
|
||||||
|
use mimalloc::MiMalloc;
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: MiMalloc = MiMalloc;
|
||||||
|
|
||||||
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||||
|
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
println!("Welcome to JapLearn");
|
println!("Welcome to JapLearn");
|
||||||
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).window(window::Settings{
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).window(window_settings())
|
||||||
position: Position::Centered,
|
|
||||||
min_size: Some(Size::new(700.0_f32.into(), 700.0_f32.into())),
|
|
||||||
platform_specific: PlatformSpecific {
|
|
||||||
application_id: "JapLearn".to_string(),
|
|
||||||
override_redirect: false
|
|
||||||
},
|
|
||||||
.. Default::default()
|
|
||||||
})
|
|
||||||
.subscription(subscription)
|
.subscription(subscription)
|
||||||
.title("JapLearn")
|
.title("JapLearn")
|
||||||
.settings(iced::Settings {
|
.settings(iced::Settings {
|
||||||
@@ -55,8 +52,26 @@ fn main() -> iced::Result {
|
|||||||
})
|
})
|
||||||
.font(include_bytes!("../noto.ttf"))
|
.font(include_bytes!("../noto.ttf"))
|
||||||
.default_font(USER_FONT)
|
.default_font(USER_FONT)
|
||||||
.theme(Theme::GruvboxDark)
|
.theme(Theme::GruvboxDark).run()
|
||||||
.run()
|
}
|
||||||
|
|
||||||
|
fn window_settings() -> window::Settings {
|
||||||
|
let mut settings = window::Settings{
|
||||||
|
position: Position::Centered,
|
||||||
|
min_size: Some(Size::new(700.0_f32.into(), 700.0_f32.into())),
|
||||||
|
.. Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
settings.platform_specific =
|
||||||
|
PlatformSpecific {
|
||||||
|
application_id: "JapLearn".to_string(),
|
||||||
|
override_redirect: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
settings
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
||||||
|
|||||||
+11
-4
@@ -27,6 +27,7 @@ use reqwest::Error;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
use crate::import::{ImportMessage, ImportState};
|
||||||
|
|
||||||
impl Default for ScreenState {
|
impl Default for ScreenState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -54,6 +55,7 @@ pub enum RootMessage {
|
|||||||
Sync(SyncMessage),
|
Sync(SyncMessage),
|
||||||
History(HistoryMessage),
|
History(HistoryMessage),
|
||||||
RepetitionSettings(RepetitionSettingsMessage),
|
RepetitionSettings(RepetitionSettingsMessage),
|
||||||
|
Import(ImportMessage),
|
||||||
Keyboard(Event),
|
Keyboard(Event),
|
||||||
DataLoaded(HashMap<u32, Vec<(NaiveDate, u32)>>),
|
DataLoaded(HashMap<u32, Vec<(NaiveDate, u32)>>),
|
||||||
None,
|
None,
|
||||||
@@ -73,7 +75,7 @@ pub enum Page {
|
|||||||
Sync(SyncState),
|
Sync(SyncState),
|
||||||
History(HistoryState),
|
History(HistoryState),
|
||||||
RepetitionSettings(RepetitionSettingsState),
|
RepetitionSettings(RepetitionSettingsState),
|
||||||
|
Import(ImportState),
|
||||||
PreviousPage,
|
PreviousPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +192,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!("Update took {:?}", time.elapsed());
|
println!("Update took {:?}", time.elapsed());
|
||||||
@@ -213,7 +216,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +237,8 @@ impl ScreenState {
|
|||||||
Word,
|
Word,
|
||||||
Sync,
|
Sync,
|
||||||
History,
|
History,
|
||||||
RepetitionSettings
|
RepetitionSettings,
|
||||||
|
Import
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("View took {:?}", time.elapsed());
|
println!("View took {:?}", time.elapsed());
|
||||||
@@ -320,6 +325,8 @@ macro_rules! state_navigate_handle {
|
|||||||
pub trait NavigatedPage<T> {
|
pub trait NavigatedPage<T> {
|
||||||
fn navigate(&self, message: &T) -> Option<Page>;
|
fn navigate(&self, message: &T) -> Option<Page>;
|
||||||
fn navigated(&mut self);
|
fn navigated(&mut self);
|
||||||
|
fn update(&mut self, message: T) -> Task<RootMessage>;
|
||||||
|
fn view(&self) -> Element<'_, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait KeyPressedPage {
|
pub trait KeyPressedPage {
|
||||||
|
|||||||
+45
-43
@@ -30,34 +30,8 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl QuizState {
|
fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
||||||
pub(crate) fn new() -> QuizState {
|
|
||||||
QuizState {
|
|
||||||
kana: "ぁ".to_string(),
|
|
||||||
correct_roman: "a".to_string(),
|
|
||||||
is_help: false,
|
|
||||||
current_roman: "".to_string(),
|
|
||||||
set: KanaSet::hiragana(),
|
|
||||||
queue: Vec::new(),
|
|
||||||
score: Score {
|
|
||||||
total: 0,
|
|
||||||
correct: 0,
|
|
||||||
fail: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for QuizState {
|
|
||||||
fn default() -> Self {
|
|
||||||
QuizState::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QuizState {
|
|
||||||
pub fn update(&mut self, message: QuizMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
ContentChanged(content) => {
|
ContentChanged(content) => {
|
||||||
if content.contains("`") {
|
if content.contains("`") {
|
||||||
@@ -86,24 +60,9 @@ impl QuizState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_showed(&mut self) {
|
|
||||||
self.current_roman = String::new();
|
|
||||||
let queue = &mut self.queue;
|
|
||||||
|
|
||||||
if queue.is_empty() {
|
|
||||||
for pair in self.set.list() {
|
|
||||||
queue.push(pair);
|
|
||||||
}
|
|
||||||
|
|
||||||
queue.shuffle(&mut rand::rng());
|
fn view(&self) -> Element<'_, QuizMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
let pair = self.queue.pop().unwrap();
|
|
||||||
self.kana = pair.0;
|
|
||||||
self.correct_roman = pair.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, QuizMessage> {
|
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
row![
|
row![
|
||||||
@@ -145,6 +104,49 @@ impl QuizState {
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl QuizState {
|
||||||
|
pub(crate) fn new() -> QuizState {
|
||||||
|
QuizState {
|
||||||
|
kana: "ぁ".to_string(),
|
||||||
|
correct_roman: "a".to_string(),
|
||||||
|
is_help: false,
|
||||||
|
current_roman: "".to_string(),
|
||||||
|
set: KanaSet::hiragana(),
|
||||||
|
queue: Vec::new(),
|
||||||
|
score: Score {
|
||||||
|
total: 0,
|
||||||
|
correct: 0,
|
||||||
|
fail: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for QuizState {
|
||||||
|
fn default() -> Self {
|
||||||
|
QuizState::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl QuizState {
|
||||||
|
fn update_showed(&mut self) {
|
||||||
|
self.current_roman = String::new();
|
||||||
|
let queue = &mut self.queue;
|
||||||
|
|
||||||
|
if queue.is_empty() {
|
||||||
|
for pair in self.set.list() {
|
||||||
|
queue.push(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.shuffle(&mut rand::rng());
|
||||||
|
}
|
||||||
|
|
||||||
|
let pair = self.queue.pop().unwrap();
|
||||||
|
self.kana = pair.0;
|
||||||
|
self.correct_roman = pair.1;
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum QuizMessage {
|
pub enum QuizMessage {
|
||||||
ContentChanged(String),
|
ContentChanged(String),
|
||||||
|
|||||||
+18
-18
@@ -29,23 +29,7 @@ impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl Default for RandomizerState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RandomizerState {
|
|
||||||
pub fn new() -> RandomizerState {
|
|
||||||
RandomizerState {
|
|
||||||
text: Default::default(),
|
|
||||||
list: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Edit(action) => {
|
Edit(action) => {
|
||||||
self.text.perform(action);
|
self.text.perform(action);
|
||||||
@@ -65,7 +49,7 @@ impl RandomizerState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text_editor(&self.text)
|
text_editor(&self.text)
|
||||||
@@ -79,5 +63,21 @@ impl RandomizerState {
|
|||||||
.into(),
|
.into(),
|
||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
|
}}
|
||||||
|
|
||||||
|
impl Default for RandomizerState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RandomizerState {
|
||||||
|
pub fn new() -> RandomizerState {
|
||||||
|
RandomizerState {
|
||||||
|
text: Default::default(),
|
||||||
|
list: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+63
-54
@@ -39,30 +39,7 @@ impl NavigatedPage<RepetitionMessage> for RepetitionState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl RepetitionState {
|
|
||||||
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
|
||||||
let mut card_set = CardSet::new(&set, state.clone());
|
|
||||||
let (word, stat) = card_set.next();
|
|
||||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
|
||||||
|
|
||||||
RepetitionState {
|
|
||||||
state,
|
|
||||||
settings: set,
|
|
||||||
set: card_set,
|
|
||||||
current_word: word,
|
|
||||||
current_statistic: stat,
|
|
||||||
open: false,
|
|
||||||
can_play: true,
|
|
||||||
sink: Arc::new(sink_handle),
|
|
||||||
opened: HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionState {
|
|
||||||
pub fn update(&mut self, message: RepetitionMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
RepetitionMessage::Back => {}
|
RepetitionMessage::Back => {}
|
||||||
RepetitionMessage::Next => return self.next(),
|
RepetitionMessage::Next => return self.next(),
|
||||||
@@ -87,6 +64,60 @@ impl RepetitionState {
|
|||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
fn view(&self) -> Element<'_, RepetitionMessage> {
|
||||||
|
back_overlay(
|
||||||
|
column![
|
||||||
|
container(self.draw_forward())
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.align_y(alignment::Vertical::Center),
|
||||||
|
rule::horizontal(2),
|
||||||
|
container(self.draw_backward())
|
||||||
|
.width(Fill)
|
||||||
|
.height(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.align_y(alignment::Vertical::Center),
|
||||||
|
container(self.answer_bar())
|
||||||
|
.width(Fill)
|
||||||
|
.align_x(Center)
|
||||||
|
.height(80),
|
||||||
|
text!(
|
||||||
|
"Затронуто слов {}, {}%",
|
||||||
|
self.opened.len(),
|
||||||
|
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
||||||
|
)
|
||||||
|
]
|
||||||
|
.height(Fill)
|
||||||
|
.width(Fill)
|
||||||
|
.into(),
|
||||||
|
RepetitionMessage::Back,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionState {
|
||||||
|
pub(crate) fn new(set: CardSetSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||||
|
let mut card_set = CardSet::new(&set, state.clone());
|
||||||
|
let (word, stat) = card_set.next();
|
||||||
|
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||||
|
|
||||||
|
RepetitionState {
|
||||||
|
state,
|
||||||
|
settings: set,
|
||||||
|
set: card_set,
|
||||||
|
current_word: word,
|
||||||
|
current_statistic: stat,
|
||||||
|
open: false,
|
||||||
|
can_play: true,
|
||||||
|
sink: Arc::new(sink_handle),
|
||||||
|
opened: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionState {
|
||||||
|
|
||||||
|
|
||||||
fn next(&mut self) -> Task<RootMessage> {
|
fn next(&mut self) -> Task<RootMessage> {
|
||||||
if self.open {
|
if self.open {
|
||||||
@@ -137,36 +168,7 @@ impl RepetitionState {
|
|||||||
state.activity.insert(id, vec![(now, 1)]);
|
state.activity.insert(id, vec![(now, 1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn view(&self) -> Element<'_, RepetitionMessage> {
|
|
||||||
back_overlay(
|
|
||||||
column![
|
|
||||||
container(self.draw_forward())
|
|
||||||
.width(Fill)
|
|
||||||
.height(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.align_y(alignment::Vertical::Center),
|
|
||||||
rule::horizontal(2),
|
|
||||||
container(self.draw_backward())
|
|
||||||
.width(Fill)
|
|
||||||
.height(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.align_y(alignment::Vertical::Center),
|
|
||||||
container(self.answer_bar())
|
|
||||||
.width(Fill)
|
|
||||||
.align_x(Center)
|
|
||||||
.height(80),
|
|
||||||
text!(
|
|
||||||
"Затронуто слов {}, {}%",
|
|
||||||
self.opened.len(),
|
|
||||||
(self.opened.len() as f32 / self.set.len() as f32 * 10000.0).round() / 100.0
|
|
||||||
)
|
|
||||||
]
|
|
||||||
.height(Fill)
|
|
||||||
.width(Fill)
|
|
||||||
.into(),
|
|
||||||
RepetitionMessage::Back,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
fn draw_forward(&self) -> Element<'_, RepetitionMessage> {
|
||||||
self.draw_card_view(self.settings.forward.as_str())
|
self.draw_card_view(self.settings.forward.as_str())
|
||||||
@@ -197,6 +199,7 @@ impl RepetitionState {
|
|||||||
"speech" => self.draw_voice(),
|
"speech" => self.draw_voice(),
|
||||||
"reading" => self.draw_reading(word),
|
"reading" => self.draw_reading(word),
|
||||||
"context" => self.draw_context(word),
|
"context" => self.draw_context(word),
|
||||||
|
"description" => self.draw_description(word),
|
||||||
_ => space().into(),
|
_ => space().into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -272,6 +275,12 @@ impl RepetitionState {
|
|||||||
Some(context) => text!("{}", context).size(24).into(),
|
Some(context) => text!("{}", context).size(24).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
|
match word.additional.get("context") {
|
||||||
|
None => space().into(),
|
||||||
|
Some(context) => text!("{}", context).size(24).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyPressedPage for RepetitionState {
|
impl KeyPressedPage for RepetitionState {
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl RepetitionSettingsState {
|
|
||||||
pub fn update(&mut self, message: RepetitionSettingsMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
Save => {
|
Save => {
|
||||||
@@ -93,7 +90,7 @@ impl RepetitionSettingsState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
fn view(&self) -> Element<'_, RepetitionSettingsMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
scrollable(
|
scrollable(
|
||||||
@@ -150,6 +147,10 @@ impl RepetitionSettingsState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionSettingsState {
|
||||||
|
|
||||||
|
|
||||||
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionSettingsMessage> {
|
fn count_view(&self, set: &CardSetSettings) -> Element<'_, RepetitionSettingsMessage> {
|
||||||
if let Some(count) = set.count {
|
if let Some(count) = set.count {
|
||||||
|
|||||||
+17
-16
@@ -59,21 +59,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
self.selected_set = None;
|
self.selected_set = None;
|
||||||
}
|
}
|
||||||
}
|
fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl RepetitionsState {
|
|
||||||
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
|
||||||
let count = state.lock().unwrap().card_sets.len();
|
|
||||||
RepetitionsState {
|
|
||||||
selected_set: None,
|
|
||||||
correct_filters: vec![true; count],
|
|
||||||
state,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RepetitionsState {
|
|
||||||
pub fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
match message {
|
match message {
|
||||||
Next => {}
|
Next => {}
|
||||||
@@ -139,7 +125,7 @@ impl RepetitionsState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, RepetitionsMessage> {
|
fn view(&self) -> Element<'_, RepetitionsMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
row![
|
row![
|
||||||
column![
|
column![
|
||||||
@@ -162,6 +148,21 @@ impl RepetitionsState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionsState {
|
||||||
|
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
|
||||||
|
let count = state.lock().unwrap().card_sets.len();
|
||||||
|
RepetitionsState {
|
||||||
|
selected_set: None,
|
||||||
|
correct_filters: vec![true; count],
|
||||||
|
state,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepetitionsState {
|
||||||
|
|
||||||
fn launch_delete_button(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
fn launch_delete_button(&self, set: &CardSetSettings) -> Element<'_, RepetitionsMessage> {
|
||||||
if set.id != 0 {
|
if set.id != 0 {
|
||||||
return row![
|
return row![
|
||||||
|
|||||||
+26
-24
@@ -64,17 +64,7 @@ impl NavigatedPage<SelectorMessage> for SelectorState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl SelectorState {
|
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
|
||||||
Self {
|
|
||||||
set: Default::default(),
|
|
||||||
is_writing: false,
|
|
||||||
state,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn update(&mut self, message: SelectorMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
SelectorMessage::Change => match self.set.chars_type {
|
SelectorMessage::Change => match self.set.chars_type {
|
||||||
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
KanaType::Katakana => self.set = KanaSet::hiragana(),
|
||||||
@@ -86,19 +76,7 @@ impl SelectorState {
|
|||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
fn view(&self) -> Element<'_, SelectorMessage> {
|
||||||
fn nav_style(theme: &Theme, status: Status) -> Style {
|
|
||||||
let mut basic = button::text(theme, status);
|
|
||||||
basic.background = if status == Status::Hovered {
|
|
||||||
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
basic.border.radius = BUTTON_RADIUS.into();
|
|
||||||
basic
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, SelectorMessage> {
|
|
||||||
container(
|
container(
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
row![
|
row![
|
||||||
@@ -132,6 +110,30 @@ impl SelectorState {
|
|||||||
.padding(10)
|
.padding(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SelectorState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> Self {
|
||||||
|
Self {
|
||||||
|
set: Default::default(),
|
||||||
|
is_writing: false,
|
||||||
|
state,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn nav_style(theme: &Theme, status: Status) -> Style {
|
||||||
|
let mut basic = button::text(theme, status);
|
||||||
|
basic.background = if status == Status::Hovered {
|
||||||
|
Some(Background::Color(Color::WHITE.scale_alpha(0.1)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
basic.border.radius = BUTTON_RADIUS.into();
|
||||||
|
basic
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn rows_selector(&self) -> Element<'_, SelectorMessage> {
|
fn rows_selector(&self) -> Element<'_, SelectorMessage> {
|
||||||
let mut row = Row::new();
|
let mut row = Row::new();
|
||||||
|
|||||||
+19
-18
@@ -49,23 +49,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {}
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
||||||
|
|
||||||
impl SyncState {
|
|
||||||
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
|
||||||
let auto_fetch;
|
|
||||||
{
|
|
||||||
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
|
||||||
}
|
|
||||||
Self {
|
|
||||||
auto_fetch,
|
|
||||||
state,
|
|
||||||
frozen: false,
|
|
||||||
progress: 0.0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update(&mut self, message: SyncMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
CopyKey => {
|
CopyKey => {
|
||||||
@@ -158,7 +142,7 @@ impl SyncState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, SyncMessage> {
|
fn view(&self) -> Element<'_, SyncMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
row![space().width(Fill), self.sync_column(), space().width(Fill)]
|
row![space().width(Fill), self.sync_column(), space().width(Fill)]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -167,6 +151,23 @@ impl SyncState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyncState {
|
||||||
|
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
|
||||||
|
let auto_fetch;
|
||||||
|
{
|
||||||
|
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
auto_fetch,
|
||||||
|
state,
|
||||||
|
frozen: false,
|
||||||
|
progress: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn sync_column(&self) -> Element<'_, SyncMessage> {
|
fn sync_column(&self) -> Element<'_, SyncMessage> {
|
||||||
let network_view: Element<'_, SyncMessage> = if self.frozen {
|
let network_view: Element<'_, SyncMessage> = if self.frozen {
|
||||||
|
|||||||
+21
-24
@@ -6,7 +6,7 @@ use crate::styling::*;
|
|||||||
use crate::word::WordMessage::*;
|
use crate::word::WordMessage::*;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::{button, column, row, rule, scrollable, space, text, text_input};
|
use iced::widget::{button, column, row, rule, scrollable, text, text_input};
|
||||||
use iced::{Element, Fill, Task};
|
use iced::{Element, Fill, Task};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@@ -26,18 +26,8 @@ impl NavigatedPage<WordMessage> for WordState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {}
|
||||||
}
|
fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
||||||
}
|
|
||||||
|
|
||||||
impl WordState {
|
|
||||||
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
|
||||||
WordState { state, index, word }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WordState {
|
|
||||||
pub fn update(&mut self, message: WordMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
match message {
|
||||||
Back => {}
|
Back => {}
|
||||||
Save => {
|
Save => {
|
||||||
@@ -74,7 +64,7 @@ impl WordState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, WordMessage> {
|
fn view(&self) -> Element<'_, WordMessage> {
|
||||||
let mut fast_add = row![];
|
let mut fast_add = row![];
|
||||||
if !self.word.additional.contains_key("reading") {
|
if !self.word.additional.contains_key("reading") {
|
||||||
fast_add = fast_add.push(
|
fast_add = fast_add.push(
|
||||||
@@ -137,38 +127,45 @@ impl WordState {
|
|||||||
Back,
|
Back,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WordState {
|
||||||
|
pub(crate) fn new(word: WordData, index: usize, state: Arc<Mutex<AppState>>) -> WordState {
|
||||||
|
WordState { state, index, word }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WordState {
|
||||||
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn get_view_for_more(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
||||||
match value.0.as_str() {
|
match value.0.as_str() {
|
||||||
"reading" => self.reading_field(value),
|
"reading" => self.reading_field(value.1),
|
||||||
"description" => self.description_field(value),
|
"description" => self.description_field(value.1),
|
||||||
"context" => self.context_field(value),
|
"context" => self.context_field(value.1),
|
||||||
_ => space().into(),
|
_ => self.additional_field(value.1, value.0.clone(), value.0.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reading_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn reading_field(&self, value: &String) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "Чтение слова".to_string(), "reading".to_string())
|
self.additional_field(value, "Чтение слова".to_string(), "reading".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn description_field(&self, value: &String) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "Описание".to_string(), "description".to_string())
|
self.additional_field(value, "Описание".to_string(), "description".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn context_field(&self, value: (&String, &String)) -> Element<'_, WordMessage> {
|
fn context_field(&self, value: &String) -> Element<'_, WordMessage> {
|
||||||
self.additional_field(value, "В контексте".to_string(), "context".to_string())
|
self.additional_field(value, "В контексте".to_string(), "context".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn additional_field(
|
fn additional_field(
|
||||||
&self,
|
&self,
|
||||||
value: (&String, &String),
|
value: &String,
|
||||||
name: String,
|
name: String,
|
||||||
id: String,
|
id: String,
|
||||||
) -> Element<'_, WordMessage> {
|
) -> Element<'_, WordMessage> {
|
||||||
column![
|
column![
|
||||||
text!("{}", name),
|
text!("{}", name),
|
||||||
row![
|
row![
|
||||||
text_input(id.clone().as_str(), &value.1)
|
text_input(id.clone().as_str(), value)
|
||||||
.on_input({
|
.on_input({
|
||||||
let value = id.clone();
|
let value = id.clone();
|
||||||
move |string| SetAdditional(value.clone(), string)
|
move |string| SetAdditional(value.clone(), string)
|
||||||
|
|||||||
+37
-35
@@ -29,6 +29,41 @@ impl NavigatedPage<WritingMessage> for WritingState {
|
|||||||
|
|
||||||
fn navigated(&mut self) {
|
fn navigated(&mut self) {
|
||||||
}
|
}
|
||||||
|
fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
||||||
|
match message {
|
||||||
|
WritingMessage::Back => todo!(),
|
||||||
|
WritingMessage::Next => self.next(),
|
||||||
|
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
fn view(&self) -> Element<'_, WritingMessage> {
|
||||||
|
container(
|
||||||
|
iced::widget::column![
|
||||||
|
checkbox(self.show_all)
|
||||||
|
.label("Показывать все сразу")
|
||||||
|
.on_toggle(WritingMessage::SwitchShowMode),
|
||||||
|
text!("{}", self.roman_total).size(34),
|
||||||
|
text!("{}", self.kana).size(48),
|
||||||
|
self.answers(),
|
||||||
|
row![
|
||||||
|
button(text!("{}", self.next_text))
|
||||||
|
.style(jl_button)
|
||||||
|
.on_press(WritingMessage::Next),
|
||||||
|
button("Закончить")
|
||||||
|
.style(jl_button)
|
||||||
|
.on_press(WritingMessage::Back),
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
]
|
||||||
|
.spacing(DEFAULT_SPACING)
|
||||||
|
.align_x(alignment::Horizontal::Center),
|
||||||
|
)
|
||||||
|
.center_x(Fill)
|
||||||
|
.center_y(Fill)
|
||||||
|
.padding(10)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WritingState {
|
impl WritingState {
|
||||||
@@ -48,14 +83,7 @@ impl WritingState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WritingState {
|
impl WritingState {
|
||||||
pub fn update(&mut self, message: WritingMessage) -> Task<RootMessage> {
|
|
||||||
match message {
|
|
||||||
WritingMessage::Back => todo!(),
|
|
||||||
WritingMessage::Next => self.next(),
|
|
||||||
WritingMessage::SwitchShowMode(b) => self.show_all = b,
|
|
||||||
}
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn next(&mut self) {
|
fn next(&mut self) {
|
||||||
if self.set.is_empty() {
|
if self.set.is_empty() {
|
||||||
@@ -85,33 +113,7 @@ impl WritingState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<'_, WritingMessage> {
|
|
||||||
container(
|
|
||||||
iced::widget::column![
|
|
||||||
checkbox(self.show_all)
|
|
||||||
.label("Показывать все сразу")
|
|
||||||
.on_toggle(WritingMessage::SwitchShowMode),
|
|
||||||
text!("{}", self.roman_total).size(34),
|
|
||||||
text!("{}", self.kana).size(48),
|
|
||||||
self.answers(),
|
|
||||||
row![
|
|
||||||
button(text!("{}", self.next_text))
|
|
||||||
.style(jl_button)
|
|
||||||
.on_press(WritingMessage::Next),
|
|
||||||
button("Закончить")
|
|
||||||
.style(jl_button)
|
|
||||||
.on_press(WritingMessage::Back),
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
]
|
|
||||||
.spacing(DEFAULT_SPACING)
|
|
||||||
.align_x(alignment::Horizontal::Center),
|
|
||||||
)
|
|
||||||
.center_x(Fill)
|
|
||||||
.center_y(Fill)
|
|
||||||
.padding(10)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn answers(&self) -> Element<'_, WritingMessage> {
|
fn answers(&self) -> Element<'_, WritingMessage> {
|
||||||
if self.set.is_empty() {
|
if self.set.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user