PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Follow-ups to #5801/#5859: precheck docs name the group nesting limit; precheck test covers valid ids and null; Free Transform refusals translated; stranded-backup error tested (#6365)
Tanish Manku2b3d05636f1c
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex e45826f34..f13d61b97 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -422,8 +422,10 @@ pub struct CopiedStyle {pub mode: photocraft_color::ColorMode,}-/// The commands whose [`Session::precheck`] is complete: it accepts exactly what `execute` does-/// (Free Transform applies its box before these, and only when they will run). Layer via Copy and+/// The commands whose [`Session::precheck`] is complete: it accepts what `execute` does (Free+/// Transform applies its box before these, and only when they will run), but for the group+/// nesting limit ([`photocraft_doc::MAX_GROUP_DEPTH`]): grouping layers already that deep is+/// refused only as the edit is made. Layer via Copy and/// Cut aren't: whether they have anything to copy (a selection over transparent pixels, a group/// or fill layer) is known only when they run.pub const PRECHECKED: &[&str] = &["layer.new.layer", "layer.new.group", "layer.new.groupFromLayers", "layer.new.layerFromBackground"];@@ -671,8 +673,8 @@ impl Session {/// something first only when the command will go through: Free Transform applies its box/// before a new layer is made.///- /// Complete for the commands in [`PRECHECKED`]: there it accepts exactly what `execute`- /// accepts (a test holds the two together). For others it checks only what they share.+ /// Complete for the commands in [`PRECHECKED`]: there it accepts what `execute` accepts, but+ /// for the group nesting limit (a test holds the two together). For others it checks only what they share.pub fn precheck(&mut self, id: &str, params: &Value) -> Result<()> {let spec = crate::commands::find(id).ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;if !(params.is_object() || params.is_null()) {diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rsindex 374131e85..5314d1f19 100644--- a/crates/engine/src/prefs/tests.rs+++ b/crates/engine/src/prefs/tests.rs@@ -878,3 +878,40 @@ fn exports_are_written_all_or_nothing() {assert_eq!(leftovers(), 1, "only c.kys.photocraft-tmp itself");let _ = std::fs::remove_dir_all(&dir);}++/// A backup that can't be put back after a failed export is named in the error, and stays where+/// it is with the user's previous text.+#[test]+fn a_stranded_backup_is_named_in_the_error() {+ use super::write_files_atomically;+ let dir = std::env::temp_dir().join(format!("photocraft-stranded-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let (a, b) = (dir.join("a.kys"), dir.join("b.html"));+ std::fs::write(&a, "old A").unwrap();+ std::fs::write(&b, "old B").unwrap();+ let (pa, pb) = (a.to_str().unwrap(), b.to_str().unwrap());+ let staged = std::cell::Cell::new(0);+ // The second staged move fails, and so does putting a.kys's backup back.+ let rename = |from: &std::path::Path, to: &std::path::Path| {+ let f = from.to_string_lossy();+ if f.ends_with("photocraft-tmp") {+ staged.set(staged.get() + 1);+ if staged.get() == 2 {+ return Err(std::io::Error::other("disk gone"));+ }+ }+ if f.ends_with("photocraft-bak") && to == a.as_path() {+ return Err(std::io::Error::other("locked"));+ }+ std::fs::rename(from, to)+ };+ let e = write_files_atomically(&[(pa, "new A"), (pb, "new B")], &rename).unwrap_err();+ assert!(e.contains(&format!("the previous {} is at", a.display())), "{e}");+ let backup: Vec<_> =+ std::fs::read_dir(&dir).unwrap().filter_map(|e| e.ok()).map(|e| e.path()).filter(|p| p.to_string_lossy().ends_with("photocraft-bak")).collect();+ assert_eq!(backup.len(), 1, "{backup:?}");+ assert!(e.contains(&backup[0].display().to_string()), "{e}");+ assert_eq!(std::fs::read_to_string(&backup[0]).unwrap(), "old A");+ assert_eq!(std::fs::read_to_string(&b).unwrap(), "old B");+ let _ = std::fs::remove_dir_all(&dir);+}diff --git a/crates/engine/tests/precheck.rs b/crates/engine/tests/precheck.rsindex a28726dfe..f549fbb8c 100644--- a/crates/engine/tests/precheck.rs+++ b/crates/engine/tests/precheck.rs@@ -1,4 +1,5 @@-//! `Session::precheck` accepts exactly what `execute` accepts for the commands it covers+//! `Session::precheck` accepts what `execute` accepts for the commands it covers (all but the+//! group nesting limit, which only the edit checks)//! (`PRECHECKED`): Free Transform applies its box before them only when they will run (#5859).use photocraft_engine::{PRECHECKED, Session};@@ -47,6 +48,9 @@ fn params() -> Vec<Value> {json!({"name": "ok"}),json!({"color": "chartreuse"}),json!({"layer": 999_999}),+ json!({"layer": 1}),+ json!({"layer": 2}),+ json!({"layer": null}),json!({"layer": "Layer 1"}),json!({"layer": "no such layer"}),json!({"layer": true}),diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 1329378dc..c73c032df 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -3805,3 +3805,6 @@ navigator Zoom ZvětšeníUndo Changes Vrátit změny{shortcut} is reserved by the system and can't be assigned. {shortcut} je vyhrazena systémem a nelze ji přiřadit.Low-Latency Drawing (vsync off, applies at next launch) Kreslení s nízkou latencí (bez vertikální synchronizace, platí po dalším spuštění)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Volná transformace se stále použije; zkuste to znovu, až skončí.+ The transform couldn't be applied. Transformaci nelze použít.diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 5f5642123..bfa6d5f8f 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -3199,3 +3199,6 @@ curves Smooth GlättenUndo Changes Änderungen rückgängig machen{shortcut} is reserved by the system and can't be assigned. {shortcut} ist vom System reserviert und kann nicht zugewiesen werden.Low-Latency Drawing (vsync off, applies at next launch) Zeichnen mit geringer Latenz (ohne VSync, gilt ab dem nächsten Start)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Frei transformieren wird noch angewendet; versuchen Sie es erneut, wenn es fertig ist.+ The transform couldn't be applied. Die Transformation konnte nicht angewendet werden.diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex 715e41cb1..eccfd0508 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3897,3 +3897,6 @@ curves Smooth ΕξομάλυνσηUndo Changes Αναίρεση αλλαγών{shortcut} is reserved by the system and can't be assigned. Η συντόμευση {shortcut} δεσμεύεται από το σύστημα και δεν μπορεί να εκχωρηθεί.Low-Latency Drawing (vsync off, applies at next launch) Σχεδίαση χαμηλής καθυστέρησης (χωρίς vsync, ισχύει στην επόμενη εκκίνηση)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Ο Ελεύθερος μετασχηματισμός εφαρμόζεται ακόμη· δοκιμάστε ξανά όταν ολοκληρωθεί.+ The transform couldn't be applied. Δεν ήταν δυνατή η εφαρμογή του μετασχηματισμού.diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 4a0f1c855..da9337eae 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -4159,3 +4159,6 @@ navigator Zoom ZoomUndo Changes Deshacer cambios{shortcut} is reserved by the system and can't be assigned. {shortcut} está reservado por el sistema y no se puede asignar.Low-Latency Drawing (vsync off, applies at next launch) Dibujo de baja latencia (sin sincronización vertical, se aplica al volver a iniciar)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Transformación libre aún se está aplicando; inténtelo de nuevo cuando termine.+ The transform couldn't be applied. No se pudo aplicar la transformación.diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 2402aec16..8b25af722 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -3202,3 +3202,6 @@ curves Smooth LisserUndo Changes Annuler les modifications{shortcut} is reserved by the system and can't be assigned. {shortcut} est réservé par le système et ne peut pas être attribué.Low-Latency Drawing (vsync off, applies at next launch) Dessin à faible latence (sans synchronisation verticale, au prochain lancement)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. La transformation manuelle est encore en cours d'application ; réessayez quand elle sera terminée.+ The transform couldn't be applied. Impossible d'appliquer la transformation.diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex 343dcadc0..2870dc6f9 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -4116,3 +4116,6 @@ cameraRaw Yellow SárgaUndo Changes Változások visszavonása{shortcut} is reserved by the system and can't be assigned. A(z) {shortcut} a rendszer számára fenntartott, nem rendelhető hozzá.Low-Latency Drawing (vsync off, applies at next launch) Kis késleltetésű rajzolás (vsync nélkül, a következő indításkor lép életbe)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. A szabad alakítás alkalmazása még folyamatban van; próbáld újra, ha befejeződött.+ The transform couldn't be applied. Az átalakítás nem alkalmazható.diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex e4ba61e1a..feca83a9c 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -3189,3 +3189,6 @@ curves Smooth HaluskanUndo Changes Batalkan Perubahan{shortcut} is reserved by the system and can't be assigned. {shortcut} dicadangkan oleh sistem dan tidak dapat ditetapkan.Low-Latency Drawing (vsync off, applies at next launch) Menggambar latensi rendah (tanpa vsync, berlaku saat peluncuran berikutnya)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Transformasi Bebas masih diterapkan; coba lagi setelah selesai.+ The transform couldn't be applied. Transformasi tidak dapat diterapkan.diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 6b933287c..a8796e64e 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -4318,3 +4318,6 @@ shape Appearance AspettoUndo Changes Annulla modifiche{shortcut} is reserved by the system and can't be assigned. {shortcut} è riservata dal sistema e non può essere assegnata.Low-Latency Drawing (vsync off, applies at next launch) Disegno a bassa latenza (senza vsync, si applica al prossimo avvio)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Trasformazione libera è ancora in corso di applicazione; riprova quando è terminata.+ The transform couldn't be applied. Impossibile applicare la trasformazione.diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 2f6b7d7f5..13efa7517 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3873,3 +3873,6 @@ curves Smooth スムーズUndo Changes 変更を取り消し{shortcut} is reserved by the system and can't be assigned. {shortcut} はシステムで予約されているため割り当てられません。Low-Latency Drawing (vsync off, applies at next launch) 低遅延描画(垂直同期オフ、次回起動時に適用)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. 自由変形を適用中です。完了してからもう一度お試しください。+ The transform couldn't be applied. 変形を適用できませんでした。diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex 3c056c627..5354b04a3 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3375,3 +3375,6 @@ curves Smooth 매끄럽게Undo Changes 변경 사항 취소{shortcut} is reserved by the system and can't be assigned. {shortcut}은(는) 시스템에서 예약되어 할당할 수 없습니다.Low-Latency Drawing (vsync off, applies at next launch) 저지연 그리기(수직 동기화 끔, 다음 실행 시 적용)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. 자유 변형을 아직 적용하는 중입니다. 완료된 후 다시 시도하세요.+ The transform couldn't be applied. 변형을 적용할 수 없습니다.diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex c80f86bf8..5a013c786 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -3957,3 +3957,6 @@ curves Smooth Vloeiend makenUndo Changes Wijzigingen ongedaan maken{shortcut} is reserved by the system and can't be assigned. {shortcut} is door het systeem gereserveerd en kan niet worden toegewezen.Low-Latency Drawing (vsync off, applies at next launch) Tekenen met lage latentie (zonder vsync, na de volgende start)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Vrije transformatie wordt nog toegepast; probeer het opnieuw als die klaar is.+ The transform couldn't be applied. De transformatie kon niet worden toegepast.diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 85df6b815..8707b5fb2 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3795,3 +3795,6 @@ curves Smooth WygładźUndo Changes Cofnij zmiany{shortcut} is reserved by the system and can't be assigned. {shortcut} jest zarezerwowany przez system i nie można go przypisać.Low-Latency Drawing (vsync off, applies at next launch) Rysowanie z małym opóźnieniem (bez synchronizacji pionowej, od następnego uruchomienia)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Przekształcanie swobodne jest nadal stosowane; spróbuj ponownie, gdy się zakończy.+ The transform couldn't be applied. Nie można zastosować przekształcenia.diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 211442ba2..ef10787ce 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -3987,3 +3987,6 @@ layerLabel No Color Sem corUndo Changes Desfazer alterações{shortcut} is reserved by the system and can't be assigned. {shortcut} é reservado pelo sistema e não pode ser atribuído.Low-Latency Drawing (vsync off, applies at next launch) Desenho de baixa latência (sem sincronização vertical, aplicado na próxima inicialização)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. A Transformação livre ainda está sendo aplicada; tente novamente quando terminar.+ The transform couldn't be applied. Não foi possível aplicar a transformação.diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 9dfcc8509..449f741e2 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -3167,3 +3167,6 @@ curves Smooth СгладитьUndo Changes Отменить изменения{shortcut} is reserved by the system and can't be assigned. Комбинация {shortcut} зарезервирована системой и не может быть назначена.Low-Latency Drawing (vsync off, applies at next launch) Рисование с малой задержкой (без вертикальной синхронизации, после перезапуска)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Свободное трансформирование ещё применяется; повторите попытку, когда оно завершится.+ The transform couldn't be applied. Не удалось применить трансформирование.diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsvindex bbc0ef528..4dedfaf7a 100644--- a/crates/ui-egui/src/i18n/sr.tsv+++ b/crates/ui-egui/src/i18n/sr.tsv@@ -4270,3 +4270,6 @@ shape Appearance IzgledUndo Changes Poništi izmene{shortcut} is reserved by the system and can't be assigned. {shortcut} je rezervisana od strane sistema i ne može se dodeliti.Low-Latency Drawing (vsync off, applies at next launch) Crtanje sa malim kašnjenjem (bez vsync-a, primenjuje se pri sledećem pokretanju)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Slobodna transformacija se još primenjuje; pokušajte ponovo kad se završi.+ The transform couldn't be applied. Transformacija nije mogla da se primeni.diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsvindex b63bdd734..f7dc6961f 100644--- a/crates/ui-egui/src/i18n/tr.tsv+++ b/crates/ui-egui/src/i18n/tr.tsv@@ -3927,3 +3927,6 @@ cameraData Lens LensUndo Changes Değişiklikleri Geri Al{shortcut} is reserved by the system and can't be assigned. {shortcut} sistem tarafından ayrılmıştır ve atanamaz.Low-Latency Drawing (vsync off, applies at next launch) Düşük gecikmeli çizim (dikey eşitleme kapalı, sonraki açılışta geçerli)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Serbest Dönüştürme hâlâ uygulanıyor; bittiğinde yeniden deneyin.+ The transform couldn't be applied. Dönüştürme uygulanamadı.diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 923ec694a..9a018c744 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -3896,3 +3896,6 @@ curves Smooth ЗгладитиUndo Changes Скасувати зміни{shortcut} is reserved by the system and can't be assigned. {shortcut} зарезервовано системою, його не можна призначити.Low-Latency Drawing (vsync off, applies at next launch) Малювання з малою затримкою (без вертикальної синхронізації, після перезапуску)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Вільне трансформування ще застосовується; спробуйте знову, коли воно завершиться.+ The transform couldn't be applied. Не вдалося застосувати трансформування.diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsvindex be40230ca..b798849d7 100644--- a/crates/ui-egui/src/i18n/vi.tsv+++ b/crates/ui-egui/src/i18n/vi.tsv@@ -3683,3 +3683,6 @@ curves Smooth Làm mượtUndo Changes Hoàn tác thay đổi{shortcut} is reserved by the system and can't be assigned. {shortcut} được hệ thống dành riêng và không thể gán.Low-Latency Drawing (vsync off, applies at next launch) Vẽ độ trễ thấp (tắt vsync, áp dụng ở lần khởi động sau)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. Biến đổi tự do vẫn đang được áp dụng; hãy thử lại khi hoàn tất.+ The transform couldn't be applied. Không thể áp dụng phép biến đổi.diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 7c563780d..766497d67 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2813,3 +2813,6 @@ curves Smooth 平滑Undo Changes 撤消更改{shortcut} is reserved by the system and can't be assigned. {shortcut} 由系统保留,无法指定。Low-Latency Drawing (vsync off, applies at next launch) 低延迟绘画(关闭垂直同步,下次启动时生效)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. 自由变换仍在应用中;请在完成后重试。+ The transform couldn't be applied. 无法应用变换。diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 9376cb05b..3627c785e 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2798,3 +2798,6 @@ curves Smooth 平滑Undo Changes 還原變更{shortcut} is reserved by the system and can't be assigned. {shortcut} 由系統保留,無法指定。Low-Latency Drawing (vsync off, applies at next launch) 低延遲繪圖(關閉垂直同步,下次啟動時生效)+# Free Transform: a new layer while the box is open (#5859)+ Free Transform is still being applied; try again when it has finished. 任意變形仍在套用中;請在完成後再試一次。+ The transform couldn't be applied. 無法套用變形。diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 27a200401..bde51ff27 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1061,10 +1061,10 @@ impl PhotocraftApp {self.session.precheck(id, ¶ms).map_err(|e| e.to_string())?;transform_tool::commit(self);if transform_tool::committing(self).is_some() {- return Err("the transform is still being applied; try again when it has finished".into());+ return Err(tl!("Free Transform is still being applied; try again when it has finished.").into());}if self.ui.transform.is_some() {- return Err(if self.ui.status.is_empty() { "the transform couldn't be applied".into() } else { self.ui.status.clone() });+ return Err(if self.ui.status.is_empty() { tl!("The transform couldn't be applied.").into() } else { self.ui.status.clone() });}}if let Some(result) = panel_docking::command(self, id, ¶ms) {