Allow cancelling draft-close confirmations without losing edits
This commit is contained in:
parent
0a13642c8f
commit
57cd9c7d80
|
|
@ -602,7 +602,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "canvas-pilot"
|
||||
version = "0.9.72"
|
||||
version = "0.9.73"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"craft-dwg",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.9.72"
|
||||
version = "0.9.73"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"
|
||||
|
|
|
|||
|
|
@ -1382,18 +1382,21 @@ impl Editor {
|
|||
if self.device.import_closing {
|
||||
open = true;
|
||||
match pending_close(ctx, "device-import-close", &self.device.error) {
|
||||
Some(true) => {
|
||||
Some(CloseChoice::Apply) => {
|
||||
self.device.import_closing = false;
|
||||
match self.apply_device_import() {
|
||||
Ok(()) => imported = true,
|
||||
Err(e) => self.device.error = e,
|
||||
}
|
||||
}
|
||||
Some(false) => {
|
||||
Some(CloseChoice::Discard) => {
|
||||
self.device.import_closing = false;
|
||||
self.device.reset_mappings();
|
||||
open = false;
|
||||
}
|
||||
Some(CloseChoice::Cancel) => {
|
||||
self.device.import_closing = false;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -2066,6 +2069,13 @@ mod tests {
|
|||
app.device.destinations = vec![Destination::Existing(1), Destination::Skip];
|
||||
app.device.open = true;
|
||||
app.device.import_closing = true;
|
||||
super::super::tests::click_text(&mut app, &ctx, "Cancel");
|
||||
assert!(app.device.open);
|
||||
assert!(!app.device.import_closing);
|
||||
assert!(app.device.destinations == vec![Destination::Existing(1), Destination::Skip]);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
assert!(app.device.pending.is_none());
|
||||
app.device.import_closing = true;
|
||||
super::super::tests::click_text(&mut app, &ctx, "Apply");
|
||||
assert!(!app.device.open);
|
||||
assert!(!app.device.sending);
|
||||
|
|
|
|||
|
|
@ -532,7 +532,7 @@ impl Editor {
|
|||
}
|
||||
if d.closing {
|
||||
match pending_close(ctx, "formats-close", &d.error) {
|
||||
Some(true) => {
|
||||
Some(CloseChoice::Apply) => {
|
||||
match d.apply(&mut self.layout, position_reference, self.keep_aspect_ratio) {
|
||||
Ok(()) => {
|
||||
self.sync();
|
||||
|
|
@ -545,7 +545,11 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(false) => return,
|
||||
Some(CloseChoice::Discard) => return,
|
||||
Some(CloseChoice::Cancel) => {
|
||||
d.closing = false;
|
||||
open = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1309,6 +1313,12 @@ mod tests {
|
|||
draft.size = [800.0, 450.0];
|
||||
draft.closing = true;
|
||||
app.format_draft = Some(draft);
|
||||
click_text(&mut app, &ctx, "Cancel");
|
||||
let draft = app.format_draft.as_mut().unwrap();
|
||||
assert!(!draft.closing);
|
||||
assert_eq!(draft.size, [800.0, 450.0]);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
draft.closing = true;
|
||||
click_text(&mut app, &ctx, "Discard");
|
||||
assert!(app.format_draft.is_none());
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
|
|
|
|||
|
|
@ -1561,7 +1561,7 @@ impl Editor {
|
|||
}
|
||||
if p.closing {
|
||||
match pending_close(ctx, "paste-close", &p.error) {
|
||||
Some(true) => match p.apply(&mut self.layout) {
|
||||
Some(CloseChoice::Apply) => match p.apply(&mut self.layout) {
|
||||
Ok(()) => {
|
||||
self.sync();
|
||||
close = true;
|
||||
|
|
@ -1571,7 +1571,8 @@ impl Editor {
|
|||
p.closing = false;
|
||||
}
|
||||
},
|
||||
Some(false) => close = true,
|
||||
Some(CloseChoice::Discard) => close = true,
|
||||
Some(CloseChoice::Cancel) => p.closing = false,
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -4542,7 +4543,13 @@ fn alignment_icon(
|
|||
}
|
||||
|
||||
// Closing a draft is a separate decision from sending anything to a device.
|
||||
fn pending_close(ctx: &egui::Context, id: &str, error: &str) -> Option<bool> {
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum CloseChoice {
|
||||
Apply,
|
||||
Discard,
|
||||
Cancel,
|
||||
}
|
||||
fn pending_close(ctx: &egui::Context, id: &str, error: &str) -> Option<CloseChoice> {
|
||||
egui::Modal::new(egui::Id::new(id))
|
||||
.show(ctx, |ui| {
|
||||
ui.heading(tr(ui.ctx(), "ui.would-you-like-to-apply-changes"));
|
||||
|
|
@ -4551,9 +4558,11 @@ fn pending_close(ctx: &egui::Context, id: &str, error: &str) -> Option<bool> {
|
|||
}
|
||||
ui.horizontal(|ui| {
|
||||
if apply_button(ui, &tr(ui.ctx(), "action.apply"), true).clicked() {
|
||||
Some(true)
|
||||
Some(CloseChoice::Apply)
|
||||
} else if ui.button(tr(ui.ctx(), "ui.discard")).clicked() {
|
||||
Some(false)
|
||||
Some(CloseChoice::Discard)
|
||||
} else if ui.button(tr(ui.ctx(), "ui.cancel")).clicked() {
|
||||
Some(CloseChoice::Cancel)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -5178,6 +5187,28 @@ mod tests {
|
|||
modifiers: egui::Modifiers::NONE,
|
||||
}
|
||||
}
|
||||
pub(super) fn cancel_pending_close(app: &mut Editor, ctx: &egui::Context) {
|
||||
frame(app, ctx, vec![]);
|
||||
let output = frame(app, ctx, vec![]);
|
||||
// The underlying editor can also have a Cancel button. Click the modal.
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == "Cancel" => {
|
||||
Some(t.pos + t.galley.size() / 2.)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("Close-confirmation Cancel button");
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
pub(super) fn click_text(app: &mut Editor, ctx: &egui::Context, text: &str) {
|
||||
frame(app, ctx, vec![]);
|
||||
let output = frame(app, ctx, vec![]);
|
||||
|
|
@ -8382,6 +8413,12 @@ mod tests {
|
|||
frame(&mut app, &ctx, vec![key(egui::Key::Escape)]);
|
||||
assert!(app.paste.as_ref().unwrap().closing);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
cancel_pending_close(&mut app, &ctx);
|
||||
let p = app.paste.as_ref().unwrap();
|
||||
assert!(!p.closing);
|
||||
assert_eq!(p.targets, vec![1]);
|
||||
assert_eq!(p.shapes[0].geometry.width, 945.0);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
#[test]
|
||||
fn exchange_background_is_automatically_excluded_from_mapping() {
|
||||
|
|
|
|||
|
|
@ -276,14 +276,18 @@ impl Editor {
|
|||
}
|
||||
if self.layer_ui.rename_closing {
|
||||
match pending_close(ctx, "rename-close", &self.error) {
|
||||
Some(true) => {
|
||||
Some(CloseChoice::Apply) => {
|
||||
apply = true;
|
||||
self.layer_ui.rename_closing = false;
|
||||
}
|
||||
Some(false) => {
|
||||
Some(CloseChoice::Discard) => {
|
||||
cancel = true;
|
||||
self.layer_ui.rename_closing = false;
|
||||
}
|
||||
Some(CloseChoice::Cancel) => {
|
||||
self.layer_ui.rename_closing = false;
|
||||
open = true;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -394,8 +398,11 @@ impl Editor {
|
|||
refresh = false;
|
||||
open = true;
|
||||
let choice = pending_close(ctx, "names-close", &self.layer_ui.error);
|
||||
if let Some(apply) = choice {
|
||||
let result = if apply {
|
||||
if choice == Some(CloseChoice::Cancel) {
|
||||
self.layer_ui.closing = false;
|
||||
self.layer_ui.deferred = 0;
|
||||
} else if let Some(choice) = choice {
|
||||
let result = if choice == CloseChoice::Apply {
|
||||
self.layout.rename_layers(&self.layer_ui.drafts)
|
||||
} else {
|
||||
Ok(())
|
||||
|
|
@ -1506,6 +1513,19 @@ mod tests {
|
|||
assert_eq!(app.layout.layer_info(1), &before);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn cancelling_rename_close_keeps_the_name_draft() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
let id = app.layout.layer_info(1).id;
|
||||
app.layer_ui.rename = Some((id, "Camera".into()));
|
||||
app.layer_ui.rename_closing = true;
|
||||
super::super::tests::cancel_pending_close(&mut app, &ctx);
|
||||
assert!(!app.layer_ui.rename_closing);
|
||||
assert_eq!(app.layer_ui.rename, Some((id, "Camera".into())));
|
||||
assert_eq!(app.layout.layer_info(1).name, "Presenter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_batch_names_applies_or_discards_without_losing_identity() {
|
||||
let ctx = egui::Context::default();
|
||||
|
|
@ -1514,6 +1534,16 @@ mod tests {
|
|||
let id = app.layout.layer_info(1).id;
|
||||
app.layer_ui.drafts[1].1 = "Camera".into();
|
||||
app.layer_ui.closing = true;
|
||||
app.layer_ui.deferred = 1;
|
||||
let count = app.layout.layers().len();
|
||||
super::super::tests::click_text(&mut app, &ctx, "Cancel");
|
||||
assert!(app.layer_ui.open);
|
||||
assert!(!app.layer_ui.closing);
|
||||
assert_eq!(app.layer_ui.deferred, 0);
|
||||
assert_eq!(app.layer_ui.drafts[1].1, "Camera");
|
||||
assert_eq!(app.layout.layers().len(), count);
|
||||
assert_eq!(app.layout.layer_info(1).name, "Presenter");
|
||||
app.layer_ui.closing = true;
|
||||
super::super::tests::click_text(&mut app, &ctx, "Apply");
|
||||
assert!(!app.layer_ui.open);
|
||||
assert_eq!(app.layout.layer_info(1).name, "Camera");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### v0.9.73
|
||||
|
||||
- Add Cancel to Apply/Discard close confirmations for layer properties, renaming,
|
||||
batch names/folders, clipboard import and device import review. Cancel returns
|
||||
to editing with the draft intact and cancels deferred layer-list actions.
|
||||
|
||||
### v0.9.72
|
||||
|
||||
- Fix input-crop capture on Midra: its PNG contains only the retained crop, unlike
|
||||
|
|
|
|||
|
|
@ -227,3 +227,12 @@ Reference images and Output format at the bottom: these apply to the workspace
|
|||
rather than the selected layer. Right-clicking empty canvas keeps these options
|
||||
at the top level. Multiple selection retains its Resize together and alignment
|
||||
actions; crop/mask resets require one selected layer.
|
||||
|
||||
|
||||
### Cancel an accidental close
|
||||
|
||||
When a draft window asks whether to **Apply** or **Discard** changes, choose
|
||||
**Cancel** to return to the window with your edits intact. Cancel neither applies
|
||||
nor discards them. This also works for clipboard and device-import reviews,
|
||||
layer properties, layer renaming and batch names/folders. If a layer-list action
|
||||
triggered the prompt, Cancel stops that action and keeps the draft open.
|
||||
|
|
|
|||
Loading…
Reference in New Issue