diff --git a/Medianno/MAAnno.h b/Medianno/MAAnno.h index 833ee34..039840a 100644 --- a/Medianno/MAAnno.h +++ b/Medianno/MAAnno.h @@ -21,6 +21,7 @@ @property (nonatomic, retain) NSManagedObject *media; - (QTTime)qtLocation; +- (NSString *)exportText; /* * Tags are never manipulated through the tag objects, but always through diff --git a/Medianno/MAAnno.mm b/Medianno/MAAnno.mm index a5f7a7a..0383d31 100644 --- a/Medianno/MAAnno.mm +++ b/Medianno/MAAnno.mm @@ -58,4 +58,13 @@ return [NSSet setWithObject:@"tags"]; } + +- (NSString *)exportText +{ + NSMutableString * text = [NSMutableString stringWithFormat:@"%@\t%@", self.location, self.notes]; + for (MATagDescription * tag in [self tagDescriptions]) + [text appendFormat:@"\t%@", [tag name]]; + return text; +} + @end diff --git a/Medianno/MADocWindow.h b/Medianno/MADocWindow.h index 6cdf45b..865037d 100644 --- a/Medianno/MADocWindow.h +++ b/Medianno/MADocWindow.h @@ -14,11 +14,16 @@ IBOutlet QTMovieView * movieView; IBOutlet NSTableView * mediaTable; IBOutlet NSTableView * annotationTable; + IBOutlet NSView * textExportAccessoryView; QTTime lastMovieTime; } +@property BOOL exportAnnotations; +@property BOOL exportTags; + - (IBAction)addMediaFiles:(id)sender; - (IBAction)exportMedia:(id)sender; +- (IBAction)exportText:(id)sender; - (void)addMedia:(NSArray *)urls; - (IBAction)addAnnotation:(id)sender; - (IBAction)mediaSkipBackward:(id)sender; diff --git a/Medianno/MADocWindow.mm b/Medianno/MADocWindow.mm index c8347ad..8ede808 100644 --- a/Medianno/MADocWindow.mm +++ b/Medianno/MADocWindow.mm @@ -11,14 +11,21 @@ #import "MADocWindow.h" #import "MAAddMediaSheet.h" #import "MADocument.h" +#import "MAMedia.h" #import "MAAnno.h" +#import "MATag.h" +#import "MATagDescription.h" @implementation MADocWindow +@synthesize exportAnnotations, exportTags; + - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; + exportAnnotations = YES; + return self; } @@ -171,17 +178,6 @@ }]; } -- (IBAction)addAnnotation:(id)sender -{ - [movieView pause:sender]; - QTTime location = [[self currentMovie] currentTime]; - MAAnno * anno = [[self document] addAnnotationForMedia:[[mediaController selectedObjects] objectAtIndex:0] location:location]; - [annotationController setSelectedObjects:[NSArray arrayWithObject:anno]]; - [annotationTable editColumn:[annotationTable columnWithIdentifier:@"tags"] - row:[annotationController selectionIndex] - withEvent:nil select:YES]; -} - - (void)delete:(id)sender { NSResponder * responder = [[self window] firstResponder]; @@ -207,6 +203,9 @@ - (BOOL)validateUserInterfaceItem:(id )item { + if ([item action] == @selector(addMedia:)) + return YES; + if ([item action] == @selector(toggleMediaPlay:)) { NSMenuItem * menuItem = (NSMenuItem *)item; if ([[self currentMovie] rate] > 0.0f) @@ -214,7 +213,7 @@ else [menuItem setTitle:NSLocalizedString(@"Play", @"Start playback")]; } - return YES; + return [mediaController selectionIndex] != NSNotFound; } #pragma mark Media navigation @@ -292,7 +291,7 @@ static NSTimeInterval sLastSkip = 0.0; return subview != [[splitView subviews] objectAtIndex:0]; } -#pragma mark Annotation Table +#pragma mark Annotations - (void)tableViewSelectionDidChange:(NSNotification *)notification { @@ -302,6 +301,67 @@ static NSTimeInterval sLastSkip = 0.0; [[self currentMovie] setCurrentTime:[firstSelectedAnno qtLocation]]; } +- (IBAction)addAnnotation:(id)sender +{ + [movieView pause:sender]; + QTTime location = [[self currentMovie] currentTime]; + MAAnno * anno = [[self document] addAnnotationForMedia:[[mediaController selectedObjects] objectAtIndex:0] location:location]; + [annotationController setSelectedObjects:[NSArray arrayWithObject:anno]]; + [annotationTable editColumn:[annotationTable columnWithIdentifier:@"tags"] + row:[annotationController selectionIndex] + withEvent:nil select:YES]; +} + +- (void)exportTextToURL:(NSURL *)url +{ + NSMutableString * text = [NSMutableString string]; + if (exportTags) { + NSSet * tagSet; + if (!exportAnnotations) { + tagSet = [[self document] allTags]; + } else { + NSMutableSet * tags = [NSMutableSet set]; + NSArray * annos; + if ([[annotationController selectionIndexes] count] > 0) + annos = [annotationController selectedObjects]; + else + annos = [annotationController arrangedObjects]; + for (MAAnno * anno in annos) + for (MATag * tag in [anno tags]) + [tags addObject:[tag tag]]; + tagSet = tags; + } + NSArray * tagsToExport = [tagSet sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]]; + for (MATagDescription * tag in tagsToExport) + [text appendFormat:@"%@\n", [tag exportText]]; + if (exportAnnotations) + [text appendString:@"\n"]; + } + if (exportAnnotations) { + NSArray * annosToExport; + if ([[annotationController selectionIndexes] count] > 0) + annosToExport = [annotationController selectedObjects]; + else + annosToExport = [annotationController arrangedObjects]; + for (MAAnno * anno in annosToExport) + [text appendFormat:@"%@\n", [anno exportText]]; + } + [text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:nil]; +} + +- (IBAction)exportText:(id)sender +{ + NSSavePanel * savePanel = [NSSavePanel savePanel]; + [savePanel setAllowedFileTypes:[NSArray arrayWithObject:@"txt"]]; + [savePanel setAccessoryView:textExportAccessoryView]; + exportAnnotations = [mediaController selectionIndex] != NSNotFound && (exportAnnotations || !exportTags); + exportTags = exportTags || !exportAnnotations; + [savePanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) { + [savePanel orderOut:self]; + if (result == NSFileHandlingPanelOKButton) + [self exportTextToURL:[savePanel URL]]; + }]; +} @end @implementation MADocumentWindow diff --git a/Medianno/MADocument.h b/Medianno/MADocument.h index c6d90a0..b6e2f94 100644 --- a/Medianno/MADocument.h +++ b/Medianno/MADocument.h @@ -21,5 +21,6 @@ - (MAAnno *)addAnnotationForMedia:(MAMedia *)media location:(QTTime)location; - (MATagDescription *)tagDescriptionForName:(NSString *)name; - (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix; +- (NSSet *)allTags; @end diff --git a/Medianno/MATagDescription.h b/Medianno/MATagDescription.h index 786dfc6..b1baf88 100644 --- a/Medianno/MATagDescription.h +++ b/Medianno/MATagDescription.h @@ -17,6 +17,9 @@ @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSString * notes; @property (nonatomic, retain) NSSet *uses; + +- (NSString *)exportText; + @end @interface MATagDescription (CoreDataGeneratedAccessors) diff --git a/Medianno/MATagDescription.mm b/Medianno/MATagDescription.mm index 9584884..24daad8 100644 --- a/Medianno/MATagDescription.mm +++ b/Medianno/MATagDescription.mm @@ -15,4 +15,9 @@ @dynamic notes; @dynamic uses; +- (NSString *)exportText +{ + return [NSString stringWithFormat:@"%@\t%@", self.name, self.notes]; +} + @end diff --git a/Medianno/en.lproj/MADocument.xib b/Medianno/en.lproj/MADocument.xib index d6a42ae..5b6c9a3 100644 --- a/Medianno/en.lproj/MADocument.xib +++ b/Medianno/en.lproj/MADocument.xib @@ -623,7 +623,7 @@ 0 Box - + 6 System textBackgroundColor @@ -692,6 +692,104 @@ YES YES + + + 34 + + YES + + + 274 + + YES + + + 268 + {{16, 39}, {144, 18}} + + + + _NS:239 + YES + + -2080244224 + 0 + Export Annotations + + _NS:239 + + 1211912703 + 2 + + NSImage + NSSwitch + + + NSSwitch + + + + 200 + 25 + + + + + 268 + {{16, 20}, {98, 18}} + + + + _NS:239 + YES + + -2080244224 + 0 + Export Tags + + _NS:239 + + 1211912703 + 2 + + + + + 200 + 25 + + + + {166, 65} + + + + _NS:632 + + + {166, 65} + + + + _NS:630 + {0, 0} + + 67239424 + 0 + Export + + + + 3 + MCAwLjgwMDAwMDAxMTkAA + + + + 0 + 0 + 0 + NO + @@ -1176,6 +1274,46 @@ 100228 + + + textExportAccessoryView + + + + 100240 + + + + value: exportAnnotations + + + + + + value: exportAnnotations + value + exportAnnotations + 2 + + + 100242 + + + + value: exportTags + + + + + + value: exportTags + value + exportTags + 2 + + + 100243 + @@ -1525,6 +1663,45 @@ + + 100229 + + + YES + + + + + Text Export Options + + + 100236 + + + YES + + + + + + 100237 + + + + + 100238 + + + YES + + + + + + 100239 + + + @@ -1584,6 +1761,11 @@ 100221.IBPluginDependency 100222.CustomClassName 100222.IBPluginDependency + 100229.IBPluginDependency + 100236.IBPluginDependency + 100237.IBPluginDependency + 100238.IBPluginDependency + 100239.IBPluginDependency 5.IBNSWindowAutoPositionCentersHorizontal 5.IBNSWindowAutoPositionCentersVertical 5.IBPluginDependency @@ -1654,6 +1836,11 @@ com.apple.InterfaceBuilder.CocoaPlugin MATokenFieldCell com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1673,7 +1860,7 @@ - 100228 + 100243 @@ -1688,6 +1875,7 @@ addAnnotation: addMediaFiles: exportMedia: + exportText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -1700,6 +1888,7 @@ id id id + id @@ -1709,6 +1898,7 @@ addAnnotation: addMediaFiles: exportMedia: + exportText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -1727,6 +1917,10 @@ exportMedia: id + + exportText: + id + mediaSkipBackward: id @@ -1750,6 +1944,7 @@ mediaController mediaTable movieView + textExportAccessoryView YES @@ -1758,6 +1953,7 @@ NSArrayController NSTableView QTMovieView + NSView @@ -1769,6 +1965,7 @@ mediaController mediaTable movieView + textExportAccessoryView YES @@ -1792,6 +1989,10 @@ movieView QTMovieView + + textExportAccessoryView + NSView + @@ -1825,5 +2026,9 @@ YES 3 + + NSSwitch + {15, 15} + diff --git a/Medianno/en.lproj/MainMenu.xib b/Medianno/en.lproj/MainMenu.xib index 6f32b69..5ad7c88 100644 --- a/Medianno/en.lproj/MainMenu.xib +++ b/Medianno/en.lproj/MainMenu.xib @@ -2,7 +2,7 @@ 1070 - 11A511 + 11B26 1617 1138 566.00 @@ -302,6 +302,16 @@ + + + YES + Export As Text… + s + 1572864 + 2147483647 + + + YES @@ -1361,6 +1371,14 @@ 592 + + + exportText: + + + + 595 + @@ -1458,6 +1476,7 @@ + @@ -2065,6 +2084,11 @@ + + 593 + + + @@ -2162,6 +2186,7 @@ 580.IBPluginDependency 583.IBPluginDependency 590.IBPluginDependency + 593.IBPluginDependency 72.IBPluginDependency 73.IBPluginDependency 74.IBPluginDependency @@ -2278,6 +2303,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -2292,7 +2318,7 @@ - 592 + 595 @@ -2333,6 +2359,7 @@ addAnnotation: addMediaFiles: exportMedia: + exportText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -2345,6 +2372,7 @@ id id id + id @@ -2354,6 +2382,7 @@ addAnnotation: addMediaFiles: exportMedia: + exportText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -2372,6 +2401,10 @@ exportMedia: id + + exportText: + id + mediaSkipBackward: id @@ -2395,8 +2428,6 @@ mediaController mediaTable movieView - tokenColumn - tokenFieldProto YES @@ -2405,8 +2436,6 @@ NSArrayController NSTableView QTMovieView - NSTableColumn - NSTokenField @@ -2418,8 +2447,6 @@ mediaController mediaTable movieView - tokenColumn - tokenFieldProto YES @@ -2443,14 +2470,6 @@ movieView QTMovieView - - tokenColumn - NSTableColumn - - - tokenFieldProto - NSTokenField -