diff --git a/Medianno/MADocWindow.h b/Medianno/MADocWindow.h index 865037d..23baadb 100644 --- a/Medianno/MADocWindow.h +++ b/Medianno/MADocWindow.h @@ -22,6 +22,7 @@ @property BOOL exportTags; - (IBAction)addMediaFiles:(id)sender; +- (IBAction)importText:(id)sender; - (IBAction)exportMedia:(id)sender; - (IBAction)exportText:(id)sender; - (void)addMedia:(NSArray *)urls; diff --git a/Medianno/MADocWindow.mm b/Medianno/MADocWindow.mm index 8ede808..ec0eaf9 100644 --- a/Medianno/MADocWindow.mm +++ b/Medianno/MADocWindow.mm @@ -203,7 +203,10 @@ - (BOOL)validateUserInterfaceItem:(id )item { - if ([item action] == @selector(addMedia:)) + if ([item action] == @selector(addMediaFiles:) + || [item action] == @selector(exportText:) + || [item action] == @selector(importText:) + ) return YES; if ([item action] == @selector(toggleMediaPlay:)) { @@ -362,6 +365,58 @@ static NSTimeInterval sLastSkip = 0.0; [self exportTextToURL:[savePanel URL]]; }]; } + +- (void)importTextFromURL:(NSURL *)url +{ + NSString * text = [NSString stringWithContentsOfURL:url usedEncoding:nil error:nil]; + NSArray * lines = [text componentsSeparatedByString:@"\n"]; + if ([lines count] > 0) { + MADocument * doc = [self document]; + MAMedia * media = + [mediaController selectionIndex] != NSNotFound ? [[mediaController selectedObjects] objectAtIndex:0] : nil; + // + // Detect whether we start with a tag + // + BOOL nextIsTag = NO; + NSString * firstLine = [lines objectAtIndex:0]; + NSRegularExpression * timeCode = [NSRegularExpression regularExpressionWithPattern:@"^\\d:\\d\\d:\\d\\d:\\d\\d" options:0 error:nil]; + if ([timeCode numberOfMatchesInString:firstLine options:0 range:NSMakeRange(0, [firstLine length])] > 0) + nextIsTag = YES; + for (NSString * line in lines) { + NSArray * components = [line componentsSeparatedByString:@"\t"]; + NSUInteger numComp = [components count]; + if ([line isEqual:@""]) { + nextIsTag = YES; + } else if (nextIsTag) { + if (!media) + break; + QTTime location= QTTimeFromString([components objectAtIndex:0]); + MAAnno * anno = [doc addAnnotationForMedia:media location:location]; + [anno setNotes:[components objectAtIndex:1]]; + NSMutableArray * tagDescs = [NSMutableArray array]; + for (NSUInteger i = 2; i 1 ? [components objectAtIndex:1] : nil; + [doc tagDescriptionForName:name notes:notes]; + } + } + } +} + +- (IBAction)importText:(id)sender +{ + NSOpenPanel * openPanel = [NSOpenPanel openPanel]; + [openPanel setAllowedFileTypes:[NSArray arrayWithObject:@"txt"]]; + [openPanel beginSheetModalForWindow:[self window] completionHandler:^(NSInteger result) { + [openPanel orderOut:self]; + if (result == NSFileHandlingPanelOKButton) + [self importTextFromURL:[openPanel URL]]; + }]; +} + @end @implementation MADocumentWindow diff --git a/Medianno/MADocument.h b/Medianno/MADocument.h index b6e2f94..014b436 100644 --- a/Medianno/MADocument.h +++ b/Medianno/MADocument.h @@ -20,6 +20,7 @@ - (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying; - (MAAnno *)addAnnotationForMedia:(MAMedia *)media location:(QTTime)location; - (MATagDescription *)tagDescriptionForName:(NSString *)name; +- (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes; - (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix; - (NSSet *)allTags; diff --git a/Medianno/MADocument.mm b/Medianno/MADocument.mm index 6bb94b0..4120edb 100644 --- a/Medianno/MADocument.mm +++ b/Medianno/MADocument.mm @@ -87,6 +87,16 @@ } } +- (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes +{ + MATagDescription * tag = [self tagDescriptionForName:name]; + + if (notes && [notes length] && ![tag.notes length]) + [tag setNotes:notes]; + + return tag; +} + - (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix { NSManagedObjectContext *moc = [self managedObjectContext]; @@ -100,4 +110,12 @@ return names; } +- (NSSet *)allTags +{ + NSManagedObjectContext *moc = [self managedObjectContext]; + NSFetchRequest * fetch = [NSFetchRequest fetchRequestWithEntityName:@"MATagDescription"]; + + return [NSSet setWithArray:[moc executeFetchRequest:fetch error:nil]]; +} + @end diff --git a/Medianno/en.lproj/MainMenu.xib b/Medianno/en.lproj/MainMenu.xib index 5ad7c88..362b37d 100644 --- a/Medianno/en.lproj/MainMenu.xib +++ b/Medianno/en.lproj/MainMenu.xib @@ -293,6 +293,15 @@ + + + Import Tags/Annotations… + a + 1572864 + 2147483647 + + + Export… @@ -1379,6 +1388,14 @@ 595 + + + importText: + + + + 598 + @@ -1477,6 +1494,7 @@ + @@ -2089,6 +2107,11 @@ + + 596 + + + @@ -2187,6 +2210,7 @@ 583.IBPluginDependency 590.IBPluginDependency 593.IBPluginDependency + 596.IBPluginDependency 72.IBPluginDependency 73.IBPluginDependency 74.IBPluginDependency @@ -2304,6 +2328,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -2318,7 +2343,7 @@ - 595 + 598 @@ -2360,6 +2385,7 @@ addMediaFiles: exportMedia: exportText: + importText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -2373,6 +2399,7 @@ id id id + id @@ -2383,6 +2410,7 @@ addMediaFiles: exportMedia: exportText: + importText: mediaSkipBackward: mediaSkipForward: toggleMediaPlay: @@ -2405,6 +2433,10 @@ exportText: id + + importText: + id + mediaSkipBackward: id @@ -2428,6 +2460,7 @@ mediaController mediaTable movieView + textExportAccessoryView YES @@ -2436,6 +2469,7 @@ NSArrayController NSTableView QTMovieView + NSView @@ -2447,6 +2481,7 @@ mediaController mediaTable movieView + textExportAccessoryView YES @@ -2470,6 +2505,10 @@ movieView QTMovieView + + textExportAccessoryView + NSView +