More fixes for dictionary panel

This commit is contained in:
micialware committed 2026-09-11 13:09:20 +03:00
1 parent 05c82bee02
commit 2568b9f292
1 file changed
+8 -41
+8 -41
View File
@@ -59,9 +59,6 @@ pub struct DictionaryState {
#[derive(Clone)] #[derive(Clone)]
pub enum DictionaryMessage { pub enum DictionaryMessage {
Back, Back,
SetTags(EntityHandle<WordData>, String),
SetKey(EntityHandle<WordData>, String),
SetValue(EntityHandle<WordData>, String),
ExtendedEdit(EntityHandle<WordData>), ExtendedEdit(EntityHandle<WordData>),
DeleteWord(EntityHandle<WordData>), DeleteWord(EntityHandle<WordData>),
NewWord, NewWord,
@@ -151,43 +148,11 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
dictionary.create(word); dictionary.create(word);
self.displayed_words_query.load(&dictionary); self.displayed_words_query.load(&dictionary);
} }
SetKey(handle, v) => {
let mut dictionary = self.state.dictionary.write();
dictionary.get_mut_static(handle).unwrap().key = v;
drop(dictionary);
return self.launch_auto_save_offset(handle);
}
SetValue(handle, v) => {
let mut dictionary = self.state.dictionary.write();
dictionary.get_mut_static(handle).unwrap().value = v;
drop(dictionary);
return self.launch_auto_save_offset(handle);
}
SetTags(i, mut v) => {
{
let mut dictionary = self.state.dictionary.write();
let word = dictionary.get_mut_static(i).unwrap();
let current_tags_value = word.tags.clone();
if v.ends_with(", ") && v.len() < current_tags_value.len() {
v = v[..v.len() - 2].to_string()
}
while let Some(index) = v.find(",,") {
v.remove(index);
}
word.tags = v;
}
self.update_tags();
return self.launch_auto_save_offset(i);
}
ExtendedEdit(i) => { ExtendedEdit(i) => {
self.word_editor = Some(self.editor_for_word(i)); self.word_editor = Some(self.editor_for_word(i));
if let Some((handle, cell, index)) = self.selected_cell.clone() {
self.selected_cell = Some((i, cell, index))
}
} }
Include(i, b) => { Include(i, b) => {
if b { if b {
@@ -278,6 +243,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
return Task::none(); return Task::none();
} }
if self.auto_save_queue[&handle] <= now { if self.auto_save_queue[&handle] <= now {
self.update_tags();
self.auto_save_queue.remove(&handle); self.auto_save_queue.remove(&handle);
let mut dictionary = self.state.dictionary.write(); let mut dictionary = self.state.dictionary.write();
@@ -288,7 +254,9 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
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));
self.word_editor = Some(self.editor_for_word(selected.0)); if self.word_editor.is_some() {
self.word_editor = Some(self.editor_for_word(handle));
}
} }
} }
info!("Saved word"); info!("Saved word");
@@ -380,10 +348,9 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
} }
self.displayed_words_query.load(&dictionary); self.displayed_words_query.load(&dictionary);
if let Some(selected) = self.selected_cell && selected.0 != i {
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);