@@ -29,7 +29,7 @@ struct WelcomeView: View {
2929 var isHovering : Bool = false
3030
3131 @State
32- var isHoveringClose : Bool = false
32+ var isHoveringCloseButton : Bool = false
3333
3434 private let openDocument : ( URL ? , @escaping ( ) -> Void ) -> Void
3535 private let newDocument : ( ) -> Void
@@ -48,6 +48,14 @@ struct WelcomeView: View {
4848 self . dismissWindow = dismissWindow
4949 }
5050
51+ private var showWhenLaunchedBinding : Binding < Bool > {
52+ Binding < Bool > {
53+ prefs. preferences. general. reopenBehavior == . welcome
54+ } set: { new in
55+ prefs. preferences. general. reopenBehavior = new ? . welcome : . openPanel
56+ }
57+ }
58+
5159 private var appVersion : String {
5260 Bundle . versionString ?? " "
5361 }
@@ -106,106 +114,13 @@ struct WelcomeView: View {
106114
107115 var body : some View {
108116 ZStack ( alignment: . topLeading) {
109- VStack ( spacing: 8 ) {
110- Spacer ( ) . frame ( height: 12 )
111- Image ( nsImage: NSApp . applicationIconImage)
112- . resizable ( )
113- . frame ( width: 128 , height: 128 )
114- Text ( NSLocalizedString ( " Welcome to CodeEdit " , comment: " " ) )
115- . font ( . system( size: 38 ) )
116- Text (
117- String (
118- format: NSLocalizedString ( " Version %@%@ (%@) " , comment: " " ) ,
119- appVersion,
120- appVersionPostfix,
121- appBuild
122- )
123- )
124- . foregroundColor ( . secondary)
125- . font ( . system( size: 13 ) )
126- . onHover { inside in
127- if inside {
128- NSCursor . pointingHand. push ( )
129- } else {
130- NSCursor . pop ( )
131- }
132- }
133- . onTapGesture {
134- copyInformation ( )
135- }
136-
137- Spacer ( ) . frame ( height: 20 )
138- HStack {
139- VStack ( alignment: . leading, spacing: 15 ) {
140- WelcomeActionView (
141- iconName: " plus.square " ,
142- title: NSLocalizedString ( " Create a new file " , comment: " " ) ,
143- subtitle: NSLocalizedString ( " Create a new file " , comment: " " )
144- )
145- . onTapGesture {
146- newDocument ( )
147- dismissWindow ( )
148- }
149- WelcomeActionView (
150- iconName: " folder " ,
151- title: NSLocalizedString ( " Open a file or folder " , comment: " " ) ,
152- subtitle: NSLocalizedString (
153- " Open an existing file or folder on your Mac " ,
154- comment: " "
155- )
156- )
157- . onTapGesture {
158- openDocument ( nil , dismissWindow)
159- }
160- WelcomeActionView (
161- iconName: " plus.square.on.square " ,
162- title: NSLocalizedString ( " Clone an existing project " , comment: " " ) ,
163- subtitle: NSLocalizedString (
164- " Start working on something from a Git repository " ,
165- comment: " "
166- )
167- )
168- . onTapGesture {
169- showGitClone = true
170- }
171- }
172- }
173- Spacer ( )
174- }
175- . frame ( width: 384 )
176- . padding ( . top, 20 )
177- . padding ( . horizontal, 56 )
178- . padding ( . bottom, 16 )
179- . background ( Color ( colorScheme == . dark ? NSColor . windowBackgroundColor : . white) )
117+ mainContent
180118
181119 if isHovering {
182- HStack ( alignment: . center) {
183- dismissButton
184- Spacer ( )
185- }
186- . padding ( 13 )
187- . transition ( AnyTransition . opacity. animation ( . easeInOut( duration: 0.25 ) ) )
120+ dismissButton
188121 }
189122 if isHovering {
190- VStack {
191- Spacer ( )
192- HStack {
193- Spacer ( )
194- Toggle (
195- " Show this window when CodeEdit launches " ,
196- isOn: . init( get: {
197- prefs. preferences. general. reopenBehavior == . welcome
198- } , set: { new in
199- prefs. preferences. general. reopenBehavior = new ? . welcome : . openPanel
200- } )
201- )
202- . toggleStyle ( . checkbox)
203- Spacer ( )
204- }
205- }
206- . padding ( . horizontal, 56 )
207- . padding ( . bottom, 16 )
208- . transition ( AnyTransition . opacity. animation ( . easeInOut( duration: 0.25 ) ) )
123+ showWhenLaunchedCheckbox
209124 }
210125 }
211126 . onHover { isHovering in
@@ -228,24 +143,116 @@ struct WelcomeView: View {
228143 }
229144 }
230145
146+ private var mainContent : some View {
147+ VStack ( spacing: 8 ) {
148+ Spacer ( ) . frame ( height: 12 )
149+ Image ( nsImage: NSApp . applicationIconImage)
150+ . resizable ( )
151+ . frame ( width: 128 , height: 128 )
152+ Text ( NSLocalizedString ( " Welcome to CodeEdit " , comment: " " ) )
153+ . font ( . system( size: 38 ) )
154+ Text (
155+ String (
156+ format: NSLocalizedString ( " Version %@%@ (%@) " , comment: " " ) ,
157+ appVersion,
158+ appVersionPostfix,
159+ appBuild
160+ )
161+ )
162+ . foregroundColor ( . secondary)
163+ . font ( . system( size: 13 ) )
164+ . onHover { hover in
165+ if hover {
166+ NSCursor . pointingHand. push ( )
167+ } else {
168+ NSCursor . pop ( )
169+ }
170+ }
171+ . onTapGesture {
172+ copyInformation ( )
173+ }
174+ . help ( " Copy System Information to Clipboard " )
175+
176+ Spacer ( ) . frame ( height: 20 )
177+ HStack {
178+ VStack ( alignment: . leading, spacing: 15 ) {
179+ WelcomeActionView (
180+ iconName: " plus.square " ,
181+ title: NSLocalizedString ( " Create a new file " , comment: " " ) ,
182+ subtitle: NSLocalizedString ( " Create a new file " , comment: " " )
183+ )
184+ . onTapGesture {
185+ newDocument ( )
186+ dismissWindow ( )
187+ }
188+ WelcomeActionView (
189+ iconName: " folder " ,
190+ title: NSLocalizedString ( " Open a file or folder " , comment: " " ) ,
191+ subtitle: NSLocalizedString (
192+ " Open an existing file or folder on your Mac " ,
193+ comment: " "
194+ )
195+ )
196+ . onTapGesture {
197+ openDocument ( nil , dismissWindow)
198+ }
199+ WelcomeActionView (
200+ iconName: " plus.square.on.square " ,
201+ title: NSLocalizedString ( " Clone an existing project " , comment: " " ) ,
202+ subtitle: NSLocalizedString (
203+ " Start working on something from a Git repository " ,
204+ comment: " "
205+ )
206+ )
207+ . onTapGesture {
208+ showGitClone = true
209+ }
210+ }
211+ }
212+ Spacer ( )
213+ }
214+ . frame ( width: 384 )
215+ . padding ( . top, 20 )
216+ . padding ( . horizontal, 56 )
217+ . padding ( . bottom, 16 )
218+ . background ( Color ( colorScheme == . dark ? NSColor . windowBackgroundColor : . white) )
219+ }
220+
231221 private var dismissButton : some View {
232222 Button (
233223 action: dismissWindow,
234224 label: {
235225 Circle ( )
236- . fill ( isHoveringClose ? . secondary : Color ( . clear) )
226+ . foregroundColor ( isHoveringCloseButton ? . secondary : . clear)
237227 . frame ( width: 13 , height: 13 )
238228 . overlay (
239229 Image ( systemName: " xmark " )
240230 . font ( . system( size: 8.5 , weight: . heavy, design: . rounded) )
241- . foregroundColor ( isHoveringClose ? Color ( NSColor . windowBackgroundColor) : . secondary)
231+ . foregroundColor ( isHoveringCloseButton ? Color ( . windowBackgroundColor) : . secondary)
242232 )
243233 }
244234 )
245- . buttonStyle ( PlainButtonStyle ( ) )
235+ . buttonStyle ( . plain )
246236 . accessibilityLabel ( Text ( " Close " ) )
247237 . onHover { hover in
248- isHoveringClose = hover
238+ isHoveringCloseButton = hover
239+ }
240+ . padding ( 13 )
241+ . transition ( AnyTransition . opacity. animation ( . easeInOut( duration: 0.25 ) ) )
242+ }
243+
244+ private var showWhenLaunchedCheckbox : some View {
245+ VStack ( alignment: . center) {
246+ Spacer ( )
247+ Toggle (
248+ " Show this window when CodeEdit launches " ,
249+ isOn: showWhenLaunchedBinding
250+ )
251+ . toggleStyle ( . checkbox)
249252 }
253+ . frame ( maxWidth: . infinity)
254+ . padding ( . horizontal, 56 )
255+ . padding ( . bottom, 16 )
256+ . transition ( AnyTransition . opacity. animation ( . easeInOut( duration: 0.25 ) ) )
250257 }
251258}
0 commit comments