forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkspaceView.swift
More file actions
174 lines (161 loc) · 7.84 KB
/
WorkspaceView.swift
File metadata and controls
174 lines (161 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
// WorkspaceView.swift
// CodeEdit
//
// Created by Austin Condiff on 3/10/22.
//
import SwiftUI
struct WorkspaceView: View {
@Environment(\.window.value)
private var window: NSWindow?
@Environment(\.colorScheme)
private var colorScheme
@FocusState var focusedEditor: Editor?
@AppSettings(\.theme.matchAppearance)
var matchAppearance
@AppSettings(\.sourceControl.general.sourceControlIsEnabled)
var sourceControlIsEnabled
@EnvironmentObject private var workspace: WorkspaceDocument
@EnvironmentObject private var editorManager: EditorManager
@EnvironmentObject private var utilityAreaViewModel: UtilityAreaViewModel
@StateObject private var themeModel: ThemeModel = .shared
@State private var showingAlert = false
@State private var terminalCollapsed = true
@State private var editorCollapsed = false
@State private var editorsHeight: CGFloat = 0
@State private var drawerHeight: CGFloat = 0
private let statusbarHeight: CGFloat = 29
private var keybindings: KeybindingManager = .shared
var body: some View {
if workspace.workspaceFileManager != nil, let sourceControlManager = workspace.sourceControlManager {
VStack {
SplitViewReader { proxy in
SplitView(axis: .vertical) {
ZStack {
GeometryReader { geo in
EditorLayoutView(
layout: editorManager.isFocusingActiveEditor
? editorManager.activeEditor.getEditorLayout() ?? editorManager.editorLayout
: editorManager.editorLayout,
focus: $focusedEditor
)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onChange(of: geo.size.height) { newHeight in
editorsHeight = newHeight
}
.onAppear {
editorsHeight = geo.size.height
}
}
}
.frame(minHeight: 170 + 29 + 29)
.collapsable()
.collapsed($utilityAreaViewModel.isMaximized)
.holdingPriority(.init(1))
Rectangle()
.collapsable()
.collapsed($utilityAreaViewModel.isCollapsed)
.opacity(0)
.frame(idealHeight: 260)
.frame(minHeight: 100)
.background {
GeometryReader { geo in
Rectangle()
.opacity(0)
.onChange(of: geo.size.height) { newHeight in
drawerHeight = newHeight
}
.onAppear {
drawerHeight = geo.size.height
}
}
}
.accessibilityHidden(true)
}
// .ignoresSafeArea(edges: .top)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(alignment: .top) {
ZStack(alignment: .top) {
UtilityAreaView()
.frame(height: utilityAreaViewModel.isMaximized ? nil : drawerHeight)
.frame(maxHeight: utilityAreaViewModel.isMaximized ? .infinity : nil)
.padding(.top, utilityAreaViewModel.isMaximized ? statusbarHeight + 1 : 0)
.offset(y: utilityAreaViewModel.isMaximized ? 0 : editorsHeight + 1)
VStack(spacing: 0) {
StatusBarView(proxy: proxy)
if utilityAreaViewModel.isMaximized {
PanelDivider()
}
}
.offset(y: utilityAreaViewModel.isMaximized ? 0 : editorsHeight - statusbarHeight)
}
.accessibilityElement(children: .contain)
}
.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 {
editorManager.activeEditor = newValue
}
}
.onChange(of: editorManager.activeEditor) { newValue in
if newValue != focusedEditor {
focusedEditor = newValue
}
}
.task {
themeModel.colorScheme = colorScheme
do {
try await sourceControlManager.refreshRemotes()
try await sourceControlManager.refreshStashEntries()
} catch {
await sourceControlManager.showAlertForError(
title: "Error refreshing Git data",
error: error
)
}
}
.onChange(of: colorScheme) { newValue in
themeModel.colorScheme = newValue
if matchAppearance {
themeModel.selectedTheme = newValue == .dark
? themeModel.selectedDarkTheme
: themeModel.selectedLightTheme
}
}
.onChange(of: sourceControlIsEnabled) { 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 {
editorManager.activeEditor = newValue
}
}
.onChange(of: editorManager.activeEditor) { newValue in
if newValue != focusedEditor {
focusedEditor = newValue
}
}
.onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { output in
if let window = output.object as? NSWindow, self.window == window {
workspace.addToWorkspaceState(
key: .workspaceWindowSize,
value: NSStringFromRect(window.frame)
)
}
}
}
}
.background(EffectView(.contentBackground))
.background(WorkspaceSheets().environmentObject(sourceControlManager))
.accessibilityElement(children: .contain)
.accessibilityLabel("workspace area")
}
}
}