Skip to content

Commit

Permalink
Bugfix import color scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Jan 27, 2022
1 parent 6f7639e commit a947a6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions QLMarkdown/Settings+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ extension Settings {
NotificationCenter.default.post(name: .themeDidAdded, object: theme)
}

@discardableResult
func removeTheme(path: String) throws -> Bool {
guard let theme = self.getAvailableThemes().first(where: { $0.path == path }) else {
return false
}
return try self.removeTheme(theme)
}

@discardableResult
func removeTheme(_ theme: ThemePreview) throws -> Bool {
guard !theme.isStandalone else { return false }
Expand Down
15 changes: 12 additions & 3 deletions QLMarkdown/Themes/ThemesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class ThemesView: NSView {
}

let dst = themesFolder.appendingPathComponent(src.lastPathComponent)

if FileManager.default.fileExists(atPath: dst.path) {
let alert = NSAlert()
alert.messageText = "A theme already exists with the same name. \nDo you want to overwrite?"
Expand All @@ -389,16 +389,25 @@ class ThemesView: NSView {
alert.addButton(withTitle: "Yes").keyEquivalent = "\r"
if alert.runModal() == .alertSecondButtonReturn {
do {
try FileManager.default.removeItem(at: dst)
try Settings.shared.removeTheme(path: dst.path)
} catch {

let alert = NSAlert()
alert.messageText = "Unable to remove previous theme!"
alert.alertStyle = .warning
alert.addButton(withTitle: "Cancel").keyEquivalent = "\u{1b}"
alert.runModal()
return
}
} else {
return
}
}
do {
try FileManager.default.copyItem(at: src, to: dst)
let theme = ThemePreview(theme: t!.pointee)
theme.path = dst.path
Settings.shared.appendTheme(theme)
self.theme = theme
} catch {
let alert = NSAlert()
alert.messageText = "Unable to import the theme!"
Expand Down

0 comments on commit a947a6f

Please sign in to comment.