From d59776d7131458caf3d69bf764cff5cdc798e5eb Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Fri, 11 Sep 2026 12:03:13 +0300 Subject: [PATCH] More keyboard handling for dictionary --- src/pages/dictionary.rs | 4 ++ src/pages/word.rs | 127 ++++++++++++++++++++-------------------- 2 files changed, 68 insertions(+), 63 deletions(-) diff --git a/src/pages/dictionary.rs b/src/pages/dictionary.rs index e096178..55c09c2 100644 --- a/src/pages/dictionary.rs +++ b/src/pages/dictionary.rs @@ -292,7 +292,11 @@ impl NavigatedPage for DictionaryState { GotoImport => {} SelectField(e, f, index) => { info!("Editing word {}", e.id); + if self.word_editor.is_some() && let Some(selected) = &self.selected_cell && selected.0 != e { + self.word_editor = Some(WordEditor::new(e, self.state.clone())); + } self.selected_cell = Some((e, f, index)); + return focus(iced::widget::Id::new("editor")); } EditField(value) => { diff --git a/src/pages/word.rs b/src/pages/word.rs index 239ec1a..0e4920e 100644 --- a/src/pages/word.rs +++ b/src/pages/word.rs @@ -5,8 +5,10 @@ use crate::navigation::{NavigatedPage, Page, RootMessage}; use crate::pages::word::WordMessage::*; use crate::styling::*; use iced::widget::button::danger; -use iced::widget::{button, column, row, space, text, text_input}; +use iced::widget::{button, column, row, rule, scrollable, space, text, text_input}; use iced::{Element, Fill, Task}; +use crate::data::repositories::Repository; +use crate::jl_button; pub struct WordEditor { state: AppState, @@ -54,68 +56,67 @@ impl WordEditor { } pub(crate) fn view(&self) -> Element<'_, WordMessage> { - // let mut fast_add = row![]; - // if !self.word.additional.contains_key("reading") { - // fast_add = fast_add.push( - // button("Чтение") - // .style(button::text) - // .on_press(AddAdditional("reading".to_string())), - // ); - // } - // if !self.word.additional.contains_key("description") { - // fast_add = fast_add.push( - // button("Описание") - // .style(button::text) - // .on_press(AddAdditional("description".to_string())), - // ); - // } - // - // if !self.word.additional.contains_key("context") { - // fast_add = fast_add.push( - // button("В контексте") - // .style(button::text) - // .on_press(AddAdditional("context".to_string())), - // ); - // } - // - // let mut col = iced::widget::column![ - // column![ - // text!("Ключ"), - // text_input("key", &self.word.key).on_input(SetKey), - // ] - // .spacing(QUARTER_SPACING), - // column![ - // text!("Значение"), - // text_input("value", &self.word.value).on_input(SetValue), - // ] - // .spacing(QUARTER_SPACING), - // column![ - // text!("Теги"), - // text_input("tags", &self.word.tags).on_input(SetTags), - // ] - // .spacing(QUARTER_SPACING), - // rule::horizontal(2), - // scrollable(fast_add), - // ]; - // - // for more in &self.word.additional { - // col = col.push(self.get_view_for_more(more)); - // } - // - // back_overlay( - // column![ - // col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill), - // row![ - // button("Сохранить").style(jl_button).on_press(Save), - // button("Удалить").style(danger).on_press(Delete), - // ] - // .spacing(DEFAULT_SPACING) - // ] - // .spacing(DEFAULT_SPACING) - // .into(), - // Back, - // ) - space().into() + let mut fast_add = row![]; + let word = self.state.dictionary.read().get_static(self.handle).unwrap(); + if !word.additional.contains_key("reading") { + fast_add = fast_add.push( + button("Чтение") + .style(button::text) + .on_press(AddAdditional("reading".to_string())), + ); + } + if !word.additional.contains_key("description") { + fast_add = fast_add.push( + button("Описание") + .style(button::text) + .on_press(AddAdditional("description".to_string())), + ); + } + + if !word.additional.contains_key("context") { + fast_add = fast_add.push( + button("В контексте") + .style(button::text) + .on_press(AddAdditional("context".to_string())), + ); + } + + let mut col = iced::widget::column![ + column![ + text!("Ключ"), + text_input("key", &word.key).on_input(SetKey), + ] + .spacing(QUARTER_SPACING), + column![ + text!("Значение"), + text_input("value", &word.value).on_input(SetValue), + ] + .spacing(QUARTER_SPACING), + column![ + text!("Теги"), + text_input("tags", &word.tags).on_input(SetTags), + ] + .spacing(QUARTER_SPACING), + rule::horizontal(2), + scrollable(fast_add), + ]; + + for more in &word.additional { + col = col.push(self.get_view_for_more(more)); + } + + column![ + col.spacing(DEFAULT_SPACING / 2.0).width(Fill).height(Fill), + row![ + jl_button!("Сохранить").on_press(Save), + button("Удалить").style(danger).on_press(Delete), + ] + .spacing(DEFAULT_SPACING) + ] + .spacing(DEFAULT_SPACING).into() + + + } }