mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-19 03:25:38 +00:00
ui: don't quit if editing a draft
Ask user to save draft or discard it.
This commit is contained in:
parent
713c4f73b9
commit
d44a68ec69
@ -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;
|
||||
|
@ -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) {}
|
||||
|
@ -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 {
|
||||
|
@ -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>;
|
||||
|
@ -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…
Reference in New Issue
Block a user