Skip to content

Commit a947a6f

Browse files
committed
Bugfix import color scheme.
1 parent 6f7639e commit a947a6f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

QLMarkdown/Settings+ext.swift

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ extension Settings {
153153
NotificationCenter.default.post(name: .themeDidAdded, object: theme)
154154
}
155155

156+
@discardableResult
157+
func removeTheme(path: String) throws -> Bool {
158+
guard let theme = self.getAvailableThemes().first(where: { $0.path == path }) else {
159+
return false
160+
}
161+
return try self.removeTheme(theme)
162+
}
163+
156164
@discardableResult
157165
func removeTheme(_ theme: ThemePreview) throws -> Bool {
158166
guard !theme.isStandalone else { return false }

QLMarkdown/Themes/ThemesView.swift

+12-3
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ class ThemesView: NSView {
380380
}
381381

382382
let dst = themesFolder.appendingPathComponent(src.lastPathComponent)
383-
383+
384384
if FileManager.default.fileExists(atPath: dst.path) {
385385
let alert = NSAlert()
386386
alert.messageText = "A theme already exists with the same name. \nDo you want to overwrite?"
@@ -389,16 +389,25 @@ class ThemesView: NSView {
389389
alert.addButton(withTitle: "Yes").keyEquivalent = "\r"
390390
if alert.runModal() == .alertSecondButtonReturn {
391391
do {
392-
try FileManager.default.removeItem(at: dst)
392+
try Settings.shared.removeTheme(path: dst.path)
393393
} catch {
394-
394+
let alert = NSAlert()
395+
alert.messageText = "Unable to remove previous theme!"
396+
alert.alertStyle = .warning
397+
alert.addButton(withTitle: "Cancel").keyEquivalent = "\u{1b}"
398+
alert.runModal()
399+
return
395400
}
396401
} else {
397402
return
398403
}
399404
}
400405
do {
401406
try FileManager.default.copyItem(at: src, to: dst)
407+
let theme = ThemePreview(theme: t!.pointee)
408+
theme.path = dst.path
409+
Settings.shared.appendTheme(theme)
410+
self.theme = theme
402411
} catch {
403412
let alert = NSAlert()
404413
alert.messageText = "Unable to import the theme!"

0 commit comments

Comments
 (0)