2
0

Content generation fix.

[UPDATED]   For safer MOC usage API.
[FIXED]     Actually set the active element so that content is generated.
This commit is contained in:
Maarten Billemont 2013-04-30 20:49:42 -04:00
parent 40f34f3d77
commit 9882bf408c
2 changed files with 27 additions and 22 deletions

View File

@ -35,8 +35,7 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
if ([[NSThread currentThread] isMainThread]) if ([[NSThread currentThread] isMainThread])
return mainManagedObjectContext; return mainManagedObjectContext;
NSManagedObjectContext NSManagedObjectContext *threadManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType];
*threadManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSConfinementConcurrencyType];
threadManagedObjectContext.parentContext = mainManagedObjectContext; threadManagedObjectContext.parentContext = mainManagedObjectContext;
return threadManagedObjectContext; return threadManagedObjectContext;

View File

@ -66,14 +66,15 @@
- (void)unlock { - (void)unlock {
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserForThread]; NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady];
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:moc];
if (!activeUser) if (!activeUser)
// No user to sign in with. // No user to sign in with.
return; return;
if ([MPMacAppDelegate get].key) if ([MPMacAppDelegate get].key)
// Already logged in. // Already logged in.
return; return;
if ([[MPMacAppDelegate get] signInAsUser:activeUser usingMasterPassword:nil]) if ([[MPMacAppDelegate get] signInAsUser:activeUser saveInContext:moc usingMasterPassword:nil])
// Load the key from the keychain. // Load the key from the keychain.
return; return;
@ -107,7 +108,8 @@
return; return;
} }
if (contextInfo == MPAlertUnlockMP) { if (contextInfo == MPAlertUnlockMP) {
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserForThread]; NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady];
MPUserEntity *activeUser = [[MPMacAppDelegate get] activeUserInContext:moc];
switch (returnCode) { switch (returnCode) {
case NSAlertAlternateReturn: case NSAlertAlternateReturn:
// "Change" button. // "Change" button.
@ -126,6 +128,7 @@
activeUser.keyID = nil; activeUser.keyID = nil;
[[MPMacAppDelegate get] forgetSavedKeyFor:activeUser]; [[MPMacAppDelegate get] forgetSavedKeyFor:activeUser];
[[MPMacAppDelegate get] signOutAnimated:YES]; [[MPMacAppDelegate get] signOutAnimated:YES];
[moc saveToStore];
} }
} }
break; break;
@ -140,8 +143,13 @@
self.contentContainer.alphaValue = 0; self.contentContainer.alphaValue = 0;
[self.progressView startAnimation:nil]; [self.progressView startAnimation:nil];
self.inProgress = YES; self.inProgress = YES;
dispatch_async( dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0 ), ^{ [MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *moc) {
BOOL success = [[MPMacAppDelegate get] signInAsUser:activeUser NSError *error = nil;
MPUserEntity *activeUser_ = (MPUserEntity *)[moc existingObjectWithID:activeUser.objectID error:&error];
if (!activeUser_)
err(@"Failed to retrieve active use while logging in: %@", error);
BOOL success = [[MPMacAppDelegate get] signInAsUser:activeUser saveInContext:moc
usingMasterPassword:[(NSSecureTextField *)alert.accessoryView stringValue]]; usingMasterPassword:[(NSSecureTextField *)alert.accessoryView stringValue]];
self.inProgress = NO; self.inProgress = NO;
@ -158,7 +166,7 @@
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:MPAlertIncorrectMP]; didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:MPAlertIncorrectMP];
} }
} ); } );
} ); }];
} }
default: default:
@ -185,10 +193,10 @@
NSError *error = nil; NSError *error = nil;
NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error]; NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error];
if (error) if (!siteResults)
err(@"While fetching elements for completion: %@", error); err(@"While fetching elements for completion: %@", error);
else if ([siteResults count]) {
if (siteResults) { _activeElementOID = ((NSManagedObject *)[siteResults objectAtIndex:0]).objectID;
for (MPElementEntity *element in siteResults) for (MPElementEntity *element in siteResults)
[mutableResults addObject:element.name]; [mutableResults addObject:element.name];
//[mutableResults addObject:query]; // For when the app should be able to create new sites. //[mutableResults addObject:query]; // For when the app should be able to create new sites.
@ -220,9 +228,6 @@
return NO; return NO;
} }
- (void)copyContents {
}
- (void)controlTextDidEndEditing:(NSNotification *)note { - (void)controlTextDidEndEditing:(NSNotification *)note {
if (note.object != self.siteField) if (note.object != self.siteField)
@ -296,7 +301,8 @@
if (![[NSPasteboard generalPasteboard] setString:content forType:NSPasteboardTypeString]) { if (![[NSPasteboard generalPasteboard] setString:content forType:NSPasteboardTypeString]) {
wrn(@"Couldn't copy password to pasteboard."); wrn(@"Couldn't copy password to pasteboard.");
return; return;
} } else
dbg(@"Copied: %@", content);
NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady]; NSManagedObjectContext *moc = [MPMacAppDelegate managedObjectContextForThreadIfReady];
MPElementEntity *activeElement = [self activeElementInContext:moc]; MPElementEntity *activeElement = [self activeElementInContext:moc];