Browse Source

ui: don't quit if editing a draft

Ask user to save draft or discard it.
tags/pre-alpha-0.3.2
Manos Pitsidianakis 2 weeks ago
parent
commit
d44a68ec69
No known key found for this signature in database
5 changed files with 35 additions and 2 deletions
  1. 6
    2
      src/bin.rs
  2. 3
    0
      ui/src/components.rs
  3. 7
    0
      ui/src/components/mail/compose.rs
  4. 15
    0
      ui/src/components/utilities.rs
  5. 4
    0
      ui/src/state.rs

+ 6
- 2
src/bin.rs View File

@@ -254,8 +254,12 @@ fn main() -> std::result::Result<(), std::io::Error> {
UIMode::Normal => {
match k {
Key::Char('q') | Key::Char('Q') => {
drop(state);
break 'main;
if state.can_quit_cleanly() {
drop(state);
break 'main;
} else {
state.redraw();
}
},
Key::Char(' ') => {
state.mode = UIMode::Execute;

+ 3
- 0
ui/src/components.rs View File

@@ -90,6 +90,9 @@ pub trait Component: Display + Debug + Send {
fn is_visible(&self) -> bool {
true
}
fn can_quit_cleanly(&mut self) -> bool {
true
}
fn set_dirty(&mut self);
fn kill(&mut self, _id: ComponentId, _context: &mut Context) {}
fn set_id(&mut self, _id: ComponentId) {}

+ 7
- 0
ui/src/components/mail/compose.rs View File

@@ -756,6 +756,13 @@ impl Component for Composer {
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}

fn can_quit_cleanly(&mut self) -> bool {
/* Play it safe and ask user for confirmation */
self.mode = ViewMode::Discard(self.id);
self.set_dirty();
false
}
}

pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) -> bool {

+ 15
- 0
ui/src/components/utilities.rs View File

@@ -1066,6 +1066,10 @@ impl Component for StatusBar {
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}

fn can_quit_cleanly(&mut self) -> bool {
self.container.can_quit_cleanly()
}
}

#[derive(Debug)]
@@ -1530,6 +1534,17 @@ impl Component for Tabbed {
fn set_id(&mut self, id: ComponentId) {
self.id = id;
}

fn can_quit_cleanly(&mut self) -> bool {
for (i, c) in self.children.iter_mut().enumerate() {
if !c.can_quit_cleanly() {
self.cursor_pos = i;
self.set_dirty();
return false;
}
}
true
}
}

type EntryIdentifier = Vec<u8>;

+ 4
- 0
ui/src/state.rs View File

@@ -514,6 +514,10 @@ impl State {
}
}

pub fn can_quit_cleanly(&mut self) -> bool {
self.components.iter_mut().all(|c| c.can_quit_cleanly())
}

pub fn register_component(&mut self, component: Box<dyn Component>) {
self.components.push(component);
}

Loading…
Cancel
Save