ui: add close dialog in compose tab discard

This commit is contained in:
Manos Pitsidianakis 2018-09-04 14:16:01 +03:00
parent 8d3a2d8236
commit 91760e5be6
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710

View File

@ -307,9 +307,15 @@ impl Component for Composer {
self.draw_header_table(grid, header_area); self.draw_header_table(grid, header_area);
self.pager.draw(grid, body_area, context); self.pager.draw(grid, body_area, context);
/* Let user choose whether to quit with/without saving or cancel */
if let ViewMode::Discard(_) = self.mode { if let ViewMode::Discard(_) = self.mode {
let mid_x = width!(area) / 2; let mid_x = width!(area) / 2;
let mid_y = height!(area) / 2; let mid_y = height!(area) / 2;
for x in mid_x - 40..=mid_x + 40 {
for y in mid_y - 11..=mid_y + 11 {
grid[(x, y)] = Cell::default();
}
}
for i in mid_x - 40..=mid_x + 40 { for i in mid_x - 40..=mid_x + 40 {
set_and_join_box(grid, (i, mid_y - 11), HORZ_BOUNDARY); set_and_join_box(grid, (i, mid_y - 11), HORZ_BOUNDARY);
@ -322,6 +328,41 @@ impl Component for Composer {
set_and_join_box(grid, (mid_x + 40, i), VERT_BOUNDARY); set_and_join_box(grid, (mid_x + 40, i), VERT_BOUNDARY);
} }
let area = ((mid_x - 20, mid_y - 7), (mid_x + 39, mid_y + 10));
let (_, y) = write_string_to_grid(
&format!("Draft \"{:10}\"", self.draft.headers()["Subject"]),
grid,
Color::Default,
Color::Default,
area,
true,
);
let (_, y) = write_string_to_grid(
"[x] quit without saving",
grid,
Color::Byte(124),
Color::Default,
(set_y(upper_left!(area), y + 2), bottom_right!(area)),
true,
);
let (_, y) = write_string_to_grid(
"[y] save draft and quit",
grid,
Color::Byte(124),
Color::Default,
(set_y(upper_left!(area), y + 1), bottom_right!(area)),
true,
);
write_string_to_grid(
"[n] cancel",
grid,
Color::Byte(124),
Color::Default,
(set_y(upper_left!(area), y + 1), bottom_right!(area)),
true,
);
} }
context.dirty_areas.push_back(area); context.dirty_areas.push_back(area);
@ -346,8 +387,7 @@ impl Component for Composer {
match event.event_type { match event.event_type {
UIEventType::Resize => { UIEventType::Resize => {
self.dirty = true; self.set_dirty();
self.initialized = false;
} }
/* Switch e-mail From: field to the `left` configured account. */ /* Switch e-mail From: field to the `left` configured account. */
UIEventType::Input(Key::Left) => { UIEventType::Input(Key::Left) => {
@ -371,9 +411,9 @@ impl Component for Composer {
} }
return true; return true;
} }
UIEventType::Input(Key::Char(k)) if self.mode.is_discard() => { UIEventType::Input(Key::Char(key)) if self.mode.is_discard() => {
match (k, &self.mode) { match (key, &self.mode) {
('y', ViewMode::Discard(u)) => { ('x', ViewMode::Discard(u)) => {
context.replies.push_back(UIEvent { context.replies.push_back(UIEvent {
id: 0, id: 0,
event_type: UIEventType::Action(Tab(Kill(u.clone()))), event_type: UIEventType::Action(Tab(Kill(u.clone()))),