Restructure addMediaURL interface
This commit is contained in:
parent
d57b567030
commit
ce6ade034d
|
@ -8,15 +8,13 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue
Block a user