2
0

All sites add button.

[ADDED]     An add site button in the all sites VC.
This commit is contained in:
Maarten Billemont 2013-02-02 00:45:30 -05:00
parent 820be14845
commit ad8317a7a0
4 changed files with 52 additions and 4 deletions

View File

@ -24,5 +24,6 @@
@property (weak, nonatomic) IBOutlet id<MPElementPickerDelegate> delegate; @property (weak, nonatomic) IBOutlet id<MPElementPickerDelegate> delegate;
- (IBAction)close:(id)sender; - (IBAction)close:(id)sender;
- (IBAction)add:(id)sender;
@end @end

View File

@ -46,6 +46,48 @@
[self dismissViewControllerAnimated:YES completion:nil]; [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 { - (NSFetchedResultsController *)fetchedResultsController {
if (!_fetchedResultsController) { if (!_fetchedResultsController) {

View File

@ -347,12 +347,11 @@
assert(activeUser); assert(activeUser);
MPElementType type = activeUser.defaultType; MPElementType type = activeUser.defaultType;
if (!type) { if (!type)
// Really shouldn't happen, but a few people crashed on this anyway. Uhh. Data store corruption? Old bugs?
type = activeUser.defaultType = MPElementTypeGeneratedLong; type = activeUser.defaultType = MPElementTypeGeneratedLong;
} NSString *typeEntityClassName = [MPAlgorithmDefault classNameOfType:type];
MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:[MPAlgorithmDefault classNameOfType:type] MPElementEntity *element = [NSEntityDescription insertNewObjectForEntityForName:typeEntityClassName
inManagedObjectContext:moc]; inManagedObjectContext:moc];
element.name = siteName; element.name = siteName;

View File

@ -1694,6 +1694,11 @@ You could use the word wall for inspiration in finding a memorable master passw
<action selector="close:" destination="idA-Pj-1U9" id="qqC-U7-8Ci"/> <action selector="close:" destination="idA-Pj-1U9" id="qqC-U7-8Ci"/>
</connections> </connections>
</barButtonItem> </barButtonItem>
<barButtonItem key="rightBarButtonItem" systemItem="add" id="CR8-WY-9Td">
<connections>
<action selector="add:" destination="idA-Pj-1U9" id="G7b-hR-IH0"/>
</connections>
</barButtonItem>
</navigationItem> </navigationItem>
</tableViewController> </tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="abw-PC-pyQ" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="abw-PC-pyQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -2197,6 +2202,7 @@ You could use the word wall for inspiration in finding a memorable master passw
<class className="MPAllSitesViewController" superclassName="UITableViewController"> <class className="MPAllSitesViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/MPAllSitesViewController.h"/> <source key="sourceIdentifier" type="project" relativePath="./Classes/MPAllSitesViewController.h"/>
<relationships> <relationships>
<relationship kind="action" name="add:"/>
<relationship kind="action" name="close:"/> <relationship kind="action" name="close:"/>
<relationship kind="outlet" name="delegate"/> <relationship kind="outlet" name="delegate"/>
</relationships> </relationships>