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

Fix issue #1488 | Utility area sidebar state specific to individual w… #1493

Merged
merged 3 commits into from
Nov 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import SwiftUI

struct UtilityAreaDebugView: View {
@EnvironmentObject private var model: UtilityAreaViewModel

@State var tabSelection = 0

var body: some View {
UtilityAreaTabView { _ in
UtilityAreaTabView(model: model.tabViewModel) { _ in
Text("Nothing to debug")
.font(.system(size: 16))
.foregroundColor(.secondary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct UtilityAreaOutputView: View {
}

var body: some View {
UtilityAreaTabView { _ in
UtilityAreaTabView(model: model.tabViewModel) { _ in
Group {
if selectedOutputSource == nil {
Text("No output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct UtilityAreaTerminalView: View {
}

var body: some View {
UtilityAreaTabView { tabState in
UtilityAreaTabView(model: model.tabViewModel) { tabState in
ZStack {
if model.selectedTerminals.isEmpty {
Text("No Selection")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ class UtilityAreaTabViewModel: ObservableObject {
@Published var hasLeadingSidebar: Bool = false

@Published var hasTrailingSidebar: Bool = false

public static let shared: UtilityAreaTabViewModel = .init()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class UtilityAreaViewModel: ObservableObject {
/// The tab bar items for the DebugAreaView
@Published var tabItems: [UtilityAreaTab] = UtilityAreaTab.allCases

/// The tab bar view model for UtilityAreaTabView
@Published var tabViewModel = UtilityAreaTabViewModel()

/// Returns the font for status bar items to use
private(set) var toolbarFont: Font = .system(size: 11, weight: .medium)

Expand Down
15 changes: 13 additions & 2 deletions CodeEdit/Features/UtilityArea/Views/UtilityAreaTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct UtilityAreaTabView<Content: View, LeadingSidebar: View, TrailingSidebar: View>: View {
@ObservedObject var model: UtilityAreaTabViewModel = UtilityAreaTabViewModel.shared
@ObservedObject var model: UtilityAreaTabViewModel

let content: (UtilityAreaTabViewModel) -> Content
let leadingSidebar: (UtilityAreaTabViewModel) -> LeadingSidebar?
Expand All @@ -18,12 +18,15 @@ struct UtilityAreaTabView<Content: View, LeadingSidebar: View, TrailingSidebar:
let hasTrailingSidebar: Bool

init(
model: UtilityAreaTabViewModel,
@ViewBuilder content: @escaping (UtilityAreaTabViewModel) -> Content,
@ViewBuilder leadingSidebar: @escaping (UtilityAreaTabViewModel) -> LeadingSidebar,
@ViewBuilder trailingSidebar: @escaping (UtilityAreaTabViewModel) -> TrailingSidebar,
hasLeadingSidebar: Bool = true,
hasTrailingSidebar: Bool = true
) {
self.model = model

self.content = content
self.leadingSidebar = leadingSidebar
self.trailingSidebar = trailingSidebar
Expand All @@ -32,10 +35,14 @@ struct UtilityAreaTabView<Content: View, LeadingSidebar: View, TrailingSidebar:
self.hasTrailingSidebar = hasTrailingSidebar
}

init(@ViewBuilder content: @escaping (UtilityAreaTabViewModel) -> Content) where
init(
model: UtilityAreaTabViewModel,
@ViewBuilder content: @escaping (UtilityAreaTabViewModel) -> Content
) where
LeadingSidebar == EmptyView,
TrailingSidebar == EmptyView {
self.init(
model: model,
content: content,
leadingSidebar: { _ in EmptyView() },
trailingSidebar: { _ in EmptyView() },
Expand All @@ -45,10 +52,12 @@ struct UtilityAreaTabView<Content: View, LeadingSidebar: View, TrailingSidebar:
}

init(
model: UtilityAreaTabViewModel,
@ViewBuilder content: @escaping (UtilityAreaTabViewModel) -> Content,
@ViewBuilder leadingSidebar: @escaping (UtilityAreaTabViewModel) -> LeadingSidebar
) where TrailingSidebar == EmptyView {
self.init(
model: model,
content: content,
leadingSidebar: leadingSidebar,
trailingSidebar: { _ in EmptyView() },
Expand All @@ -57,10 +66,12 @@ struct UtilityAreaTabView<Content: View, LeadingSidebar: View, TrailingSidebar:
}

init(
model: UtilityAreaTabViewModel,
@ViewBuilder content: @escaping (UtilityAreaTabViewModel) -> Content,
@ViewBuilder trailingSidebar: @escaping (UtilityAreaTabViewModel) -> TrailingSidebar
) where LeadingSidebar == EmptyView {
self.init(
model: model,
content: content,
leadingSidebar: { _ in EmptyView() },
trailingSidebar: trailingSidebar,
Expand Down