Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions BugHub for Mac/BugHub/BugHub/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
}
}

// If no repo windows were restored, show the repo picker window
if (!hasOpenRepoWindow)
[self openRepoChooser:nil];
if (!hasOpenRepoWindow) {
NSString* lastOpenedRepo = [[NSUserDefaults standardUserDefaults] stringForKey:@"lastOpenedRepository"];
// If no repo windows were restored, show the repo picker window
if(lastOpenedRepo) [self openRepoWindow:lastOpenedRepo];
else [self openRepoChooser:nil];
}

}

[self checkAPIStatus];
Expand Down
41 changes: 34 additions & 7 deletions BugHub for Mac/BugHub/BugHub/NewRepoWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ - (void)windowDidLoad

if (!authenticatedUser)
return;

[self.identifierField setStringValue:[NSString stringWithFormat:@"%@/", authenticatedUser]];
[self loadRepos:authenticatedUser];

NSString* lastUsedUsername = [self usernameFromRepoIdentifier:[self lastOpenedRepository]];
NSString* userToBeUsed = lastUsedUsername ? lastUsedUsername : authenticatedUser;

[self.identifierField setStringValue:[NSString stringWithFormat:@"%@/", userToBeUsed]];
[self loadRepos:userToBeUsed];
}

- (void)dealloc
Expand Down Expand Up @@ -219,6 +222,16 @@ - (void)loadRepos:(NSString *)aUsername

}

-(NSString*)usernameFromRepoIdentifier:(NSString*)repoIdentifier
{
NSInteger indexOfSlash = [repoIdentifier rangeOfString:@"/"].location;

if (indexOfSlash == NSNotFound)
return nil;

return [repoIdentifier substringToIndex:indexOfSlash];
}

- (void)controlTextDidChange:(NSNotification *)obj
{
if ([obj object] != self.identifierField)
Expand All @@ -227,12 +240,12 @@ - (void)controlTextDidChange:(NSNotification *)obj
NSString *text = [self.identifierField stringValue];
BOOL isValidID = [BHRepository isValidIdentifier:text];

NSInteger indexOfSlash = [text rangeOfString:@"/"].location;
NSString* username = [self usernameFromRepoIdentifier:text];

if (indexOfSlash == NSNotFound)
if (!username)
return;

[self loadRepos:[text substringToIndex:indexOfSlash]];
[self loadRepos:username];
[self filterRepos];

[self.openButton setEnabled:isValidID];
Expand All @@ -248,6 +261,17 @@ - (void)windowWillClose:(NSNotification *)notification
[(AppDelegate *)[NSApp delegate] windowControllerDidClose:self];
}

-(NSString*)lastOpenedRepository
{
return [[NSUserDefaults standardUserDefaults] stringForKey:@"lastOpenedRepository"];
}

-(BOOL)rememberLastOpenedRepository:(NSString*)repositoryName
{
[[NSUserDefaults standardUserDefaults]setObject:repositoryName forKey:@"lastOpenedRepository"];
return [[NSUserDefaults standardUserDefaults] synchronize];
}

- (IBAction)openRepo:(id)sender
{
if (sender == self.repoListView)
Expand All @@ -257,7 +281,9 @@ - (IBAction)openRepo:(id)sender
if (clickedRow == NSNotFound)
return;

[(AppDelegate *)[NSApp delegate] openRepoWindow:[[_filteredRepos objectAtIndex:clickedRow] identifier]];
NSString* repoIdentifier = [[_filteredRepos objectAtIndex:clickedRow] identifier];
[(AppDelegate *)[NSApp delegate] openRepoWindow:repoIdentifier];
[self rememberLastOpenedRepository:repoIdentifier];
[self closeWindow:nil];
return;
}
Expand All @@ -269,6 +295,7 @@ - (IBAction)openRepo:(id)sender
return;

[(AppDelegate *)[NSApp delegate] openRepoWindow:text];
[self rememberLastOpenedRepository:text];
[self closeWindow:nil];
}

Expand Down