From 0ca7b0042e158d5173b5fa26662fab6361c39955 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 10 Oct 2020 17:53:53 +0300 Subject: [PATCH] utilities: ensure Form/Button widgets are not always non-dirty --- src/components/mail/compose.rs | 14 +++++++- src/components/utilities/widgets.rs | 50 +++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index 98d844d3..3bc8867a 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -1520,7 +1520,19 @@ impl Component for Composer { fn is_dirty(&self) -> bool { match self.mode { ViewMode::Embed => true, - _ => self.dirty || self.pager.is_dirty() || self.form.is_dirty(), + ViewMode::Edit => self.dirty || self.pager.is_dirty() || self.form.is_dirty(), + ViewMode::Discard(_, ref widget) => { + widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() + } + ViewMode::SelectRecipients(ref widget) => { + widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() + } + ViewMode::Send(ref widget) => { + widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() + } + ViewMode::WaitingForSendResult(ref widget, _) => { + widget.is_dirty() || self.pager.is_dirty() || self.form.is_dirty() + } } } diff --git a/src/components/utilities/widgets.rs b/src/components/utilities/widgets.rs index b9167c60..045e6d80 100644 --- a/src/components/utilities/widgets.rs +++ b/src/components/utilities/widgets.rs @@ -337,6 +337,7 @@ impl FormWidget { pub fn hide_buttons(&mut self) { self.hide_buttons = true; + self.buttons.set_dirty(false); } pub fn len(&self) -> usize { @@ -499,9 +500,9 @@ impl Component for FormWidget { ), theme_default, ); - self.dirty = false; + self.set_dirty(false); + context.dirty_areas.push_back(area); } - context.dirty_areas.push_back(area); } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { if self.focus == FormFocus::Buttons && self.buttons.process_event(event, context) { @@ -512,42 +513,59 @@ impl Component for FormWidget { UIEvent::Input(Key::Up) if self.focus == FormFocus::Buttons => { self.focus = FormFocus::Fields; self.buttons.set_focus(false); + self.set_dirty(true); + return true; } UIEvent::InsertInput(Key::Up) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } UIEvent::Input(Key::Up) => { self.cursor = self.cursor.saturating_sub(1); + self.set_dirty(true); + return true; } UIEvent::InsertInput(Key::Down) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } UIEvent::Input(Key::Down) if self.cursor < self.layout.len().saturating_sub(1) => { self.cursor += 1; + self.set_dirty(true); + return true; } UIEvent::Input(Key::Down) if self.focus == FormFocus::Fields => { self.focus = FormFocus::Buttons; self.buttons.set_focus(true); + self.set_dirty(true); if self.hide_buttons { - self.set_dirty(true); return false; } + return true; } UIEvent::InsertInput(Key::Char('\t')) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } UIEvent::Input(Key::Char('\n')) if self.focus == FormFocus::Fields => { self.focus = FormFocus::TextInput; context .replies .push_back(UIEvent::ChangeMode(UIMode::Insert)); + self.set_dirty(true); + return true; } UIEvent::InsertInput(Key::Right) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } UIEvent::InsertInput(Key::Left) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); @@ -557,6 +575,8 @@ impl Component for FormWidget { .replies .push_back(UIEvent::ChangeMode(UIMode::Normal)); } + self.set_dirty(true); + return true; } UIEvent::ChangeMode(UIMode::Normal) if self.focus == FormFocus::TextInput => { self.focus = FormFocus::Fields; @@ -565,17 +585,18 @@ impl Component for FormWidget { UIEvent::InsertInput(Key::Backspace) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } UIEvent::InsertInput(_) if self.focus == FormFocus::TextInput => { let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap(); field.process_event(event, context); + self.set_dirty(true); + return true; } - _ => { - return false; - } + _ => {} } - self.set_dirty(true); - true + false } fn is_dirty(&self) -> bool { self.dirty || self.buttons.is_dirty() @@ -690,19 +711,22 @@ where .remove(&self.layout[self.cursor]) .unwrap_or_default(), ); + self.set_dirty(true); + return true; } UIEvent::Input(Key::Left) => { self.cursor = self.cursor.saturating_sub(1); + self.set_dirty(true); + return true; } UIEvent::Input(Key::Right) if self.cursor < self.layout.len().saturating_sub(1) => { self.cursor += 1; + self.set_dirty(true); + return true; } - _ => { - return false; - } + _ => {} } - self.set_dirty(true); - true + false } fn is_dirty(&self) -> bool { self.dirty