31
31
32
32
#import " AboutWindowController.h"
33
33
#import " CloneWindowController.h"
34
+ #import " PreferencesWindowController.h"
34
35
#import " WelcomeWindowController.h"
35
36
36
37
#define __ENABLE_SUDDEN_TERMINATION__ 1
37
38
38
39
#define kNotificationUserInfoKey_Action @" action" // NSString
39
40
40
- #define kPreferencePaneIdentifier_General @" general"
41
-
42
41
#define kInstallerName @" install.sh"
43
42
#define kToolName @" gitup"
44
43
#define kToolInstallPath @" /usr/local/bin/" kToolName
45
44
46
45
@interface AppDelegate () <NSUserNotificationCenterDelegate , SUUpdaterDelegate>
47
46
@property (nonatomic , strong ) AboutWindowController *aboutWindowController;
48
47
@property (nonatomic , strong ) CloneWindowController *cloneWindowController;
48
+ @property (nonatomic , strong ) PreferencesWindowController *preferencesWindowController;
49
49
@property (nonatomic , strong ) WelcomeWindowController *welcomeWindowController;
50
50
@end
51
51
@@ -58,6 +58,7 @@ @implementation AppDelegate {
58
58
}
59
59
60
60
#pragma mark - Properties
61
+
61
62
- (AboutWindowController *)aboutWindowController {
62
63
if (!_aboutWindowController) {
63
64
_aboutWindowController = [[AboutWindowController alloc ] init ];
@@ -72,6 +73,24 @@ - (CloneWindowController *)cloneWindowController {
72
73
return _cloneWindowController;
73
74
}
74
75
76
+ - (void )didChangeReleaseChannel : (BOOL )didChange {
77
+ if (didChange) {
78
+ _manualCheck = NO ;
79
+ [_updater checkForUpdatesInBackground ];
80
+ }
81
+ }
82
+
83
+ - (PreferencesWindowController *)preferencesWindowController {
84
+ if (!_preferencesWindowController) {
85
+ _preferencesWindowController = [[PreferencesWindowController alloc ] init ];
86
+ __weak typeof (self) weakSelf = self;
87
+ _preferencesWindowController.didChangeReleaseChannel = ^(BOOL didChange) {
88
+ [weakSelf didChangeReleaseChannel: didChange];
89
+ };
90
+ }
91
+ return _preferencesWindowController;
92
+ }
93
+
75
94
- (WelcomeWindowController *)welcomeWindowController {
76
95
if (!_welcomeWindowController) {
77
96
_welcomeWindowController = [[WelcomeWindowController alloc ] init ];
@@ -94,12 +113,12 @@ + (void)initialize {
94
113
GICommitMessageViewUserDefaultKey_ShowMargins : @(YES ),
95
114
GICommitMessageViewUserDefaultKey_EnableSpellChecking : @(YES ),
96
115
GIUserDefaultKey_FontSize : @(GIDefaultFontSize),
97
- kUserDefaultsKey_ReleaseChannel : kReleaseChannel_Stable ,
116
+ kUserDefaultsKey_ReleaseChannel : PreferencesWindowController_ReleaseChannel_Stable ,
98
117
kUserDefaultsKey_CheckInterval : @(15 * 60 ),
99
118
kUserDefaultsKey_FirstLaunch : @(YES ),
100
119
kUserDefaultsKey_DiffWhitespaceMode : @(kGCLiveRepositoryDiffWhitespaceMode_Normal ),
101
120
kUserDefaultsKey_ShowWelcomeWindow : @(YES ),
102
- kUserDefaultsKey_Theme : kTheme_SystemPreference ,
121
+ kUserDefaultsKey_Theme : PreferencesWindowController_Theme_SystemPreference ,
103
122
};
104
123
[[NSUserDefaults standardUserDefaults ] registerDefaults: defaults];
105
124
}
@@ -138,52 +157,10 @@ - (void)_openDocumentAtURL:(NSURL *)url {
138
157
[self _openRepositoryWithURL: url withCloneMode: kCloneMode_None windowModeID: NSNotFound ];
139
158
}
140
159
141
- - (void )awakeFromNib {
142
-
143
- _preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General ;
144
- [self selectPreferencePane: nil ];
145
-
146
- [_channelPopUpButton.menu removeAllItems ];
147
- for (NSString * string in @[ kReleaseChannel_Stable , kReleaseChannel_Continuous ]) {
148
- NSMenuItem * item = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(string, nil ) action: NULL keyEquivalent: @" " ];
149
- item.representedObject = string;
150
- [_channelPopUpButton.menu addItem: item];
151
- }
152
-
153
- NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
154
- [self _applyTheme: theme];
155
- [_themePopUpButton.menu removeAllItems ];
156
- for (NSString * string in [self _themePreferences ]) {
157
- NSMenuItem * item = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(string, nil ) action: NULL keyEquivalent: @" " ];
158
- item.representedObject = string;
159
- [_themePopUpButton.menu addItem: item];
160
- }
161
- }
162
-
163
160
- (void )handleDocumentCountChanged {
164
161
[self .welcomeWindowController handleDocumentCountChanged ];
165
162
}
166
163
167
- - (void )_updatePreferencePanel {
168
- NSString * channel = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_ReleaseChannel ];
169
- for (NSMenuItem * item in _channelPopUpButton.menu .itemArray ) {
170
- if ([item.representedObject isEqualToString: channel]) {
171
- [_channelPopUpButton selectItem: item];
172
- break ;
173
- }
174
- }
175
- }
176
-
177
- - (void )_updateThemePopUpButton {
178
- NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
179
- for (NSMenuItem * item in _themePopUpButton.menu .itemArray ) {
180
- if ([item.representedObject isEqualToString: theme]) {
181
- [_themePopUpButton selectItem: item];
182
- break ;
183
- }
184
- }
185
- }
186
-
187
164
- (void )_showNotificationWithTitle : (NSString *)title action : (SEL )action message : (NSString *)format , ... NS_FORMAT_FUNCTION(3 , 4 ) {
188
165
NSUserNotification * notification = [[NSUserNotification alloc ] init ];
189
166
if (action) {
@@ -199,17 +176,6 @@ - (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(
199
176
[[NSUserNotificationCenter defaultUserNotificationCenter ] deliverNotification: notification];
200
177
}
201
178
202
- #pragma mark - Loading Xibs
203
- - (id )_loadWindowFromBundleXibWithName : (NSString *)name expectedClass : (Class )class {
204
- NSBundle *mainBundle = [NSBundle mainBundle ];
205
- NSArray *objects = @[];
206
- [mainBundle loadNibNamed: name owner: self topLevelObjects: &objects];
207
- NSArray *filteredObjects = [objects filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (id _Nullable evaluatedObject, NSDictionary <NSString *,id > * _Nullable bindings) {
208
- return [evaluatedObject isKindOfClass: class];
209
- }]];
210
- return filteredObjects.firstObject ;
211
- }
212
-
213
179
#pragma mark - NSApplicationDelegate
214
180
215
181
- (void )applicationWillFinishLaunching : (NSNotification *)notification {
@@ -248,6 +214,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
248
214
}
249
215
#endif
250
216
217
+ // Locate installed apps.
218
+ [GILaunchServicesLocator setup ];
219
+
251
220
// Initialize user notification center
252
221
[[NSUserNotificationCenter defaultUserNotificationCenter ] setDelegate: self ];
253
222
@@ -303,8 +272,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
303
272
}
304
273
305
274
// Load theme preference
306
- NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
307
- [self _applyTheme: theme];
275
+ [PreferencesThemeService applySelectedTheme ];
308
276
309
277
#if __ENABLE_SUDDEN_TERMINATION__
310
278
// Enable sudden termination
@@ -413,44 +381,6 @@ - (IBAction)openDocument:(id)sender {
413
381
[[NSDocumentController sharedDocumentController ] openDocument: sender];
414
382
}
415
383
416
- - (IBAction )changeReleaseChannel : (id )sender {
417
- NSString * oldChannel = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_ReleaseChannel ];
418
- NSString * newChannel = _channelPopUpButton.selectedItem .representedObject ;
419
- if (![newChannel isEqualToString: oldChannel]) {
420
- [[NSUserDefaults standardUserDefaults ] setObject: newChannel forKey: kUserDefaultsKey_ReleaseChannel ];
421
-
422
- _manualCheck = NO ;
423
- [_updater checkForUpdatesInBackground ];
424
- }
425
- }
426
-
427
- - (NSArray *)_themePreferences {
428
- return @[ kTheme_SystemPreference , kTheme_Dark , kTheme_Light ];
429
- }
430
-
431
- - (void )_applyTheme : (NSString *)theme {
432
- if (@available (macOS 10.14 , *)) {
433
- NSInteger index = [[self _themePreferences ] indexOfObject: theme];
434
- switch (index) {
435
- case 0 :
436
- NSApp .appearance = nil ;
437
- break ;
438
- case 1 :
439
- NSApp .appearance = [NSAppearance appearanceNamed: NSAppearanceNameDarkAqua ];
440
- break ;
441
- case 2 :
442
- NSApp .appearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua ];
443
- break ;
444
- }
445
- }
446
- [[NSUserDefaults standardUserDefaults ] setObject: theme forKey: kUserDefaultsKey_Theme ];
447
- }
448
-
449
- - (IBAction )changeTheme : (id )sender {
450
- NSString * theme = _themePopUpButton.selectedItem .representedObject ;
451
- [self _applyTheme: theme];
452
- }
453
-
454
384
- (IBAction )viewWiki : (id )sender {
455
385
[[NSWorkspace sharedWorkspace ] openURL: [NSURL URLWithString: kURL_Wiki ]];
456
386
}
@@ -469,24 +399,7 @@ - (IBAction)showAboutPanel:(id)sender {
469
399
}
470
400
471
401
- (IBAction )showPreferences : (id )sender {
472
- [self _updatePreferencePanel ];
473
- [self _updateThemePopUpButton ];
474
- [_preferencesWindow makeKeyAndOrderFront: nil ];
475
- }
476
-
477
- - (IBAction )selectPreferencePane : (id )sender {
478
- [_preferencesTabView selectTabViewItemWithIdentifier: _preferencesToolbar.selectedItemIdentifier];
479
- NSSize size = NSSizeFromString (_preferencesTabView.selectedTabViewItem .label );
480
- NSRect rect = [_preferencesWindow contentRectForFrameRect: _preferencesWindow.frame];
481
- if (sender) {
482
- rect.origin .y += rect.size .height ;
483
- }
484
- rect.size .width = size.width ;
485
- rect.size .height = size.height ;
486
- if (sender) {
487
- rect.origin .y -= rect.size .height ;
488
- }
489
- [_preferencesWindow setFrame: [_preferencesWindow frameRectForContentRect: rect] display: YES animate: (sender ? YES : NO )];
402
+ [self .preferencesWindowController showWindow: nil ];
490
403
}
491
404
492
405
- (IBAction )resetPreferences : (id )sender {
0 commit comments