From 2dab6c25daab91eb3289e8e5882aa068b041e6a4 Mon Sep 17 00:00:00 2001 From: Austin Condiff Date: Tue, 3 Sep 2024 10:53:34 -0500 Subject: [PATCH] Cleaned up theme search UI. --- CodeEdit.xcodeproj/project.pbxproj | 8 +-- .../CodeEditUI/Views/SearchField.swift | 51 +++++++++++++++ .../ThemeSettings/ThemeSearchField.swift | 58 ----------------- .../ThemeSettings/ThemeSettingsView.swift | 63 +++++-------------- 4 files changed, 72 insertions(+), 108 deletions(-) create mode 100644 CodeEdit/Features/CodeEditUI/Views/SearchField.swift delete mode 100644 CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSearchField.swift diff --git a/CodeEdit.xcodeproj/project.pbxproj b/CodeEdit.xcodeproj/project.pbxproj index 41407c0ef..a5314dc11 100644 --- a/CodeEdit.xcodeproj/project.pbxproj +++ b/CodeEdit.xcodeproj/project.pbxproj @@ -319,7 +319,7 @@ 617DB3DA2C25B07F00B58BFE /* TaskNotificationsDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3D92C25B07F00B58BFE /* TaskNotificationsDetailView.swift */; }; 617DB3DC2C25B14A00B58BFE /* ActivityViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3DB2C25B14A00B58BFE /* ActivityViewer.swift */; }; 617DB3DF2C25E13800B58BFE /* TaskNotificationHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 617DB3DE2C25E13800B58BFE /* TaskNotificationHandlerTests.swift */; }; - 61816B832C81DC2C00C71BF7 /* ThemeSearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */; }; + 61816B832C81DC2C00C71BF7 /* SearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61816B822C81DC2C00C71BF7 /* SearchField.swift */; }; 618725A12C29EFCC00987354 /* SchemeDropDownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A02C29EFCC00987354 /* SchemeDropDownView.swift */; }; 618725A42C29F00400987354 /* WorkspaceMenuItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A32C29F00400987354 /* WorkspaceMenuItemView.swift */; }; 618725A62C29F02500987354 /* DropdownMenuItemStyleModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618725A52C29F02500987354 /* DropdownMenuItemStyleModifier.swift */; }; @@ -979,7 +979,7 @@ 617DB3D92C25B07F00B58BFE /* TaskNotificationsDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskNotificationsDetailView.swift; sourceTree = ""; }; 617DB3DB2C25B14A00B58BFE /* ActivityViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewer.swift; sourceTree = ""; }; 617DB3DE2C25E13800B58BFE /* TaskNotificationHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskNotificationHandlerTests.swift; sourceTree = ""; }; - 61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeSearchField.swift; sourceTree = ""; }; + 61816B822C81DC2C00C71BF7 /* SearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchField.swift; sourceTree = ""; }; 618725A02C29EFCC00987354 /* SchemeDropDownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchemeDropDownView.swift; sourceTree = ""; }; 618725A32C29F00400987354 /* WorkspaceMenuItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceMenuItemView.swift; sourceTree = ""; }; 618725A52C29F02500987354 /* DropdownMenuItemStyleModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropdownMenuItemStyleModifier.swift; sourceTree = ""; }; @@ -2031,6 +2031,7 @@ B67DB0FB2AFDF71F002DC647 /* IconToggleStyle.swift */, 587B9D8D29300ABD00AC7927 /* SearchPanel.swift */, 6CABB1A029C5593800340467 /* SearchPanelView.swift */, + 61816B822C81DC2C00C71BF7 /* SearchField.swift */, 587B9D8929300ABD00AC7927 /* PanelDivider.swift */, B67DB0EE2AF3E381002DC647 /* PaneTextField.swift */, 587B9D8E29300ABD00AC7927 /* PressActionsModifier.swift */, @@ -2471,7 +2472,6 @@ children = ( B6F0518D29DA29F900D72287 /* Models */, 58F2EAAF292FB2B0004A9BDE /* ThemeSettingsView.swift */, - 61816B822C81DC2C00C71BF7 /* ThemeSearchField.swift */, B6EA1FF729DB78DB001BF195 /* ThemeSettingThemeRow.swift */, B6EA1FFA29DB78F6001BF195 /* ThemeSettingsThemeDetails.swift */, B6EA1FFC29DB792C001BF195 /* ThemeSettingsColorPreview.swift */, @@ -4255,7 +4255,7 @@ 6C97EBCC2978760400302F95 /* AcknowledgementsWindowController.swift in Sources */, 284DC84F2978B7B400BF2770 /* ContributorsView.swift in Sources */, B62AEDC92A2704F3009A9F52 /* UtilityAreaTabView.swift in Sources */, - 61816B832C81DC2C00C71BF7 /* ThemeSearchField.swift in Sources */, + 61816B832C81DC2C00C71BF7 /* SearchField.swift in Sources */, 30B088052C0D53080063A882 /* LanguageServer+DocumentLink.swift in Sources */, 58798250292E78D80085B254 /* CodeFileDocument.swift in Sources */, 5878DAA5291AE76700DD95A3 /* OpenQuicklyView.swift in Sources */, diff --git a/CodeEdit/Features/CodeEditUI/Views/SearchField.swift b/CodeEdit/Features/CodeEditUI/Views/SearchField.swift new file mode 100644 index 000000000..ed6c8e2c7 --- /dev/null +++ b/CodeEdit/Features/CodeEditUI/Views/SearchField.swift @@ -0,0 +1,51 @@ +// +// SearchField.swift +// CodeEdit +// +// Created by Austin Condiff on 9/3/24. +// + +import SwiftUI + +struct SearchField: NSViewRepresentable { + @Binding var text: String + var placeholder: String + + init(_ placeholder: String, text: Binding) { + self.placeholder = placeholder + self._text = text + } + + func makeNSView(context: Context) -> NSSearchField { + let searchField = NSSearchField() + searchField.delegate = context.coordinator + searchField.placeholderString = placeholder + return searchField + } + + func updateNSView(_ nsView: NSSearchField, context: Context) { + nsView.stringValue = text + } + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject, NSSearchFieldDelegate { + var parent: SearchField + + init(_ parent: SearchField) { + self.parent = parent + } + + func controlTextDidChange(_ obj: Notification) { + if let searchField = obj.object as? NSSearchField { + parent.text = searchField.stringValue + } + } + } +} + +#Preview { + SearchField("Search", text: .constant("Test")) +} diff --git a/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSearchField.swift b/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSearchField.swift deleted file mode 100644 index 2df783925..000000000 --- a/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSearchField.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// ThemeSearchField.swift -// CodeEdit -// -// Created by Tommy Ludwig on 30.08.24. -// - -import SwiftUI - -struct ThemeSearchField: View { - @Binding var themeSearchQuery: String - var body: some View { - VStack { - HStack(alignment: .top) { - Image(systemName: "magnifyingglass") - .padding(.leading, 2) - .padding(.trailing, -7) - - TextField("", text: $themeSearchQuery) - .textFieldStyle(PlainTextFieldStyle()) - .multilineTextAlignment(.leading) - .overlay { - HStack { - Text("Search") - .foregroundStyle(.secondary) - .opacity(themeSearchQuery.isEmpty ? 1 : 0) - .padding(.leading, 6.5) - - Spacer() - } - } - } - .padding(3) - .overlay( - RoundedRectangle(cornerRadius: 5) - .foregroundStyle(.secondary) -// .blendMode(.overlay) - .blendMode(.difference) - .opacity(0.1) - ) - .overlay { - RoundedRectangle(cornerRadius: 5) - .stroke(Color.gray, lineWidth: 1) - .foregroundStyle(.secondary) - .opacity(0.2) - } -// TextField(text: $themeSearchQuery, prompt: Text("Search")) { -// Label("Test", systemImage: "magnifyingglass") -// } -// .textFieldStyle(.roundedBorder) -// .padding() - } - } -} - -#Preview { - ThemeSearchField(themeSearchQuery: .constant("Test")) -} diff --git a/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift b/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift index c6ccfb0d8..a533c12ae 100644 --- a/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift +++ b/CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift @@ -23,28 +23,24 @@ struct ThemeSettingsView: View { var body: some View { VStack { - Form { - Form { - Section { - HStack { - ThemeSearchField(themeSearchQuery: $themeSearchQuery) + SettingsForm { + Section { + HStack { + SearchField("Search", text: $themeSearchQuery) - Button { + Button { - } label: { - Image(systemName: "plus") - } + } label: { + Image(systemName: "plus") + } - Button { + Button { - } label: { - Image(systemName: "ellipsis") - } + } label: { + Image(systemName: "ellipsis") } } } - .formStyle(.columns) - if themeSearchQuery.isEmpty { Section { changeThemeOnSystemAppearance @@ -57,36 +53,12 @@ struct ThemeSettingsView: View { Section { VStack(spacing: 0) { - // HStack { - // TextField("Search Themes", text: $themeSearchQuery) - // .textFieldStyle(.roundedBorder) - // - // Button { - // withAnimation { - // themeModel.selectedAppearance = themeModel.selectedAppearance == .dark ? .light : .dark - // } - // } label: { - //// Image(systemName: "arrow.up.arrow.down") - //// .rotationEffect(.degrees(themeModel.selectedAppearance == .dark ? 0 : 180)) - //// .animation(.easeInOut, value: themeModel.selectedAppearance) - // Image( - // systemName: themeModel.selectedAppearance == .dark ? - // "moon.circle.fill" : "sun.max.circle" - // ).font(.title2) - // } - // .buttonStyle(.icon) - // } - // .padding(10) - // .padding(.leading, 10) - - VStack(spacing: 0) { - ForEach(filteredThemes) { theme in - Divider().padding(.horizontal, 10) - ThemeSettingsThemeRow( - theme: $themeModel.themes[themeModel.themes.firstIndex(of: theme)!], - active: themeModel.getThemeActive(theme) - ).id(theme) - } + ForEach(filteredThemes) { theme in + Divider().padding(.horizontal, 10) + ThemeSettingsThemeRow( + theme: $themeModel.themes[themeModel.themes.firstIndex(of: theme)!], + active: themeModel.getThemeActive(theme) + ).id(theme) } } .padding(-10) @@ -128,7 +100,6 @@ struct ThemeSettingsView: View { } } - .formStyle(.grouped) } }