Add alert to verify overlaying an existing theme

This commit is contained in:
Maurice Parker 2021-09-09 06:03:28 -05:00
parent c031aa5cbe
commit b4d9423ff2
2 changed files with 35 additions and 8 deletions

View File

@ -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()
}
}
}
}

View File

@ -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)