Skip to content

Commit 8fae08c

Browse files
Debug area tabs (#1261)
1 parent 851dc79 commit 8fae08c

38 files changed

+1087
-544
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 78 additions & 46 deletions
Large diffs are not rendered by default.

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeEdit/Features/NavigatorSidebar/NavigatorSidebarTabBar.swift renamed to CodeEdit/Features/CodeEditUI/Views/AreaTabBar.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
//
2-
// SideBarTabBar.swift
2+
// AreaTabBar.swift
33
// CodeEdit
44
//
5-
// Created by Lukas Pistrol on 17.03.22.
5+
// Created by Austin Condiff on 5/25/23.
66
//
77

88
import SwiftUI
9-
import CodeEditSymbols
109

11-
struct NavigatorSidebarTabBar: View {
10+
protocol AreaTab: View, Identifiable, Hashable {
11+
var title: String { get }
12+
var systemImage: String { get }
13+
}
14+
15+
struct AreaTabBar<Tab: AreaTab>: View {
1216
@Environment(\.controlActiveState) private var activeState
1317

14-
var items: [NavigatorTab]
18+
var items: [Tab]
1519

16-
@Binding var selection: NavigatorTab.ID
20+
@Binding var selection: Tab?
1721

1822
var position: SettingsData.SidebarTabBarPosition
1923

@@ -33,11 +37,9 @@ struct NavigatorSidebarTabBar: View {
3337
GeometryReader { proxy in
3438
iconsView(size: proxy.size)
3539
.frame(maxWidth: .infinity, maxHeight: .infinity)
36-
.overlay(alignment: .top) { Divider() }
37-
.overlay(alignment: .bottom) { Divider() }
3840
.animation(.default, value: items)
3941
}
40-
.frame(maxWidth: .infinity, idealHeight: 29)
42+
.frame(maxWidth: .infinity, idealHeight: 27)
4143
.fixedSize(horizontal: false, vertical: true)
4244
}
4345

@@ -46,9 +48,6 @@ struct NavigatorSidebarTabBar: View {
4648
iconsView(size: proxy.size)
4749
.padding(.vertical, 5)
4850
.frame(maxWidth: .infinity, maxHeight: .infinity)
49-
.overlay(alignment: .trailing) {
50-
HStack { Divider() }
51-
}
5251
.animation(.default, value: items)
5352
}
5453
.frame(idealWidth: 40, maxHeight: .infinity)
@@ -84,16 +83,16 @@ struct NavigatorSidebarTabBar: View {
8483
}
8584

8685
private func makeIcon(
87-
tab: NavigatorTab,
86+
tab: Tab,
8887
scale: Image.Scale = .medium,
8988
size: CGSize
9089
) -> some View {
9190
Button {
92-
selection = tab.id
91+
selection = tab
9392
} label: {
9493
getSafeImage(named: tab.systemImage, accessibilityDescription: tab.title)
9594
.font(.system(size: 12.5))
96-
.symbolVariant(tab.id == selection ? .fill : .none)
95+
.symbolVariant(tab == selection ? .fill : .none)
9796
.frame(
9897
width: position == .side ? 40 : 24,
9998
height: position == .side ? 28 : size.height,
@@ -110,7 +109,7 @@ struct NavigatorSidebarTabBar: View {
110109
// .frame(width: .zero)
111110
// }
112111
}
113-
.buttonStyle(.icon(isActive: tab.id == selection, size: nil))
112+
.buttonStyle(.icon(isActive: tab == selection, size: nil))
114113
}
115114

116115
private func getSafeImage(named: String, accessibilityDescription: String?) -> Image {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// DebugAreaTab.swift
3+
// CodeEdit
4+
//
5+
// Created by Wouter Hennen on 02/06/2023.
6+
//
7+
8+
import SwiftUI
9+
10+
enum DebugAreaTab: AreaTab, CaseIterable {
11+
var id: Self { self }
12+
13+
case terminal
14+
case debugConsole
15+
case output
16+
17+
var title: String {
18+
switch self {
19+
case .terminal:
20+
return "Terminal"
21+
case .debugConsole:
22+
return "Debug Console"
23+
case .output:
24+
return "Output"
25+
}
26+
}
27+
28+
var systemImage: String {
29+
switch self {
30+
case .terminal:
31+
return "terminal"
32+
case .debugConsole:
33+
return "ladybug"
34+
case .output:
35+
return "list.bullet.indent"
36+
}
37+
}
38+
39+
var body: some View {
40+
switch self {
41+
case .terminal:
42+
DebugAreaTerminalView()
43+
case .debugConsole:
44+
DebugAreaDebugView()
45+
case .output:
46+
DebugAreaOutputView()
47+
}
48+
}
49+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// DebugAreaView.swift
3+
// CodeEditModules/StatusBar
4+
//
5+
// Created by Lukas Pistrol on 22.03.22.
6+
//
7+
8+
import SwiftUI
9+
10+
struct DebugAreaView: View {
11+
@Environment(\.colorScheme)
12+
private var colorScheme
13+
14+
@EnvironmentObject
15+
private var model: DebugAreaViewModel
16+
17+
@State var selection: DebugAreaTab? = .terminal
18+
19+
var body: some View {
20+
VStack(spacing: 0) {
21+
if let selection {
22+
selection
23+
} else {
24+
Text("Tab not found")
25+
.frame(maxWidth: .infinity, maxHeight: .infinity)
26+
}
27+
}
28+
.safeAreaInset(edge: .leading, spacing: 0) {
29+
HStack(spacing: 0) {
30+
AreaTabBar(items: DebugAreaTab.allCases, selection: $selection, position: .side)
31+
Divider()
32+
.overlay(Color(nsColor: colorScheme == .dark ? .black : .clear))
33+
}
34+
}
35+
.overlay(alignment: .bottomTrailing) {
36+
HStack(spacing: 5) {
37+
Divider()
38+
HStack(spacing: 0) {
39+
Button {
40+
model.isMaximized.toggle()
41+
} label: {
42+
Image(systemName: "arrowtriangle.up.square")
43+
}
44+
.buttonStyle(.icon(isActive: model.isMaximized, size: 24))
45+
}
46+
}
47+
.padding(.horizontal, 5)
48+
.padding(.vertical, 8)
49+
.frame(maxHeight: 27)
50+
}
51+
}
52+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// PaneToolbar.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 5/31/23.
6+
//
7+
8+
import SwiftUI
9+
10+
struct PaneToolbar<Content: View>: View {
11+
@ViewBuilder var content: Content
12+
@EnvironmentObject var model: DebugAreaTabViewModel
13+
@Environment(\.paneArea) var paneArea: PaneArea?
14+
15+
var body: some View {
16+
HStack(spacing: 5) {
17+
if model.hasLeadingSidebar
18+
&& (
19+
((paneArea == .main || paneArea == .mainLeading)
20+
&& model.leadingSidebarIsCollapsed)
21+
|| paneArea == .leading
22+
) {
23+
PaneToolbarSection {
24+
Spacer()
25+
.frame(width: 24)
26+
}
27+
.opacity(0)
28+
Divider().opacity(0)
29+
}
30+
content
31+
if model.hasTrailingSidebar
32+
&& (
33+
((paneArea == .main || paneArea == .mainTrailing)
34+
&& model.trailingSidebarIsCollapsed)
35+
|| paneArea == .trailing
36+
) || !model.hasTrailingSidebar {
37+
Divider().opacity(0)
38+
PaneToolbarSection {
39+
if model.hasTrailingSidebar {
40+
Spacer()
41+
.frame(width: 24)
42+
}
43+
Spacer()
44+
.frame(width: 24)
45+
}
46+
.opacity(0)
47+
}
48+
}
49+
.buttonStyle(.icon(size: 24))
50+
.padding(.horizontal, 5)
51+
.padding(.vertical, 8)
52+
.frame(maxHeight: 27)
53+
}
54+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// View+paneToolbar.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 5/31/23.
6+
//
7+
8+
import SwiftUI
9+
10+
extension View {
11+
func paneToolbar<Content: View>(@ViewBuilder content: () -> Content) -> some View {
12+
self
13+
.clipped()
14+
.safeAreaInset(edge: .bottom, spacing: 0) {
15+
PaneToolbar {
16+
content()
17+
}
18+
}
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// DebugAreaTabViewModel.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 5/31/23.
6+
//
7+
8+
import SwiftUI
9+
10+
class DebugAreaTabViewModel: ObservableObject {
11+
@Published
12+
var leadingSidebarIsCollapsed: Bool = false
13+
14+
@Published
15+
var trailingSidebarIsCollapsed: Bool = false
16+
17+
@Published
18+
var hasLeadingSidebar: Bool = false
19+
20+
@Published
21+
var hasTrailingSidebar: Bool = false
22+
23+
public static let shared: DebugAreaTabViewModel = .init()
24+
}

CodeEdit/Features/StatusBar/ViewModels/StatusBarViewModel.swift renamed to CodeEdit/Features/DebugArea/ViewModels/DebugAreaViewModel.swift

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,29 @@
11
//
2-
// StatusBarModel.swift
3-
// CodeEditModules/StatusBar
2+
// DebugAreaViewModel.swift
3+
// CodeEdit
44
//
55
// Created by Lukas Pistrol on 20.03.22.
66
//
77

88
import SwiftUI
99

10-
/// # StatusBarModel
10+
/// # DebugAreaViewModel
1111
///
1212
/// A model class to host and manage data for the ``StatusBarView``
1313
///
14-
class StatusBarViewModel: ObservableObject {
15-
16-
enum Tab: Hashable {
17-
case terminal
18-
case debugger
19-
case output(ExtensionInfo)
20-
21-
static func allCases(extensions: [ExtensionInfo]) -> [Tab] {
22-
[.terminal, .debugger] + extensions.map { .output($0) }
23-
}
24-
}
25-
26-
private let isStatusBarDrawerCollapsedStateName: String
27-
= "\(String(describing: StatusBarViewModel.self))-IsStatusBarDrawerCollapsed"
14+
class DebugAreaViewModel: ObservableObject {
15+
private let isDebugAreaViewCollapsedStateName: String
16+
= "\(String(describing: DebugAreaViewModel.self))-IsDebugAreaViewCollapsed"
2817
private let statusBarDrawerHeightStateName: String
29-
= "\(String(describing: StatusBarViewModel.self))-StatusBarDrawerHeight"
30-
31-
@Published
32-
var selectedTab: Tab = .terminal
18+
= "\(String(describing: DebugAreaViewModel.self))-DebugAreaViewHeight"
3319

3420
/// Returns the current location of the cursor in an editing view
3521
@Published
3622
var cursorLocation: CursorLocation = .init(line: 1, column: 1) // Implementation needed!!
3723

38-
/// Returns true when the drawer is visible
24+
/// Indicates whether debugger is collapse or not
3925
@Published
40-
var isExpanded: Bool = false
26+
var isCollapsed: Bool = false
4127

4228
/// Returns true when the drawer is visible
4329
@Published
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// DebugAreaDebugView.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 5/25/23.
6+
//
7+
8+
import SwiftUI
9+
10+
struct DebugAreaDebugView: View {
11+
@State var tabSelection = 0
12+
13+
var body: some View {
14+
DebugAreaTabView { _ in
15+
Text("Nothing to debug")
16+
.font(.system(size: 16))
17+
.foregroundColor(.secondary)
18+
.frame(maxWidth: .infinity, maxHeight: .infinity)
19+
.paneToolbar {
20+
EmptyView()
21+
}
22+
} leadingSidebar: { _ in
23+
List(selection: $tabSelection) {
24+
EmptyView()
25+
}
26+
.listStyle(.automatic)
27+
.accentColor(.secondary)
28+
.paneToolbar {
29+
// Button {
30+
// // add
31+
// } label: {
32+
// Image(systemName: "plus")
33+
// }
34+
// Button {
35+
// // remove
36+
// } label: {
37+
// Image(systemName: "minus")
38+
// }
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)