diff --git a/assets/locales/pending/recovery-discard-all.json b/assets/locales/pending/recovery-discard-all.json new file mode 100644 index 000000000..0bfd65aee --- /dev/null +++ b/assets/locales/pending/recovery-discard-all.json @@ -0,0 +1,56 @@ +{ + "en": { + "recovery.discard_all": "Discard all", + "recovery.discard_all_detail": "This cannot be undone.", + "recovery.discard_all_title": "Discard {count} autosaves?", + "recovery.discard_all_title_one": "Discard 1 autosave?" + }, + "ar": { + "recovery.discard_all": "تجاهل الكل", + "recovery.discard_all_detail": "لا يمكن التراجع عن هذا الإجراء.", + "recovery.discard_all_title": "تجاهل {count} من الحفظ التلقائي؟", + "recovery.discard_all_title_one": "تجاهل حفظ تلقائي واحد؟" + }, + "de": { + "recovery.discard_all": "Alle verwerfen", + "recovery.discard_all_detail": "Dies kann nicht rückgängig gemacht werden.", + "recovery.discard_all_title": "{count} automatische Sicherungen verwerfen?", + "recovery.discard_all_title_one": "1 automatische Sicherung verwerfen?" + }, + "fr": { + "recovery.discard_all": "Tout abandonner", + "recovery.discard_all_detail": "Cette action est irréversible.", + "recovery.discard_all_title": "Abandonner {count} sauvegardes automatiques ?", + "recovery.discard_all_title_one": "Abandonner 1 sauvegarde automatique ?" + }, + "he": { + "recovery.discard_all": "השלכת הכול", + "recovery.discard_all_detail": "לא ניתן לבטל פעולה זו.", + "recovery.discard_all_title": "להשליך {count} שמירות אוטומטיות?", + "recovery.discard_all_title_one": "להשליך שמירה אוטומטית אחת?" + }, + "ja": { + "recovery.discard_all": "すべて破棄", + "recovery.discard_all_detail": "この操作は元に戻せません。", + "recovery.discard_all_title": "{count} 件の自動保存を破棄しますか?", + "recovery.discard_all_title_one": "1 件の自動保存を破棄しますか?" + }, + "ko": { + "recovery.discard_all": "모두 버리기", + "recovery.discard_all_detail": "이 작업은 되돌릴 수 없습니다.", + "recovery.discard_all_title": "자동 저장 {count}개를 버리시겠습니까?", + "recovery.discard_all_title_one": "자동 저장 1개를 버리시겠습니까?" + }, + "vi": { + "recovery.discard_all": "Hủy bỏ tất cả", + "recovery.discard_all_detail": "Không thể hoàn tác thao tác này.", + "recovery.discard_all_title": "Hủy bỏ {count} bản tự động lưu?", + "recovery.discard_all_title_one": "Hủy bỏ 1 bản tự động lưu?" + }, + "zh": { + "recovery.discard_all": "全部放弃", + "recovery.discard_all_detail": "此操作无法撤消。", + "recovery.discard_all_title": "放弃 {count} 个自动保存?", + "recovery.discard_all_title_one": "放弃 1 个自动保存?" + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index c42ccfd94..52fc17f41 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -592,6 +592,8 @@ pub struct SolveApp { pub network_prompt: Option, /// Designs left by crashed apps, offered for recovery. pub recoverable: Vec, + /// Discard all was clicked in the recovery window: its confirmation is showing (#9299). + pub recovery_discard_all: bool, /// The bodies of a just-opened Y-up file, offered to be stood up (`stand_up`). pub stand_up: Option>, /// The placement of the component that file came in as: the offer turns it. @@ -780,6 +782,7 @@ impl SolveApp { disk_prompt: false, network_prompt: None, recoverable: Vec::new(), + recovery_discard_all: false, stand_up: None, stand_up_occurrence: None, stand_up_reason: false, diff --git a/crates/ui-egui/src/recovery_ui.rs b/crates/ui-egui/src/recovery_ui.rs index 4416c9abf..1c4851309 100644 --- a/crates/ui-egui/src/recovery_ui.rs +++ b/crates/ui-egui/src/recovery_ui.rs @@ -125,33 +125,53 @@ pub(crate) fn ago(secs: u64) -> String { pub fn show(app: &mut SolveApp, ctx: &egui::Context) { // File view presents the same entries inline, without a second window covering them. if app.home.open || app.recoverable.is_empty() { + app.recovery_discard_all = false; + return; + } + if app.recovery_discard_all { + confirm_discard_all(app, ctx); return; } let mut act: Option<(Entry, bool)> = None; + let mut discard_all = false; let (closed, action) = ui_kit::Window::new(egui::Id::new("sc_recover_prompt"), "restore", crate::i18n::tr_label("Recover unsaved design?")) .actions("", crate::i18n::tr_label("Later"), None) - .show(ctx, true, |ui| { - ui_kit::text( - ui, - crate::i18n::tr_label("SolidCraft closed before these designs were saved. Their last autosave can be opened."), - ui_kit::Text::Report("intro", false), - ); - for (index, e) in app.recoverable.iter().take(20).enumerate() { - ui_kit::divider(ui, &format!("entry:{index}")); - ui_kit::label_actions(ui, &e.name, |ui| { - if ui_kit::button(ui, crate::i18n::tr_label("Recover"), ui_kit::Button::Normal).clicked() { - act = Some((e.clone(), true)); - } - if ui_kit::button(ui, crate::i18n::tr_label("Discard"), ui_kit::Button::Normal).clicked() { - act = Some((e.clone(), false)); - } - }); - let file = e.path.clone().unwrap_or_else(|| crate::i18n::tr("recovery.never_saved").to_string()); - let detail = - crate::i18n::format("recovery.detail", &[("file", &file), ("features", &e.features.to_string()), ("when", &ago(e.saved_at))]); - ui_kit::text(ui, &detail, ui_kit::Text::Note(&format!("detail:{index}"))); - } - }); + .show_with_left( + ctx, + true, + |ui| { + ui_kit::text( + ui, + crate::i18n::tr_label("SolidCraft closed before these designs were saved. Their last autosave can be opened."), + ui_kit::Text::Report("intro", false), + ); + for (index, e) in app.recoverable.iter().take(20).enumerate() { + ui_kit::divider(ui, &format!("entry:{index}")); + ui_kit::label_actions(ui, &e.name, |ui| { + if ui_kit::button(ui, crate::i18n::tr_label("Recover"), ui_kit::Button::Normal).clicked() { + act = Some((e.clone(), true)); + } + if ui_kit::button(ui, crate::i18n::tr_label("Discard"), ui_kit::Button::Normal).clicked() { + act = Some((e.clone(), false)); + } + }); + let file = e.path.clone().unwrap_or_else(|| crate::i18n::tr("recovery.never_saved").to_string()); + let detail = + crate::i18n::format("recovery.detail", &[("file", &file), ("features", &e.features.to_string()), ("when", &ago(e.saved_at))]); + ui_kit::text(ui, &detail, ui_kit::Text::Note(&format!("detail:{index}"))); + } + }, + // Away from Later: it asks first, then discards every listed autosave (#9299). + |ui| { + let response = ui_kit::button(ui, crate::i18n::tr("recovery.discard_all"), ui_kit::Button::Normal); + crate::scenario::publish_target("recovery:discard_all", response.rect); + discard_all = response.clicked(); + }, + ); + if discard_all { + app.recovery_discard_all = true; + return; + } let later = closed || action != ui_kit::Action::None; if let Some((entry, recover)) = act { apply(app, entry, recover); @@ -161,6 +181,38 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { } } +/// Discard all asks first; Cancel (or the close button) goes back to the list unchanged. +fn confirm_discard_all(app: &mut SolveApp, ctx: &egui::Context) { + let count = app.recoverable.len(); + let title = if count == 1 { + crate::i18n::tr("recovery.discard_all_title_one").to_string() + } else { + crate::i18n::format("recovery.discard_all_title", &[("count", &count.to_string())]) + }; + let (closed, action) = ui_kit::Confirm::new(egui::Id::new("sc_recover_discard_all"), "delete", &title) + .tone(ui_kit::Tone::Danger) + .actions(crate::i18n::tr("recovery.discard_all"), crate::i18n::tr("ui.cancel"), None) + .show(ctx, true, |ui| { + ui_kit::text(ui, crate::i18n::tr("recovery.discard_all_detail"), ui_kit::Text::Report("discard_all", false)); + }); + match action { + ui_kit::Action::Ok => { + app.recovery_discard_all = false; + discard_all(app); + } + ui_kit::Action::Cancel => app.recovery_discard_all = false, + _ if closed => app.recovery_discard_all = false, + _ => {} + } +} + +/// Discard every listed autosave, each the way its own Discard button does. +fn discard_all(app: &mut SolveApp) { + for entry in std::mem::take(&mut app.recoverable) { + apply(app, entry, false); + } +} + /// Shared recovery action for the launch prompt and File view; dirty work is never replaced. pub(crate) fn apply(app: &mut SolveApp, entry: Entry, recover: bool) { let dir_s = app.autosave.as_ref().map(|a| a.dir.clone()).or_else(recovery::default_dir).map(|d| d.to_string_lossy().to_string()); @@ -492,4 +544,50 @@ mod tests { h.frames(2); assert!(h.app.recoverable.is_empty(), "Later hides the card for this launch"); } + + /// #9299: Discard all asks first; Cancel keeps every entry, confirming discards them all. + #[test] + fn discard_all_asks_first_then_discards_every_listed_autosave() { + let (mut crashed, dir) = app("discard-all", Duration::ZERO); + for i in 0..3 { + if i > 0 { + documents::new_tab(&mut crashed); + } + name(&mut crashed, &format!("Design {i}")); + edit(&mut crashed); + } + tick_and_wait(&mut crashed); + drop(crashed); + assert_eq!(recovery::orphans(&dir).len(), 3); + + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + start(&mut h.app, &dir, Duration::from_secs(3600)); + h.frames(4); + assert_eq!(h.app.recoverable.len(), 3); + assert!(crate::scenario::handle_at("recovery:discard_all").is_some()); + h.step(&json!({"widget": "Discard all"})).unwrap(); + h.frames(2); + assert!(h.app.recovery_discard_all, "Discard all opens its confirmation"); + assert!(h.widget("Cancel").is_some() && h.widget("Discard all").is_some(), "a confirmation first"); + assert!(h.widget("Discard 3 autosaves?").is_some(), "the title counts the autosaves"); + assert!(h.widget("Later").is_none(), "the confirmation replaces the list"); + assert_eq!(recovery::orphans(&dir).len(), 3, "nothing discarded before the answer"); + h.step(&json!({"widget": "Cancel"})).unwrap(); + h.frames(2); + assert!(h.widget("Later").is_some(), "Cancel goes back to the list"); + assert_eq!(h.app.recoverable.len(), 3); + assert_eq!(recovery::orphans(&dir).len(), 3); + + h.step(&json!({"widget": "Discard all"})).unwrap(); + h.frames(2); + h.step(&json!({"widget": "Discard all"})).unwrap(); + h.frames(2); + assert!(h.app.recoverable.is_empty()); + assert!(!h.app.recovery_discard_all); + assert!(recovery::orphans(&dir).is_empty(), "every listed autosave is gone"); + assert!(h.widget("Later").is_none()); + drop(h); + let _ = fs::remove_dir_all(dir); + } }