Skip to content

Commit 3ba8da7

Browse files
lolgearlucasderraugh
authored andcommitted
Windows Separation Remastered: Welcome (#599)
* application: main menu welcome window has been extracted into separate xib. * application: windows welcome window has been incapsulated. * application: app delegate loading from xibs has been added. welcome window has been introduced. * application: project has been updated. * application: app delegate loading xibs from bundle has been added.
1 parent bc8d340 commit 3ba8da7

File tree

7 files changed

+305
-232
lines changed

7 files changed

+305
-232
lines changed

GitUp/Application/AppDelegate.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
@property(nonatomic, weak) IBOutlet NSTextField* versionTextField;
3636
@property(nonatomic, weak) IBOutlet NSTextField* copyrightTextField;
3737

38-
@property(nonatomic, strong) IBOutlet NSWindow* welcomeWindow;
39-
@property(nonatomic, weak) IBOutlet NSPopUpButton* recentPopUpButton;
40-
@property(nonatomic, weak) IBOutlet GILinkButton* twitterButton;
41-
@property(nonatomic, weak) IBOutlet GILinkButton* forumsButton;
42-
4338
+ (instancetype)sharedDelegate;
4439
+ (BOOL)loadPlainTextAuthenticationFormKeychainForURL:(NSURL*)url user:(NSString*)user username:(NSString**)username password:(NSString**)password allowInteraction:(BOOL)allowInteraction;
4540
+ (void)savePlainTextAuthenticationToKeychainForURL:(NSURL*)url withUsername:(NSString*)username password:(NSString*)password;

GitUp/Application/AppDelegate.m

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#import "ToolProtocol.h"
3030
#import "GARawTracker.h"
3131

32+
#import "WelcomeWindow.h"
33+
3234
#define __ENABLE_SUDDEN_TERMINATION__ 1
3335

3436
#define kNotificationUserInfoKey_Action @"action" // NSString
@@ -40,14 +42,14 @@
4042
#define kToolInstallPath @"/usr/local/bin/" kToolName
4143

4244
@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
45+
@property(nonatomic, strong) WelcomeWindow* welcomeWindow;
4346
@end
4447

4548
@implementation AppDelegate {
4649
SUUpdater* _updater;
4750
BOOL _updatePending;
4851
BOOL _manualCheck;
4952
NSInteger _allowWelcome;
50-
CGFloat _welcomeMaxHeight;
5153

5254
BOOL _authenticationUseKeychain;
5355
NSURL* _authenticationURL;
@@ -189,46 +191,10 @@ - (void)_openDocument:(NSMenuItem*)sender {
189191
[self _openRepositoryWithURL:sender.representedObject withCloneMode:kCloneMode_None windowModeID:NSNotFound];
190192
}
191193

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-
222194
- (void)awakeFromNib {
223-
_welcomeMaxHeight = _welcomeWindow.frame.size.height;
224195

225196
_allowWelcome = -1;
226197

227-
_twitterButton.textAlignment = NSLeftTextAlignment;
228-
_twitterButton.textFont = [NSFont boldSystemFontOfSize:11];
229-
_forumsButton.textAlignment = NSLeftTextAlignment;
230-
_forumsButton.textFont = [NSFont boldSystemFontOfSize:11];
231-
232198
_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General;
233199
[self selectPreferencePane:nil];
234200

@@ -239,8 +205,6 @@ - (void)awakeFromNib {
239205
[_channelPopUpButton.menu addItem:item];
240206
}
241207

242-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_willShowRecentPopUpMenu:) name:NSPopUpButtonWillPopUpNotification object:_recentPopUpButton];
243-
244208
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
245209
[self _applyTheme:theme];
246210
[_themePopUpButton.menu removeAllItems];
@@ -299,6 +263,36 @@ - (void)handleDocumentCountChanged {
299263
}
300264
}
301265

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+
302296
#pragma mark - NSApplicationDelegate
303297

304298
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
@@ -394,6 +388,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
394388
// Load theme preference
395389
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
396390
[self _applyTheme:theme];
391+
392+
// Load xibs
393+
[self _loadWindowsFromBundle];
397394

398395
#if __ENABLE_SUDDEN_TERMINATION__
399396
// Enable sudden termination

0 commit comments

Comments
 (0)