Add cancel button to unsaved changes dialogs, fixes #189

This commit is contained in:
Jeremy Soller 2024-05-31 08:29:30 -06:00
parent 0ae48666d8
commit 62605f73c7
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
4 changed files with 47 additions and 68 deletions

52
Cargo.lock generated
View file

@ -1100,7 +1100,7 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"atomicwrites",
"cosmic-config-derive",
@ -1119,7 +1119,7 @@ dependencies = [
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"quote",
"syn 1.0.109",
@ -1227,7 +1227,7 @@ dependencies = [
[[package]]
name = "cosmic-theme"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"almost",
"cosmic-config",
@ -2612,7 +2612,7 @@ dependencies = [
[[package]]
name = "iced"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"dnd",
"iced_accessibility",
@ -2630,7 +2630,7 @@ dependencies = [
[[package]]
name = "iced_accessibility"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"accesskit",
"accesskit_winit",
@ -2639,7 +2639,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"bitflags 2.5.0",
"dnd",
@ -2659,7 +2659,7 @@ dependencies = [
[[package]]
name = "iced_futures"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"futures",
"iced_core",
@ -2672,7 +2672,7 @@ dependencies = [
[[package]]
name = "iced_graphics"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -2696,7 +2696,7 @@ dependencies = [
[[package]]
name = "iced_renderer"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"iced_graphics",
"iced_tiny_skia",
@ -2708,7 +2708,7 @@ dependencies = [
[[package]]
name = "iced_runtime"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"dnd",
"iced_core",
@ -2720,7 +2720,7 @@ dependencies = [
[[package]]
name = "iced_style"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"iced_core",
"once_cell",
@ -2730,7 +2730,7 @@ dependencies = [
[[package]]
name = "iced_tiny_skia"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"bytemuck",
"cosmic-text",
@ -2747,7 +2747,7 @@ dependencies = [
[[package]]
name = "iced_wgpu"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"bitflags 2.5.0",
"bytemuck",
@ -2773,7 +2773,7 @@ dependencies = [
[[package]]
name = "iced_widget"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"dnd",
"iced_renderer",
@ -2789,7 +2789,7 @@ dependencies = [
[[package]]
name = "iced_winit"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"dnd",
"iced_graphics",
@ -3148,7 +3148,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libcosmic"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic.git#af58d81c6fc731b5ef32cb3125717fd7ff17af30"
source = "git+https://github.com/pop-os/libcosmic.git#f60c6893eb828f0e5c2caa8e0a96938938bb3262"
dependencies = [
"apply",
"ashpd",
@ -5802,9 +5802,9 @@ dependencies = [
[[package]]
name = "wayland-backend"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40"
checksum = "34e9e6b6d4a2bb4e7e69433e0b35c7923b95d4dc8503a84d25ec917a4bbfdf07"
dependencies = [
"cc",
"downcast-rs",
@ -5816,9 +5816,9 @@ dependencies = [
[[package]]
name = "wayland-client"
version = "0.31.2"
version = "0.31.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f"
checksum = "1e63801c85358a431f986cffa74ba9599ff571fc5774ac113ed3b490c19a1133"
dependencies = [
"bitflags 2.5.0",
"rustix 0.38.34",
@ -5839,9 +5839,9 @@ dependencies = [
[[package]]
name = "wayland-cursor"
version = "0.31.1"
version = "0.31.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba"
checksum = "a206e8b2b53b1d3fcb9428fec72bc278ce539e2fa81fe2bfc1ab27703d5187b9"
dependencies = [
"rustix 0.38.34",
"wayland-client",
@ -5888,9 +5888,9 @@ dependencies = [
[[package]]
name = "wayland-scanner"
version = "0.31.1"
version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283"
checksum = "67da50b9f80159dec0ea4c11c13e24ef9e7574bd6ce24b01860a175010cea565"
dependencies = [
"proc-macro2",
"quick-xml",
@ -5899,9 +5899,9 @@ dependencies = [
[[package]]
name = "wayland-sys"
version = "0.31.1"
version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af"
checksum = "105b1842da6554f91526c14a2a2172897b7f745a805d62af4ce698706be79c12"
dependencies = [
"dlib",
"log",

View file

@ -30,6 +30,7 @@ project-search = Project search
## Prompt save changes
prompt-save-changes-title = Unsaved changes
prompt-unsaved-changes = You have unsaved changes. Save?
cancel = Cancel
discard = Discard changes
save-all = Save all

View file

@ -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);

View file

@ -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 {