Add cancel button to unsaved changes dialogs, fixes #189
This commit is contained in:
parent
0ae48666d8
commit
62605f73c7
4 changed files with 47 additions and 68 deletions
50
src/main.rs
50
src/main.rs
|
|
@ -321,6 +321,7 @@ pub enum Message {
|
|||
Cut,
|
||||
DefaultFont(usize),
|
||||
DefaultFontSize(usize),
|
||||
DialogCancel,
|
||||
DialogMessage(DialogMessage),
|
||||
Find(Option<bool>),
|
||||
FindCaseSensitive(bool),
|
||||
|
|
@ -1459,41 +1460,18 @@ impl Application for App {
|
|||
|
||||
match dialog {
|
||||
DialogPage::PromptSaveClose(entity) => {
|
||||
// "Save" is displayed regardless if the file was already saved because the message handles
|
||||
// "Save As" if necessary
|
||||
let save = fl!("save");
|
||||
let save_button =
|
||||
widget::button::suggested(save).on_press(Message::Save(Some(*entity)));
|
||||
|
||||
// "Save As" is only shown if the file has been saved previously
|
||||
// Rationale: The user may want to save the modified buffer as a new file
|
||||
let save_as_button = match self.tab_model.data(*entity) {
|
||||
Some(Tab::Editor(tab)) if tab.path_opt.is_some() => {
|
||||
let save_as = fl!("save-as");
|
||||
let save_as_button = widget::button::suggested(save_as)
|
||||
.on_press(Message::SaveAsDialog(Some(*entity)));
|
||||
Some(save_as_button)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
// Discards unsaved changes
|
||||
let discard = fl!("discard");
|
||||
let discard_button =
|
||||
widget::button::destructive(discard).on_press(Message::TabCloseForce(*entity));
|
||||
|
||||
let mut dialog = widget::dialog(fl!("prompt-save-changes-title"))
|
||||
widget::button::suggested(fl!("save")).on_press(Message::Save(Some(*entity)));
|
||||
let discard_button = widget::button::destructive(fl!("discard"))
|
||||
.on_press(Message::TabCloseForce(*entity));
|
||||
let cancel_button =
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel);
|
||||
let dialog = widget::dialog(fl!("prompt-save-changes-title"))
|
||||
.body(fl!("prompt-unsaved-changes"))
|
||||
.icon(icon::from_name("dialog-warning-symbolic").size(64))
|
||||
.primary_action(save_button);
|
||||
dialog = if let Some(save_as_button) = save_as_button {
|
||||
dialog
|
||||
.secondary_action(save_as_button)
|
||||
.tertiary_action(discard_button)
|
||||
} else {
|
||||
dialog.secondary_action(discard_button)
|
||||
};
|
||||
|
||||
.primary_action(save_button)
|
||||
.secondary_action(discard_button)
|
||||
.tertiary_action(cancel_button);
|
||||
Some(dialog.into())
|
||||
}
|
||||
DialogPage::PromptSaveQuit(entities) => {
|
||||
|
|
@ -1528,12 +1506,15 @@ impl Application for App {
|
|||
}
|
||||
let discard_button =
|
||||
widget::button::destructive(fl!("discard")).on_press(Message::QuitForce);
|
||||
let cancel_button =
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel);
|
||||
let dialog = widget::dialog(fl!("prompt-save-changes-title"))
|
||||
.body(fl!("prompt-unsaved-changes"))
|
||||
.icon(icon::from_name("dialog-warning-symbolic").size(64))
|
||||
.control(column)
|
||||
.primary_action(save_button)
|
||||
.secondary_action(discard_button);
|
||||
.secondary_action(discard_button)
|
||||
.tertiary_action(cancel_button);
|
||||
|
||||
Some(dialog.into())
|
||||
}
|
||||
|
|
@ -1668,6 +1649,9 @@ impl Application for App {
|
|||
log::warn!("failed to find font with index {}", index);
|
||||
}
|
||||
},
|
||||
Message::DialogCancel => {
|
||||
self.dialog_page_opt = None;
|
||||
}
|
||||
Message::DialogMessage(dialog_message) => {
|
||||
if let Some(dialog) = &mut self.dialog_opt {
|
||||
return dialog.update(dialog_message);
|
||||
|
|
|
|||
|
|
@ -1007,10 +1007,7 @@ where
|
|||
// Do this first as the horizontal scrollbar is on top of the buffer
|
||||
if let Some(scrollbar_h_rect) = state.scrollbar_h_rect.get() {
|
||||
if scrollbar_h_rect.contains(Point::new(x_logical, y_logical)) {
|
||||
state.dragging = Some(Dragging::ScrollbarH {
|
||||
start_x: x,
|
||||
start_scroll: editor.with_buffer(|buffer| buffer.scroll()),
|
||||
});
|
||||
state.dragging = Some(Dragging::ScrollbarH { start_x: x });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1120,10 +1117,7 @@ where
|
|||
buffer.set_scroll(scroll);
|
||||
});
|
||||
}
|
||||
Dragging::ScrollbarH {
|
||||
start_x,
|
||||
start_scroll,
|
||||
} => {
|
||||
Dragging::ScrollbarH { start_x } => {
|
||||
editor.with_buffer_mut(|buffer| {
|
||||
//TODO: store this in state?
|
||||
let mut max_line_width = 0.0;
|
||||
|
|
@ -1211,7 +1205,7 @@ enum ClickKind {
|
|||
enum Dragging {
|
||||
Buffer,
|
||||
ScrollbarV { start_y: f32, start_scroll: Scroll },
|
||||
ScrollbarH { start_x: f32, start_scroll: Scroll },
|
||||
ScrollbarH { start_x: f32 },
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue