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 +