Change selection type on extended editing

This commit is contained in:
micialware committed 2026-09-22 15:48:18 +03:00
1 parent b210b2013d
commit 8b673e52da
1 file changed
+56 -24
+56 -24
View File
@@ -21,19 +21,19 @@ use chrono::{DateTime, TimeDelta, Utc};
use hashbrown::{HashMap, HashSet};
use iced::alignment::Vertical::Center;
use iced::widget::button::Style;
use iced::widget::button::{danger, text};
use iced::widget::button::{danger};
use iced::widget::operation::focus;
use iced::widget::space::horizontal;
use iced::widget::text_input::Status::Active;
use iced::widget::text_input::default;
use iced::widget::*;
use iced::{Border, Color, Shadow, Task};
use iced::widget::{row, container, column, text_input, space, button, scrollable, text, Row, checkbox, Column, toggler, lazy};
use iced::{Border, Color, Element, Shadow, Task};
use iced_core::Length::{Fill, FillPortion};
use iced_core::border::Radius;
use iced_core::keyboard;
use iced_core::keyboard::Key::Named;
use iced_core::keyboard::key::Physical::Code;
use iced_core::keyboard::{Event, Modifiers};
use iced_core::{keyboard, Padding, Theme};
use log::info;
use rand::random_range;
use std::ops::Add;
@@ -98,6 +98,7 @@ pub enum BasicWordFields {
Key,
Value,
Tags,
TotalLine,
}
const FIELDS: &[BasicWordFields] = &[Key, Value, Tags];
@@ -151,8 +152,8 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
}
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))
if let Some((_, _, index)) = self.selected_cell.clone() {
self.selected_cell = Some((i, TotalLine, index))
}
}
Include(i, b) => {
@@ -295,6 +296,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
Tags => {
word.tags = value;
}
_ => {}
}
}
@@ -379,17 +381,19 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
Task::none()
}
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
fn view(&self) -> Element<'_, DictionaryMessage> {
back_overlay(
row![
iced::widget::column![
column![
self.groups_panel(),
column![
row![horizontal().width(8), self.words_list(),],
self.selection_editor(),
],
row![
self.add_word_button(),
horizontal().width(Fill),
button("Импорт").style(text).on_press(GotoImport),
button("Импорт").style(button::text).on_press(GotoImport),
]
]
.spacing(5)
@@ -463,7 +467,7 @@ impl DictionaryState {
)
}
fn words_list(&self) -> iced::Element<'_, DictionaryMessage> {
fn words_list(&self) -> Element<'_, DictionaryMessage> {
let time = Instant::now();
let mut col = Column::new().width(Fill);
@@ -513,7 +517,7 @@ impl DictionaryState {
scrollable(col).height(Fill).into()
}
fn word_line<'a>(data: &WordLineState) -> Row<'a, DictionaryMessage> {
fn word_line<'a>(data: &WordLineState) -> Element<'a, DictionaryMessage> {
let mut line = Row::new().width(Fill).align_y(Center);
let handle = data.handle;
line = line.push(
@@ -583,10 +587,30 @@ impl DictionaryState {
.style(button::primary)
.width(15)
};
line.push(line_button()).push(space().width(10))
let assembled = line.push(line_button()).push(space().width(10));
if let Some(selection) = data.selection
&& selection == TotalLine
{
return container(assembled.padding(Padding {
top: 2.0,
right: 0.0,
bottom: 2.0,
left: 0.0,
}))
.style(|theme: &Theme| {
let mut style = container::Style::default();
style.border.color = theme.extended_palette().secondary.base.color;
style.border.width = 3.0_f32;
style
})
.into();
}
assembled.into()
}
fn right_panel(&self) -> iced::Element<'_, DictionaryMessage> {
fn right_panel(&self) -> Element<'_, DictionaryMessage> {
if let Some(editor) = &self.word_editor {
container(editor.view().map(EditorAction))
.width(FillPortion(3))
@@ -596,10 +620,10 @@ impl DictionaryState {
}
}
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
fn filters(&self) -> Element<'_, DictionaryMessage> {
let dict = &self.state.dictionary.read();
iced::widget::column![
column![
jl_text_input!("Поиск", &self.search)
.on_input(Search)
.width(Fill),
@@ -622,7 +646,7 @@ impl DictionaryState {
.into()
}
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
fn tags_selector(&self) -> Element<'_, DictionaryMessage> {
let mut col = Column::new().width(Fill);
col = col.push(
button("Сбросить")
@@ -717,10 +741,12 @@ impl DictionaryState {
info!("Time {}", time.elapsed().as_micros());
}
fn selection_editor(&self) -> iced::Element<'_, DictionaryMessage> {
fn selection_editor(&self) -> Element<'_, DictionaryMessage> {
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()
&& selected.1 != TotalLine
{
let mut dictionary = self.state.dictionary.write();
let word = dictionary.get_mut_static(selected.0).unwrap();
@@ -734,6 +760,7 @@ impl DictionaryState {
Tags => {
display = word.tags.clone();
}
_ => {}
}
editable = true;
}
@@ -752,9 +779,9 @@ impl DictionaryState {
field.into()
}
fn groups_panel(&self) -> iced::Element<'_, DictionaryMessage> {
fn groups_panel(&self) -> Element<'_, DictionaryMessage> {
let mut row = Row::new();
row = row.push(button("+").style(text).on_press(CreateGroup));
row = row.push(button("+").style(button::text).on_press(CreateGroup));
let groups = &self.state.word_groups.read();
@@ -762,7 +789,7 @@ impl DictionaryState {
let group_name = groups.get(&mut group).unwrap().name.clone();
row = row.push(
button(text!("{}", group_name))
.style(text)
.style(button::text)
.on_press(SelectGroup(group)),
);
}
@@ -770,7 +797,7 @@ impl DictionaryState {
let groups = self.state.word_groups.read();
let group = groups.get_static(self.selected_group).unwrap();
iced::widget::column![
column![
scrollable(row).width(Fill).horizontal(),
row![
jl_button!("⇳").on_press(ChangeDirection),
@@ -786,7 +813,7 @@ impl DictionaryState {
.into()
}
fn group_delete_button(&self) -> iced::Element<'_, DictionaryMessage> {
fn group_delete_button(&self) -> Element<'_, DictionaryMessage> {
if self.selected_group.real() && self.selected_group.id != 1.into() {
button("Удалить").style(danger).on_press(DeleteGroup).into()
} else {
@@ -794,7 +821,7 @@ impl DictionaryState {
}
}
fn add_word_button(&self) -> iced::Element<'_, DictionaryMessage> {
fn add_word_button(&self) -> Element<'_, DictionaryMessage> {
let button = jl_button!("Добавить слово");
if self.selected_group.real() {
@@ -839,6 +866,11 @@ impl KeyPressedPage for DictionaryState {
keyboard::key::Code::Escape => {
if self.word_editor.is_some() {
self.word_editor = None;
if let Some(selected) = self.selected_cell
&& selected.1 == TotalLine
{
self.selected_cell = None;
}
} else if self.selected_cell.is_some() {
self.selected_cell = None;
}