@@ -14,15 +14,9 @@ struct WorkspaceView: View {
14
14
@Environment ( \. colorScheme)
15
15
private var colorScheme
16
16
17
- @FocusState var focusedEditor : Editor ?
18
-
19
17
@AppSettings ( \. theme. matchAppearance)
20
18
var matchAppearance
21
19
22
- @EnvironmentObject private var workspace : WorkspaceDocument
23
- @EnvironmentObject private var editorManager : EditorManager
24
- @EnvironmentObject private var utilityAreaViewModel : UtilityAreaViewModel
25
-
26
20
@StateObject private var themeModel : ThemeModel = . shared
27
21
28
22
@State private var showingAlert = false
@@ -32,61 +26,143 @@ struct WorkspaceView: View {
32
26
private var keybindings : KeybindingManager = . shared
33
27
34
28
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))
91
105
}
92
106
}
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