From ad8317a7a0e0b228fb94e81be0a79b815672ed6c Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 2 Feb 2013 00:45:30 -0500 Subject: [PATCH] All sites add button. [ADDED] An add site button in the all sites VC. --- MasterPassword/iOS/MPAllSitesViewController.h | 1 + MasterPassword/iOS/MPAllSitesViewController.m | 42 +++++++++++++++++++ MasterPassword/iOS/MPSearchDelegate.m | 7 ++-- .../iOS/MainStoryboard_iPhone.storyboard | 6 +++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/MasterPassword/iOS/MPAllSitesViewController.h b/MasterPassword/iOS/MPAllSitesViewController.h index c5691760..5fc5163f 100644 --- a/MasterPassword/iOS/MPAllSitesViewController.h +++ b/MasterPassword/iOS/MPAllSitesViewController.h @@ -24,5 +24,6 @@ @property (weak, nonatomic) IBOutlet id delegate; - (IBAction)close:(id)sender; +- (IBAction)add:(id)sender; @end diff --git a/MasterPassword/iOS/MPAllSitesViewController.m b/MasterPassword/iOS/MPAllSitesViewController.m index 2714e44b..e813108c 100644 --- a/MasterPassword/iOS/MPAllSitesViewController.m +++ b/MasterPassword/iOS/MPAllSitesViewController.m @@ -46,6 +46,48 @@ [self dismissViewControllerAnimated:YES completion:nil]; } +- (IBAction)add:(id)sender { + + [PearlAlert showAlertWithTitle:@"Site To Add" message:nil viewStyle:UIAlertViewStylePlainTextInput initAlert:nil + tappedButtonBlock:^(UIAlertView *alert, NSInteger buttonIndex) { + if (alert.cancelButtonIndex == buttonIndex) + return; + + NSString *siteName = [alert textFieldAtIndex:0].text; + if (![siteName length]) + return; + + [MPAppDelegate managedObjectContextPerform:^(NSManagedObjectContext *moc) { + MPUserEntity *activeUser = [[MPAppDelegate get] activeUserInContext:moc]; + assert(activeUser); + + MPElementType type = activeUser.defaultType; + if (!type) + type = activeUser.defaultType = MPElementTypeGeneratedLong; + NSString *typeEntityClassName = [MPAlgorithmDefault classNameOfType:type]; + + MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:typeEntityClassName + inManagedObjectContext:moc]; + + element.name = siteName; + element.user = activeUser; + element.type = type; + element.version = MPAlgorithmDefaultVersion; + [element saveContext]; + + NSManagedObjectID *elementOID = [element objectID]; + dispatch_async(dispatch_get_main_queue(), ^{ + MPElementEntity *element_ = (MPElementEntity *)[[MPAppDelegate managedObjectContextForThreadIfReady] + objectRegisteredForID:elementOID]; + [self.delegate didSelectElement:element_]; + [self close:nil]; + }); + }]; + + } + cancelTitle:[PearlStrings get].commonButtonCancel otherTitles:[PearlStrings get].commonButtonOkay, nil]; +} + - (NSFetchedResultsController *)fetchedResultsController { if (!_fetchedResultsController) { diff --git a/MasterPassword/iOS/MPSearchDelegate.m b/MasterPassword/iOS/MPSearchDelegate.m index 956a9ecd..975d40d6 100644 --- a/MasterPassword/iOS/MPSearchDelegate.m +++ b/MasterPassword/iOS/MPSearchDelegate.m @@ -347,12 +347,11 @@ assert(activeUser); MPElementType type = activeUser.defaultType; - if (!type) { - // Really shouldn't happen, but a few people crashed on this anyway. Uhh. Data store corruption? Old bugs? + if (!type) type = activeUser.defaultType = MPElementTypeGeneratedLong; - } + NSString *typeEntityClassName = [MPAlgorithmDefault classNameOfType:type]; - MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:[MPAlgorithmDefault classNameOfType:type] + MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:typeEntityClassName inManagedObjectContext:moc]; element.name = siteName; diff --git a/MasterPassword/iOS/MainStoryboard_iPhone.storyboard b/MasterPassword/iOS/MainStoryboard_iPhone.storyboard index 25cf4613..f9c4939f 100644 --- a/MasterPassword/iOS/MainStoryboard_iPhone.storyboard +++ b/MasterPassword/iOS/MainStoryboard_iPhone.storyboard @@ -1694,6 +1694,11 @@ You could use the word wall for inspiration in finding a memorable master passw + + + + + @@ -2197,6 +2202,7 @@ You could use the word wall for inspiration in finding a memorable master passw +