Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
6CB9144B29BEC7F100BC47F2 /* (null) in Sources */ = {isa = PBXBuildFile; };
6CBD1BC62978DE53006639D5 /* Font+Caption3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CBD1BC52978DE53006639D5 /* Font+Caption3.swift */; };
6CC9E4B229B5669900C97388 /* Environment+ActiveTabGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CC9E4B129B5669900C97388 /* Environment+ActiveTabGroup.swift */; };
6CD03B6A29FC773F001BD1D0 /* SettingsInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD03B6929FC773F001BD1D0 /* SettingsInjector.swift */; };
6CDA84AD284C1BA000C1CC3A /* TabBarContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CDA84AC284C1BA000C1CC3A /* TabBarContextMenu.swift */; };
6CDEFC9629E22C2700B7C684 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 6CDEFC9529E22C2700B7C684 /* Introspect */; };
6CFF967429BEBCC300182D6F /* FindCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFF967329BEBCC300182D6F /* FindCommands.swift */; };
Expand Down Expand Up @@ -697,6 +698,7 @@
6CABB1A029C5593800340467 /* OverlayView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverlayView.swift; sourceTree = "<group>"; };
6CBD1BC52978DE53006639D5 /* Font+Caption3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Caption3.swift"; sourceTree = "<group>"; };
6CC9E4B129B5669900C97388 /* Environment+ActiveTabGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Environment+ActiveTabGroup.swift"; sourceTree = "<group>"; };
6CD03B6929FC773F001BD1D0 /* SettingsInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInjector.swift; sourceTree = "<group>"; };
6CDA84AC284C1BA000C1CC3A /* TabBarContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarContextMenu.swift; sourceTree = "<group>"; };
6CFF967329BEBCC300182D6F /* FindCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindCommands.swift; sourceTree = "<group>"; };
6CFF967529BEBCD900182D6F /* FileCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileCommands.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2041,6 +2043,7 @@
58F2EADB292FB2B0004A9BDE /* SettingsData.swift */,
58F2EAD2292FB2B0004A9BDE /* Settings.swift */,
6C5FDF7929E6160000BC08C0 /* AppSettings.swift */,
6CD03B6929FC773F001BD1D0 /* SettingsInjector.swift */,
6C0D0C6729E861B000AE4D3F /* SettingsSidebarFix.swift */,
850C631129D6B03400E1444C /* SettingsPage.swift */,
);
Expand Down Expand Up @@ -2814,6 +2817,7 @@
5878DAB2291D627C00DD95A3 /* PathBarView.swift in Sources */,
043C321627E3201F006AE443 /* WorkspaceDocument.swift in Sources */,
58F2EAEC292FB2B0004A9BDE /* IgnoredFiles.swift in Sources */,
6CD03B6A29FC773F001BD1D0 /* SettingsInjector.swift in Sources */,
58798236292E30B90085B254 /* FeedbackType.swift in Sources */,
587B9E6D29301D8F00AC7927 /* GitLabEventNote.swift in Sources */,
587B9E9129301D8F00AC7927 /* BitBucketOAuthRouter.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion CodeEdit/Features/CodeFile/CodeFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ final class CodeFileDocument: NSDocument, ObservableObject, QLPreviewItem {
let windowController = NSWindowController(window: window)
addWindowController(windowController)

window.contentView = NSHostingView(rootView: WindowCodeFileView(codeFile: self))
window.contentView = NSHostingView(rootView: SettingsInjector {
WindowCodeFileView(codeFile: self)
})

window.makeKeyAndOrderFront(nil)
window.center()
Expand Down
21 changes: 13 additions & 8 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ struct CodeFileView: View {
@ObservedObject
private var codeFile: CodeFileDocument

@AppSettings var settings
@AppSettings(\.textEditing.defaultTabWidth) var defaultTabWidth
@AppSettings(\.textEditing.lineHeightMultiple) var lineHeightMultiple
@AppSettings(\.textEditing.wrapLinesToEditorWidth) var wrapLinesToEditorWidth
@AppSettings(\.textEditing.font) var settingsFont
@AppSettings(\.theme.useThemeBackground) var useThemeBackground
@AppSettings(\.theme.matchAppearance) var matchAppearance

@Environment(\.colorScheme)
private var colorScheme
Expand Down Expand Up @@ -56,7 +61,7 @@ struct CodeFileView: View {

@State
private var font: NSFont = {
return Settings.shared.preferences.textEditing.font.current()
return Settings[\.textEditing].font.current()
}()

@Environment(\.edgeInsets)
Expand All @@ -71,11 +76,11 @@ struct CodeFileView: View {
language: getLanguage(),
theme: $selectedTheme.editor.editorTheme,
font: $font,
tabWidth: $settings.textEditing.defaultTabWidth,
lineHeight: $settings.textEditing.lineHeightMultiple,
wrapLines: $settings.textEditing.wrapLinesToEditorWidth,
tabWidth: $defaultTabWidth,
lineHeight: $lineHeightMultiple,
wrapLines: $wrapLinesToEditorWidth,
cursorPosition: $codeFile.cursorPosition,
useThemeBackground: settings.theme.useThemeBackground,
useThemeBackground: useThemeBackground,
contentInsets: edgeInsets.nsEdgeInsets,
isEditable: isEditable
)
Expand All @@ -99,13 +104,13 @@ struct CodeFileView: View {
self.selectedTheme = theme
}
.onChange(of: colorScheme) { newValue in
if settings.theme.matchAppearance {
if matchAppearance {
ThemeModel.shared.selectedTheme = newValue == .dark
? ThemeModel.shared.selectedDarkTheme!
: ThemeModel.shared.selectedLightTheme!
}
}
.onChange(of: settings.textEditing.font) { _ in
.onChange(of: settingsFont) { _ in
font = Settings.shared.preferences.textEditing.font.current()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let feedbackPerformer = NSHapticFeedbackManager.defaultPerformer
let splitVC = CodeEditSplitViewController(workspace: workspace, feedbackPerformer: feedbackPerformer)

let navigatorView = NavigatorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
let navigatorView = SettingsInjector {
NavigatorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
}

let navigator = NSSplitViewItem(
sidebarWithViewController: NSHostingController(rootView: navigatorView)
Expand All @@ -98,10 +100,12 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
navigator.collapseBehavior = .useConstraints
splitVC.addSplitViewItem(navigator)

let workspaceView = WindowObserver(window: window!) {
WorkspaceView()
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
let workspaceView = SettingsInjector {
WindowObserver(window: window!) {
WorkspaceView()
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
}
}

let mainContent = NSSplitViewItem(
Expand All @@ -110,9 +114,11 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
mainContent.titlebarSeparatorStyle = .line
splitVC.addSplitViewItem(mainContent)

let inspectorView = InspectorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
let inspectorView = SettingsInjector {
InspectorSidebarView(workspace: workspace)
.environmentObject(workspace)
.environmentObject(workspace.tabManager)
}

let inspector = NSSplitViewItem(
viewController: NSHostingController(rootView: inspectorView)
Expand Down Expand Up @@ -220,9 +226,9 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let toolbarItem = NSToolbarItem(itemIdentifier: .branchPicker)
let view = NSHostingView(
rootView: ToolbarBranchPicker(
shellClient: currentWorld.shellClient,
workspace: workspace?.workspaceClient
)
shellClient: currentWorld.shellClient,
workspace: workspace?.workspaceClient
)
)
toolbarItem.view = view

Expand Down Expand Up @@ -261,7 +267,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
let panel = OverlayPanel()
self.commandPalettePanel = panel
let contentView = CommandPaletteView(state: state, closePalette: panel.close)
panel.contentView = NSHostingView(rootView: contentView)
panel.contentView = NSHostingView(rootView: SettingsInjector { contentView })
window?.addChildWindow(panel, ordered: .above)
panel.makeKeyAndOrderFront(self)
}
Expand All @@ -288,7 +294,7 @@ final class CodeEditWindowController: NSWindowController, NSToolbarDelegate, Obs
workspace.tabManager.openTab(item: file)
}

panel.contentView = NSHostingView(rootView: contentView)
panel.contentView = NSHostingView(rootView: SettingsInjector { contentView })
window?.addChildWindow(panel, ordered: .above)
panel.makeKeyAndOrderFront(self)
}
Expand Down
3 changes: 0 additions & 3 deletions CodeEdit/Features/Documents/Views/WorkspaceCodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import UniformTypeIdentifiers
struct WorkspaceCodeFileView: View {
var file: WorkspaceClient.FileItem

@StateObject
private var prefs: Settings = .shared

@ViewBuilder
var codeView: some View {
if let document = file.fileDocument {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

final class FeedbackWindowController: NSWindowController, NSToolbarDelegate {
convenience init<T: View>(view: T, size: NSSize) {
let hostingController = NSHostingController(rootView: view)
let hostingController = NSHostingController(rootView: SettingsInjector { view })
let window = NSWindow(contentViewController: hostingController)
self.init(window: window)
window.title = "Feedback for CodeEdit"
Expand Down
3 changes: 0 additions & 3 deletions CodeEdit/Features/Feedback/FeedbackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ struct FeedbackView: View {
@ObservedObject
private var feedbackModel: FeedbackModel = .shared

@StateObject
var prefs: Settings = .shared

@State
var showsAlert: Bool = false

Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/Keybindings/KeybindingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class KeybindingManager {
}

/// Wrapper for KeyboardShortcut. It contains name, keybindings.
struct KeyboardShortcutWrapper: Codable {
struct KeyboardShortcutWrapper: Codable, Hashable {
var keyboardShortcut: KeyboardShortcut {
return KeyboardShortcut.init(.init(Character(keybinding)), modifiers: parsedModifier)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ struct FindNavigatorResultList: NSViewControllerRepresentable {
@EnvironmentObject
var workspace: WorkspaceDocument

@AppSettings var settings
@AppSettings(\.general.projectNavigatorSize) var projectNavigatorSize

typealias NSViewControllerType = FindNavigatorListViewController

func makeNSViewController(context: Context) -> FindNavigatorListViewController {
let controller = FindNavigatorListViewController(workspace: workspace)
controller.setSearchResults(workspace.searchState?.searchResult ?? [])
controller.rowHeight = settings.general.projectNavigatorSize.rowHeight
controller.rowHeight = projectNavigatorSize.rowHeight
context.coordinator.controller = controller
return controller
}
Expand All @@ -30,8 +30,8 @@ struct FindNavigatorResultList: NSViewControllerRepresentable {
workspace.searchState?.searchResult ?? [],
searchId: workspace.searchState?.searchId
)
if nsViewController.rowHeight != settings.general.projectNavigatorSize.rowHeight {
nsViewController.rowHeight = settings.general.projectNavigatorSize.rowHeight
if nsViewController.rowHeight != projectNavigatorSize.rowHeight {
nsViewController.rowHeight = projectNavigatorSize.rowHeight
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ protocol OutlineTableViewCellDelegate: AnyObject {
/// A `NSTableCellView` showing an ``icon`` and a ``label``
final class OutlineTableViewCell: NSTableCellView {

@AppSettings var settings

var label: NSTextField!
var icon: NSImageView!
private var fileItem: WorkspaceClient.FileItem!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ struct OutlineView: NSViewControllerRepresentable {
@EnvironmentObject
var workspace: WorkspaceDocument

@AppSettings var settings

// This is mainly just used to trigger a view update.
@Binding
var selection: WorkspaceClient.FileItem?
Expand All @@ -25,19 +23,19 @@ struct OutlineView: NSViewControllerRepresentable {
func makeNSViewController(context: Context) -> OutlineViewController {
let controller = OutlineViewController()
controller.workspace = workspace
controller.iconColor = settings.general.fileIconStyle
controller.iconColor = Settings[\.general].fileIconStyle

context.coordinator.controller = controller

return controller
}

func updateNSViewController(_ nsViewController: OutlineViewController, context: Context) {
nsViewController.iconColor = settings.general.fileIconStyle
nsViewController.rowHeight = settings.general.projectNavigatorSize.rowHeight
nsViewController.fileExtensionsVisibility = settings.general.fileExtensionsVisibility
nsViewController.shownFileExtensions = settings.general.shownFileExtensions
nsViewController.hiddenFileExtensions = settings.general.hiddenFileExtensions
nsViewController.iconColor = Settings[\.general].fileIconStyle
nsViewController.rowHeight = Settings[\.general].projectNavigatorSize.rowHeight
nsViewController.fileExtensionsVisibility = Settings[\.general].fileExtensionsVisibility
nsViewController.shownFileExtensions = Settings[\.general].shownFileExtensions
nsViewController.hiddenFileExtensions = Settings[\.general].hiddenFileExtensions
nsViewController.updateSelection()
return
}
Expand Down
3 changes: 0 additions & 3 deletions CodeEdit/Features/PathBar/Views/PathBarComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ struct PathBarComponent: View {
@Environment(\.controlActiveState)
private var activeState

@StateObject
private var prefs: Settings = .shared

@State
var position: NSPoint?

Expand Down
50 changes: 40 additions & 10 deletions CodeEdit/Features/Settings/Models/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,54 @@ import Foundation
import SwiftUI

@propertyWrapper
struct AppSettings: DynamicProperty {
@ObservedObject
private var prefs: Settings
struct AppSettings<T>: DynamicProperty where T: Equatable {

init(_ prefs: Settings = .shared) {
self.prefs = prefs
var settings: Environment<T>

let keyPath: WritableKeyPath<SettingsData, T>

@available(*,
deprecated,
message: """
Use init(_ keyPath:) instead, otherwise the view will be reevaluated on every settings change.
"""
)
init() where T == SettingsData {
self.keyPath = \.self
self.settings = .init(\.settings)
}

var wrappedValue: SettingsData {
init(_ keyPath: WritableKeyPath<SettingsData, T>) {
self.keyPath = keyPath
let newKeyPath = (\EnvironmentValues.settings).appending(path: keyPath)
self.settings = .init(newKeyPath)
}

var wrappedValue: T {
get {
prefs.preferences
settings.wrappedValue
}
nonmutating set {
prefs.preferences = newValue
Settings.shared.preferences[keyPath: keyPath] = newValue
}
}

var projectedValue: Binding<T> {
.init {
settings.wrappedValue
} set: {
Settings.shared.preferences[keyPath: keyPath] = $0
}
}
}

struct SettingsDataEnvironmentKey: EnvironmentKey {
static var defaultValue: SettingsData = .init()
}

var projectedValue: Binding<SettingsData> {
$prefs.preferences
extension EnvironmentValues {
var settings: SettingsDataEnvironmentKey.Value {
get { self[SettingsDataEnvironmentKey.self] }
set { self[SettingsDataEnvironmentKey.self] = newValue }
}
}
Loading