Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
144e258292 | ||
|
|
48cd68d1c7 | ||
|
|
a5526dc5e9 | ||
|
|
1d4b37e381 | ||
|
|
96a58c61bc | ||
|
|
1847d4f44f | ||
|
|
b1902b35cb | ||
|
|
5d12f3b02a | ||
|
|
0e867a33ce |
No files matched your search
Generated
+782
-35
File diff suppressed because it is too large.
Load diff
+6
-5
@@ -1,15 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "jap_learn"
|
name = "jap_learn"
|
||||||
version = "0.1.3"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { version = "0.14.0", features = ["tokio", "svg", "lazy", "crisp", "tiny-skia", "wayland", "wgpu"], default-features = false}
|
iced = { version = "0.14.0", features = ["tokio", "svg", "lazy", "crisp", "tiny-skia", "wayland", "wgpu", "tester"], default-features = false}
|
||||||
iced_core = "0.14.0"
|
iced_core = "0.14.0"
|
||||||
rand = "0.10.2"
|
rand = "0.10.3"
|
||||||
dirs = "7.0.0"
|
dirs = "7.0.0"
|
||||||
serde_json = "1.0.151"
|
serde_json = "1.0.151"
|
||||||
rhai = { version = "1.26.0", features = ["sync"] }
|
rhai = { version = "1.26.1", features = ["sync"] }
|
||||||
chrono = "0.4.45"
|
chrono = "0.4.45"
|
||||||
rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] }
|
||||||
reqwest = { version = "0.13.5", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0.13.5", features = ["json", "stream", "multipart"] }
|
||||||
@@ -27,7 +27,8 @@ parking_lot = "0.12.5"
|
|||||||
env_logger = "0.11.11"
|
env_logger = "0.11.11"
|
||||||
log = "0.4.34"
|
log = "0.4.34"
|
||||||
fsrs = "6.6.2"
|
fsrs = "6.6.2"
|
||||||
litemap = { version = "0.8.3", features = ["serde"] }
|
litemap = { version = "0.8.3" }
|
||||||
|
remote_marker = {git = "https://gitea.micialware.ru/micialware/remote_marker"}
|
||||||
|
|
||||||
[profile.super-release]
|
[profile.super-release]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,6 @@
|
|||||||
use crate::data::repositories::Repository;
|
use crate::data::repositories::Repository;
|
||||||
use crate::data_provider::card_states::CardStateRepository;
|
use crate::data_provider::card_states::CardStateRepository;
|
||||||
|
use crate::data_provider::custom_fields::CustomFieldRepository;
|
||||||
use crate::data_provider::decks::DeckRepository;
|
use crate::data_provider::decks::DeckRepository;
|
||||||
use crate::data_provider::history::HistoryRepository;
|
use crate::data_provider::history::HistoryRepository;
|
||||||
use crate::data_provider::settings::get_setting;
|
use crate::data_provider::settings::get_setting;
|
||||||
@@ -17,7 +18,6 @@ use log::info;
|
|||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::data_provider::custom_fields::CustomFieldRepository;
|
|
||||||
|
|
||||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||||
|
|
||||||
|
|||||||
+15
-3
@@ -1,20 +1,21 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
use crate::core::srs::OrderModule::{Fsrs, RandomSRS, SemiRandomSRS, WorstWordsSRS};
|
use crate::core::srs::OrderModule::{Fsrs, RandomSRS, SemiRandomSRS, WorstWordsSRS};
|
||||||
use crate::core::srs::{
|
use crate::core::srs::{
|
||||||
FsrsModule, OrderMode, OrderModule, RandomSRSModule, SRSModule, SemiRandomSRSModule,
|
FsrsModule, OrderMode, OrderModule, RandomSRSModule, SRSModule, SemiRandomSRSModule,
|
||||||
WordOpenMode, WorstWordsSRSModule,
|
WordOpenMode, WorstWordsSRSModule,
|
||||||
};
|
};
|
||||||
|
use crate::data::Id;
|
||||||
use crate::data::entities::*;
|
use crate::data::entities::*;
|
||||||
use crate::data::repositories::Repository;
|
use crate::data::repositories::Repository;
|
||||||
use crate::data_provider::card_states::CardStateRepositoryInner;
|
use crate::data_provider::card_states::CardStateRepositoryInner;
|
||||||
use crate::notification::MaybeError;
|
use crate::notification::MaybeError;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
use litemap::LiteMap;
|
||||||
use log::info;
|
use log::info;
|
||||||
use rhai::{Engine, Scope};
|
use rhai::{Engine, Scope};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use crate::data::Id;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DeckData {
|
pub struct DeckData {
|
||||||
@@ -26,6 +27,11 @@ pub struct DeckData {
|
|||||||
open_mode: OrderMode,
|
open_mode: OrderMode,
|
||||||
settings: DeckSettings,
|
settings: DeckSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DisplayStyle {
|
||||||
|
properties: LiteMap<String, String>,
|
||||||
|
}
|
||||||
|
|
||||||
impl DeckData {
|
impl DeckData {
|
||||||
pub fn new(settings: &DeckSettings, open_mode: OrderMode, state: AppState) -> Self {
|
pub fn new(settings: &DeckSettings, open_mode: OrderMode, state: AppState) -> Self {
|
||||||
let states_repo = state.card_states.read();
|
let states_repo = state.card_states.read();
|
||||||
@@ -156,7 +162,13 @@ impl DeckData {
|
|||||||
if let Ok(ast) = ast {
|
if let Ok(ast) = ast {
|
||||||
let groups = state.word_groups.read().iter().cloned().collect::<Vec<_>>();
|
let groups = state.word_groups.read().iter().cloned().collect::<Vec<_>>();
|
||||||
let dictionary = &state.dictionary.read();
|
let dictionary = &state.dictionary.read();
|
||||||
let fields : HashMap<Id, String> = HashMap::from_iter(state.custom_fields.read().iter().map(|f| (f.id, f.identifier.clone())));
|
let fields: HashMap<Id, String> = HashMap::from_iter(
|
||||||
|
state
|
||||||
|
.custom_fields
|
||||||
|
.read()
|
||||||
|
.iter()
|
||||||
|
.map(|f| (f.id, f.identifier.clone())),
|
||||||
|
);
|
||||||
let query = dictionary.query_par(Arc::new(move |word| {
|
let query = dictionary.query_par(Arc::new(move |word| {
|
||||||
let mut more = rhai::Map::new();
|
let mut more = rhai::Map::new();
|
||||||
for kv in &word.additional {
|
for kv in &word.additional {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, WordOpenMode};
|
use crate::core::srs::{FADE_PER_DAY, MAX_SCORE, WordOpenMode};
|
||||||
use crate::data::{Id, SmallId, INVALID_ID};
|
use crate::data::{INVALID_ID, Id};
|
||||||
use crate::data_provider::history::HistoryRepositoryInner;
|
use crate::data_provider::history::HistoryRepositoryInner;
|
||||||
use chrono::{DateTime, Local, NaiveDate, Utc};
|
use chrono::{DateTime, Local, NaiveDate, Utc};
|
||||||
use fsrs::MemoryState;
|
use fsrs::MemoryState;
|
||||||
@@ -101,6 +101,9 @@ impl HistoryRepositoryInner {
|
|||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if count != 0 {
|
||||||
|
counts.push((date, count));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
counts
|
counts
|
||||||
}
|
}
|
||||||
@@ -130,8 +133,8 @@ impl DeckSettings {
|
|||||||
DeckSettings {
|
DeckSettings {
|
||||||
id: 0.into(),
|
id: 0.into(),
|
||||||
name,
|
name,
|
||||||
forward: "".to_string(),
|
forward: String::new(),
|
||||||
backward: "".to_string(),
|
backward: String::new(),
|
||||||
filter: "true".to_string(),
|
filter: "true".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
|
|||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.cache.len()
|
self.cache.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, index: usize) -> Option<EntityHandle<T>> {
|
pub fn get(&self, index: usize) -> Option<EntityHandle<T>> {
|
||||||
self.cache.get(index).cloned()
|
self.cache.get(index).cloned()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::helpers::into_result;
|
use crate::helpers::into_result;
|
||||||
use crate::notification::NotificationData;
|
use crate::notification::NotificationData;
|
||||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||||
|
use crate::pages::import::AnkiSchema;
|
||||||
use log::info;
|
use log::info;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use crate::pages::import::AnkiSchema;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||||
@@ -26,14 +26,13 @@ pub struct ImportNote {
|
|||||||
pub fields: Vec<String>,
|
pub fields: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_groups(connection: &Connection, schema: AnkiSchema) -> Result<ImportData, NotificationData> {
|
pub fn load_groups(
|
||||||
|
connection: &Connection,
|
||||||
|
schema: AnkiSchema,
|
||||||
|
) -> Result<ImportData, NotificationData> {
|
||||||
match schema {
|
match schema {
|
||||||
AnkiSchema::Old => {
|
AnkiSchema::Old => load_old_schema(connection),
|
||||||
load_old_schema(connection)
|
AnkiSchema::Beta => load_new_schema(connection),
|
||||||
}
|
|
||||||
AnkiSchema::Beta => {
|
|
||||||
load_new_schema(connection)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::data::Id;
|
||||||
use crate::data::entities::WordData;
|
use crate::data::entities::WordData;
|
||||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||||
use crate::data::Id;
|
|
||||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||||
use litemap::LiteMap;
|
use litemap::LiteMap;
|
||||||
use rusqlite::{Error, Params, Row};
|
use rusqlite::{Error, Params, Row};
|
||||||
@@ -69,25 +69,15 @@ fn additional_to_string(map: &LiteMap<Id, String>) -> String {
|
|||||||
parts.join("")
|
parts.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn additional_from_string_temp(data: String) -> LiteMap<Id, String> {
|
|
||||||
|
|
||||||
let pre_map : LiteMap<String, String> = serde_json::from_str(data.as_str()).unwrap();
|
|
||||||
LiteMap::from(pre_map.iter().map(|(k, v)| (match k.as_str() {
|
|
||||||
"reading" => Id(1),
|
|
||||||
"description" => Id(2),
|
|
||||||
"context" => Id(3),
|
|
||||||
&_ => Id(0) }, v.to_string())).collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn additional_from_string(data: String) -> LiteMap<Id, String> {
|
fn additional_from_string(data: String) -> LiteMap<Id, String> {
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
return LiteMap::new()
|
return LiteMap::new();
|
||||||
}
|
}
|
||||||
let parts = data.split('').collect::<Vec<&str>>();
|
let parts = data.split('').collect::<Vec<&str>>();
|
||||||
let chunks = parts.chunks(2).collect::<Vec<&[&str]>>();
|
let chunks = parts.chunks(2).collect::<Vec<&[&str]>>();
|
||||||
let mut map = LiteMap::with_capacity(parts.len());
|
let mut map = LiteMap::with_capacity(parts.len());
|
||||||
for part in &chunks {
|
for part in &chunks {
|
||||||
let id : Id = part[0].parse().unwrap();
|
let id: Id = part[0].parse().unwrap();
|
||||||
let value: String = part[1].to_string();
|
let value: String = part[1].to_string();
|
||||||
map.insert(id, value);
|
map.insert(id, value);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -32,6 +32,8 @@ use iced::{Element, Task};
|
|||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
use chrono::Local;
|
||||||
|
use remote_marker::{alias, push};
|
||||||
|
|
||||||
impl Default for ScreenState {
|
impl Default for ScreenState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -91,6 +93,9 @@ pub struct ScreenState {
|
|||||||
|
|
||||||
impl ScreenState {
|
impl ScreenState {
|
||||||
pub fn boot() -> (ScreenState, Task<RootMessage>) {
|
pub fn boot() -> (ScreenState, Task<RootMessage>) {
|
||||||
|
let time = Local::now().timestamp_millis();
|
||||||
|
alias("frame", format!("frame_{}", time).as_str());
|
||||||
|
alias("update", format!("update_{}", time).as_str());
|
||||||
info!("Booting");
|
info!("Booting");
|
||||||
create_db();
|
create_db();
|
||||||
info!("Db created");
|
info!("Db created");
|
||||||
@@ -186,7 +191,7 @@ impl ScreenState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
debug!("Update took {:?}", time.elapsed());
|
debug!("Update took {:?}", time.elapsed());
|
||||||
|
push("update", time.elapsed().as_nanos());
|
||||||
task.0
|
task.0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +236,7 @@ impl ScreenState {
|
|||||||
let notifications = self.notification_manager.draw().map(Notification);
|
let notifications = self.notification_manager.draw().map(Notification);
|
||||||
|
|
||||||
debug!("View took {:?}", time.elapsed());
|
debug!("View took {:?}", time.elapsed());
|
||||||
|
push("frame", time.elapsed().as_nanos());
|
||||||
stack![view, notifications].width(Fill).height(Fill).into()
|
stack![view, notifications].width(Fill).height(Fill).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -138,8 +138,8 @@ impl NotificationManager {
|
|||||||
|
|
||||||
fn draw_data<'a>(data: &NotificationData) -> Element<'a, NotificationMessage> {
|
fn draw_data<'a>(data: &NotificationData) -> Element<'a, NotificationMessage> {
|
||||||
match data {
|
match data {
|
||||||
NotificationData::DataLoaded => {
|
NotificationData::DataSynced => {
|
||||||
text!("Данные успешно загружены на сервер")
|
text!("Данные успешно синхронизированы")
|
||||||
}
|
}
|
||||||
NotificationData::ImportError => {
|
NotificationData::ImportError => {
|
||||||
text!("Ошибка при импорте данных из Anki")
|
text!("Ошибка при импорте данных из Anki")
|
||||||
@@ -168,6 +168,9 @@ impl NotificationManager {
|
|||||||
NotificationData::CompressError => {
|
NotificationData::CompressError => {
|
||||||
text!("Ошибка сжатия или распаковки данных")
|
text!("Ошибка сжатия или распаковки данных")
|
||||||
}
|
}
|
||||||
|
NotificationData::LocalVersionChanged => {
|
||||||
|
text!("Локальная версия будет заменена")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.into()
|
.into()
|
||||||
@@ -184,7 +187,7 @@ pub enum NotificationRequest {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum NotificationData {
|
pub enum NotificationData {
|
||||||
PermissionDenied,
|
PermissionDenied,
|
||||||
DataLoaded,
|
DataSynced,
|
||||||
ImportError,
|
ImportError,
|
||||||
IncorrectAnkiFile,
|
IncorrectAnkiFile,
|
||||||
OpenFileError,
|
OpenFileError,
|
||||||
@@ -193,6 +196,7 @@ pub enum NotificationData {
|
|||||||
DbSaveError,
|
DbSaveError,
|
||||||
DbLoadError,
|
DbLoadError,
|
||||||
CompressError,
|
CompressError,
|
||||||
|
LocalVersionChanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MaybeError = Result<(), NotificationData>;
|
pub type MaybeError = Result<(), NotificationData>;
|
||||||
+48
-27
@@ -1,7 +1,7 @@
|
|||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
|
use crate::data::Id;
|
||||||
use crate::data::entities::{EntityHandle, WordData, WordGroup};
|
use crate::data::entities::{EntityHandle, WordData, WordGroup};
|
||||||
use crate::data::repositories::{Query, Repository};
|
use crate::data::repositories::{Query, Repository};
|
||||||
use crate::data::Id;
|
|
||||||
use crate::data_provider::word_groups::{WordGroupDataLayer, WordGroupRepositoryInner};
|
use crate::data_provider::word_groups::{WordGroupDataLayer, WordGroupRepositoryInner};
|
||||||
use crate::data_provider::words::WordDataLayer;
|
use crate::data_provider::words::WordDataLayer;
|
||||||
use crate::data_provider::words::WordRepositoryInner;
|
use crate::data_provider::words::WordRepositoryInner;
|
||||||
@@ -13,10 +13,10 @@ use crate::pages::dictionary::SelectionChangeDirection::*;
|
|||||||
use crate::pages::dictionary_quiz::DictionaryQuizState;
|
use crate::pages::dictionary_quiz::DictionaryQuizState;
|
||||||
use crate::pages::import::ImportState;
|
use crate::pages::import::ImportState;
|
||||||
use crate::pages::word::{WordEditor, WordMessage};
|
use crate::pages::word::{WordEditor, WordMessage};
|
||||||
use crate::push_error_task;
|
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::widgets::hard_mouse_area::hard_mouse_area;
|
use crate::widgets::hard_mouse_area::hard_mouse_area;
|
||||||
use crate::{jl_button, push_error};
|
use crate::{jl_button, push_error};
|
||||||
|
use crate::{jl_text_input, push_error_task};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
use iced::alignment::Vertical::Center;
|
use iced::alignment::Vertical::Center;
|
||||||
@@ -24,15 +24,16 @@ use iced::widget::button::Style;
|
|||||||
use iced::widget::button::{danger, text};
|
use iced::widget::button::{danger, text};
|
||||||
use iced::widget::operation::focus;
|
use iced::widget::operation::focus;
|
||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
use iced::widget::text_input::default;
|
|
||||||
use iced::widget::text_input::Status::Active;
|
use iced::widget::text_input::Status::Active;
|
||||||
|
use iced::widget::text_input::default;
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{Border, Color, Shadow, Task};
|
use iced::{Border, Color, Shadow, Task};
|
||||||
|
use iced_core::Length::{Fill, FillPortion};
|
||||||
|
use iced_core::border::Radius;
|
||||||
use iced_core::keyboard;
|
use iced_core::keyboard;
|
||||||
|
use iced_core::keyboard::Key::Named;
|
||||||
use iced_core::keyboard::key::Physical::Code;
|
use iced_core::keyboard::key::Physical::Code;
|
||||||
use iced_core::keyboard::{Event, Modifiers};
|
use iced_core::keyboard::{Event, Modifiers};
|
||||||
use iced_core::keyboard::Key::Named;
|
|
||||||
use iced_core::Length::{Fill, FillPortion};
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use rand::random_range;
|
use rand::random_range;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
@@ -81,7 +82,7 @@ pub enum DictionaryMessage {
|
|||||||
EditField(String),
|
EditField(String),
|
||||||
ChangeSelectedField(SelectionChangeDirection),
|
ChangeSelectedField(SelectionChangeDirection),
|
||||||
EditorAction(WordMessage),
|
EditorAction(WordMessage),
|
||||||
ExtendedWordEdited
|
ExtendedWordEdited,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Copy)]
|
#[derive(Clone, PartialEq, Eq, Hash, Copy)]
|
||||||
@@ -253,7 +254,9 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
let _ = dictionary.save(&mut handle);
|
let _ = dictionary.save(&mut handle);
|
||||||
if reload_query {
|
if reload_query {
|
||||||
self.displayed_words_query.load(&dictionary);
|
self.displayed_words_query.load(&dictionary);
|
||||||
if let Some(selected) = self.selected_cell && selected.0 == original {
|
if let Some(selected) = self.selected_cell
|
||||||
|
&& selected.0 == original
|
||||||
|
{
|
||||||
self.selected_cell = Some((handle, selected.1, selected.2));
|
self.selected_cell = Some((handle, selected.1, selected.2));
|
||||||
if self.word_editor.is_some() {
|
if self.word_editor.is_some() {
|
||||||
self.word_editor = Some(self.editor_for_word(handle));
|
self.word_editor = Some(self.editor_for_word(handle));
|
||||||
@@ -267,7 +270,10 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
GotoImport => {}
|
GotoImport => {}
|
||||||
SelectField(e, f, index) => {
|
SelectField(e, f, index) => {
|
||||||
info!("Editing word {}", e.id);
|
info!("Editing word {}", e.id);
|
||||||
if self.word_editor.is_some() && let Some(selected) = &self.selected_cell && selected.0 != e {
|
if self.word_editor.is_some()
|
||||||
|
&& let Some(selected) = &self.selected_cell
|
||||||
|
&& selected.0 != e
|
||||||
|
{
|
||||||
self.word_editor = Some(self.editor_for_word(e));
|
self.word_editor = Some(self.editor_for_word(e));
|
||||||
}
|
}
|
||||||
self.selected_cell = Some((e, f, index));
|
self.selected_cell = Some((e, f, index));
|
||||||
@@ -349,18 +355,16 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.displayed_words_query.load(&dictionary);
|
self.displayed_words_query.load(&dictionary);
|
||||||
self.selected_cell = None;
|
self.selected_cell = None;
|
||||||
self.word_editor = None;
|
self.word_editor = None;
|
||||||
|
|
||||||
}
|
}
|
||||||
EditorAction(action) => {
|
EditorAction(action) => {
|
||||||
let result = self.word_editor.as_mut().unwrap().update(action);
|
let result = self.word_editor.as_mut().unwrap().update(action);
|
||||||
if let Some(result) = result {
|
if let Some(result) = result {
|
||||||
match result {
|
match result {
|
||||||
DeleteWord(_) |
|
DeleteWord(_) | ExtendedWordEdited => {
|
||||||
ExtendedWordEdited => {
|
|
||||||
return Task::done(RootMessage::Dictionary(result));
|
return Task::done(RootMessage::Dictionary(result));
|
||||||
},
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -387,7 +391,8 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
button("Импорт").style(text).on_press(GotoImport),
|
button("Импорт").style(text).on_press(GotoImport),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
.spacing(5).width(FillPortion(4)),
|
.spacing(5)
|
||||||
|
.width(FillPortion(4)),
|
||||||
self.right_panel(),
|
self.right_panel(),
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -408,7 +413,7 @@ impl DictionaryState {
|
|||||||
tag_map: HashMap::new(),
|
tag_map: HashMap::new(),
|
||||||
words_tags: vec![],
|
words_tags: vec![],
|
||||||
reverse: false,
|
reverse: false,
|
||||||
search: "".to_string(),
|
search: String::new(),
|
||||||
no_typing: true,
|
no_typing: true,
|
||||||
reverse_list: true,
|
reverse_list: true,
|
||||||
auto_save_queue: HashMap::new(),
|
auto_save_queue: HashMap::new(),
|
||||||
@@ -425,7 +430,9 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn editor_for_word(&self, handle: EntityHandle<WordData>) -> WordEditor<DictionaryMessage> {
|
fn editor_for_word(&self, handle: EntityHandle<WordData>) -> WordEditor<DictionaryMessage> {
|
||||||
WordEditor::new(handle, self.state.clone()).on_delete(DeleteWord(handle)).on_edit(ExtendedWordEdited)
|
WordEditor::new(handle, self.state.clone())
|
||||||
|
.on_delete(DeleteWord(handle))
|
||||||
|
.on_edit(ExtendedWordEdited)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&mut self) {
|
fn init(&mut self) {
|
||||||
@@ -580,7 +587,9 @@ impl DictionaryState {
|
|||||||
|
|
||||||
fn right_panel(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn right_panel(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
if let Some(editor) = &self.word_editor {
|
if let Some(editor) = &self.word_editor {
|
||||||
container(editor.view().map(EditorAction)).width(FillPortion(3)).into()
|
container(editor.view().map(EditorAction))
|
||||||
|
.width(FillPortion(3))
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
self.filters()
|
self.filters()
|
||||||
}
|
}
|
||||||
@@ -590,7 +599,7 @@ impl DictionaryState {
|
|||||||
let dict = &self.state.dictionary.read();
|
let dict = &self.state.dictionary.read();
|
||||||
|
|
||||||
iced::widget::column![
|
iced::widget::column![
|
||||||
text_input("Поиск", &self.search)
|
jl_text_input!("Поиск", &self.search)
|
||||||
.on_input(Search)
|
.on_input(Search)
|
||||||
.width(Fill),
|
.width(Fill),
|
||||||
text!("Всего слов: {}", dict.len()),
|
text!("Всего слов: {}", dict.len()),
|
||||||
@@ -708,7 +717,8 @@ impl DictionaryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn selection_editor(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn selection_editor(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
let mut display = "".to_string();
|
let mut display = String::new();
|
||||||
|
let mut editable = false;
|
||||||
if let Some(selected) = self.selected_cell.as_ref() {
|
if let Some(selected) = self.selected_cell.as_ref() {
|
||||||
let mut dictionary = self.state.dictionary.write();
|
let mut dictionary = self.state.dictionary.write();
|
||||||
let word = dictionary.get_mut_static(selected.0).unwrap();
|
let word = dictionary.get_mut_static(selected.0).unwrap();
|
||||||
@@ -724,12 +734,21 @@ impl DictionaryState {
|
|||||||
display = word.tags.clone();
|
display = word.tags.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
editable = true;
|
||||||
}
|
}
|
||||||
text_input("", display.as_str())
|
let mut field = jl_text_input!("", display.as_str())
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.id(iced::widget::Id::new("editor"))
|
.id(iced::widget::Id::new("editor"))
|
||||||
.on_input(EditField)
|
.style(|theme, status| {
|
||||||
.into()
|
let mut default = default(theme, status);
|
||||||
|
default.border.radius = Radius::new(0);
|
||||||
|
default
|
||||||
|
});
|
||||||
|
if editable {
|
||||||
|
field = field.on_input(EditField)
|
||||||
|
}
|
||||||
|
|
||||||
|
field.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn groups_panel(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn groups_panel(&self) -> iced::Element<'_, DictionaryMessage> {
|
||||||
@@ -754,7 +773,7 @@ impl DictionaryState {
|
|||||||
scrollable(row).width(Fill).horizontal(),
|
scrollable(row).width(Fill).horizontal(),
|
||||||
row![
|
row![
|
||||||
jl_button!("⇳").on_press(ChangeDirection),
|
jl_button!("⇳").on_press(ChangeDirection),
|
||||||
text_input("Название группы слов", &group.name)
|
jl_text_input!("Название группы слов", &group.name)
|
||||||
.on_input(EditGroup)
|
.on_input(EditGroup)
|
||||||
.width(250)
|
.width(250)
|
||||||
.on_submit(SaveGroup),
|
.on_submit(SaveGroup),
|
||||||
@@ -806,18 +825,20 @@ impl KeyPressedPage for DictionaryState {
|
|||||||
Task::done(RootMessage::Dictionary(ChangeSelectedField(Previous)))
|
Task::done(RootMessage::Dictionary(ChangeSelectedField(Previous)))
|
||||||
}
|
}
|
||||||
keyboard::key::Code::Tab => {
|
keyboard::key::Code::Tab => {
|
||||||
return if *mods == Modifiers::CTRL && let Some(selected) = self.selected_cell {
|
return if *mods == Modifiers::CTRL
|
||||||
|
&& let Some(selected) = self.selected_cell
|
||||||
|
{
|
||||||
Task::done(RootMessage::Dictionary(ExtendedEdit(selected.0)))
|
Task::done(RootMessage::Dictionary(ExtendedEdit(selected.0)))
|
||||||
} else if let Named(keyboard::key::Named::Alt) = modifier {
|
} else if let Named(keyboard::key::Named::Alt) = modifier {
|
||||||
Task::done(RootMessage::Dictionary(ChangeSelectedField(Backward)))
|
Task::done(RootMessage::Dictionary(ChangeSelectedField(Backward)))
|
||||||
} else {
|
} else {
|
||||||
Task::done(RootMessage::Dictionary(ChangeSelectedField(Forward)))
|
Task::done(RootMessage::Dictionary(ChangeSelectedField(Forward)))
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
keyboard::key::Code::Escape => {
|
keyboard::key::Code::Escape => {
|
||||||
if self.word_editor.is_some() {
|
if self.word_editor.is_some() {
|
||||||
self.word_editor = None;
|
self.word_editor = None;
|
||||||
}else if self.selected_cell.is_some() {
|
} else if self.selected_cell.is_some() {
|
||||||
self.selected_cell = None;
|
self.selected_cell = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
use crate::data::entities::{EntityHandle, WordData};
|
use crate::data::entities::{EntityHandle, WordData};
|
||||||
use crate::data::repositories::Repository;
|
use crate::data::repositories::Repository;
|
||||||
use crate::jl_button;
|
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::RootMessage;
|
use crate::navigation::RootMessage;
|
||||||
use crate::navigation::*;
|
use crate::navigation::*;
|
||||||
@@ -9,6 +8,7 @@ use crate::pages::dictionary::split_with_coma;
|
|||||||
use crate::pages::dictionary_quiz::DictionaryQuizMessage::*;
|
use crate::pages::dictionary_quiz::DictionaryQuizMessage::*;
|
||||||
use crate::pages::quiz::Score;
|
use crate::pages::quiz::Score;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
|
use crate::{jl_button, jl_text_input};
|
||||||
use iced::Background::Color;
|
use iced::Background::Color;
|
||||||
use iced::border::Radius;
|
use iced::border::Radius;
|
||||||
use iced::widget::container::Style;
|
use iced::widget::container::Style;
|
||||||
@@ -76,7 +76,7 @@ impl NavigatedPage<DictionaryQuizMessage> for DictionaryQuizState {
|
|||||||
]
|
]
|
||||||
.align_x(alignment::Horizontal::Center)
|
.align_x(alignment::Horizontal::Center)
|
||||||
.spacing(5),
|
.spacing(5),
|
||||||
text_input("Перевод", &self.answer)
|
jl_text_input!("Перевод", &self.answer)
|
||||||
.size(28)
|
.size(28)
|
||||||
.width(250)
|
.width(250)
|
||||||
.on_input(AnswerChanged)
|
.on_input(AnswerChanged)
|
||||||
@@ -114,9 +114,9 @@ impl DictionaryQuizState {
|
|||||||
state,
|
state,
|
||||||
words,
|
words,
|
||||||
current_set: Vec::new(),
|
current_set: Vec::new(),
|
||||||
answer: "".to_string(),
|
answer: String::new(),
|
||||||
view: "---".to_string(),
|
view: "---".to_string(),
|
||||||
correct: "".to_string(),
|
correct: String::new(),
|
||||||
score: Default::default(),
|
score: Default::default(),
|
||||||
is_help: false,
|
is_help: false,
|
||||||
reverse,
|
reverse,
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ impl HistoryState {
|
|||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
group_id: Default::default(),
|
group_id: Default::default(),
|
||||||
key: "Удаленное слово".to_string(),
|
key: "Удаленное слово".to_string(),
|
||||||
value: "".to_string(),
|
value: String::new(),
|
||||||
tags: "".to_string(),
|
tags: String::new(),
|
||||||
additional: Default::default(),
|
additional: Default::default(),
|
||||||
});
|
});
|
||||||
(word, item.clone())
|
(word, item.clone())
|
||||||
|
|||||||
+12
-7
@@ -9,9 +9,9 @@ use crate::navigation::{NavigatedPage, Page, RootMessage};
|
|||||||
use crate::notification::NotificationData::{CompressError, OpenFileError};
|
use crate::notification::NotificationData::{CompressError, OpenFileError};
|
||||||
use crate::notification::{MaybeError, NotificationData};
|
use crate::notification::{MaybeError, NotificationData};
|
||||||
use crate::pages::import::ImportMessage::*;
|
use crate::pages::import::ImportMessage::*;
|
||||||
use crate::push_error;
|
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::{jl_button, push_error_task};
|
use crate::{jl_button, push_error_task};
|
||||||
|
use crate::{jl_text_input, push_error};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::container::success;
|
use iced::widget::container::success;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
@@ -269,7 +269,7 @@ impl ImportState {
|
|||||||
self.available_properties(),
|
self.available_properties(),
|
||||||
button("Добавить напрямую").on_press(SetupDirect),
|
button("Добавить напрямую").on_press(SetupDirect),
|
||||||
row![
|
row![
|
||||||
text_input("Пользовательское поле", &self.custom_property_name)
|
jl_text_input!("Пользовательское поле", &self.custom_property_name)
|
||||||
.on_input(EditCustomProperty),
|
.on_input(EditCustomProperty),
|
||||||
button("Установить привязку").on_press(SetupCustomProperty)
|
button("Установить привязку").on_press(SetupCustomProperty)
|
||||||
]
|
]
|
||||||
@@ -297,7 +297,7 @@ impl ImportState {
|
|||||||
.on_toggle(SwitchSkipEmpty),
|
.on_toggle(SwitchSkipEmpty),
|
||||||
column![
|
column![
|
||||||
text!("Разделитель при множественном объединении"),
|
text!("Разделитель при множественном объединении"),
|
||||||
text_input("", &self.separator).on_input(EditSeparator)
|
jl_text_input!("", &self.separator).on_input(EditSeparator)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
@@ -329,7 +329,7 @@ impl ImportState {
|
|||||||
import_data: None,
|
import_data: None,
|
||||||
selected_index: 0,
|
selected_index: 0,
|
||||||
selected_property: None,
|
selected_property: None,
|
||||||
custom_property_name: "".to_string(),
|
custom_property_name: String::new(),
|
||||||
skip_empty: true,
|
skip_empty: true,
|
||||||
separator: ", ".to_string(),
|
separator: ", ".to_string(),
|
||||||
progress: None,
|
progress: None,
|
||||||
@@ -582,7 +582,11 @@ impl ImportState {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|field| field.identifier.clone())
|
.map(|field| field.identifier.clone())
|
||||||
.collect();
|
.collect();
|
||||||
current_fields.append(&mut vec!["key".to_string(), "value".to_string(), "tags".to_string()]);
|
current_fields.append(&mut vec![
|
||||||
|
"key".to_string(),
|
||||||
|
"value".to_string(),
|
||||||
|
"tags".to_string(),
|
||||||
|
]);
|
||||||
for (field, _) in import_group {
|
for (field, _) in import_group {
|
||||||
if current_fields.contains(field) {
|
if current_fields.contains(field) {
|
||||||
continue;
|
continue;
|
||||||
@@ -600,5 +604,6 @@ impl ImportState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum AnkiSchema {
|
pub enum AnkiSchema {
|
||||||
Old, Beta
|
Old,
|
||||||
}
|
Beta,
|
||||||
|
}
|
||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
use crate::app::USER_FONT;
|
use crate::app::USER_FONT;
|
||||||
use crate::core::kana_set::KanaSet;
|
use crate::core::kana_set::KanaSet;
|
||||||
use crate::jl_button;
|
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::pages::quiz::QuizMessage::*;
|
use crate::pages::quiz::QuizMessage::*;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
|
use crate::{jl_button, jl_text_input};
|
||||||
use iced::widget::*;
|
use iced::widget::*;
|
||||||
use iced::{Element, Fill, Task, alignment};
|
use iced::{Element, Fill, Task, alignment};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
@@ -77,7 +77,7 @@ impl NavigatedPage<QuizMessage> for QuizState {
|
|||||||
]
|
]
|
||||||
.align_y(alignment::Vertical::Center)
|
.align_y(alignment::Vertical::Center)
|
||||||
.spacing(20),
|
.spacing(20),
|
||||||
text_input("Романдзи", &self.current_roman)
|
jl_text_input!("Романдзи", &self.current_roman)
|
||||||
.size(28)
|
.size(28)
|
||||||
.width(150)
|
.width(150)
|
||||||
.on_input(ContentChanged),
|
.on_input(ContentChanged),
|
||||||
@@ -113,7 +113,7 @@ impl QuizState {
|
|||||||
kana: "ぁ".to_string(),
|
kana: "ぁ".to_string(),
|
||||||
correct_roman: "a".to_string(),
|
correct_roman: "a".to_string(),
|
||||||
is_help: false,
|
is_help: false,
|
||||||
current_roman: "".to_string(),
|
current_roman: String::new(),
|
||||||
set: KanaSet::hiragana(),
|
set: KanaSet::hiragana(),
|
||||||
queue: Vec::new(),
|
queue: Vec::new(),
|
||||||
score: Score {
|
score: Score {
|
||||||
|
|||||||
@@ -270,13 +270,13 @@ impl RepetitionState {
|
|||||||
fn draw_context(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
fn draw_context(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
match word.additional.get(&Id(3)) {
|
match word.additional.get(&Id(3)) {
|
||||||
None => space().into(),
|
None => space().into(),
|
||||||
Some(context) => text!("{}", context).size(24).into(),
|
Some(context) => text!("{}", context).center().size(24).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
fn draw_description(&self, word: &WordData) -> Element<'_, RepetitionMessage> {
|
||||||
match word.additional.get(&Id(2)) {
|
match word.additional.get(&Id(2)) {
|
||||||
None => space().into(),
|
None => space().into(),
|
||||||
Some(context) => text!("{}", context).size(24).into(),
|
Some(context) => text!("{}", context).center().size(24).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use crate::app::AppState;
|
|||||||
use crate::core::deck::DeckData;
|
use crate::core::deck::DeckData;
|
||||||
use crate::data::entities::{DeckSettings, EntityHandle};
|
use crate::data::entities::{DeckSettings, EntityHandle};
|
||||||
use crate::data::repositories::{BatchedRepository, Repository};
|
use crate::data::repositories::{BatchedRepository, Repository};
|
||||||
use crate::jl_button;
|
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::notification::MaybeError;
|
use crate::notification::MaybeError;
|
||||||
use crate::pages::repetition_settings::RepetitionSettingsMessage::*;
|
use crate::pages::repetition_settings::RepetitionSettingsMessage::*;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
|
use crate::{jl_button, jl_text_input};
|
||||||
use crate::{push_error, push_error_task};
|
use crate::{push_error, push_error_task};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
@@ -143,22 +143,22 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
|||||||
column![
|
column![
|
||||||
column![
|
column![
|
||||||
text!("Название набора"),
|
text!("Название набора"),
|
||||||
text_input("", &self.settings_data.name).on_input(SetName),
|
jl_text_input!("", &self.settings_data.name).on_input(SetName),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Передняя сторона"),
|
text!("Передняя сторона"),
|
||||||
text_input("", &self.settings_data.forward).on_input(SetForward),
|
jl_text_input!("", &self.settings_data.forward).on_input(SetForward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Задняя сторона"),
|
text!("Задняя сторона"),
|
||||||
text_input("", &self.settings_data.backward).on_input(SetBackward),
|
jl_text_input!("", &self.settings_data.backward).on_input(SetBackward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Фильтр"),
|
text!("Фильтр"),
|
||||||
text_input("", &self.settings_data.filter)
|
jl_text_input!("", &self.settings_data.filter)
|
||||||
.style(|x, status| {
|
.style(|x, status| {
|
||||||
let mut primary = Theme::default()(x, status);
|
let mut primary = Theme::default()(x, status);
|
||||||
if !self.correct_filter {
|
if !self.correct_filter {
|
||||||
@@ -220,7 +220,7 @@ fn update_deck_stats(deck: &DeckSettings, state: &AppState) -> MaybeError {
|
|||||||
.map(|w| w.id)
|
.map(|w| w.id)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
filtered_words.iter().for_each(|word_id| {
|
filtered_words.iter().for_each(|word_id| {
|
||||||
if let Some(index) = db_stats.iter().position(|stat_id| stat_id.id == *word_id) {
|
if let Some(index) = db_stats.iter().position(|stat_id| stat_id.word_id == *word_id) {
|
||||||
db_stats.remove(index);
|
db_stats.remove(index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use crate::core::deck::DeckData;
|
|||||||
use crate::core::srs::{AppendMode, OrderMode};
|
use crate::core::srs::{AppendMode, OrderMode};
|
||||||
use crate::data::entities::{CardState, DeckSettings, EntityHandle, WordData};
|
use crate::data::entities::{CardState, DeckSettings, EntityHandle, WordData};
|
||||||
use crate::data::repositories::{BatchedRepository, Repository};
|
use crate::data::repositories::{BatchedRepository, Repository};
|
||||||
use crate::jl_button;
|
|
||||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::notification::MaybeError;
|
use crate::notification::MaybeError;
|
||||||
@@ -14,6 +13,7 @@ use crate::pages::repetitions::RepetitionsMessage::*;
|
|||||||
use crate::push_error;
|
use crate::push_error;
|
||||||
use crate::push_error_task;
|
use crate::push_error_task;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
|
use crate::{jl_button, jl_text_input};
|
||||||
use chrono::{Days, Local, Utc};
|
use chrono::{Days, Local, Utc};
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
pub use iced::widget::button::{Catalog, Style};
|
pub use iced::widget::button::{Catalog, Style};
|
||||||
@@ -96,6 +96,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
} else {
|
} else {
|
||||||
self.fill_deck_word_indices();
|
self.fill_deck_word_indices();
|
||||||
}
|
}
|
||||||
|
_ = self.state.history.write().reload()
|
||||||
}
|
}
|
||||||
fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
fn update(&mut self, message: RepetitionsMessage) -> Task<RootMessage> {
|
||||||
match message {
|
match message {
|
||||||
@@ -302,7 +303,7 @@ impl RepetitionsState {
|
|||||||
column![
|
column![
|
||||||
text!("Название набора"),
|
text!("Название набора"),
|
||||||
row![
|
row![
|
||||||
text_input("", &deck.name).on_input(SetName),
|
jl_text_input!("", &deck.name).on_input(SetName),
|
||||||
button(svg(Handle::from_memory(SETTINGS_ICON)))
|
button(svg(Handle::from_memory(SETTINGS_ICON)))
|
||||||
.width(43)
|
.width(43)
|
||||||
.on_press(GoToSettings),
|
.on_press(GoToSettings),
|
||||||
@@ -315,17 +316,17 @@ impl RepetitionsState {
|
|||||||
column![
|
column![
|
||||||
column![
|
column![
|
||||||
text!("Передняя сторона"),
|
text!("Передняя сторона"),
|
||||||
text_input("", &deck.forward).on_input(SetForward),
|
jl_text_input!("", &deck.forward).on_input(SetForward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Задняя сторона"),
|
text!("Задняя сторона"),
|
||||||
text_input("", &deck.backward).on_input(SetBackward),
|
jl_text_input!("", &deck.backward).on_input(SetBackward),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Фильтр"),
|
text!("Фильтр"),
|
||||||
text_input("", &deck.filter).on_input(SetFilter),
|
jl_text_input!("", &deck.filter).on_input(SetFilter),
|
||||||
jl_button!("Проверить фильтр").on_press(TryFilter),
|
jl_button!("Проверить фильтр").on_press(TryFilter),
|
||||||
self.count_view(deck),
|
self.count_view(deck),
|
||||||
]
|
]
|
||||||
|
|||||||
+20
-1
@@ -15,6 +15,7 @@ use iced::widget::{button, column, container, progress_bar, row, space, text, to
|
|||||||
use iced::{Center, Element, Fill, Font, Length, Task};
|
use iced::{Center, Element, Fill, Font, Length, Task};
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use crate::notification::NotificationData::LocalVersionChanged;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum SyncMessage {
|
pub enum SyncMessage {
|
||||||
@@ -31,11 +32,13 @@ pub enum SyncMessage {
|
|||||||
Disable,
|
Disable,
|
||||||
DisableSync,
|
DisableSync,
|
||||||
SwitchAutoSync,
|
SwitchAutoSync,
|
||||||
|
ResetRealLoad,
|
||||||
}
|
}
|
||||||
pub struct SyncState {
|
pub struct SyncState {
|
||||||
state: AppState,
|
state: AppState,
|
||||||
auto_fetch: bool,
|
auto_fetch: bool,
|
||||||
frozen: bool,
|
frozen: bool,
|
||||||
|
real_load: bool,
|
||||||
progress: f32,
|
progress: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +102,18 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
GetLast => {
|
GetLast => {
|
||||||
|
if self.real_load == false {
|
||||||
|
self.real_load = true;
|
||||||
|
return Task::batch([
|
||||||
|
Task::future(async {
|
||||||
|
tokio::time::sleep(Duration::from_millis(3000)).await;
|
||||||
|
return RootMessage::Sync(ResetRealLoad);
|
||||||
|
}),
|
||||||
|
Task::done(RootMessage::PushNotification(NotificationRequest::Warning(LocalVersionChanged)))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.real_load = false;
|
||||||
let id = self.state.sync_data.read().key.clone().unwrap();
|
let id = self.state.sync_data.read().key.clone().unwrap();
|
||||||
let tasks = Task::batch([
|
let tasks = Task::batch([
|
||||||
Task::perform(
|
Task::perform(
|
||||||
@@ -134,7 +149,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Task::done(RootMessage::PushNotification(NotificationRequest::Info(
|
return Task::done(RootMessage::PushNotification(NotificationRequest::Info(
|
||||||
NotificationData::DataLoaded,
|
NotificationData::DataSynced,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
Disable => {}
|
Disable => {}
|
||||||
@@ -166,6 +181,9 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
return push_error_task!(err);
|
return push_error_task!(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ResetRealLoad => {
|
||||||
|
self.real_load = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
@@ -189,6 +207,7 @@ impl SyncState {
|
|||||||
auto_fetch,
|
auto_fetch,
|
||||||
state,
|
state,
|
||||||
frozen: false,
|
frozen: false,
|
||||||
|
real_load: false,
|
||||||
progress: 0.0,
|
progress: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-15
@@ -2,11 +2,12 @@ use crate::app::AppState;
|
|||||||
use crate::data::Id;
|
use crate::data::Id;
|
||||||
use crate::data::entities::{CustomField, EntityHandle, WordData};
|
use crate::data::entities::{CustomField, EntityHandle, WordData};
|
||||||
use crate::data::repositories::Repository;
|
use crate::data::repositories::Repository;
|
||||||
|
use crate::jl_text_input;
|
||||||
use crate::pages::word::WordMessage::*;
|
use crate::pages::word::WordMessage::*;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::space::horizontal;
|
use iced::widget::space::horizontal;
|
||||||
use iced::widget::{button, column, row, rule, scrollable, text, text_input};
|
use iced::widget::{button, column, row, rule, scrollable, text};
|
||||||
use iced::{Element, Fill};
|
use iced::{Element, Fill};
|
||||||
use iced_core::Padding;
|
use iced_core::Padding;
|
||||||
|
|
||||||
@@ -34,10 +35,10 @@ impl<Message> WordEditor<Message> {
|
|||||||
word.value = n;
|
word.value = n;
|
||||||
}
|
}
|
||||||
SetAdditional(key, value) => {
|
SetAdditional(key, value) => {
|
||||||
word.additional.insert(key, value.clone());
|
word.additional.insert(key, value.replace("", ""));
|
||||||
}
|
}
|
||||||
AddAdditional(key) => {
|
AddAdditional(key) => {
|
||||||
word.additional.insert(key, "".to_string());
|
word.additional.insert(key, String::new());
|
||||||
}
|
}
|
||||||
RemoveAdditional(key) => {
|
RemoveAdditional(key) => {
|
||||||
word.additional.remove(&key);
|
word.additional.remove(&key);
|
||||||
@@ -65,23 +66,29 @@ impl<Message> WordEditor<Message> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut col = iced::widget::column![
|
let mut col = iced::widget::column![
|
||||||
column![text!("Ключ"), text_input("key", &word.key).on_input(SetKey),]
|
column![
|
||||||
.spacing(QUARTER_SPACING),
|
text!("Ключ"),
|
||||||
|
jl_text_input!("key", &word.key).on_input(SetKey),
|
||||||
|
]
|
||||||
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Значение"),
|
text!("Значение"),
|
||||||
text_input("value", &word.value).on_input(SetValue),
|
jl_text_input!("value", &word.value).on_input(SetValue),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
column![
|
column![
|
||||||
text!("Теги"),
|
text!("Теги"),
|
||||||
text_input("tags", &word.tags).on_input(SetTags),
|
jl_text_input!("tags", &word.tags).on_input(SetTags),
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
rule::horizontal(2),
|
rule::horizontal(2),
|
||||||
scrollable(fast_add.padding(Padding{
|
scrollable(fast_add.padding(Padding {
|
||||||
|
top: 0.0,
|
||||||
|
right: 0.0,
|
||||||
top: 0.0 , right: 0.0 , bottom: 4.0 , left: 0.0 , })).horizontal(),
|
bottom: 4.0,
|
||||||
|
left: 0.0,
|
||||||
|
}))
|
||||||
|
.horizontal(),
|
||||||
];
|
];
|
||||||
|
|
||||||
for more in &word.additional {
|
for more in &word.additional {
|
||||||
@@ -140,12 +147,10 @@ impl<Message> WordEditor<Message> {
|
|||||||
column![
|
column![
|
||||||
text!("{}", name),
|
text!("{}", name),
|
||||||
row![
|
row![
|
||||||
text_input(name, value)
|
jl_text_input!(name, value)
|
||||||
.on_input(move |string| SetAdditional(id, string))
|
.on_input(move |string| SetAdditional(id, string))
|
||||||
.width(Fill),
|
.width(Fill),
|
||||||
button("-")
|
button("-").on_press(RemoveAdditional(id)).style(danger),
|
||||||
.on_press(RemoveAdditional(id))
|
|
||||||
.style(danger),
|
|
||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -65,11 +65,11 @@ impl WritingState {
|
|||||||
let mut list = set.list();
|
let mut list = set.list();
|
||||||
list.shuffle(&mut rand::rng());
|
list.shuffle(&mut rand::rng());
|
||||||
WritingState {
|
WritingState {
|
||||||
kana: "".to_string(),
|
kana: String::new(),
|
||||||
set: list.clone(),
|
set: list.clone(),
|
||||||
original_set: list,
|
original_set: list,
|
||||||
kana_total: "".to_string(),
|
kana_total: String::new(),
|
||||||
roman_total: "".to_string(),
|
roman_total: String::new(),
|
||||||
next_text: "Дальше".to_string(),
|
next_text: "Дальше".to_string(),
|
||||||
show_all: false,
|
show_all: false,
|
||||||
}
|
}
|
||||||
@@ -79,9 +79,9 @@ impl WritingState {
|
|||||||
impl WritingState {
|
impl WritingState {
|
||||||
fn next(&mut self) {
|
fn next(&mut self) {
|
||||||
if self.set.is_empty() {
|
if self.set.is_empty() {
|
||||||
self.kana = "".to_string();
|
self.kana = String::new();
|
||||||
self.roman_total = "".to_string();
|
self.roman_total = String::new();
|
||||||
self.kana_total = "".to_string();
|
self.kana_total = String::new();
|
||||||
|
|
||||||
self.set = self.original_set.clone();
|
self.set = self.original_set.clone();
|
||||||
self.set.shuffle(&mut rand::rng());
|
self.set.shuffle(&mut rand::rng());
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ pub fn jl_button_style(theme: &Theme, status: Status) -> Style {
|
|||||||
};
|
};
|
||||||
style
|
style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn jl_text_input_style(
|
||||||
|
theme: &Theme,
|
||||||
|
status: iced::widget::text_input::Status,
|
||||||
|
) -> iced::widget::text_input::Style {
|
||||||
|
let mut style = iced::widget::text_input::default(theme, status);
|
||||||
|
style.border.radius = Radius::new(BUTTON_RADIUS);
|
||||||
|
style
|
||||||
|
}
|
||||||
pub fn cta_button(theme: &Theme, status: Status) -> Style {
|
pub fn cta_button(theme: &Theme, status: Status) -> Style {
|
||||||
let mut style = secondary(theme, status);
|
let mut style = secondary(theme, status);
|
||||||
style.border.width = 1.0;
|
style.border.width = 1.0;
|
||||||
@@ -37,6 +46,13 @@ macro_rules! jl_button {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! jl_text_input {
|
||||||
|
($placeholder:expr, $content:expr) => {
|
||||||
|
iced::widget::text_input($placeholder, $content).style($crate::styling::jl_text_input_style)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn back_overlay<'a, T: Clone + 'a>(content: Element<'a, T>, back_message: T) -> Element<'a, T> {
|
pub fn back_overlay<'a, T: Clone + 'a>(content: Element<'a, T>, back_message: T) -> Element<'a, T> {
|
||||||
container(
|
container(
|
||||||
iced::widget::column![jl_button!("Назад").on_press(back_message), content]
|
iced::widget::column![jl_button!("Назад").on_press(back_message), content]
|
||||||
|
|||||||
@@ -215,7 +215,9 @@ where
|
|||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
if self.on_move.is_none() && let Event::Mouse(mouse::Event::CursorMoved {..}) = event {
|
if self.on_move.is_none()
|
||||||
|
&& let Event::Mouse(mouse::Event::CursorMoved { .. }) = event
|
||||||
|
{
|
||||||
self.content.as_widget_mut().update(
|
self.content.as_widget_mut().update(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
event,
|
event,
|
||||||
@@ -228,7 +230,9 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.on_enter.is_none() && let Event::Mouse(mouse::Event::CursorEntered {..}) = event {
|
if self.on_enter.is_none()
|
||||||
|
&& let Event::Mouse(mouse::Event::CursorEntered { .. }) = event
|
||||||
|
{
|
||||||
self.content.as_widget_mut().update(
|
self.content.as_widget_mut().update(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
event,
|
event,
|
||||||
@@ -240,7 +244,9 @@ where
|
|||||||
viewport,
|
viewport,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.on_exit.is_none() && let Event::Mouse(mouse::Event::CursorLeft {..}) = event {
|
if self.on_exit.is_none()
|
||||||
|
&& let Event::Mouse(mouse::Event::CursorLeft { .. }) = event
|
||||||
|
{
|
||||||
self.content.as_widget_mut().update(
|
self.content.as_widget_mut().update(
|
||||||
&mut tree.children[0],
|
&mut tree.children[0],
|
||||||
event,
|
event,
|
||||||
@@ -252,7 +258,7 @@ where
|
|||||||
viewport,
|
viewport,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if shell.is_event_captured() {
|
if shell.is_event_captured() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user