Commit a947a6f 1 parent 6f7639e commit a947a6f Copy full SHA for a947a6f
File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -153,6 +153,14 @@ extension Settings {
153
153
NotificationCenter . default. post ( name: . themeDidAdded, object: theme)
154
154
}
155
155
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
+
156
164
@discardableResult
157
165
func removeTheme( _ theme: ThemePreview ) throws -> Bool {
158
166
guard !theme. isStandalone else { return false }
Original file line number Diff line number Diff line change @@ -380,7 +380,7 @@ class ThemesView: NSView {
380
380
}
381
381
382
382
let dst = themesFolder. appendingPathComponent ( src. lastPathComponent)
383
-
383
+
384
384
if FileManager . default. fileExists ( atPath: dst. path) {
385
385
let alert = NSAlert ( )
386
386
alert. messageText = " A theme already exists with the same name. \n Do you want to overwrite? "
@@ -389,16 +389,25 @@ class ThemesView: NSView {
389
389
alert. addButton ( withTitle: " Yes " ) . keyEquivalent = " \r "
390
390
if alert. runModal ( ) == . alertSecondButtonReturn {
391
391
do {
392
- try FileManager . default . removeItem ( at : dst)
392
+ try Settings . shared . removeTheme ( path : dst. path )
393
393
} 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
395
400
}
396
401
} else {
397
402
return
398
403
}
399
404
}
400
405
do {
401
406
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
402
411
} catch {
403
412
let alert = NSAlert ( )
404
413
alert. messageText = " Unable to import the theme! "
You can’t perform that action at this time.
0 commit comments