Skip to content

Commit

Permalink
Windows Separation Remastered: Welcome (git-up#599)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lolgear authored and lucasderraugh committed Oct 16, 2019
1 parent bc8d340 commit 3ba8da7
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 232 deletions.
5 changes: 0 additions & 5 deletions GitUp/Application/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
@property(nonatomic, weak) IBOutlet NSTextField* versionTextField;
@property(nonatomic, weak) IBOutlet NSTextField* copyrightTextField;

@property(nonatomic, strong) IBOutlet NSWindow* welcomeWindow;
@property(nonatomic, weak) IBOutlet NSPopUpButton* recentPopUpButton;
@property(nonatomic, weak) IBOutlet GILinkButton* twitterButton;
@property(nonatomic, weak) IBOutlet GILinkButton* forumsButton;

+ (instancetype)sharedDelegate;
+ (BOOL)loadPlainTextAuthenticationFormKeychainForURL:(NSURL*)url user:(NSString*)user username:(NSString**)username password:(NSString**)password allowInteraction:(BOOL)allowInteraction;
+ (void)savePlainTextAuthenticationToKeychainForURL:(NSURL*)url withUsername:(NSString*)username password:(NSString*)password;
Expand Down
75 changes: 36 additions & 39 deletions GitUp/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#import "ToolProtocol.h"
#import "GARawTracker.h"

#import "WelcomeWindow.h"

#define __ENABLE_SUDDEN_TERMINATION__ 1

#define kNotificationUserInfoKey_Action @"action" // NSString
Expand All @@ -40,14 +42,14 @@
#define kToolInstallPath @"/usr/local/bin/" kToolName

@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
@property(nonatomic, strong) WelcomeWindow* welcomeWindow;
@end

@implementation AppDelegate {
SUUpdater* _updater;
BOOL _updatePending;
BOOL _manualCheck;
NSInteger _allowWelcome;
CGFloat _welcomeMaxHeight;

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

- (void)_willShowRecentPopUpMenu:(NSNotification*)notification {
NSMenu* menu = _recentPopUpButton.menu;
while (menu.numberOfItems > 1) {
[menu removeItemAtIndex:1];
}
NSArray* array = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
if (array.count) {
for (NSURL* url in array) {
NSString* path = url.path;
NSString* title = path.lastPathComponent;
for (NSMenuItem* item in menu.itemArray) { // TODO: Handle identical second-to-last path component
if ([item.title caseInsensitiveCompare:title] == NSOrderedSame) {
title = [NSString stringWithFormat:@"%@%@", path.lastPathComponent, [[path stringByDeletingLastPathComponent] lastPathComponent]];
path = [(NSURL*)item.representedObject path];
item.title = [NSString stringWithFormat:@"%@%@", path.lastPathComponent, [[path stringByDeletingLastPathComponent] lastPathComponent]];
break;
}
}
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:title action:@selector(_openDocument:) keyEquivalent:@""];
item.target = self;
item.representedObject = url;
[menu addItem:item];
}
} else {
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"No Repositories", nil) action:NULL keyEquivalent:@""];
item.enabled = NO;
[menu addItem:item];
}
}

- (void)awakeFromNib {
_welcomeMaxHeight = _welcomeWindow.frame.size.height;

_allowWelcome = -1;

_twitterButton.textAlignment = NSLeftTextAlignment;
_twitterButton.textFont = [NSFont boldSystemFontOfSize:11];
_forumsButton.textAlignment = NSLeftTextAlignment;
_forumsButton.textFont = [NSFont boldSystemFontOfSize:11];

_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General;
[self selectPreferencePane:nil];

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

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_willShowRecentPopUpMenu:) name:NSPopUpButtonWillPopUpNotification object:_recentPopUpButton];

NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
[self _applyTheme:theme];
[_themePopUpButton.menu removeAllItems];
Expand Down Expand Up @@ -299,6 +263,36 @@ - (void)handleDocumentCountChanged {
}
}

#pragma mark - Loading Xibs
- (id)_loadWindowFromBundleXibWithName:(NSString *)name expectedClass:(Class)class {
NSBundle *mainBundle = [NSBundle mainBundle];
NSArray *objects = @[];
[mainBundle loadNibNamed:name owner:self topLevelObjects:&objects];
NSArray *filteredObjects = [objects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
return [evaluatedObject isKindOfClass:class];
}]];
return filteredObjects.firstObject;
}

- (void)_loadWindowsFromBundle {
self.welcomeWindow = [self _loadWindowFromBundleXibWithName:@"Welcome" expectedClass:NSWindow.class];
[self _windowsPostSetup];
}

- (void)_windowsPostSetup {
_allowWelcome = -1;

__weak NSDocumentController *documentController = NSDocumentController.sharedDocumentController;
self.welcomeWindow.getRecentDocuments = ^NSArray<NSURL *> * _Nonnull{
return documentController.recentDocumentURLs;
};
__weak typeof(self) weakSelf = self;
self.welcomeWindow.configureItem = ^(NSMenuItem * _Nonnull item) {
item.target = weakSelf;
item.action = @selector(_openDocument:);
};
}

#pragma mark - NSApplicationDelegate

- (void)applicationWillFinishLaunching:(NSNotification*)notification {
Expand Down Expand Up @@ -394,6 +388,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
// Load theme preference
NSString* theme = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_Theme];
[self _applyTheme:theme];

// Load xibs
[self _loadWindowsFromBundle];

#if __ENABLE_SUDDEN_TERMINATION__
// Enable sudden termination
Expand Down
Loading

0 comments on commit 3ba8da7

Please sign in to comment.