8
8
import SwiftUI
9
9
10
10
struct EditorTabBarTrailingAccessories : View {
11
+ @AppSettings ( \. textEditing. wrapLinesToEditorWidth)
12
+ var wrapLinesToEditorWidth
13
+ @AppSettings ( \. textEditing. showMinimap)
14
+ var showMinimap
15
+
11
16
@Environment ( \. splitEditor)
12
17
var splitEditor
13
18
@@ -21,15 +26,49 @@ struct EditorTabBarTrailingAccessories: View {
21
26
22
27
@EnvironmentObject private var editor : Editor
23
28
29
+ @Binding var codeFile : CodeFileDocument ?
30
+
24
31
var body : some View {
25
- HStack ( spacing: 0 ) {
32
+ HStack ( spacing: 6 ) {
33
+ // Once more options are implemented that are available for non-code documents, remove this if statement
34
+ if let codeFile {
35
+ editorOptionsMenu ( codeFile: codeFile)
36
+ Divider ( )
37
+ . padding ( . vertical, 10 )
38
+ }
26
39
splitviewButton
27
40
}
41
+ . buttonStyle ( . icon)
42
+ . disabled ( editorManager. isFocusingActiveEditor)
43
+ . opacity ( editorManager. isFocusingActiveEditor ? 0.5 : 1 )
28
44
. padding ( . horizontal, 7 )
29
45
. opacity ( activeState != . inactive ? 1.0 : 0.5 )
30
46
. frame ( maxHeight: . infinity) // Fill out vertical spaces.
31
47
}
32
48
49
+ func editorOptionsMenu( codeFile: CodeFileDocument ) -> some View {
50
+ // This is a button so it gets the same styling from the Group in `body`.
51
+ Button ( action: { } , label: { Image ( systemName: " slider.horizontal.3 " ) } )
52
+ . overlay {
53
+ Menu {
54
+ Toggle ( " Show Minimap " , isOn: $showMinimap)
55
+ . keyboardShortcut ( " M " , modifiers: [ . command, . shift, . control] )
56
+ Divider ( )
57
+ Toggle (
58
+ " Wrap Lines " ,
59
+ isOn: Binding (
60
+ get: { codeFile. wrapLines ?? wrapLinesToEditorWidth } ,
61
+ set: {
62
+ codeFile. wrapLines = $0
63
+ }
64
+ )
65
+ )
66
+ } label: { }
67
+ . menuStyle ( . borderlessButton)
68
+ . menuIndicator ( . hidden)
69
+ }
70
+ }
71
+
33
72
var splitviewButton : some View {
34
73
Group {
35
74
switch ( editor. parent? . axis, modifierKeys. contains ( . option) ) {
@@ -53,9 +92,6 @@ struct EditorTabBarTrailingAccessories: View {
53
92
EmptyView ( )
54
93
}
55
94
}
56
- . buttonStyle ( . icon)
57
- . disabled ( editorManager. isFocusingActiveEditor)
58
- . opacity ( editorManager. isFocusingActiveEditor ? 0.5 : 1 )
59
95
}
60
96
61
97
func split( edge: Edge ) {
@@ -73,6 +109,6 @@ struct EditorTabBarTrailingAccessories: View {
73
109
74
110
struct TabBarTrailingAccessories_Previews : PreviewProvider {
75
111
static var previews : some View {
76
- EditorTabBarTrailingAccessories ( )
112
+ EditorTabBarTrailingAccessories ( codeFile : . constant ( nil ) )
77
113
}
78
114
}
0 commit comments