Skip to content

Commit

Permalink
Add DocumentError.notEditable
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jan 21, 2025
1 parent 2696f99 commit 483ec1f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
82 changes: 82 additions & 0 deletions CotEditor/Resources/Localizables/Application/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,88 @@
}
}
},
"DocumentError.notEditable.description" : {
"extractionState" : "extracted_with_value",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Das Dokument kann nicht bearbeitet werden."
}
},
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "The document is not editable."
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "The document is not editable."
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "El documento no es editable."
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Le document n’est pas modifiable."
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "この書類は編集できません。"
}
}
}
},
"DocumentError.notEditable.recoverySuggestion" : {
"extractionState" : "extracted_with_value",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Um Änderungen am Inhalt des Dokuments vorzunehmen, lass es zunächst die Bearbeitung zu."
}
},
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "To make changes to the contents of the document, first allow editing it."
}
},
"en-GB" : {
"stringUnit" : {
"state" : "translated",
"value" : "To make changes to the contents of the document, first allow editing it."
}
},
"es" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Para efectuar cambios en el contenido del documento, primero permitir su edición."
}
},
"fr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Pour modifier le contenu du document, autoriser d'abord les modifications."
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "書類の内容を変更するためには、まず書類を編集可能にしてください。"
}
}
}
},
"DocumentOpeningError.binaryFile.description" : {
"extractionState" : "extracted_with_value",
"localizations" : {
Expand Down
39 changes: 39 additions & 0 deletions CotEditor/Sources/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ extension Document: EditorSource {

guard fileEncoding != self.fileEncoding else { return }

guard self.isEditable else {
return self.presentErrorAsSheet(DocumentError.notEditable)
}

// register undo
if let undoManager = self.undoManager {
undoManager.registerUndo(withTarget: self) { [currentFileEncoding = self.fileEncoding, shouldSaveEncodingXattr = self.shouldSaveEncodingXattr] target in
Expand Down Expand Up @@ -1418,6 +1422,41 @@ extension Document: EditorSource {

// MARK: - Errors

private enum DocumentError: LocalizedError {

case notEditable


var errorDescription: String? {

switch self {
case .notEditable:
String(localized: "DocumentError.notEditable.description",
defaultValue: "The document is not editable.")
}
}


var recoverySuggestion: String? {

switch self {
case .notEditable:
String(localized: "DocumentError.notEditable.recoverySuggestion",
defaultValue: "To make changes to the contents of the document, first allow editing it.")
}
}


var helpAnchor: String? {

switch self {
case .notEditable:
"howto_readonly"
}
}
}


enum ReinterpretationError: LocalizedError {

case noFile
Expand Down

0 comments on commit 483ec1f

Please sign in to comment.