mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Restore all persisted warnings and keep the reset confirmation
This commit is contained in:
1 parent
fde7050af0
commit
de1112fb5e
3 files changed
+49
-7
No files matched your search
@@ -11,6 +11,9 @@ pub const WARNING_DIALOG_KEYS: &[&str] = &[
|
||||
"edit.assignProfile.layers",
|
||||
"notes.delete.confirmation",
|
||||
"contentAwareMove.noPixelsSelected",
|
||||
"contentAwareFill.customSampling",
|
||||
"quickMask.noPixelsSelected",
|
||||
"objectSelection.notFound",
|
||||
"layer.layerMask.replace",
|
||||
];
|
||||
/// A restored warning starts with its checkbox checked the first time the dialog is shown.
|
||||
|
||||
@@ -122,8 +122,6 @@ pub(crate) struct PrefsDialog {
|
||||
pick: Option<ColorRequest>,
|
||||
/// The message of a typed value a custom row clamped to its range, until `take` opens the alert for it.
|
||||
range_alert: Option<String>,
|
||||
/// General's reset button asks for confirmation outside the staged draft.
|
||||
reset_warning_dialogs: bool,
|
||||
/// The edits Apply or OK made, until `take` writes them.
|
||||
edits: Vec<Edits>,
|
||||
}
|
||||
@@ -205,7 +203,6 @@ impl StackDialog for PrefsDialog {
|
||||
if let Some(message) = ui.data_mut(|data| data.remove_temp::<String>(super::custom_rows::range_alert_id())) {
|
||||
self.range_alert = Some(message);
|
||||
}
|
||||
self.reset_warning_dialogs |= ui.data_mut(|data| data.remove_temp::<bool>(super::custom_rows::reset_warning_dialogs_id())).unwrap_or(false);
|
||||
self.file_edits();
|
||||
out.closed.map(|closed| match closed {
|
||||
Closed::Ok => DialogResult::Ok(PrefsAnswer(std::mem::take(&mut self.edits), self.range_alert.take())),
|
||||
@@ -284,7 +281,6 @@ pub fn open_preferences(app: &mut PhotocraftApp, section: &str) {
|
||||
custom,
|
||||
pick: None,
|
||||
range_alert: None,
|
||||
reset_warning_dialogs: false,
|
||||
edits: Vec::new(),
|
||||
};
|
||||
app.framework.dialogs.open(dialog);
|
||||
@@ -349,12 +345,10 @@ pub(crate) fn take(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
_ => (Vec::new(), None),
|
||||
};
|
||||
let mut picked = None;
|
||||
let mut reset_warning_dialogs = false;
|
||||
if let Some(dialog) = app.framework.dialogs.get_mut::<PrefsDialog>() {
|
||||
batches.append(&mut dialog.edits);
|
||||
picked = dialog.pick.take();
|
||||
range_alert = dialog.range_alert.take().or(range_alert);
|
||||
reset_warning_dialogs = std::mem::take(&mut dialog.reset_warning_dialogs);
|
||||
} else {
|
||||
crate::color_picker_ui::cancel_window_picker(app, ctx, PickWindow::Preferences);
|
||||
}
|
||||
@@ -364,7 +358,8 @@ pub(crate) fn take(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
if let Some(message) = range_alert {
|
||||
let _ = crate::dialogs::alerts::alert(app, message);
|
||||
}
|
||||
if reset_warning_dialogs {
|
||||
// The reset button requests its own confirmation, even when Preferences closes in this pass.
|
||||
if ctx.data_mut(|data| data.remove_temp::<bool>(super::custom_rows::reset_warning_dialogs_id())).unwrap_or(false) {
|
||||
crate::dialogs::alerts::ask_reset_warning_dialogs(app);
|
||||
}
|
||||
if let Some((key, color)) = crate::color_picker_ui::answer_for_window(app, PickWindow::Preferences)
|
||||
|
||||
@@ -134,3 +134,47 @@ fn automation_can_reset_warnings_without_opening_a_dialog_or_recording_an_action
|
||||
assert_eq!(app.run(RESET_WARNING_DIALOGS, json!({}))?["reset"], 0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_preferences_does_not_consume_the_pending_reset_confirmation() {
|
||||
use super::super::custom_rows::reset_warning_dialogs_id;
|
||||
|
||||
for confirm_preferences in [false, true] {
|
||||
let files = Arc::new(MemoryFiles::new());
|
||||
let mut h = harness(&files, Some("general"));
|
||||
seed(h.state_mut());
|
||||
let ctx = h.ctx.clone();
|
||||
let id = craft::ui::dialog::dialog_id("photocraft.preferences");
|
||||
// The General button has emitted its request when the host also closes Preferences.
|
||||
ctx.data_mut(|data| data.insert_temp(reset_warning_dialogs_id(), true));
|
||||
let dialogs = &mut h.state_mut().framework.dialogs;
|
||||
let closed = if confirm_preferences { dialogs.confirm_by_id(&ctx, id) } else { dialogs.cancel_by_id(&ctx, id) };
|
||||
assert!(closed);
|
||||
assert!(!super::window_open(h.state()));
|
||||
super::take(h.state_mut(), &ctx);
|
||||
h.run_steps(4);
|
||||
assert!(h.query_all_by_label(ASK).next().is_some());
|
||||
assert!(alerts::dismissed(h.state(), WARNING), "closing Preferences does not confirm the reset");
|
||||
h.key_press(Key::Enter);
|
||||
h.run_steps(4);
|
||||
assert_restored(h.state());
|
||||
assert!(h.query_all_by_label(ASK).next().is_none(), "the request is consumed once");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_restores_dismissals_from_object_selection_quick_mask_and_content_aware_fill() -> Result<(), String> {
|
||||
let keys = ["objectSelection.notFound", "quickMask.noPixelsSelected", "contentAwareFill.customSampling"];
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.edit_prefs(|prefs| {
|
||||
for key in keys {
|
||||
prefs.dialogs.insert(key.into(), json!({"skip": true}));
|
||||
}
|
||||
});
|
||||
assert_eq!(app.run(RESET_WARNING_DIALOGS, json!({}))?["reset"], keys.len());
|
||||
for key in keys {
|
||||
assert!(!alerts::dismissed(&app, key));
|
||||
assert_eq!(app.session.prefs().dialogs.get(key).and_then(|v| v.get(WARNING_DIALOG_RESTORED)), Some(&Value::Bool(true)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user