From ce6ade034d9ea41481dc5c3d2958ffa414af21ab Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Fri, 12 Aug 2011 15:46:50 +0200 Subject: [PATCH] Restructure addMediaURL interface --- Medianno/MAAddMediaSheet.h | 4 +--- Medianno/MAAddMediaSheet.mm | 11 ++++++++--- Medianno/MADocWindow.mm | 5 +---- Medianno/MADocument.h | 2 +- Medianno/MADocument.mm | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Medianno/MAAddMediaSheet.h b/Medianno/MAAddMediaSheet.h index 7d4b147..902feb7 100644 --- a/Medianno/MAAddMediaSheet.h +++ b/Medianno/MAAddMediaSheet.h @@ -8,15 +8,13 @@ #import -typedef void (^MAAddMediaBlock)(NSURL * url, NSDate * date); - @interface MAAddMediaSheet : NSWindowController { } @property (readonly) NSArray * media; @property BOOL copyMedia; -- (void)runWithParentWindow:(NSWindow *)win media:(NSArray *)urls addMedia:(MAAddMediaBlock)block; +- (void)runWithParentWindow:(NSWindowController *)parent media:(NSArray *)urls; - (IBAction)useModificationDates:(id)sender; diff --git a/Medianno/MAAddMediaSheet.mm b/Medianno/MAAddMediaSheet.mm index 0f216ae..c958cdb 100644 --- a/Medianno/MAAddMediaSheet.mm +++ b/Medianno/MAAddMediaSheet.mm @@ -8,6 +8,7 @@ #import "MAAddMediaSheet.h" #import "MAAppController.h" +#import "MADocument.h" @implementation MAAddMediaSheet @@ -22,17 +23,21 @@ return self; } -- (void)runWithParentWindow:(NSWindow *)win media:(NSArray *)mediaUrls addMedia:(MAAddMediaBlock)block +- (void)runWithParentWindow:(NSWindowController *)parent media:(NSArray *)mediaUrls { NSMutableArray * m = [[NSMutableArray alloc] initWithCapacity:[mediaUrls count]]; for (NSURL * url in mediaUrls) [m addObject:[NSMutableDictionary dictionaryWithObject:url forKey:@"url"]]; media = m; [self useModificationDates:self]; - [NSApp beginSheet:[self window] modalForWindow:win didEndBlock:^(NSInteger returnCode) { + [NSApp beginSheet:[self window] modalForWindow:[parent window] didEndBlock:^(NSInteger returnCode) { if (returnCode == NSAlertFirstButtonReturn) { + MADocument * doc = [parent document]; [media enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - block([obj objectForKey:@"url"], [obj objectForKey:@"date"]); + NSURL * url = [obj objectForKey:@"url"]; + NSString * name= [[url lastPathComponent] stringByDeletingPathExtension]; + NSDate * date= [obj objectForKey:@"date"]; + [doc addMediaURL:url name:name date:date copying:copyMedia]; }]; } [[self window] orderOut:self]; diff --git a/Medianno/MADocWindow.mm b/Medianno/MADocWindow.mm index 4d2059a..6fac596 100644 --- a/Medianno/MADocWindow.mm +++ b/Medianno/MADocWindow.mm @@ -80,10 +80,7 @@ } [expandedURLs addObject:url]; } - MADocument * doc = [self document]; - [[[MAAddMediaSheet alloc] init] runWithParentWindow:[self window] media:expandedURLs addMedia:^(NSURL *url,NSDate *date) { - [doc addMediaURL:url date:date]; - }]; + [[[MAAddMediaSheet alloc] init] runWithParentWindow:self media:expandedURLs]; } @end diff --git a/Medianno/MADocument.h b/Medianno/MADocument.h index bcf1e80..e8cd3bf 100644 --- a/Medianno/MADocument.h +++ b/Medianno/MADocument.h @@ -12,6 +12,6 @@ } -- (void)addMediaURL:(NSURL *)url date:(NSDate *)date; +- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying; @end diff --git a/Medianno/MADocument.mm b/Medianno/MADocument.mm index 5ea2e9f..b8f8981 100644 --- a/Medianno/MADocument.mm +++ b/Medianno/MADocument.mm @@ -227,7 +227,7 @@ static NSString *StoreFileName = @"MediannoDB.sql"; #pragma mark - #pragma mark Media management -- (void)addMediaURL:(NSURL *)url date:(NSDate *)date +- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying { NSManagedObjectContext *moc = [self managedObjectContext]; MAMedia * media = [NSEntityDescription insertNewObjectForEntityForName:@"MAMedia" inManagedObjectContext:moc];