Implement dragging into annotation table
This commit is contained in:
parent
531877b222
commit
ec7bb0a476
|
@ -11,6 +11,8 @@
|
||||||
#import <QTKit/QTKit.h>
|
#import <QTKit/QTKit.h>
|
||||||
|
|
||||||
@class MATag;
|
@class MATag;
|
||||||
|
@class MAMedia;
|
||||||
|
@class MADocument;
|
||||||
|
|
||||||
@interface MAAnno : NSManagedObject {
|
@interface MAAnno : NSManagedObject {
|
||||||
@private
|
@private
|
||||||
|
@ -22,6 +24,7 @@
|
||||||
|
|
||||||
- (QTTime)qtLocation;
|
- (QTTime)qtLocation;
|
||||||
- (NSString *)exportText;
|
- (NSString *)exportText;
|
||||||
|
- (MAAnno *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)media;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tags are never manipulated through the tag objects, but always through
|
* Tags are never manipulated through the tag objects, but always through
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#import "MAAnno.h"
|
#import "MAAnno.h"
|
||||||
#import "MATag.h"
|
#import "MATag.h"
|
||||||
#import "MATagDescription.h"
|
#import "MATagDescription.h"
|
||||||
|
#import "MADocument.h"
|
||||||
|
|
||||||
#import <vector>
|
#import <vector>
|
||||||
|
|
||||||
|
@ -114,7 +115,6 @@
|
||||||
return [NSSet setWithObject:@"tags"];
|
return [NSSet setWithObject:@"tags"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (NSString *)exportText
|
- (NSString *)exportText
|
||||||
{
|
{
|
||||||
NSMutableString * text = [NSMutableString stringWithFormat:@"%@\t%@", self.location, self.notes];
|
NSMutableString * text = [NSMutableString stringWithFormat:@"%@\t%@", self.location, self.notes];
|
||||||
|
@ -123,4 +123,15 @@
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (MAAnno *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)media;
|
||||||
|
{
|
||||||
|
MAAnno * anno = [doc addAnnotationForMedia:media location:QTTimeFromString(self.location)];
|
||||||
|
anno.notes = self.notes;
|
||||||
|
NSMutableArray * tagDescs = [NSMutableArray array];
|
||||||
|
for (MATagDescription * tag in self.tagDescriptions)
|
||||||
|
[tagDescs addObject:[tag copyToDocument:doc withMedia:media]];
|
||||||
|
anno.tagDescriptions = tagDescs;
|
||||||
|
|
||||||
|
return anno;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -10,15 +10,17 @@
|
||||||
#import <QTKit/QTKit.h>
|
#import <QTKit/QTKit.h>
|
||||||
|
|
||||||
@class MAMovieWindow;
|
@class MAMovieWindow;
|
||||||
|
@class MAMedia;
|
||||||
|
|
||||||
@interface MADocWindow : NSWindowController <NSWindowDelegate,NSTokenFieldCellDelegate,NSTableViewDelegate> {
|
@interface MADocWindow : NSWindowController
|
||||||
|
<NSWindowDelegate,NSTokenFieldCellDelegate,NSTableViewDelegate,NSTableViewDataSource>
|
||||||
|
{
|
||||||
IBOutlet NSArrayController* mediaController;
|
IBOutlet NSArrayController* mediaController;
|
||||||
IBOutlet NSArrayController* annotationController;
|
IBOutlet NSArrayController* annotationController;
|
||||||
IBOutlet QTMovieView * movieView;
|
IBOutlet QTMovieView * movieView;
|
||||||
IBOutlet NSTableView * mediaTable;
|
IBOutlet NSTableView * mediaTable;
|
||||||
IBOutlet NSTableView * annotationTable;
|
IBOutlet NSTableView * annotationTable;
|
||||||
IBOutlet NSView * textExportAccessoryView;
|
IBOutlet NSView * textExportAccessoryView;
|
||||||
IBOutlet MAMovieWindow * moviePanel;
|
|
||||||
QTMovie * currentMovie;
|
QTMovie * currentMovie;
|
||||||
NSString * currentMovieTitle;
|
NSString * currentMovieTitle;
|
||||||
QTTime lastMovieTime;
|
QTTime lastMovieTime;
|
||||||
|
@ -39,6 +41,7 @@
|
||||||
- (QTTime)currentMovieTime;
|
- (QTTime)currentMovieTime;
|
||||||
- (void)moviePanelDidAppear;
|
- (void)moviePanelDidAppear;
|
||||||
- (void)moviePanelDidClose;
|
- (void)moviePanelDidClose;
|
||||||
|
- (MAMedia *)currentMedia;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,7 @@ static const char * kMADocWindowObserver = "MADocWindowObserver";
|
||||||
//
|
//
|
||||||
// Current movie changed
|
// Current movie changed
|
||||||
//
|
//
|
||||||
if ([[mediaController selectionIndexes] count] > 0) {
|
if (MAMedia * currentMedia = [self currentMedia]) {
|
||||||
MAMedia * currentMedia = [[mediaController selectedObjects] objectAtIndex:0];
|
|
||||||
currentMovie = [[QTMovie alloc] initWithFile:[currentMedia media] error:nil];
|
currentMovie = [[QTMovie alloc] initWithFile:[currentMedia media] error:nil];
|
||||||
currentMovieTitle = [currentMedia name];
|
currentMovieTitle = [currentMedia name];
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,6 +107,14 @@ static const char * kMADocWindowObserver = "MADocWindowObserver";
|
||||||
|
|
||||||
#pragma mark Media management
|
#pragma mark Media management
|
||||||
|
|
||||||
|
- (MAMedia *)currentMedia
|
||||||
|
{
|
||||||
|
if ([[mediaController selectionIndexes] count] > 0)
|
||||||
|
return [[mediaController selectedObjects] objectAtIndex:0];
|
||||||
|
else
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (QTTime)currentMovieTime
|
- (QTTime)currentMovieTime
|
||||||
{
|
{
|
||||||
return [currentMovie currentTime];
|
return [currentMovie currentTime];
|
||||||
|
@ -369,7 +376,7 @@ static NSTimeInterval sLastSkip = 0.0;
|
||||||
{
|
{
|
||||||
[currentMovie stop];
|
[currentMovie stop];
|
||||||
QTTime location = [self currentMovieTime];
|
QTTime location = [self currentMovieTime];
|
||||||
MAAnno * anno = [[self document] addAnnotationForMedia:[[mediaController selectedObjects] objectAtIndex:0] location:location];
|
MAAnno * anno = [[self document] addAnnotationForMedia:[self currentMedia] location:location];
|
||||||
[annotationController setSelectedObjects:[NSArray arrayWithObject:anno]];
|
[annotationController setSelectedObjects:[NSArray arrayWithObject:anno]];
|
||||||
[annotationTable editColumn:[annotationTable columnWithIdentifier:@"tags"]
|
[annotationTable editColumn:[annotationTable columnWithIdentifier:@"tags"]
|
||||||
row:[annotationController selectionIndex]
|
row:[annotationController selectionIndex]
|
||||||
|
@ -433,8 +440,7 @@ static NSTimeInterval sLastSkip = 0.0;
|
||||||
NSArray * lines = [text componentsSeparatedByString:@"\n"];
|
NSArray * lines = [text componentsSeparatedByString:@"\n"];
|
||||||
if ([lines count] > 0) {
|
if ([lines count] > 0) {
|
||||||
MADocument * doc = [self document];
|
MADocument * doc = [self document];
|
||||||
MAMedia * media =
|
MAMedia * media = [self currentMedia];
|
||||||
[mediaController selectionIndex] != NSNotFound ? [[mediaController selectedObjects] objectAtIndex:0] : nil;
|
|
||||||
//
|
//
|
||||||
// Detect whether we start with a tag
|
// Detect whether we start with a tag
|
||||||
//
|
//
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#import "MAAnno.h"
|
#import "MAAnno.h"
|
||||||
#import "MAMedia.h"
|
#import "MAMedia.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define kMADragType @"org.aereperennius.medianno"
|
#define kMADragType @"org.aereperennius.medianno"
|
||||||
|
|
||||||
@interface MAPasteboardData : NSObject <NSPasteboardWriting> {
|
@interface MAPasteboardData : NSObject <NSPasteboardWriting> {
|
||||||
|
@ -66,6 +68,9 @@
|
||||||
|
|
||||||
- (void)registerOurDragTypes
|
- (void)registerOurDragTypes
|
||||||
{
|
{
|
||||||
|
[mediaTable registerForDraggedTypes:
|
||||||
|
[NSArray arrayWithObjects:kMADragType,NSFilenamesPboardType, nil]];
|
||||||
|
|
||||||
[annotationTable setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
|
[annotationTable setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
|
||||||
[annotationTable setVerticalMotionCanBeginDrag:NO];
|
[annotationTable setVerticalMotionCanBeginDrag:NO];
|
||||||
[annotationTable registerForDraggedTypes:
|
[annotationTable registerForDraggedTypes:
|
||||||
|
@ -81,6 +86,63 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (Class)classOfDraggedObjects:(id)drag
|
||||||
|
{
|
||||||
|
NSArray * dragObjects = (NSArray *)[drag longValue];
|
||||||
|
|
||||||
|
return [dragObjects count] ? [[dragObjects objectAtIndex:0] class] : nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// We don't allow within-table dragging
|
||||||
|
//
|
||||||
|
if (tableView == [info draggingSource])
|
||||||
|
return NSDragOperationNone;
|
||||||
|
NSPasteboard * pb = [info draggingPasteboard];
|
||||||
|
if (id drag = [pb propertyListForType:kMADragType]) {
|
||||||
|
//
|
||||||
|
// We don't allow media drops in annotation table
|
||||||
|
//
|
||||||
|
Class dragClass = [self classOfDraggedObjects:drag];
|
||||||
|
if (tableView == annotationTable) {
|
||||||
|
if (dragClass == [MAMedia class] || (dragClass == [MAAnno class] && ![self currentMedia]))
|
||||||
|
return NSDragOperationNone;
|
||||||
|
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
||||||
|
} else {
|
||||||
|
if (dragClass == [MAMedia class] || dragClass == [MATagDescription class]) {
|
||||||
|
[tableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
||||||
|
} else {
|
||||||
|
row = std::min<NSInteger>(row, [[mediaController arrangedObjects] count]-1);
|
||||||
|
[tableView setDropRow:row dropOperation:NSTableViewDropOn];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NSDragOperationCopy;
|
||||||
|
}
|
||||||
|
return NSDragOperationNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
|
||||||
|
{
|
||||||
|
NSPasteboard * pb = [info draggingPasteboard];
|
||||||
|
MADocument * doc = [self document];
|
||||||
|
MAMedia * media = nil;
|
||||||
|
|
||||||
|
if (tableView == annotationTable) {
|
||||||
|
media = [self currentMedia];
|
||||||
|
} else if (dropOperation == NSTableViewDropOn) {
|
||||||
|
NSArray * allMedia = [mediaController arrangedObjects];
|
||||||
|
if (row >= 0 && row < [allMedia count])
|
||||||
|
media = [allMedia objectAtIndex:row];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id drag = [pb propertyListForType:kMADragType])
|
||||||
|
for (id obj in (NSArray *)[drag longValue])
|
||||||
|
[obj copyToDocument:doc withMedia:media];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MATagWindow (Dragging)
|
@implementation MATagWindow (Dragging)
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#import <CoreData/CoreData.h>
|
#import <CoreData/CoreData.h>
|
||||||
|
|
||||||
@class MATag;
|
@class MATag;
|
||||||
|
@class MADocument;
|
||||||
|
@class MAMedia;
|
||||||
|
|
||||||
@interface MATagDescription : NSManagedObject {
|
@interface MATagDescription : NSManagedObject {
|
||||||
@private
|
@private
|
||||||
|
@ -19,6 +21,7 @@
|
||||||
@property (nonatomic, retain) NSSet *uses;
|
@property (nonatomic, retain) NSSet *uses;
|
||||||
|
|
||||||
- (NSString *)exportText;
|
- (NSString *)exportText;
|
||||||
|
- (MATagDescription *)copyToDocument:(MADocument *)doc withMedia:(MAMedia *)media;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#import "MATagDescription.h"
|
#import "MATagDescription.h"
|
||||||
#import "MATag.h"
|
#import "MATag.h"
|
||||||
|
#import "MADocument.h"
|
||||||
|
|
||||||
@implementation MATagDescription
|
@implementation MATagDescription
|
||||||
@dynamic name;
|
@dynamic name;
|
||||||
|
@ -30,4 +30,10 @@
|
||||||
[tag.annotation didChangeValueForKey:@"tags"];
|
[tag.annotation didChangeValueForKey:@"tags"];
|
||||||
[self didChangeValueForKey:@"name"];
|
[self didChangeValueForKey:@"name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (MATagDescription *)copyToDocument:(MADocument *)doc withMedia:(id)media
|
||||||
|
{
|
||||||
|
return [doc tagDescriptionForName:self.name notes:self.notes];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user