Skip to content

Commit 4ac87ee

Browse files
Import, duplicate and delete themes (#1718)
* Put UI in place to configure theme tokens to be bold and or or italic from within theme details in settings * Added isBundled flag to Theme. Added ability to import, duplicate, and delete themes. * Renaming theme file when displayName is changed. Persisting changes to theme files. * Changed theme details UI when adding theme, cancel deletes new theme when adding. * Removed dev text in theme details * Sorting the keys in the JSON output when modifying a theme * Added delete button to theme details sheet * PR Issues * PR Issues * Moved view functions to ThemeModel * Storing and updating colorScheme in ThemeModel because otherwise it would always be set to light * Update Theme While Editing, Warnings --------- Co-authored-by: Khan Winter <35942988+thecoolwinter@users.noreply.github.com>
1 parent 051a837 commit 4ac87ee

File tree

11 files changed

+672
-376
lines changed

11 files changed

+672
-376
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
B61A606129F188AB009B43F9 /* ExternalLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61A606029F188AB009B43F9 /* ExternalLink.swift */; };
470470
B61A606929F4481A009B43F9 /* MonospacedFontPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61A606829F4481A009B43F9 /* MonospacedFontPicker.swift */; };
471471
B61DA9DF29D929E100BF4A43 /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B61DA9DE29D929E100BF4A43 /* GeneralSettingsView.swift */; };
472+
B62423302C21EE280096668B /* ThemeModel+CRUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = B624232F2C21EE280096668B /* ThemeModel+CRUD.swift */; };
472473
B628B7932B18369800F9775A /* GitClient+Validate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B628B7922B18369800F9775A /* GitClient+Validate.swift */; };
473474
B628B7B72B223BAD00F9775A /* FindModePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = B628B7B62B223BAD00F9775A /* FindModePicker.swift */; };
474475
B62AEDAA2A1FCBE5009A9F52 /* AreaTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B62AEDA92A1FCBE5009A9F52 /* AreaTabBar.swift */; };
@@ -548,6 +549,7 @@
548549
B6F0517929D9E3C900D72287 /* SourceControlGitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F0517829D9E3C900D72287 /* SourceControlGitView.swift */; };
549550
B6F0517B29D9E46400D72287 /* SourceControlSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F0517A29D9E46400D72287 /* SourceControlSettingsView.swift */; };
550551
B6F0517D29D9E4B100D72287 /* TerminalSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6F0517C29D9E4B100D72287 /* TerminalSettingsView.swift */; };
552+
B6FA3F882BF41C940023DE9C /* ThemeSettingsThemeToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6FA3F872BF41C940023DE9C /* ThemeSettingsThemeToken.swift */; };
551553
B6FF04782B6C08AC002C2C78 /* DefaultThemes in Resources */ = {isa = PBXBuildFile; fileRef = B6FF04772B6C08AC002C2C78 /* DefaultThemes */; };
552554
D7012EE827E757850001E1EF /* FindNavigatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7012EE727E757850001E1EF /* FindNavigatorView.swift */; };
553555
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */; };
@@ -746,7 +748,7 @@
746748
5878DA81291863F900DD95A3 /* AcknowledgementsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcknowledgementsView.swift; sourceTree = "<group>"; };
747749
5878DA832918642000DD95A3 /* ParsePackagesResolved.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParsePackagesResolved.swift; sourceTree = "<group>"; };
748750
5878DA862918642F00DD95A3 /* AcknowledgementsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AcknowledgementsViewModel.swift; sourceTree = "<group>"; };
749-
5878DAA1291AE76700DD95A3 /* QuickOpenView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickOpenView.swift; sourceTree = "<group>"; };
751+
5878DAA1291AE76700DD95A3 /* QuickOpenView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = QuickOpenView.swift; sourceTree = "<group>"; wrapsLines = 1; };
750752
5878DAA2291AE76700DD95A3 /* QuickOpenPreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickOpenPreviewView.swift; sourceTree = "<group>"; };
751753
5878DAA3291AE76700DD95A3 /* QuickOpenViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickOpenViewModel.swift; sourceTree = "<group>"; };
752754
5878DAA4291AE76700DD95A3 /* QuickOpenItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuickOpenItem.swift; sourceTree = "<group>"; };
@@ -1069,6 +1071,7 @@
10691071
B61A606029F188AB009B43F9 /* ExternalLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalLink.swift; sourceTree = "<group>"; };
10701072
B61A606829F4481A009B43F9 /* MonospacedFontPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonospacedFontPicker.swift; sourceTree = "<group>"; };
10711073
B61DA9DE29D929E100BF4A43 /* GeneralSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsView.swift; sourceTree = "<group>"; };
1074+
B624232F2C21EE280096668B /* ThemeModel+CRUD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ThemeModel+CRUD.swift"; sourceTree = "<group>"; };
10721075
B628B7922B18369800F9775A /* GitClient+Validate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Validate.swift"; sourceTree = "<group>"; };
10731076
B628B7B62B223BAD00F9775A /* FindModePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindModePicker.swift; sourceTree = "<group>"; };
10741077
B62AEDA92A1FCBE5009A9F52 /* AreaTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AreaTabBar.swift; sourceTree = "<group>"; };
@@ -1153,6 +1156,7 @@
11531156
B6F0517829D9E3C900D72287 /* SourceControlGitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlGitView.swift; sourceTree = "<group>"; };
11541157
B6F0517A29D9E46400D72287 /* SourceControlSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlSettingsView.swift; sourceTree = "<group>"; };
11551158
B6F0517C29D9E4B100D72287 /* TerminalSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalSettingsView.swift; sourceTree = "<group>"; };
1159+
B6FA3F872BF41C940023DE9C /* ThemeSettingsThemeToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeSettingsThemeToken.swift; sourceTree = "<group>"; };
11561160
B6FF04772B6C08AC002C2C78 /* DefaultThemes */ = {isa = PBXFileReference; lastKnownFileType = folder; path = DefaultThemes; sourceTree = "<group>"; };
11571161
D7012EE727E757850001E1EF /* FindNavigatorView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = FindNavigatorView.swift; sourceTree = "<group>"; tabWidth = 4; };
11581162
D7211D4227E066CE008F2ED7 /* Localized+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Localized+Ex.swift"; sourceTree = "<group>"; };
@@ -2387,6 +2391,7 @@
23872391
B6EA1FF729DB78DB001BF195 /* ThemeSettingThemeRow.swift */,
23882392
B6EA1FFA29DB78F6001BF195 /* ThemeSettingsThemeDetails.swift */,
23892393
B6EA1FFC29DB792C001BF195 /* ThemeSettingsColorPreview.swift */,
2394+
B6FA3F872BF41C940023DE9C /* ThemeSettingsThemeToken.swift */,
23902395
);
23912396
path = ThemeSettings;
23922397
sourceTree = "<group>";
@@ -3202,6 +3207,7 @@
32023207
children = (
32033208
58F2EAE0292FB2B0004A9BDE /* ThemeSettings.swift */,
32043209
B6EA1FE429DA33DB001BF195 /* ThemeModel.swift */,
3210+
B624232F2C21EE280096668B /* ThemeModel+CRUD.swift */,
32053211
B6EA1FE629DA341D001BF195 /* Theme.swift */,
32063212
);
32073213
path = Models;
@@ -3687,6 +3693,7 @@
36873693
58798219292D92370085B254 /* SearchModeModel.swift in Sources */,
36883694
6C5C891B2A3F736500A94FE1 /* FocusedValues.swift in Sources */,
36893695
611192062B08CCF600D4459B /* SearchIndexer+Add.swift in Sources */,
3696+
B62423302C21EE280096668B /* ThemeModel+CRUD.swift in Sources */,
36903697
B62AEDD72A27B3D0009A9F52 /* UtilityAreaTabViewModel.swift in Sources */,
36913698
85773E1E2A3E0A1F00C5D926 /* SettingsSearchResult.swift in Sources */,
36923699
B66A4E4F29C917B8004573B4 /* WelcomeWindow.swift in Sources */,
@@ -3944,6 +3951,7 @@
39443951
58798236292E30B90085B254 /* FeedbackType.swift in Sources */,
39453952
587B9E6D29301D8F00AC7927 /* GitLabEventNote.swift in Sources */,
39463953
587B9E9129301D8F00AC7927 /* BitBucketOAuthRouter.swift in Sources */,
3954+
B6FA3F882BF41C940023DE9C /* ThemeSettingsThemeToken.swift in Sources */,
39473955
B6E41C7429DD40010088F9F4 /* View+HideSidebarToggle.swift in Sources */,
39483956
611191FA2B08CC9000D4459B /* SearchIndexer.swift in Sources */,
39493957
58822532292C280D00E83CDE /* UtilityAreaViewModel.swift in Sources */,

CodeEdit/Features/Editor/Views/CodeFileView.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct CodeFileView: View {
4646

4747
@EnvironmentObject private var editorManager: EditorManager
4848

49-
@StateObject private var themeModel: ThemeModel = .shared
49+
@ObservedObject private var themeModel: ThemeModel = .shared
5050

5151
private var cancellables = Set<AnyCancellable>()
5252

@@ -77,7 +77,9 @@ struct CodeFileView: View {
7777
codeFile.undoManager = self.undoManager.manager
7878
}
7979

80-
@State private var selectedTheme = ThemeModel.shared.selectedTheme ?? ThemeModel.shared.themes.first!
80+
private var currentTheme: Theme {
81+
themeModel.selectedTheme ?? themeModel.themes.first!
82+
}
8183

8284
@State private var font: NSFont = Settings[\.textEditing].font.current
8385

@@ -107,7 +109,7 @@ struct CodeFileView: View {
107109
CodeEditSourceEditor(
108110
codeFile.content ?? NSTextStorage(),
109111
language: getLanguage(),
110-
theme: selectedTheme.editor.editorTheme,
112+
theme: currentTheme.editor.editorTheme,
111113
font: font,
112114
tabWidth: codeFile.defaultTabWidth ?? defaultTabWidth,
113115
indentOption: (codeFile.indentOption ?? indentOption).textViewOption(),
@@ -131,17 +133,9 @@ struct CodeFileView: View {
131133
EffectView(.contentBackground)
132134
}
133135
}
134-
.colorScheme(
135-
selectedTheme.appearance == .dark
136-
? .dark
137-
: .light
138-
)
136+
.colorScheme(currentTheme.appearance == .dark ? .dark : .light)
139137
// minHeight zero fixes a bug where the app would freeze if the contents of the file are empty.
140138
.frame(minHeight: .zero, maxHeight: .infinity)
141-
.onChange(of: themeModel.selectedTheme) { newValue in
142-
guard let theme = newValue else { return }
143-
self.selectedTheme = theme
144-
}
145139
.onChange(of: settingsFont) { newFontSetting in
146140
font = newFontSetting.current
147141
}
@@ -162,10 +156,12 @@ struct CodeFileView: View {
162156
}
163157

164158
private func getBracketPairHighlight() -> BracketPairHighlight? {
165-
let theme = ThemeModel.shared.selectedTheme ?? ThemeModel.shared.themes.first!
166-
let color = Settings[\.textEditing].bracketHighlight.useCustomColor
167-
? Settings[\.textEditing].bracketHighlight.color.nsColor
168-
: theme.editor.text.nsColor.withAlphaComponent(0.8)
159+
let color = if Settings[\.textEditing].bracketHighlight.useCustomColor {
160+
Settings[\.textEditing].bracketHighlight.color.nsColor
161+
} else {
162+
currentTheme.editor.text.nsColor.withAlphaComponent(0.8)
163+
}
164+
169165
switch Settings[\.textEditing].bracketHighlight.highlightType {
170166
case .disabled:
171167
return nil

CodeEdit/Features/Settings/Pages/ThemeSettings/Models/Theme.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ struct Theme: Identifiable, Codable, Equatable, Hashable, Loopable {
3939
/// An URL for reference
4040
var distributionURL: String
4141

42+
/// If the theme is bundled with CodeEdit or not
43+
var isBundled: Bool = false
44+
45+
/// The URL for the theme file
46+
var fileURL: URL?
47+
4248
/// The `unique name` of the theme
4349
var name: String
4450

@@ -66,6 +72,7 @@ struct Theme: Identifiable, Codable, Equatable, Hashable, Loopable {
6672
license: String,
6773
metadataDescription: String,
6874
distributionURL: String,
75+
isBundled: Bool,
6976
name: String,
7077
displayName: String,
7178
appearance: ThemeType,
@@ -75,6 +82,7 @@ struct Theme: Identifiable, Codable, Equatable, Hashable, Loopable {
7582
self.license = license
7683
self.metadataDescription = metadataDescription
7784
self.distributionURL = distributionURL
85+
self.isBundled = isBundled
7886
self.name = name
7987
self.displayName = displayName
8088
self.appearance = appearance

0 commit comments

Comments
 (0)