Restructure addMediaURL interface

This commit is contained in:
Matthias Neeracher 2011-08-12 15:46:50 +02:00
parent d57b567030
commit ce6ade034d
5 changed files with 12 additions and 12 deletions

View File

@ -8,15 +8,13 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
typedef void (^MAAddMediaBlock)(NSURL * url, NSDate * date);
@interface MAAddMediaSheet : NSWindowController { @interface MAAddMediaSheet : NSWindowController {
} }
@property (readonly) NSArray * media; @property (readonly) NSArray * media;
@property BOOL copyMedia; @property BOOL copyMedia;
- (void)runWithParentWindow:(NSWindow *)win media:(NSArray *)urls addMedia:(MAAddMediaBlock)block; - (void)runWithParentWindow:(NSWindowController *)parent media:(NSArray *)urls;
- (IBAction)useModificationDates:(id)sender; - (IBAction)useModificationDates:(id)sender;

View File

@ -8,6 +8,7 @@
#import "MAAddMediaSheet.h" #import "MAAddMediaSheet.h"
#import "MAAppController.h" #import "MAAppController.h"
#import "MADocument.h"
@implementation MAAddMediaSheet @implementation MAAddMediaSheet
@ -22,17 +23,21 @@
return self; 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]]; NSMutableArray * m = [[NSMutableArray alloc] initWithCapacity:[mediaUrls count]];
for (NSURL * url in mediaUrls) for (NSURL * url in mediaUrls)
[m addObject:[NSMutableDictionary dictionaryWithObject:url forKey:@"url"]]; [m addObject:[NSMutableDictionary dictionaryWithObject:url forKey:@"url"]];
media = m; media = m;
[self useModificationDates:self]; [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) { if (returnCode == NSAlertFirstButtonReturn) {
MADocument * doc = [parent document];
[media enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [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]; [[self window] orderOut:self];

View File

@ -80,10 +80,7 @@
} }
[expandedURLs addObject:url]; [expandedURLs addObject:url];
} }
MADocument * doc = [self document]; [[[MAAddMediaSheet alloc] init] runWithParentWindow:self media:expandedURLs];
[[[MAAddMediaSheet alloc] init] runWithParentWindow:[self window] media:expandedURLs addMedia:^(NSURL *url,NSDate *date) {
[doc addMediaURL:url date:date];
}];
} }
@end @end

View File

@ -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 @end

View File

@ -227,7 +227,7 @@ static NSString *StoreFileName = @"MediannoDB.sql";
#pragma mark - #pragma mark -
#pragma mark Media management #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]; NSManagedObjectContext *moc = [self managedObjectContext];
MAMedia * media = [NSEntityDescription insertNewObjectForEntityForName:@"MAMedia" inManagedObjectContext:moc]; MAMedia * media = [NSEntityDescription insertNewObjectForEntityForName:@"MAMedia" inManagedObjectContext:moc];