From 15a42a4570c0caca2aa1bbab8359f2450a61fd41 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Wed, 6 Aug 2014 10:23:12 +0200 Subject: [PATCH 1/2] Last used repository is saved to user defaults The last used repository is saved to the user defaults after opening a repository. This allows to list repositories from other group-accounts the user is member of in the "open" dialog window. --- .../BugHub/BugHub/NewRepoWindowController.m | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/BugHub for Mac/BugHub/BugHub/NewRepoWindowController.m b/BugHub for Mac/BugHub/BugHub/NewRepoWindowController.m index 9e52c4a..ca3e485 100644 --- a/BugHub for Mac/BugHub/BugHub/NewRepoWindowController.m +++ b/BugHub for Mac/BugHub/BugHub/NewRepoWindowController.m @@ -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 @@ -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) @@ -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]; @@ -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) @@ -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; } @@ -269,6 +295,7 @@ - (IBAction)openRepo:(id)sender return; [(AppDelegate *)[NSApp delegate] openRepoWindow:text]; + [self rememberLastOpenedRepository:text]; [self closeWindow:nil]; } From 50a922dba45e354ac343b40ba869b639c6446262 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Wed, 6 Aug 2014 10:35:04 +0200 Subject: [PATCH 2/2] Opens the last opened repository after start --- BugHub for Mac/BugHub/BugHub/AppDelegate.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BugHub for Mac/BugHub/BugHub/AppDelegate.m b/BugHub for Mac/BugHub/BugHub/AppDelegate.m index b7b9a18..aeb5a71 100644 --- a/BugHub for Mac/BugHub/BugHub/AppDelegate.m +++ b/BugHub for Mac/BugHub/BugHub/AppDelegate.m @@ -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];