File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed
Sections/GeneralPreferences Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ extension AppPreferences {
3939 /// The reopen behavior of the app
4040 var reopenBehavior : ReopenBehavior = . welcome
4141
42+ /// Decides what the app does after a workspace is closed
43+ var reopenWindowAfterClose : ReopenWindowBehavior = . doNothing
44+
45+ /// The size of the project navigator
4246 var projectNavigatorSize : ProjectNavigatorSize = . medium
4347
4448 /// The Find Navigator Detail line limit
@@ -96,6 +100,10 @@ extension AppPreferences {
96100 ReopenBehavior . self,
97101 forKey: . reopenBehavior
98102 ) ?? . welcome
103+ self . reopenWindowAfterClose = try container. decodeIfPresent (
104+ ReopenWindowBehavior . self,
105+ forKey: . reopenWindowAfterClose
106+ ) ?? . doNothing
99107 self . projectNavigatorSize = try container. decodeIfPresent (
100108 ProjectNavigatorSize . self,
101109 forKey: . projectNavigatorSize
@@ -212,6 +220,12 @@ extension AppPreferences {
212220 case newDocument
213221 }
214222
223+ enum ReopenWindowBehavior : String , Codable {
224+ case showWelcomeWindow
225+ case doNothing
226+ case quit
227+ }
228+
215229 enum ProjectNavigatorSize : String , Codable {
216230 case small
217231 case medium
Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ struct GeneralPreferencesView: View {
4040 fileExtensionsSection
4141 fileIconStyleSection
4242 tabBarStyleSection
43- reopenBehaviorSection
43+ Group {
44+ reopenBehaviorSection
45+ reopenAfterWindowCloseBehaviourSection
46+ }
4447 projectNavigatorSizeSection
4548 findNavigatorDetailSection
4649 Group {
@@ -162,6 +165,24 @@ private extension GeneralPreferencesView {
162165 }
163166 }
164167
168+ var reopenAfterWindowCloseBehaviourSection : some View {
169+ PreferencesSection ( " After last window closed " ) {
170+ Picker (
171+ " After last window closed: " ,
172+ selection: $prefs. preferences. general. reopenWindowAfterClose
173+ ) {
174+ Text ( " Do nothing " )
175+ . tag ( AppPreferences . ReopenWindowBehavior. doNothing)
176+ Divider ( )
177+ Text ( " Show Welcome Window " )
178+ . tag ( AppPreferences . ReopenWindowBehavior. showWelcomeWindow)
179+ Text ( " Quit " )
180+ . tag ( AppPreferences . ReopenWindowBehavior. quit)
181+ }
182+ . frame ( width: inputWidth)
183+ }
184+ }
185+
165186 var projectNavigatorSizeSection : some View {
166187 PreferencesSection ( " Project Navigator Size " ) {
167188 Picker ( " Project Navigator Size " , selection: $prefs. preferences. general. projectNavigatorSize) {
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ final class CodeEditDocumentController: NSDocumentController {
1212 FileManager . default
1313 } ( )
1414
15+ private var prefs : AppPreferencesModel = . shared
16+
1517 override func newDocument( _ sender: Any ? ) {
1618 guard let newDocumentUrl = self . newDocumentUrl else { return }
1719
@@ -76,6 +78,18 @@ final class CodeEditDocumentController: NSDocumentController {
7678
7779 override func removeDocument( _ document: NSDocument ) {
7880 super. removeDocument ( document)
81+
82+ if CodeEditDocumentController . shared. documents. isEmpty {
83+ switch prefs. preferences. general. reopenWindowAfterClose {
84+ case . showWelcomeWindow:
85+ // Opens the welcome window
86+ NSApp . openWindow ( . welcome)
87+ case . quit:
88+ // Quits CodeEdit
89+ NSApplication . shared. terminate ( nil )
90+ case . doNothing: break
91+ }
92+ }
7993 }
8094
8195 override func clearRecentDocuments( _ sender: Any ? ) {
You can’t perform that action at this time.
0 commit comments