Updated word display #19
+8
-41
@@ -59,9 +59,6 @@ pub struct DictionaryState {
|
||||
#[derive(Clone)]
|
||||
pub enum DictionaryMessage {
|
||||
Back,
|
||||
SetTags(EntityHandle<WordData>, String),
|
||||
SetKey(EntityHandle<WordData>, String),
|
||||
SetValue(EntityHandle<WordData>, String),
|
||||
ExtendedEdit(EntityHandle<WordData>),
|
||||
DeleteWord(EntityHandle<WordData>),
|
||||
NewWord,
|
||||
@@ -151,43 +148,11 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
dictionary.create(word);
|
||||
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) => {
|
||||
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) => {
|
||||
if b {
|
||||
@@ -278,6 +243,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
return Task::none();
|
||||
}
|
||||
if self.auto_save_queue[&handle] <= now {
|
||||
self.update_tags();
|
||||
self.auto_save_queue.remove(&handle);
|
||||
|
||||
let mut dictionary = self.state.dictionary.write();
|
||||
@@ -288,7 +254,9 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
if let Some(selected) = self.selected_cell && selected.0 == original {
|
||||
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");
|
||||
@@ -380,10 +348,9 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
}
|
||||
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
if let Some(selected) = self.selected_cell && selected.0 != i {
|
||||
self.selected_cell = None;
|
||||
self.word_editor = None;
|
||||
}
|
||||
|
||||
}
|
||||
EditorAction(action) => {
|
||||
let result = self.word_editor.as_mut().unwrap().update(action);
|
||||
|
||||
Reference in new issue
Block a user