mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +01:00
Add alert to verify overlaying an existing theme
This commit is contained in:
parent
c031aa5cbe
commit
b4d9423ff2
@ -846,16 +846,37 @@ private extension AppDelegate {
|
||||
alert.addButton(withTitle: NSLocalizedString("Install Theme", comment: "Install Theme"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Install Theme"))
|
||||
|
||||
alert.beginSheetModal(for: window) { [weak self] result in
|
||||
func importTheme() {
|
||||
do {
|
||||
try ArticleThemesManager.shared.importTheme(filename: filename)
|
||||
confirmImportSuccess(themeName: theme.name)
|
||||
} catch {
|
||||
NSApplication.shared.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
alert.beginSheetModal(for: window) { result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
guard let self = self else { return }
|
||||
|
||||
do {
|
||||
try ArticleThemesManager.shared.importTheme(filename: filename)
|
||||
self.confirmImportSuccess(themeName: theme.name)
|
||||
} catch {
|
||||
NSApplication.shared.presentError(error)
|
||||
|
||||
if ArticleThemesManager.shared.themeExists(filename: filename) {
|
||||
let alert = NSAlert()
|
||||
alert.alertStyle = .warning
|
||||
|
||||
let localizedMessageText = NSLocalizedString("The theme “%@” already exists. Overwrite it?", comment: "Overwrite theme")
|
||||
alert.messageText = NSString.localizedStringWithFormat(localizedMessageText as NSString, theme.name) as String
|
||||
|
||||
alert.addButton(withTitle: NSLocalizedString("Overwrite", comment: "Overwrite"))
|
||||
alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "Cancel Install Theme"))
|
||||
|
||||
alert.beginSheetModal(for: window) { result in
|
||||
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
|
||||
importTheme()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
importTheme()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,12 @@ final class ArticleThemesManager {
|
||||
|
||||
// MARK: API
|
||||
|
||||
func themeExists(filename: String) -> Bool {
|
||||
let filenameLastPathComponent = (filename as NSString).lastPathComponent
|
||||
let toFilename = (folderPath as NSString).appendingPathComponent(filenameLastPathComponent)
|
||||
return FileManager.default.fileExists(atPath: toFilename)
|
||||
}
|
||||
|
||||
func importTheme(filename: String) throws {
|
||||
let filenameLastPathComponent = (filename as NSString).lastPathComponent
|
||||
let toFilename = (folderPath as NSString).appendingPathComponent(filenameLastPathComponent)
|
||||
|
Loading…
x
Reference in New Issue
Block a user