From 328b4970404c07db18cde205a509239294156ed7 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Wed, 10 Aug 2011 16:27:02 +0200 Subject: [PATCH] Create initial folder structure --- Medianno/MADocument.m | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Medianno/MADocument.m b/Medianno/MADocument.m index c8bd235..f50ad3b 100644 --- a/Medianno/MADocument.m +++ b/Medianno/MADocument.m @@ -33,16 +33,6 @@ #pragma mark - #pragma mark MADocument -- (id)init -{ - self = [super init]; - if (self) { - // Add your subclass-specific initialization here. - // If an error occurs here, send a [self release] message and return nil. - } - return self; -} - /* This is the name of the Core Data store file contained within the document package. You can change this whatever you want -- the user will not see this file. @@ -51,6 +41,29 @@ static NSString *StoreFileName = @"MediannoDB.sql"; @implementation MADocument +- (id)initWithType:(NSString *)typeName error:(NSError **)outError +{ + self = [super initWithType:typeName error:outError]; + if (self) { + /* + * Start with a root folder and an inbox folder + */ + NSManagedObjectContext *moc = [self managedObjectContext]; + [[moc undoManager] disableUndoRegistration]; + MAFolder * rootFolder = [NSEntityDescription insertNewObjectForEntityForName:@"MAFolder" + inManagedObjectContext:moc]; + [rootFolder setName:@""]; + MAFolder * inboxFolder = [NSEntityDescription insertNewObjectForEntityForName:@"MAFolder" + inManagedObjectContext:moc]; + [inboxFolder setName:@"Inbox"]; + [inboxFolder setParent:rootFolder]; + + [moc processPendingChanges]; + [[moc undoManager] enableUndoRegistration]; + } + return self; +} + - (NSString *)windowNibName { // Override returning the nib file name of the document