From 81dbe391d5e98bc647beaa2e6ecb0e1163faa14c Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Fri, 12 Aug 2011 18:25:39 +0200 Subject: [PATCH] Properly set folder/notes property of new media --- Medianno/MADocument.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Medianno/MADocument.mm b/Medianno/MADocument.mm index 87a4201..feda324 100644 --- a/Medianno/MADocument.mm +++ b/Medianno/MADocument.mm @@ -52,17 +52,31 @@ return YES; } +#pragma mark - +#pragma mark Folder management + +- (MAFolder *)inboxFolder +{ + NSManagedObjectContext *moc = [self managedObjectContext]; + NSFetchRequest * inbox = [NSFetchRequest fetchRequestWithEntityName:@"MAFolder"]; + [inbox setPredicate:[NSPredicate predicateWithFormat:@"name == 'Inbox' AND parent == NULL"]]; + return [[moc executeFetchRequest:inbox error:nil] objectAtIndex:0]; +} + #pragma mark - #pragma mark Media management - (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying { NSManagedObjectContext *moc = [self managedObjectContext]; + MAFolder *inbox = [self inboxFolder]; MAMedia * media = [NSEntityDescription insertNewObjectForEntityForName:@"MAMedia" inManagedObjectContext:moc]; NSString * path = [url path]; media.media = path; media.date = [date timeIntervalSince1970]; media.name = name; + media.notes = @""; + media.folder= inbox; [moc processPendingChanges]; }