parent
713c4f73b9
commit
d44a68ec69
|
@ -254,8 +254,12 @@ fn main() -> std::result::Result<(), std::io::Error> {
|
||||||
UIMode::Normal => {
|
UIMode::Normal => {
|
||||||
match k {
|
match k {
|
||||||
Key::Char('q') | Key::Char('Q') => {
|
Key::Char('q') | Key::Char('Q') => {
|
||||||
drop(state);
|
if state.can_quit_cleanly() {
|
||||||
break 'main;
|
drop(state);
|
||||||
|
break 'main;
|
||||||
|
} else {
|
||||||
|
state.redraw();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Key::Char(' ') => {
|
Key::Char(' ') => {
|
||||||
state.mode = UIMode::Execute;
|
state.mode = UIMode::Execute;
|
||||||
|
|
|
@ -90,6 +90,9 @@ pub trait Component: Display + Debug + Send {
|
||||||
fn is_visible(&self) -> bool {
|
fn is_visible(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
fn can_quit_cleanly(&mut self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
fn set_dirty(&mut self);
|
fn set_dirty(&mut self);
|
||||||
fn kill(&mut self, _id: ComponentId, _context: &mut Context) {}
|
fn kill(&mut self, _id: ComponentId, _context: &mut Context) {}
|
||||||
fn set_id(&mut self, _id: ComponentId) {}
|
fn set_id(&mut self, _id: ComponentId) {}
|
||||||
|
|
|
@ -756,6 +756,13 @@ impl Component for Composer {
|
||||||
fn set_id(&mut self, id: ComponentId) {
|
fn set_id(&mut self, id: ComponentId) {
|
||||||
self.id = id;
|
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 {
|
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) {
|
fn set_id(&mut self, id: ComponentId) {
|
||||||
self.id = id;
|
self.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_quit_cleanly(&mut self) -> bool {
|
||||||
|
self.container.can_quit_cleanly()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -1530,6 +1534,17 @@ impl Component for Tabbed {
|
||||||
fn set_id(&mut self, id: ComponentId) {
|
fn set_id(&mut self, id: ComponentId) {
|
||||||
self.id = id;
|
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>;
|
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>) {
|
pub fn register_component(&mut self, component: Box<dyn Component>) {
|
||||||
self.components.push(component);
|
self.components.push(component);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue