Skip to content

Commit

Permalink
Hiding History Inspector when source control is disabled in Settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
austincondiff committed Oct 29, 2024
1 parent 89ccc14 commit 78b8184
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
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.enableSourceControl)
private var enableSourceControl: 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: enableSourceControl) { _ in
updateTabItems()
}
}

private func updateTabItems() {
viewModel.tabItems = [.file] +
(enableSourceControl ? [.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 @@ -73,7 +73,7 @@ struct NavigatorAreaView: View {
return nil
}
}
if let selectedTab = viewModel.selectedTab,
if let selectedTab = viewModel.selectedTab,
!viewModel.tabItems.isEmpty &&
!viewModel.tabItems.contains(selectedTab) {
viewModel.selectedTab = viewModel.tabItems[0]
Expand Down

0 comments on commit 78b8184

Please sign in to comment.