mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Fix unwanted theme copy
This commit is contained in:
parent
b5cfc5463a
commit
43970a70ab
@ -14,6 +14,7 @@
|
||||
### Fixes
|
||||
|
||||
- Fix an issue that the application could not responding by updating a relatively large document from external processes.
|
||||
- Fix an issue that the application unwontedly copied the bundled theme setting files to the user domain.
|
||||
- Fix an issue that the Share command was not available in the theme setting list.
|
||||
- Fix the layout of the Go To dialog.
|
||||
|
||||
|
@ -143,6 +143,18 @@ extension SettingFileManaging {
|
||||
}
|
||||
|
||||
|
||||
/// Returns the bundled version of the setting, or `nil` if not exists.
|
||||
///
|
||||
/// - Parameter name: The setting name.
|
||||
/// - Returns: A setting, or `nil` if not exists.
|
||||
func bundledSetting(name: String) -> Setting? {
|
||||
|
||||
guard let url = self.urlForBundledSetting(name: name) else { return nil }
|
||||
|
||||
return try? self.loadSetting(at: url)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Public Methods
|
||||
|
||||
|
@ -123,18 +123,6 @@ final class SyntaxManager: SettingFileManaging {
|
||||
}
|
||||
|
||||
|
||||
/// Returns the bundled version of the setting, or `nil` if not exists.
|
||||
///
|
||||
/// - Parameter name: The setting name.
|
||||
/// - Returns: A setting, or `nil` if not exists.
|
||||
func bundledSetting(name: SettingName) -> Setting? {
|
||||
|
||||
guard let url = self.urlForBundledSetting(name: name) else { return nil }
|
||||
|
||||
return try? self.loadSetting(at: url)
|
||||
}
|
||||
|
||||
|
||||
/// Saves the given setting file to the user domain.
|
||||
///
|
||||
/// - Parameters:
|
||||
@ -152,8 +140,8 @@ final class SyntaxManager: SettingFileManaging {
|
||||
|
||||
let setting = setting.sanitized
|
||||
|
||||
// just remove the current custom setting file in the user domain if new syntax is just the same as bundled one
|
||||
// so that application uses bundled one
|
||||
// just remove the current custom setting file in the user domain
|
||||
// if the new setting is the same as bundled one
|
||||
if setting == self.bundledSetting(name: name) {
|
||||
if fileURL.isReachable {
|
||||
try FileManager.default.removeItem(at: fileURL)
|
||||
|
@ -118,21 +118,31 @@ final class ThemeManager: SettingFileManaging {
|
||||
}
|
||||
|
||||
|
||||
/// Saves the given setting file.
|
||||
/// Saves the given setting file to the user domain.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - setting: The setting to save.
|
||||
/// - name: The name of the setting to save.
|
||||
func save(setting: Setting, name: String) throws {
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
||||
|
||||
let data = try encoder.encode(setting)
|
||||
let fileURL = self.preparedURLForUserSetting(name: name)
|
||||
|
||||
try FileManager.default.createIntermediateDirectories(to: fileURL)
|
||||
try data.write(to: fileURL)
|
||||
// just remove the current custom setting file in the user domain
|
||||
// if the new setting is the same as bundled one
|
||||
if setting == self.bundledSetting(name: name) {
|
||||
if fileURL.isReachable {
|
||||
try FileManager.default.removeItem(at: fileURL)
|
||||
}
|
||||
} else {
|
||||
// save file to user domain
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
||||
|
||||
let data = try encoder.encode(setting)
|
||||
|
||||
try FileManager.default.createIntermediateDirectories(to: fileURL)
|
||||
try data.write(to: fileURL)
|
||||
}
|
||||
|
||||
self.cachedSettings[name] = setting
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user