29
29
#import " ToolProtocol.h"
30
30
#import " GARawTracker.h"
31
31
32
+ #import " WelcomeWindow.h"
33
+
32
34
#define __ENABLE_SUDDEN_TERMINATION__ 1
33
35
34
36
#define kNotificationUserInfoKey_Action @" action" // NSString
40
42
#define kToolInstallPath @" /usr/local/bin/" kToolName
41
43
42
44
@interface AppDelegate () <NSUserNotificationCenterDelegate , SUUpdaterDelegate>
45
+ @property (nonatomic , strong ) WelcomeWindow* welcomeWindow;
43
46
@end
44
47
45
48
@implementation AppDelegate {
46
49
SUUpdater* _updater;
47
50
BOOL _updatePending;
48
51
BOOL _manualCheck;
49
52
NSInteger _allowWelcome;
50
- CGFloat _welcomeMaxHeight;
51
53
52
54
BOOL _authenticationUseKeychain;
53
55
NSURL * _authenticationURL;
@@ -189,46 +191,10 @@ - (void)_openDocument:(NSMenuItem*)sender {
189
191
[self _openRepositoryWithURL: sender.representedObject withCloneMode: kCloneMode_None windowModeID: NSNotFound ];
190
192
}
191
193
192
- - (void )_willShowRecentPopUpMenu : (NSNotification *)notification {
193
- NSMenu * menu = _recentPopUpButton.menu ;
194
- while (menu.numberOfItems > 1 ) {
195
- [menu removeItemAtIndex: 1 ];
196
- }
197
- NSArray * array = [[NSDocumentController sharedDocumentController ] recentDocumentURLs ];
198
- if (array.count ) {
199
- for (NSURL * url in array) {
200
- NSString * path = url.path ;
201
- NSString * title = path.lastPathComponent ;
202
- for (NSMenuItem * item in menu.itemArray ) { // TODO: Handle identical second-to-last path component
203
- if ([item.title caseInsensitiveCompare: title] == NSOrderedSame) {
204
- title = [NSString stringWithFormat: @" %@ — %@ " , path.lastPathComponent, [[path stringByDeletingLastPathComponent ] lastPathComponent ]];
205
- path = [(NSURL *)item.representedObject path ];
206
- item.title = [NSString stringWithFormat: @" %@ — %@ " , path.lastPathComponent, [[path stringByDeletingLastPathComponent ] lastPathComponent ]];
207
- break ;
208
- }
209
- }
210
- NSMenuItem * item = [[NSMenuItem alloc ] initWithTitle: title action: @selector (_openDocument: ) keyEquivalent: @" " ];
211
- item.target = self;
212
- item.representedObject = url;
213
- [menu addItem: item];
214
- }
215
- } else {
216
- NSMenuItem * item = [[NSMenuItem alloc ] initWithTitle: NSLocalizedString(@" No Repositories" , nil ) action: NULL keyEquivalent: @" " ];
217
- item.enabled = NO ;
218
- [menu addItem: item];
219
- }
220
- }
221
-
222
194
- (void )awakeFromNib {
223
- _welcomeMaxHeight = _welcomeWindow.frame .size .height ;
224
195
225
196
_allowWelcome = -1 ;
226
197
227
- _twitterButton.textAlignment = NSLeftTextAlignment ;
228
- _twitterButton.textFont = [NSFont boldSystemFontOfSize: 11 ];
229
- _forumsButton.textAlignment = NSLeftTextAlignment ;
230
- _forumsButton.textFont = [NSFont boldSystemFontOfSize: 11 ];
231
-
232
198
_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General ;
233
199
[self selectPreferencePane: nil ];
234
200
@@ -239,8 +205,6 @@ - (void)awakeFromNib {
239
205
[_channelPopUpButton.menu addItem: item];
240
206
}
241
207
242
- [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (_willShowRecentPopUpMenu: ) name: NSPopUpButtonWillPopUpNotification object: _recentPopUpButton];
243
-
244
208
NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
245
209
[self _applyTheme: theme];
246
210
[_themePopUpButton.menu removeAllItems ];
@@ -299,6 +263,36 @@ - (void)handleDocumentCountChanged {
299
263
}
300
264
}
301
265
266
+ #pragma mark - Loading Xibs
267
+ - (id )_loadWindowFromBundleXibWithName : (NSString *)name expectedClass : (Class )class {
268
+ NSBundle *mainBundle = [NSBundle mainBundle ];
269
+ NSArray *objects = @[];
270
+ [mainBundle loadNibNamed: name owner: self topLevelObjects: &objects];
271
+ NSArray *filteredObjects = [objects filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (id _Nullable evaluatedObject, NSDictionary <NSString *,id > * _Nullable bindings) {
272
+ return [evaluatedObject isKindOfClass: class];
273
+ }]];
274
+ return filteredObjects.firstObject ;
275
+ }
276
+
277
+ - (void )_loadWindowsFromBundle {
278
+ self.welcomeWindow = [self _loadWindowFromBundleXibWithName: @" Welcome" expectedClass: NSWindow .class];
279
+ [self _windowsPostSetup ];
280
+ }
281
+
282
+ - (void )_windowsPostSetup {
283
+ _allowWelcome = -1 ;
284
+
285
+ __weak NSDocumentController *documentController = NSDocumentController .sharedDocumentController ;
286
+ self.welcomeWindow .getRecentDocuments = ^NSArray <NSURL *> * _Nonnull{
287
+ return documentController.recentDocumentURLs ;
288
+ };
289
+ __weak typeof (self) weakSelf = self;
290
+ self.welcomeWindow .configureItem = ^(NSMenuItem * _Nonnull item) {
291
+ item.target = weakSelf;
292
+ item.action = @selector (_openDocument: );
293
+ };
294
+ }
295
+
302
296
#pragma mark - NSApplicationDelegate
303
297
304
298
- (void )applicationWillFinishLaunching : (NSNotification *)notification {
@@ -394,6 +388,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
394
388
// Load theme preference
395
389
NSString * theme = [[NSUserDefaults standardUserDefaults ] stringForKey: kUserDefaultsKey_Theme ];
396
390
[self _applyTheme: theme];
391
+
392
+ // Load xibs
393
+ [self _loadWindowsFromBundle ];
397
394
398
395
#if __ENABLE_SUDDEN_TERMINATION__
399
396
// Enable sudden termination
0 commit comments