Mac: New sites.
[MOVED] Creation of new elements moved to shared code. [FIXED] When switching user, unset active key. [FIXED] Synchronize content calculation to avoid race issues while typing. [ADDED] Ability to create new sites. [FIXED] Unset active element when hitting backspace or escape.
This commit is contained in:
@@ -55,9 +55,11 @@
|
||||
return;
|
||||
|
||||
__weak MPElementListAllViewController *wSelf = self;
|
||||
[self addElementNamed:[alert textFieldAtIndex:0].text completion:^(BOOL success) {
|
||||
if (success)
|
||||
[[MPiOSAppDelegate get] addElementNamed:[alert textFieldAtIndex:0].text completion:^(MPElementEntity *element) {
|
||||
if (element) {
|
||||
[wSelf.delegate didSelectElement:element];
|
||||
[wSelf close:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
cancelTitle:[PearlStrings get].commonButtonCancel otherTitles:[PearlStrings get].commonButtonOkay, nil];
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
@property(readonly) NSDateFormatter *dateFormatter;
|
||||
|
||||
- (void)updateData;
|
||||
- (void)addElementNamed:(NSString *)siteName completion:(void (^)(BOOL success))completion;
|
||||
- (void)configureCell:(UITableViewCell *)cell inTableView:(UITableView *)tableView atTableIndexPath:(NSIndexPath *)indexPath;
|
||||
- (void)customTableViewUpdates;
|
||||
|
||||
|
||||
@@ -23,48 +23,6 @@
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (void)addElementNamed:(NSString *)siteName completion:(void (^)(BOOL success))completion {
|
||||
|
||||
if (![siteName length]) {
|
||||
if (completion)
|
||||
completion( false );
|
||||
return;
|
||||
}
|
||||
|
||||
[MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
|
||||
MPUserEntity *activeUser = [[MPiOSAppDelegate 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.lastUsed = [NSDate date];
|
||||
element.version = MPAlgorithmDefaultVersion;
|
||||
[moc saveToStore];
|
||||
|
||||
NSError *error = nil;
|
||||
if (element.objectID.isTemporaryID && ![moc obtainPermanentIDsForObjects:@[ element ] error:&error])
|
||||
err(@"Failed to obtain a permanent object ID after creating new element: %@", error);
|
||||
|
||||
NSManagedObjectID *elementOID = [element objectID];
|
||||
dispatch_async( dispatch_get_main_queue(), ^{
|
||||
MPElementEntity *element_ = (MPElementEntity *)[[MPiOSAppDelegate managedObjectContextForThreadIfReady]
|
||||
objectRegisteredForID:elementOID];
|
||||
[self.delegate didSelectElement:element_];
|
||||
if (completion)
|
||||
completion( true );
|
||||
} );
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSFetchedResultsController *)fetchedResultsControllerByLastUsed {
|
||||
|
||||
if (!_fetchedResultsControllerByLastUsed) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import "MPElementListSearchController.h"
|
||||
#import "MPMainViewController.h"
|
||||
#import "MPiOSAppDelegate.h"
|
||||
#import "MPAppDelegate_Store.h"
|
||||
|
||||
@interface MPElementListSearchController()
|
||||
|
||||
@@ -216,7 +217,11 @@
|
||||
if (buttonIndex == [alert cancelButtonIndex])
|
||||
return;
|
||||
|
||||
[self addElementNamed:siteName completion:nil];
|
||||
__weak MPElementListController *wSelf = self;
|
||||
[[MPiOSAppDelegate get] addElementNamed:siteName completion:^(MPElementEntity *element) {
|
||||
if (element)
|
||||
[wSelf.delegate didSelectElement:element];
|
||||
}];
|
||||
} cancelTitle:[PearlStrings get].commonButtonCancel otherTitles:[PearlStrings get].commonButtonYes, nil];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user