From 0e2724cf1b4c3b42e0bbc25117d88cb8960bf406 Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Sat, 8 Apr 2023 15:17:06 +0800 Subject: [PATCH] Confirm on deleting --- .../Localization/de.lproj/Localizable.strings | 4 ++- .../Localization/en.lproj/Localizable.strings | 4 ++- .../Localization/ja.lproj/Localizable.strings | 4 ++- .../Localization/ko.lproj/Localizable.strings | 8 +++-- .../zh-Hans.lproj/Localizable.strings | 4 ++- CodeApp/Managers/MainApp.swift | 29 ++++++++++++------- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/CodeApp/Localization/de.lproj/Localizable.strings b/CodeApp/Localization/de.lproj/Localizable.strings index 47c667b73..f006d21cb 100644 --- a/CodeApp/Localization/de.lproj/Localizable.strings +++ b/CodeApp/Localization/de.lproj/Localizable.strings @@ -377,6 +377,7 @@ "common.dont_save" = "Nicht speichern"; "common.cancel" = "Abbrechen"; "common.revert" = "Rückgängig machen"; +"common.delete" = "Löschen"; "notification.source" = "Quelle: %@"; @@ -420,6 +421,7 @@ "file.copy" = "Kopieren nach.."; "file.download" = "Herunterladen auf.."; "file.confirm_save %@" = "Möchten Sie die Änderungen an %@ speichern?"; +"file.confirm_delete %@" = "Möchten Sie %@ wirklich löschen?"; "actions.new_window" = "Neues Fenster"; @@ -463,4 +465,4 @@ "remote.setup_remote_server" = "Dokumentation zur Fernzugriffsfunktion"; "remote.private_key_content" = "Inhalt des privaten Schlüssels"; "remote.setup_note" = "Um Schlüsselpaare zu generieren, führen Sie ssh-keygen im Terminal aus. Lassen Sie die Passphrase leer, falls keine vorhanden ist."; -"remote.import_from_file" = "Importieren aus Datei"; \ No newline at end of file +"remote.import_from_file" = "Importieren aus Datei"; diff --git a/CodeApp/Localization/en.lproj/Localizable.strings b/CodeApp/Localization/en.lproj/Localizable.strings index beb173fbd..256781272 100644 --- a/CodeApp/Localization/en.lproj/Localizable.strings +++ b/CodeApp/Localization/en.lproj/Localizable.strings @@ -268,6 +268,7 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice "common.dont_save" = "Don't Save"; "common.cancel" = "Cancel"; "common.revert" = "Revert"; +"common.delete" = "Delete"; "notification.source" = "Source: %@"; @@ -311,6 +312,7 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice "file.copy" = "Copy to.."; "file.download" = "Download to.."; "file.confirm_save %@" = "Do you want to save the changes made to %@?"; +"file.confirm_delete %@" = "Are you sure you want to delete %@?"; "actions.new_window" = "New Window"; @@ -355,4 +357,4 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice "remote.setup_remote_server" = "Documentation on remote access feature"; "remote.private_key_content" = "Private key content"; "remote.setup_note" = "To generate key-pairs, run ssh-keygen in the terminal. Leave the passphrase empty if there isn't one."; -"remote.import_from_file" = "Import from file"; \ No newline at end of file +"remote.import_from_file" = "Import from file"; diff --git a/CodeApp/Localization/ja.lproj/Localizable.strings b/CodeApp/Localization/ja.lproj/Localizable.strings index 3f775cb7d..5b58e5f18 100644 --- a/CodeApp/Localization/ja.lproj/Localizable.strings +++ b/CodeApp/Localization/ja.lproj/Localizable.strings @@ -378,6 +378,7 @@ "common.dont_save" = "保存しない"; "common.cancel" = "キャンセル"; "common.revert" = "元に戻す"; +"common.delete" = "削除"; "notification.source" = "Source: %@"; @@ -421,6 +422,7 @@ "file.copy" = "コピー.."; "file.download" = "ダウンロード.."; "file.confirm_save %@" = "%@ に加えた変更を保存しますか?"; +"file.confirm_delete %@" = "%@ を削除しますか?"; "actions.new_window" = "新しいウィンドウ"; @@ -464,4 +466,4 @@ "remote.setup_remote_server" = "リモート アクセス機能に関するドキュメント"; "remote.private_key_content" = "秘密鍵の内容"; "remote.setup_note" = "キーペアを生成するには、ターミナルで ssh-keygen を実行します。 パスフレーズがない場合は空のままにします。"; -"remote.import_from_file" = "ファイルからインポート"; \ No newline at end of file +"remote.import_from_file" = "ファイルからインポート"; diff --git a/CodeApp/Localization/ko.lproj/Localizable.strings b/CodeApp/Localization/ko.lproj/Localizable.strings index 04e840410..f191a81ed 100644 --- a/CodeApp/Localization/ko.lproj/Localizable.strings +++ b/CodeApp/Localization/ko.lproj/Localizable.strings @@ -369,7 +369,7 @@ "Enable spell check in text files" = "텍스트 파일에서 맞춤법 검사 활성화"; "Spell checking on content changed" = "변경한 내용에 대해 맞춤법 검사"; -"common.configure" = ""; +"common.configure" = "설정"; "common.open_folder" = "폴더 열기"; "common.compare" = "비교"; "common.overwrite" = "덮어쓰기"; @@ -377,6 +377,7 @@ "common.dont_save" = "저장하지 않음"; "common.cancel" = "취소"; "common.revert" = "되돌리기"; +"common.delete" = "삭제"; "notification.source" = "원천: %@"; @@ -419,7 +420,8 @@ "file.copy" = "에게 복사.."; "file.download" = "다운로드.."; -"file.confirm_save %@" = "파일을 저장하시겠습니까?"; +"file.confirm_save %@" = "%@을 저장하시겠습니까?"; +"file.confirm_delete %@" = "%@을 삭제하시겠습니까?"; "actions.new_window" = "새창"; @@ -463,4 +465,4 @@ "remote.setup_remote_server" = "원격 액세스 기능에 대한 설명서"; "remote.private_key_content" = "개인 키 내용"; "remote.setup_note" = "키 쌍을 생성하려면 터미널에서 ssh-keygen을 실행하십시오. 암호가 없는 경우 암호를 비워 둡니다."; -"remote.import_from_file" = "파일에서 가져 오기"; \ No newline at end of file +"remote.import_from_file" = "파일에서 가져 오기"; diff --git a/CodeApp/Localization/zh-Hans.lproj/Localizable.strings b/CodeApp/Localization/zh-Hans.lproj/Localizable.strings index f82a77b4a..d292638d9 100644 --- a/CodeApp/Localization/zh-Hans.lproj/Localizable.strings +++ b/CodeApp/Localization/zh-Hans.lproj/Localizable.strings @@ -368,6 +368,7 @@ "common.dont_save" = "不保存"; "common.cancel" = "取消"; "common.revert" = "还原"; +"common.delete" = "删除"; "notification.source" = "来源: %@"; @@ -411,6 +412,7 @@ "file.copy" = "复制到.."; "file.download" = "下载到.."; "file.confirm_save %@" = "是否要保存 %@?"; +"file.confirm_delete %@" = "你确定要删除 %@ 吗?"; "actions.new_window" = "新窗口"; @@ -454,4 +456,4 @@ "remote.setup_remote_server" = "有关远程访问功能的文档"; "remote.private_key_content" = "私钥内容"; "remote.setup_note" = "要生成密钥,请在终端中运行 ssh-keygen。如果没有密钥密码,请留空。"; -"remote.import_from_file" = "从文件导入"; \ No newline at end of file +"remote.import_from_file" = "从文件导入"; diff --git a/CodeApp/Managers/MainApp.swift b/CodeApp/Managers/MainApp.swift index 5cd1f2048..e0763bd1c 100644 --- a/CodeApp/Managers/MainApp.swift +++ b/CodeApp/Managers/MainApp.swift @@ -308,17 +308,26 @@ class MainApp: ObservableObject { } func trashItem(url: URL) { - workSpaceStorage.removeItem(at: url) { error in - if let error = error { - self.notificationManager.showErrorMessage(error.localizedDescription) - return - } - if let editorToTrash = self.textEditors.first(where: { $0.url == url }) { - Task { @MainActor in - self.closeEditor(editor: editorToTrash) + alertManager.showAlert( + title: "file.confirm_delete \(url.lastPathComponent)", + content: AnyView( + Group { + Button("common.delete", role: .destructive) { + self.workSpaceStorage.removeItem(at: url) { error in + if let error = error { + self.notificationManager.showErrorMessage(error.localizedDescription) + return + } + if let editorToTrash = self.textEditors.first(where: { $0.url == url }) { + Task { @MainActor in + self.closeEditor(editor: editorToTrash) + } + } + } + } + Button("common.cancel", role: .cancel) {} } - } - } + )) } func decodeStringData(data: Data) throws -> (String, String.Encoding) {