Implement dragging import/export of URLs
This commit is contained in:
parent
b1a1104361
commit
9b42529dc3
|
@ -8,6 +8,8 @@
|
|||
|
||||
#import "MAColorForURL.h"
|
||||
|
||||
#import <QTKit/QTKit.h>
|
||||
|
||||
@implementation MAColorForURL
|
||||
|
||||
+ (Class)transformedValueClass
|
||||
|
@ -22,7 +24,8 @@
|
|||
|
||||
- (id)transformedValue:(id)value
|
||||
{
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:value])
|
||||
NSURL * mediaURL = [NSURL URLWithString:value];
|
||||
if ([QTMovie canInitWithURL:mediaURL])
|
||||
return [NSColor blackColor];
|
||||
else
|
||||
return [NSColor redColor];
|
||||
|
|
|
@ -94,8 +94,9 @@ static const char * kMADocWindowObserver = "MADocWindowObserver";
|
|||
// Current movie changed
|
||||
//
|
||||
if (MAMedia * currentMedia = [self currentMedia]) {
|
||||
currentMovie = [[QTMovie alloc] initWithFile:[currentMedia media] error:nil];
|
||||
currentMovieTitle = [currentMedia name];
|
||||
NSURL * mediaURL = [NSURL URLWithString:[currentMedia media]];
|
||||
currentMovie = [[QTMovie alloc] initWithURL:mediaURL error:nil];
|
||||
currentMovieTitle = [currentMedia name];
|
||||
} else {
|
||||
currentMovie = nil;
|
||||
currentMovieTitle = @"";
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
- (MAMedia *)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date
|
||||
{
|
||||
NSString * path = [url path];
|
||||
NSString * path = [url absoluteString];
|
||||
NSNumber * size;
|
||||
[url getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
|
||||
int64_t fileSize = [size longLongValue];
|
||||
|
|
|
@ -41,10 +41,13 @@
|
|||
|
||||
- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard
|
||||
{
|
||||
if (![contents count] || [[contents objectAtIndex:0] class] != [MAMedia class])
|
||||
MAMedia * media;
|
||||
if (![contents count] || [(media = [contents objectAtIndex:0]) class] != [MAMedia class])
|
||||
return [NSArray arrayWithObjects:kMADragType, kUTTypeUTF8PlainText, nil];
|
||||
else if ([[NSURL URLWithString:[media media]] isFileURL])
|
||||
return [NSArray arrayWithObjects:kMADragType, kUTTypeFileURL, nil];
|
||||
else
|
||||
return [NSArray arrayWithObjects:kMADragType, NSFilenamesPboardType, nil];
|
||||
return [NSArray arrayWithObjects:kMADragType, kUTTypeURL, nil];
|
||||
}
|
||||
|
||||
- (NSPasteboardWritingOptions)writingOptionsForType:(NSString *)type pasteboard:(NSPasteboard *)pasteboard
|
||||
|
@ -61,11 +64,8 @@
|
|||
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;
|
||||
} else if ([type isEqual:(NSString *)kUTTypeURL] || [type isEqual:(NSString *)kUTTypeFileURL]) {
|
||||
return [contents count]>0 ? [[contents objectAtIndex:0] media] : nil;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
@ -76,8 +76,9 @@
|
|||
|
||||
- (void)registerOurDragTypes
|
||||
{
|
||||
[mediaTable setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
|
||||
[mediaTable registerForDraggedTypes:
|
||||
[NSArray arrayWithObjects:kMADragType,NSFilenamesPboardType, nil]];
|
||||
[NSArray arrayWithObjects:kMADragType, NSFilenamesPboardType, kUTTypeURL, nil]];
|
||||
|
||||
[annotationTable setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
|
||||
[annotationTable setVerticalMotionCanBeginDrag:NO];
|
||||
|
@ -110,7 +111,8 @@
|
|||
if (tableView == [info draggingSource])
|
||||
return NSDragOperationNone;
|
||||
NSPasteboard * pb = [info draggingPasteboard];
|
||||
if (id drag = [pb propertyListForType:kMADragType]) {
|
||||
id drag;
|
||||
if ((drag = [pb propertyListForType:kMADragType])) {
|
||||
//
|
||||
// We don't allow media drops in annotation table
|
||||
//
|
||||
|
@ -128,7 +130,17 @@
|
|||
}
|
||||
}
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
} else if (tableView == mediaTable) {
|
||||
if ((drag = [pb propertyListForType:NSFilenamesPboardType])) {
|
||||
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
||||
return NSDragOperationLink;
|
||||
} else if ((drag = [pb stringForType:(NSString *)kUTTypeURL])
|
||||
|| (drag = [pb stringForType:(NSString *)kUTTypeFileURL])
|
||||
) {
|
||||
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
||||
return NSDragOperationLink;
|
||||
}
|
||||
}
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
|
@ -145,10 +157,21 @@
|
|||
if (row >= 0 && row < [allMedia count])
|
||||
media = [allMedia objectAtIndex:row];
|
||||
}
|
||||
|
||||
if (id drag = [pb propertyListForType:kMADragType])
|
||||
|
||||
id drag;
|
||||
if ((drag = [pb propertyListForType:kMADragType])) {
|
||||
for (id obj in (NSArray *)[drag longValue])
|
||||
[obj copyToDocument:doc withMedia:media];
|
||||
} else if ((drag = [pb propertyListForType:NSFilenamesPboardType])) {
|
||||
NSMutableArray * urls = [NSMutableArray array];
|
||||
for (NSString * path in drag)
|
||||
[urls addObject:[NSURL fileURLWithPath:path]];
|
||||
[self addMedia:urls];
|
||||
} else if ((drag = [pb stringForType:(NSString *)kUTTypeURL])
|
||||
|| (drag = [pb stringForType:(NSString *)kUTTypeFileURL])
|
||||
) {
|
||||
[self addMedia:[NSArray arrayWithObject:[NSURL URLWithString:drag]]];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
- (MAMedia *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)m
|
||||
{
|
||||
MAMedia * media = [doc addMediaURL:[NSURL fileURLWithPath:self.media]
|
||||
MAMedia * media = [doc addMediaURL:[NSURL URLWithString:self.media]
|
||||
name:self.name
|
||||
date:[NSDate dateWithTimeIntervalSinceReferenceDate:self.date]];
|
||||
media.notes = self.notes;
|
||||
|
|
Loading…
Reference in New Issue
Block a user