Allow text file editing
This commit is contained in:
@ -71,12 +71,15 @@ struct SecurityBookmark {
|
||||
return write(data, to: relativePath)
|
||||
}
|
||||
|
||||
func write(_ string: String,
|
||||
/**
|
||||
Write text to a file at the relative path.
|
||||
*/
|
||||
func write(_ content: String,
|
||||
to relativePath: String,
|
||||
createParentFolder: Bool = true,
|
||||
ifFileExists overwrite: OverwriteBehaviour = .writeIfChanged) -> Bool {
|
||||
guard let data = string.data(using: .utf8) else {
|
||||
delegate?.securityBookmark(error: "Failed to encode string to write to \(relativePath)")
|
||||
guard let data = content.data(using: .utf8) else {
|
||||
delegate?.securityBookmark(error: "Failed to encode content to write to \(relativePath)")
|
||||
return false
|
||||
}
|
||||
return write(data, to: relativePath, createParentFolder: createParentFolder, ifFileExists: overwrite)
|
||||
|
@ -360,6 +360,12 @@ final class Storage: ObservableObject {
|
||||
return contentScope.readData(at: path)
|
||||
}
|
||||
|
||||
func save(fileContent: String, for fileId: String) -> Bool {
|
||||
guard let contentScope else { return false }
|
||||
let path = filePath(file: fileId)
|
||||
return contentScope.write(fileContent, to: path)
|
||||
}
|
||||
|
||||
// MARK: Settings
|
||||
|
||||
func loadSettings() -> Settings.Data? {
|
||||
|
Reference in New Issue
Block a user