diff --git a/Medianno/MADocument.h b/Medianno/MADocument.h index 0721706..49e657d 100644 --- a/Medianno/MADocument.h +++ b/Medianno/MADocument.h @@ -17,7 +17,7 @@ NSFileWrapper * mediaWrapper; } -- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date; +- (MAMedia *)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date; - (MAAnno *)addAnnotationForMedia:(MAMedia *)media location:(QTTime)location; - (MATagDescription *)tagDescriptionForName:(NSString *)name; - (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes; diff --git a/Medianno/MADocument.mm b/Medianno/MADocument.mm index ce7d7be..2598c77 100644 --- a/Medianno/MADocument.mm +++ b/Medianno/MADocument.mm @@ -40,7 +40,7 @@ #pragma mark Media management -- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date +- (MAMedia *)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date { NSString * path = [url path]; NSNumber * size; @@ -71,6 +71,8 @@ } media.date = fileDate; media.media = path; + + return media; } #pragma mark Annotation management diff --git a/Medianno/MADragging.mm b/Medianno/MADragging.mm index df74d26..4ecfc11 100644 --- a/Medianno/MADragging.mm +++ b/Medianno/MADragging.mm @@ -41,7 +41,10 @@ - (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard { - return [NSArray arrayWithObjects:kMADragType, kUTTypeUTF8PlainText, nil]; + if (![contents count] || [[contents objectAtIndex:0] class] != [MAMedia class]) + return [NSArray arrayWithObjects:kMADragType, kUTTypeUTF8PlainText, nil]; + else + return [NSArray arrayWithObjects:kMADragType, NSFilenamesPboardType, nil]; } - (NSPasteboardWritingOptions)writingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard @@ -58,6 +61,11 @@ for (id obj in contents) [stringBuffer appendFormat:@"%@\n", [obj exportText]]; return stringBuffer; + } else if ([type isEqual:NSFilenamesPboardType]) { + NSMutableArray * urls = [NSMutableArray array]; + for (MAMedia * obj in contents) + [urls addObject:[NSURL fileURLWithPath:[obj media]]]; + return urls; } return nil; } @@ -79,7 +87,8 @@ - (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard { - NSArray * objects = [[annotationController arrangedObjects] objectsAtIndexes:rowIndexes]; + NSArrayController * controller = tableView==annotationTable ? annotationController : mediaController; + NSArray * objects = [[controller arrangedObjects] objectsAtIndexes:rowIndexes]; [pboard clearContents]; [pboard writeObjects:[NSArray arrayWithObject:[MAPasteboardData pasteboardDataWithArray:objects]]]; diff --git a/Medianno/MAMedia.h b/Medianno/MAMedia.h index 2b0db1b..549c8a0 100644 --- a/Medianno/MAMedia.h +++ b/Medianno/MAMedia.h @@ -10,7 +10,7 @@ #import #import -@class MAAnno, MAFolder; +@class MAAnno, MADocument; @interface MAMedia : NSManagedObject { @private @@ -23,6 +23,8 @@ @property (nonatomic, retain) NSSet *annotations; @property (nonatomic) int64_t size; +- (MAMedia *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)media; + @end @interface MAMedia (CoreDataGeneratedAccessors) diff --git a/Medianno/MAMedia.mm b/Medianno/MAMedia.mm index e8a18b4..9d3e5c3 100644 --- a/Medianno/MAMedia.mm +++ b/Medianno/MAMedia.mm @@ -7,6 +7,8 @@ // #import "MAMedia.h" +#import "MAAnno.h" +#import "MADocument.h" @implementation MAMedia @dynamic media; @@ -16,4 +18,15 @@ @dynamic annotations; @dynamic size; +- (MAMedia *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)m +{ + MAMedia * media = [doc addMediaURL:[NSURL fileURLWithPath:self.media] + name:self.name + date:[NSDate dateWithTimeIntervalSinceReferenceDate:self.date]]; + media.notes = self.notes; + for (MAAnno * anno in self.annotations) + [media addAnnotationsObject:[anno copyToDocument:doc withMedia:media]]; + return media; +} + @end