From 5eb0f7f5bf541b851c25d5a4d72989945cb97a6b Mon Sep 17 00:00:00 2001 From: Austin Condiff Date: Tue, 29 Oct 2024 13:47:08 -0500 Subject: [PATCH] Hiding branch picker in the toolbar when source control is disabled in Settings by clearing the current branch stored in the source control manager. --- .../CodeEditUI/Views/ToolbarBranchPicker.swift | 12 ++++++++---- CodeEdit/WorkspaceView.swift | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift b/CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift index db50b1b63..193e4d98b 100644 --- a/CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift +++ b/CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift @@ -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( @@ -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.enableSourceControl { + await self.sourceControlManager?.refreshCurrentBranch() + await self.sourceControlManager?.refreshBranches() + } } } diff --git a/CodeEdit/WorkspaceView.swift b/CodeEdit/WorkspaceView.swift index 8e3c9f224..c2a15162c 100644 --- a/CodeEdit/WorkspaceView.swift +++ b/CodeEdit/WorkspaceView.swift @@ -19,6 +19,9 @@ struct WorkspaceView: View { @AppSettings(\.theme.matchAppearance) var matchAppearance + @AppSettings(\.sourceControl.general.enableSourceControl) + var enableSourceControl + @EnvironmentObject private var workspace: WorkspaceDocument @EnvironmentObject private var editorManager: EditorManager @EnvironmentObject private var utilityAreaViewModel: UtilityAreaViewModel @@ -130,6 +133,15 @@ struct WorkspaceView: View { : themeModel.selectedLightTheme } } + .onChange(of: enableSourceControl) { newValue in + if !newValue { + Task { + await sourceControlManager.refreshCurrentBranch() + } + } else { + sourceControlManager.currentBranch = nil + } + } .onChange(of: focusedEditor) { newValue in /// Update active tab group only if the new one is not the same with it. if let newValue, editorManager.activeEditor != newValue {