Change selection type on extended editing
This commit is contained in:
1 parent
b210b2013d
commit
8b673e52da
1 file changed
+58
-26
+58
-26
@@ -21,19 +21,19 @@ use chrono::{DateTime, TimeDelta, Utc};
|
|||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
use iced::alignment::Vertical::Center;
|
use iced::alignment::Vertical::Center;
|
||||||
use iced::widget::button::Style;
|
use iced::widget::button::Style;
|
||||||
use iced::widget::button::{danger, text};
|
use iced::widget::button::{danger};
|
||||||
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::Status::Active;
|
use iced::widget::text_input::Status::Active;
|
||||||
use iced::widget::text_input::default;
|
use iced::widget::text_input::default;
|
||||||
use iced::widget::*;
|
use iced::widget::{row, container, column, text_input, space, button, scrollable, text, Row, checkbox, Column, toggler, lazy};
|
||||||
use iced::{Border, Color, Shadow, Task};
|
use iced::{Border, Color, Element, Shadow, Task};
|
||||||
use iced_core::Length::{Fill, FillPortion};
|
use iced_core::Length::{Fill, FillPortion};
|
||||||
use iced_core::border::Radius;
|
use iced_core::border::Radius;
|
||||||
use iced_core::keyboard;
|
|
||||||
use iced_core::keyboard::Key::Named;
|
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, Padding, Theme};
|
||||||
use log::info;
|
use log::info;
|
||||||
use rand::random_range;
|
use rand::random_range;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
@@ -98,6 +98,7 @@ pub enum BasicWordFields {
|
|||||||
Key,
|
Key,
|
||||||
Value,
|
Value,
|
||||||
Tags,
|
Tags,
|
||||||
|
TotalLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELDS: &[BasicWordFields] = &[Key, Value, Tags];
|
const FIELDS: &[BasicWordFields] = &[Key, Value, Tags];
|
||||||
@@ -151,8 +152,8 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
}
|
}
|
||||||
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() {
|
if let Some((_, _, index)) = self.selected_cell.clone() {
|
||||||
self.selected_cell = Some((i, cell, index))
|
self.selected_cell = Some((i, TotalLine, index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Include(i, b) => {
|
Include(i, b) => {
|
||||||
@@ -295,6 +296,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
Tags => {
|
Tags => {
|
||||||
word.tags = value;
|
word.tags = value;
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,17 +381,19 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn view(&self) -> Element<'_, DictionaryMessage> {
|
||||||
back_overlay(
|
back_overlay(
|
||||||
row![
|
row![
|
||||||
iced::widget::column![
|
column![
|
||||||
self.groups_panel(),
|
self.groups_panel(),
|
||||||
row![horizontal().width(8), self.words_list(),],
|
column![
|
||||||
self.selection_editor(),
|
row![horizontal().width(8), self.words_list(),],
|
||||||
|
self.selection_editor(),
|
||||||
|
],
|
||||||
row![
|
row![
|
||||||
self.add_word_button(),
|
self.add_word_button(),
|
||||||
horizontal().width(Fill),
|
horizontal().width(Fill),
|
||||||
button("Импорт").style(text).on_press(GotoImport),
|
button("Импорт").style(button::text).on_press(GotoImport),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
.spacing(5)
|
.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 time = Instant::now();
|
||||||
let mut col = Column::new().width(Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
|
|
||||||
@@ -513,7 +517,7 @@ impl DictionaryState {
|
|||||||
scrollable(col).height(Fill).into()
|
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 mut line = Row::new().width(Fill).align_y(Center);
|
||||||
let handle = data.handle;
|
let handle = data.handle;
|
||||||
line = line.push(
|
line = line.push(
|
||||||
@@ -583,10 +587,30 @@ impl DictionaryState {
|
|||||||
.style(button::primary)
|
.style(button::primary)
|
||||||
.width(15)
|
.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 {
|
if let Some(editor) = &self.word_editor {
|
||||||
container(editor.view().map(EditorAction))
|
container(editor.view().map(EditorAction))
|
||||||
.width(FillPortion(3))
|
.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();
|
let dict = &self.state.dictionary.read();
|
||||||
|
|
||||||
iced::widget::column![
|
column![
|
||||||
jl_text_input!("Поиск", &self.search)
|
jl_text_input!("Поиск", &self.search)
|
||||||
.on_input(Search)
|
.on_input(Search)
|
||||||
.width(Fill),
|
.width(Fill),
|
||||||
@@ -622,7 +646,7 @@ impl DictionaryState {
|
|||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tags_selector(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn tags_selector(&self) -> Element<'_, DictionaryMessage> {
|
||||||
let mut col = Column::new().width(Fill);
|
let mut col = Column::new().width(Fill);
|
||||||
col = col.push(
|
col = col.push(
|
||||||
button("Сбросить")
|
button("Сбросить")
|
||||||
@@ -717,10 +741,12 @@ impl DictionaryState {
|
|||||||
info!("Time {}", time.elapsed().as_micros());
|
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 display = String::new();
|
||||||
let mut editable = false;
|
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 mut dictionary = self.state.dictionary.write();
|
||||||
let word = dictionary.get_mut_static(selected.0).unwrap();
|
let word = dictionary.get_mut_static(selected.0).unwrap();
|
||||||
|
|
||||||
@@ -734,6 +760,7 @@ impl DictionaryState {
|
|||||||
Tags => {
|
Tags => {
|
||||||
display = word.tags.clone();
|
display = word.tags.clone();
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
editable = true;
|
editable = true;
|
||||||
}
|
}
|
||||||
@@ -752,9 +779,9 @@ impl DictionaryState {
|
|||||||
field.into()
|
field.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn groups_panel(&self) -> iced::Element<'_, DictionaryMessage> {
|
fn groups_panel(&self) -> Element<'_, DictionaryMessage> {
|
||||||
let mut row = Row::new();
|
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();
|
let groups = &self.state.word_groups.read();
|
||||||
|
|
||||||
@@ -762,7 +789,7 @@ impl DictionaryState {
|
|||||||
let group_name = groups.get(&mut group).unwrap().name.clone();
|
let group_name = groups.get(&mut group).unwrap().name.clone();
|
||||||
row = row.push(
|
row = row.push(
|
||||||
button(text!("{}", group_name))
|
button(text!("{}", group_name))
|
||||||
.style(text)
|
.style(button::text)
|
||||||
.on_press(SelectGroup(group)),
|
.on_press(SelectGroup(group)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -770,7 +797,7 @@ impl DictionaryState {
|
|||||||
let groups = self.state.word_groups.read();
|
let groups = self.state.word_groups.read();
|
||||||
let group = groups.get_static(self.selected_group).unwrap();
|
let group = groups.get_static(self.selected_group).unwrap();
|
||||||
|
|
||||||
iced::widget::column![
|
column![
|
||||||
scrollable(row).width(Fill).horizontal(),
|
scrollable(row).width(Fill).horizontal(),
|
||||||
row![
|
row![
|
||||||
jl_button!("⇳").on_press(ChangeDirection),
|
jl_button!("⇳").on_press(ChangeDirection),
|
||||||
@@ -786,7 +813,7 @@ impl DictionaryState {
|
|||||||
.into()
|
.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() {
|
if self.selected_group.real() && self.selected_group.id != 1.into() {
|
||||||
button("Удалить").style(danger).on_press(DeleteGroup).into()
|
button("Удалить").style(danger).on_press(DeleteGroup).into()
|
||||||
} else {
|
} 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!("Добавить слово");
|
let button = jl_button!("Добавить слово");
|
||||||
|
|
||||||
if self.selected_group.real() {
|
if self.selected_group.real() {
|
||||||
@@ -839,6 +866,11 @@ impl KeyPressedPage for DictionaryState {
|
|||||||
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;
|
||||||
|
if let Some(selected) = self.selected_cell
|
||||||
|
&& selected.1 == TotalLine
|
||||||
|
{
|
||||||
|
self.selected_cell = None;
|
||||||
|
}
|
||||||
} else if self.selected_cell.is_some() {
|
} else if self.selected_cell.is_some() {
|
||||||
self.selected_cell = None;
|
self.selected_cell = None;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user