Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Control Settings #1926

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
89ccc14
Hiding source control navigator when source control is disabled in Se…
austincondiff Oct 29, 2024
78b8184
Hiding History Inspector when source control is disabled in Settings.
austincondiff Oct 29, 2024
e58ab76
Hiding Source Control menu when source control is disabled in Settings.
austincondiff Oct 29, 2024
7adc787
If enableSourceControl or refreshStatusLocally setting is false then …
austincondiff Oct 29, 2024
5eb0f7f
Hiding branch picker in the toolbar when source control is disabled i…
austincondiff Oct 29, 2024
b7c9797
Enabled fetch and refresh server status automatically setting. When d…
austincondiff Oct 31, 2024
409c4ce
Author name, author email, and prefer rebase when pulling settings us…
austincondiff Nov 1, 2024
7ddb5e8
Default branch setting uses the users global git config instead of Co…
austincondiff Nov 1, 2024
ae6ba40
Show merge commits per file log setting now shows merge commits if en…
austincondiff Nov 1, 2024
241ebbd
Fixed swiftlint error
austincondiff Nov 1, 2024
996be19
Added Ignored Files list in source control settings. Refactored searc…
austincondiff Nov 2, 2024
52b03ef
Fixed a small race condition
austincondiff Nov 2, 2024
528fe57
Merge branch 'main' into source-control-settings
austincondiff Nov 2, 2024
90934f2
Added type to hasAppeared variable in SourceControlGitView.
austincondiff Nov 2, 2024
9635fe5
Renamed `enableSourceControl` to `sourceControlIsEnabled`. Added docu…
austincondiff Nov 16, 2024
71ee6c6
Ignored files can be changed while preserving comments and white spac…
austincondiff Nov 25, 2024
dbf88a9
Merge branch 'main' into source-control-settings
austincondiff Nov 25, 2024
23148b3
Fixed SwiftLint errors
austincondiff Nov 25, 2024
eab7301
Ignore pattern reorder fixes
austincondiff Nov 26, 2024
b31e07d
Writing relative url to gitconfig upon adding first pattern
austincondiff Nov 26, 2024
284df2e
Cleaned up unecessary function
austincondiff Nov 26, 2024
dbf0929
Trying to fix test
austincondiff Nov 26, 2024
0565305
Dynamically resolve gitignore file path.
austincondiff Nov 30, 2024
93b0be5
Fixing test
austincondiff Nov 30, 2024
464bdea
Added source control settings header. Moved feature icon into new vie…
austincondiff Dec 2, 2024
24658a2
Moved tabs below source control toggle
austincondiff Dec 3, 2024
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
48 changes: 40 additions & 8 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension CEWorkspaceFileManager {
// Can be ignored for now, these I think not related to tree changes
continue
case .rootChanged:
// TODO: Handle workspace root changing.
// TODO: #1880 - Handle workspace root changing.
continue
case .itemCreated, .itemCloned, .itemRemoved, .itemRenamed:
for fileItem in fileItems {
Expand All @@ -48,7 +48,10 @@ extension CEWorkspaceFileManager {
self.notifyObservers(updatedItems: files)
}

self.handleGitEvents(events: events)
if Settings.shared.preferences.sourceControl.general.sourceControlIsEnabled &&
Settings.shared.preferences.sourceControl.general.refreshStatusLocally {
self.handleGitEvents(events: events)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ struct ToolbarBranchPicker: View {
isHovering = active
}
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { (_) in
Task {
await sourceControlManager?.refreshCurrentBranch()
if self.currentBranch != nil {
Task {
await sourceControlManager?.refreshCurrentBranch()
}
}
}
.onReceive(
Expand All @@ -82,8 +84,10 @@ struct ToolbarBranchPicker: View {
self.currentBranch = branch
}
.task {
await self.sourceControlManager?.refreshCurrentBranch()
await self.sourceControlManager?.refreshBranches()
if Settings.shared.preferences.sourceControl.general.sourceControlIsEnabled {
await self.sourceControlManager?.refreshCurrentBranch()
await self.sourceControlManager?.refreshBranches()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ final class HistoryInspectorModel: ObservableObject {
do {
let commitHistory = try await sourceControlManager
.gitClient
.getCommitHistory(maxCount: 40, fileLocalPath: fileURL)
.getCommitHistory(
maxCount: 40,
fileLocalPath: fileURL,
showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
)
await setCommitHistory(commitHistory)
} catch {
await setCommitHistory([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import SwiftUI

struct HistoryInspectorView: View {
@AppSettings(\.sourceControl.git.showMergeCommitsPerFileLog)
var showMergeCommitsPerFileLog

@EnvironmentObject private var workspace: WorkspaceDocument

@EnvironmentObject private var editorManager: EditorManager
Expand Down Expand Up @@ -60,5 +63,10 @@ struct HistoryInspectorView: View {
await model.setWorkspace(sourceControlManager: workspace.sourceControlManager)
await model.setFile(url: editorManager.activeEditor.selectedTab?.file.url.path)
}
.onChange(of: showMergeCommitsPerFileLog) { _ in
Task {
await model.updateCommitHistory()
}
}
}
}
47 changes: 27 additions & 20 deletions CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// InspectorAreaView.swift
// CodeEdit
//
// Created by Austin Condiff on 3/21/22.
//

import SwiftUI

struct InspectorAreaView: View {
Expand All @@ -15,26 +8,17 @@ struct InspectorAreaView: View {

@EnvironmentObject private var editorManager: EditorManager

@AppSettings(\.sourceControl.general.sourceControlIsEnabled)
private var sourceControlIsEnabled: Bool

@AppSettings(\.general.inspectorTabBarPosition)
var sidebarPosition: SettingsData.SidebarTabBarPosition

@State private var selection: InspectorTab? = .file

init(viewModel: InspectorAreaViewModel) {
self.viewModel = viewModel

viewModel.tabItems = [.file, .gitHistory]
viewModel.tabItems += extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .inspector {
return InspectorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
.joined()
updateTabItems()
}

func getExtension(_ id: String) -> ExtensionInfo? {
Expand Down Expand Up @@ -73,5 +57,28 @@ struct InspectorAreaView: View {
.formStyle(.grouped)
.accessibilityElement(children: .contain)
.accessibilityLabel("inspector")
.onChange(of: sourceControlIsEnabled) { _ in
updateTabItems()
}
}

private func updateTabItems() {
viewModel.tabItems = [.file] +
(sourceControlIsEnabled ? [.gitHistory] : []) +
extensionManager
.extensions
.flatMap { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .inspector {
return InspectorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
if let selectedTab = selection,
!viewModel.tabItems.isEmpty &&
!viewModel.tabItems.contains(selectedTab) {
selection = viewModel.tabItems[0]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct SourceControlNavigatorHistoryView: View {
case error(error: Error)
}

@AppSettings(\.sourceControl.git.showMergeCommitsPerFileLog)
var showMergeCommitsPerFileLog

@EnvironmentObject var sourceControlManager: SourceControlManager

@State var commitHistoryStatus: Status = .loading
Expand All @@ -28,7 +31,10 @@ struct SourceControlNavigatorHistoryView: View {
commitHistoryStatus = .loading
let commits = try await sourceControlManager
.gitClient
.getCommitHistory(branchName: sourceControlManager.currentBranch?.name)
.getCommitHistory(
branchName: sourceControlManager.currentBranch?.name,
showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
)
await MainActor.run {
commitHistory = commits
commitHistoryStatus = .ready
Expand Down Expand Up @@ -102,5 +108,10 @@ struct SourceControlNavigatorHistoryView: View {
.task {
await updateCommitHistory()
}
.onChange(of: showMergeCommitsPerFileLog) { _ in
Task {
await updateCommitHistory()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import SwiftUI
struct SourceControlNavigatorView: View {
@EnvironmentObject private var workspace: WorkspaceDocument

@AppSettings(\.sourceControl.general.fetchRefreshServerStatus)
var fetchRefreshServerStatus

var body: some View {
if let sourceControlManager = workspace.workspaceFileManager?.sourceControlManager {
VStack(spacing: 0) {
Expand All @@ -18,7 +21,9 @@ struct SourceControlNavigatorView: View {
.task {
do {
while true {
try await sourceControlManager.fetch()
if fetchRefreshServerStatus {
try await sourceControlManager.fetch()
}
try await Task.sleep(for: .seconds(10))
}
} catch {
Expand Down
41 changes: 28 additions & 13 deletions CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ struct NavigatorAreaView: View {
@AppSettings(\.general.navigatorTabBarPosition)
var sidebarPosition: SettingsData.SidebarTabBarPosition

@AppSettings(\.sourceControl.general.sourceControlIsEnabled)
private var sourceControlIsEnabled: Bool

init(workspace: WorkspaceDocument, viewModel: NavigatorSidebarViewModel) {
self.workspace = workspace
self.viewModel = viewModel

viewModel.tabItems = [.project, .sourceControl, .search] +
extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .navigator {
return NavigatorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
.joined()
updateTabItems()
}

var body: some View {
Expand Down Expand Up @@ -63,5 +54,29 @@ struct NavigatorAreaView: View {
.environmentObject(workspace)
.accessibilityElement(children: .contain)
.accessibilityLabel("navigator")
.onChange(of: sourceControlIsEnabled) { _ in
updateTabItems()
}
}

private func updateTabItems() {
viewModel.tabItems = [.project] +
(sourceControlIsEnabled ? [.sourceControl] : []) +
[.search] +
extensionManager
.extensions
.flatMap { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .navigator {
return NavigatorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
if let selectedTab = viewModel.selectedTab,
!viewModel.tabItems.isEmpty &&
!viewModel.tabItems.contains(selectedTab) {
viewModel.selectedTab = viewModel.tabItems[0]
}
}
}
16 changes: 16 additions & 0 deletions CodeEdit/Features/Settings/Models/GlobPattern.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GlobPattern.swift
// CodeEdit
//
// Created by Austin Condiff on 11/2/24.
//

import Foundation

struct GlobPattern: Identifiable, Hashable, Decodable, Encodable {
/// Ephimeral UUID used to track its representation in the UI
var id = UUID()

/// The Glob Pattern to render
var value: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

import SwiftUI

struct GlobPattern: Identifiable, Hashable, Decodable, Encodable {
/// Ephimeral UUID used to track its representation in the UI
var id = UUID()

/// The Glob Pattern to render
var value: String
}

/// The Search Settings View Model. Accessible via the singleton "``SearchSettings/shared``".
///
/// **Usage:**
Expand Down Expand Up @@ -55,6 +47,9 @@ final class SearchSettingsModel: ObservableObject {
baseURL.appendingPathComponent("settings.json", isDirectory: true)
}

/// Selected patterns
@Published var selection: Set<UUID> = []

/// Stores the new values from the Search Settings Model into the settings.json whenever
/// `ignoreGlobPatterns` is updated
@Published var ignoreGlobPatterns: [GlobPattern] {
Expand All @@ -64,4 +59,18 @@ final class SearchSettingsModel: ObservableObject {
}
}
}

func getPattern(for id: UUID) -> GlobPattern? {
return ignoreGlobPatterns.first(where: { $0.id == id })
}

func addPattern() {
ignoreGlobPatterns.append(GlobPattern(value: ""))
}

func removePatterns(_ selection: Set<UUID>? = nil) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are using a set here, we can take advantage of its constant look up times:

if let selection, !selection.isEmpty {
    let patternsToRemove = Set(selection.compactMap { getPattern(for: $0) })
    ignoreGlobPatterns.subtract(patternsToRemove)
}
self.selection.removeAll()

let patternsToRemove = selection?.compactMap { getPattern(for: $0) } ?? []
ignoreGlobPatterns.removeAll { patternsToRemove.contains($0) }
self.selection.removeAll()
}
}
Loading