Skip to content

Commit 15de1d5

Browse files
committed
polish status bar as divider
1 parent 2f94292 commit 15de1d5

File tree

2 files changed

+139
-75
lines changed

2 files changed

+139
-75
lines changed

CodeEdit/Features/Editor/Views/EditorLayoutView.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ struct EditorLayoutView: View {
2727
switch layout {
2828
case .one(let detailEditor):
2929
EditorAreaView(editor: detailEditor, focus: $focus)
30-
.transformEnvironment(\.edgeInsets) { insets in
31-
switch isAtEdge {
32-
case .all:
33-
insets.top += toolbarHeight
34-
insets.bottom += StatusBarView.height + 5
35-
case .top:
36-
insets.top += toolbarHeight
37-
case .bottom:
38-
insets.bottom += StatusBarView.height + 5
39-
default:
40-
return
41-
}
42-
}
30+
4331
case .vertical(let data), .horizontal(let data):
4432
SubEditorLayoutView(data: data, focus: $focus)
4533
}

CodeEdit/WorkspaceView.swift

Lines changed: 138 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,9 @@ struct WorkspaceView: View {
1414
@Environment(\.colorScheme)
1515
private var colorScheme
1616

17-
@FocusState var focusedEditor: Editor?
18-
1917
@AppSettings(\.theme.matchAppearance)
2018
var matchAppearance
2119

22-
@EnvironmentObject private var workspace: WorkspaceDocument
23-
@EnvironmentObject private var editorManager: EditorManager
24-
@EnvironmentObject private var utilityAreaViewModel: UtilityAreaViewModel
25-
2620
@StateObject private var themeModel: ThemeModel = .shared
2721

2822
@State private var showingAlert = false
@@ -32,61 +26,143 @@ struct WorkspaceView: View {
3226
private var keybindings: KeybindingManager = .shared
3327

3428
var body: some View {
35-
if workspace.workspaceFileManager != nil {
36-
VStack {
37-
SplitViewReader { proxy in
38-
SplitView(axis: .vertical) {
39-
EditorLayoutView(
40-
layout: editorManager.isFocusingActiveEditor
41-
? editorManager.activeEditor.getEditorLayout() ?? editorManager.editorLayout
42-
: editorManager.editorLayout,
43-
focus: $focusedEditor
44-
)
45-
.collapsable()
46-
.collapsed($utilityAreaViewModel.isMaximized)
47-
.frame(minHeight: 170 + 29 + 29)
48-
.frame(maxWidth: .infinity, maxHeight: .infinity)
49-
.holdingPriority(.init(1))
50-
.safeAreaInset(edge: .bottom, spacing: 0) {
51-
StatusBarView(proxy: proxy)
52-
}
53-
UtilityAreaView()
54-
.collapsable()
55-
.collapsed($utilityAreaViewModel.isCollapsed)
56-
.frame(idealHeight: 260)
57-
.frame(minHeight: 100)
58-
}
59-
.edgesIgnoringSafeArea(.top)
60-
.frame(maxWidth: .infinity, maxHeight: .infinity)
61-
.onChange(of: focusedEditor) { newValue in
62-
/// update active tab group only if the new one is not the same with it.
63-
if let newValue, editorManager.activeEditor != newValue {
64-
editorManager.activeEditor = newValue
65-
}
66-
}
67-
.onChange(of: editorManager.activeEditor) { newValue in
68-
if newValue != focusedEditor {
69-
focusedEditor = newValue
70-
}
71-
}
72-
.onChange(of: colorScheme) { newValue in
73-
if matchAppearance {
74-
themeModel.selectedTheme = newValue == .dark
75-
? themeModel.selectedDarkTheme
76-
: themeModel.selectedLightTheme
77-
}
78-
}
79-
.onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { output in
80-
if let window = output.object as? NSWindow, self.window == window {
81-
workspace.addToWorkspaceState(
82-
key: .workspaceWindowSize,
83-
value: NSStringFromRect(window.frame)
84-
)
85-
}
86-
}
87-
}
88-
}
89-
.background(EffectView(.contentBackground))
90-
}
29+
WorkspaceSplitView()
30+
// VStack {
31+
// SplitViewReader { proxy in
32+
// let editor = EditorLayoutView(
33+
// layout: editorManager.isFocusingActiveEditor
34+
// ? editorManager.activeEditor.getEditorLayout() ?? editorManager.editorLayout
35+
// : editorManager.editorLayout,
36+
// focus: $focusedEditor
37+
// )
38+
// .collapsable()
39+
// .collapsed($utilityAreaViewModel.isMaximized)
40+
// .frame(minHeight: 170 + 29 + 29)
41+
// .frame(maxWidth: .infinity, maxHeight: .infinity)
42+
//
43+
// let utility = UtilityAreaView()
44+
// .collapsable()
45+
// .collapsed($utilityAreaViewModel.isCollapsed)
46+
// .frame(idealHeight: 260)
47+
// .frame(minHeight: 100)
48+
//
49+
// let splitView = NSSplitView()
50+
// splitView.addArrangedSubview(NSHostingView(rootView: editor))
51+
// splitView.addArrangedSubview(NSHostingView(rootView: utility))
52+
//
53+
// SplitView(axis: .vertical) {
54+
// EditorLayoutView(
55+
// layout: editorManager.isFocusingActiveEditor
56+
// ? editorManager.activeEditor.getEditorLayout() ?? editorManager.editorLayout
57+
// : editorManager.editorLayout,
58+
// focus: $focusedEditor
59+
// )
60+
// .collapsable()
61+
// .collapsed($utilityAreaViewModel.isMaximized)
62+
// .frame(minHeight: 170 + 29 + 29)
63+
// .frame(maxWidth: .infinity, maxHeight: .infinity)
64+
// .holdingPriority(.init(1))
65+
// .safeAreaInset(edge: .bottom, spacing: 0) {
66+
// StatusBarView(proxy: proxy)
67+
// }
68+
// UtilityAreaView()
69+
// .collapsable()
70+
// .collapsed($utilityAreaViewModel.isCollapsed)
71+
// .frame(idealHeight: 260)
72+
// .frame(minHeight: 100)
73+
// }
74+
// .edgesIgnoringSafeArea(.top)
75+
// .frame(maxWidth: .infinity, maxHeight: .infinity)
76+
// .onChange(of: focusedEditor) { newValue in
77+
// /// update active tab group only if the new one is not the same with it.
78+
// if let newValue, editorManager.activeEditor != newValue {
79+
// editorManager.activeEditor = newValue
80+
// }
81+
// }
82+
// .onChange(of: editorManager.activeEditor) { newValue in
83+
// if newValue != focusedEditor {
84+
// focusedEditor = newValue
85+
// }
86+
// }
87+
// .onChange(of: colorScheme) { newValue in
88+
// if matchAppearance {
89+
// themeModel.selectedTheme = newValue == .dark
90+
// ? themeModel.selectedDarkTheme
91+
// : themeModel.selectedLightTheme
92+
// }
93+
// }
94+
// .onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { output in
95+
// if let window = output.object as? NSWindow, self.window == window {
96+
// workspace.addToWorkspaceState(
97+
// key: .workspaceWindowSize,
98+
// value: NSStringFromRect(window.frame)
99+
// )
100+
// }
101+
// }
102+
// }
103+
// }
104+
// .background(EffectView(.contentBackground))
91105
}
92106
}
107+
108+
struct WorkspaceSplitView: NSViewRepresentable {
109+
@EnvironmentObject private var workspace: WorkspaceDocument
110+
@EnvironmentObject private var editorManager: EditorManager
111+
@EnvironmentObject private var utilityAreaViewModel: UtilityAreaViewModel
112+
@FocusState var focusedEditor: Editor?
113+
114+
final class CustomSplitView: NSSplitView {
115+
override var dividerThickness: CGFloat { StatusBarView.height }
116+
override var dividerColor: NSColor { .clear }
117+
}
118+
119+
func makeNSView(context: Context) -> NSSplitView {
120+
let editor = EditorLayoutView(
121+
layout: editorManager.isFocusingActiveEditor
122+
? editorManager.activeEditor.getEditorLayout() ?? editorManager.editorLayout
123+
: editorManager.editorLayout,
124+
focus: $focusedEditor
125+
)
126+
.collapsable()
127+
.collapsed($utilityAreaViewModel.isMaximized)
128+
.frame(minHeight: 170 + 29 + 29)
129+
.frame(maxWidth: .infinity, maxHeight: .infinity)
130+
131+
let utility = UtilityAreaView()
132+
.collapsable()
133+
.collapsed($utilityAreaViewModel.isCollapsed)
134+
.frame(idealHeight: 260)
135+
.frame(minHeight: 100)
136+
137+
let splitView = CustomSplitView()
138+
splitView.arrangesAllSubviews = false
139+
let editorPane = NSHostingView(rootView: editor)
140+
let utilityPane = NSHostingView(rootView: utility)
141+
splitView.addArrangedSubview(editorPane)
142+
splitView.addArrangedSubview(utilityPane)
143+
144+
let dividerView = NSHostingView(rootView: StatusBarView())
145+
dividerView.translatesAutoresizingMaskIntoConstraints = false
146+
let constraints = [
147+
dividerView.topAnchor.constraint(equalTo: splitView.subviews[0].bottomAnchor),
148+
dividerView.bottomAnchor.constraint(equalTo: splitView.subviews[1].topAnchor),
149+
dividerView.leadingAnchor.constraint(equalTo: splitView.leadingAnchor),
150+
dividerView.trailingAnchor.constraint(equalTo: splitView.trailingAnchor)
151+
]
152+
splitView.addSubview(dividerView)
153+
NSLayoutConstraint.activate(constraints)
154+
155+
splitView.adjustSubviews()
156+
157+
158+
return splitView
159+
}
160+
161+
func updateNSView(_ nsView: NSSplitView, context: Context) {
162+
163+
}
164+
165+
typealias NSViewType = NSSplitView
166+
167+
168+
}

0 commit comments

Comments
 (0)