Import Annotations/Tags from Text file
This commit is contained in:
parent
1ffab4eced
commit
7dd5af9737
|
@ -22,6 +22,7 @@
|
||||||
@property BOOL exportTags;
|
@property BOOL exportTags;
|
||||||
|
|
||||||
- (IBAction)addMediaFiles:(id)sender;
|
- (IBAction)addMediaFiles:(id)sender;
|
||||||
|
- (IBAction)importText:(id)sender;
|
||||||
- (IBAction)exportMedia:(id)sender;
|
- (IBAction)exportMedia:(id)sender;
|
||||||
- (IBAction)exportText:(id)sender;
|
- (IBAction)exportText:(id)sender;
|
||||||
- (void)addMedia:(NSArray *)urls;
|
- (void)addMedia:(NSArray *)urls;
|
||||||
|
|
|
@ -203,7 +203,10 @@
|
||||||
|
|
||||||
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
|
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
|
||||||
{
|
{
|
||||||
if ([item action] == @selector(addMedia:))
|
if ([item action] == @selector(addMediaFiles:)
|
||||||
|
|| [item action] == @selector(exportText:)
|
||||||
|
|| [item action] == @selector(importText:)
|
||||||
|
)
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
if ([item action] == @selector(toggleMediaPlay:)) {
|
if ([item action] == @selector(toggleMediaPlay:)) {
|
||||||
|
@ -362,6 +365,58 @@ static NSTimeInterval sLastSkip = 0.0;
|
||||||
[self exportTextToURL:[savePanel URL]];
|
[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<numComp; ++i)
|
||||||
|
[tagDescs addObject:[doc tagDescriptionForName:[components objectAtIndex:i]]];
|
||||||
|
[anno setTagDescriptions:tagDescs];
|
||||||
|
} else {
|
||||||
|
NSString * name = [components objectAtIndex:0];
|
||||||
|
NSString * notes = numComp > 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
|
@end
|
||||||
|
|
||||||
@implementation MADocumentWindow
|
@implementation MADocumentWindow
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying;
|
- (void)addMediaURL:(NSURL *)url name:(NSString *)name date:(NSDate *)date copying:(BOOL)copying;
|
||||||
- (MAAnno *)addAnnotationForMedia:(MAMedia *)media location:(QTTime)location;
|
- (MAAnno *)addAnnotationForMedia:(MAMedia *)media location:(QTTime)location;
|
||||||
- (MATagDescription *)tagDescriptionForName:(NSString *)name;
|
- (MATagDescription *)tagDescriptionForName:(NSString *)name;
|
||||||
|
- (MATagDescription *)tagDescriptionForName:(NSString *)name notes:(NSString *)notes;
|
||||||
- (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix;
|
- (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix;
|
||||||
- (NSSet *)allTags;
|
- (NSSet *)allTags;
|
||||||
|
|
||||||
|
|
|
@ -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
|
- (NSArray *)tagNamesMatchingPrefix:(NSString *)prefix
|
||||||
{
|
{
|
||||||
NSManagedObjectContext *moc = [self managedObjectContext];
|
NSManagedObjectContext *moc = [self managedObjectContext];
|
||||||
|
@ -100,4 +110,12 @@
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSSet *)allTags
|
||||||
|
{
|
||||||
|
NSManagedObjectContext *moc = [self managedObjectContext];
|
||||||
|
NSFetchRequest * fetch = [NSFetchRequest fetchRequestWithEntityName:@"MATagDescription"];
|
||||||
|
|
||||||
|
return [NSSet setWithArray:[moc executeFetchRequest:fetch error:nil]];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -293,6 +293,15 @@
|
||||||
<reference key="NSOnImage" ref="1033313550"/>
|
<reference key="NSOnImage" ref="1033313550"/>
|
||||||
<reference key="NSMixedImage" ref="310636482"/>
|
<reference key="NSMixedImage" ref="310636482"/>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="NSMenuItem" id="627623477">
|
||||||
|
<reference key="NSMenu" ref="720053764"/>
|
||||||
|
<string key="NSTitle">Import Tags/Annotations…</string>
|
||||||
|
<string key="NSKeyEquiv">a</string>
|
||||||
|
<int key="NSKeyEquivModMask">1572864</int>
|
||||||
|
<int key="NSMnemonicLoc">2147483647</int>
|
||||||
|
<reference key="NSOnImage" ref="1033313550"/>
|
||||||
|
<reference key="NSMixedImage" ref="310636482"/>
|
||||||
|
</object>
|
||||||
<object class="NSMenuItem" id="678484874">
|
<object class="NSMenuItem" id="678484874">
|
||||||
<reference key="NSMenu" ref="720053764"/>
|
<reference key="NSMenu" ref="720053764"/>
|
||||||
<string key="NSTitle">Export…</string>
|
<string key="NSTitle">Export…</string>
|
||||||
|
@ -1379,6 +1388,14 @@
|
||||||
</object>
|
</object>
|
||||||
<int key="connectionID">595</int>
|
<int key="connectionID">595</int>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBConnectionRecord">
|
||||||
|
<object class="IBActionConnection" key="connection">
|
||||||
|
<string key="label">importText:</string>
|
||||||
|
<reference key="source" ref="1014"/>
|
||||||
|
<reference key="destination" ref="627623477"/>
|
||||||
|
</object>
|
||||||
|
<int key="connectionID">598</int>
|
||||||
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||||
<object class="NSArray" key="orderedObjects">
|
<object class="NSArray" key="orderedObjects">
|
||||||
|
@ -1477,6 +1494,7 @@
|
||||||
<reference ref="7029338"/>
|
<reference ref="7029338"/>
|
||||||
<reference ref="678484874"/>
|
<reference ref="678484874"/>
|
||||||
<reference ref="995690267"/>
|
<reference ref="995690267"/>
|
||||||
|
<reference ref="627623477"/>
|
||||||
</object>
|
</object>
|
||||||
<reference key="parent" ref="379814623"/>
|
<reference key="parent" ref="379814623"/>
|
||||||
</object>
|
</object>
|
||||||
|
@ -2089,6 +2107,11 @@
|
||||||
<reference key="object" ref="995690267"/>
|
<reference key="object" ref="995690267"/>
|
||||||
<reference key="parent" ref="720053764"/>
|
<reference key="parent" ref="720053764"/>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBObjectRecord">
|
||||||
|
<int key="objectID">596</int>
|
||||||
|
<reference key="object" ref="627623477"/>
|
||||||
|
<reference key="parent" ref="720053764"/>
|
||||||
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||||
|
@ -2187,6 +2210,7 @@
|
||||||
<string>583.IBPluginDependency</string>
|
<string>583.IBPluginDependency</string>
|
||||||
<string>590.IBPluginDependency</string>
|
<string>590.IBPluginDependency</string>
|
||||||
<string>593.IBPluginDependency</string>
|
<string>593.IBPluginDependency</string>
|
||||||
|
<string>596.IBPluginDependency</string>
|
||||||
<string>72.IBPluginDependency</string>
|
<string>72.IBPluginDependency</string>
|
||||||
<string>73.IBPluginDependency</string>
|
<string>73.IBPluginDependency</string>
|
||||||
<string>74.IBPluginDependency</string>
|
<string>74.IBPluginDependency</string>
|
||||||
|
@ -2304,6 +2328,7 @@
|
||||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
|
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||||
|
@ -2318,7 +2343,7 @@
|
||||||
<reference key="dict.values" ref="0"/>
|
<reference key="dict.values" ref="0"/>
|
||||||
</object>
|
</object>
|
||||||
<nil key="sourceID"/>
|
<nil key="sourceID"/>
|
||||||
<int key="maxID">595</int>
|
<int key="maxID">598</int>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||||
|
@ -2360,6 +2385,7 @@
|
||||||
<string>addMediaFiles:</string>
|
<string>addMediaFiles:</string>
|
||||||
<string>exportMedia:</string>
|
<string>exportMedia:</string>
|
||||||
<string>exportText:</string>
|
<string>exportText:</string>
|
||||||
|
<string>importText:</string>
|
||||||
<string>mediaSkipBackward:</string>
|
<string>mediaSkipBackward:</string>
|
||||||
<string>mediaSkipForward:</string>
|
<string>mediaSkipForward:</string>
|
||||||
<string>toggleMediaPlay:</string>
|
<string>toggleMediaPlay:</string>
|
||||||
|
@ -2373,6 +2399,7 @@
|
||||||
<string>id</string>
|
<string>id</string>
|
||||||
<string>id</string>
|
<string>id</string>
|
||||||
<string>id</string>
|
<string>id</string>
|
||||||
|
<string>id</string>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableDictionary" key="actionInfosByName">
|
<object class="NSMutableDictionary" key="actionInfosByName">
|
||||||
|
@ -2383,6 +2410,7 @@
|
||||||
<string>addMediaFiles:</string>
|
<string>addMediaFiles:</string>
|
||||||
<string>exportMedia:</string>
|
<string>exportMedia:</string>
|
||||||
<string>exportText:</string>
|
<string>exportText:</string>
|
||||||
|
<string>importText:</string>
|
||||||
<string>mediaSkipBackward:</string>
|
<string>mediaSkipBackward:</string>
|
||||||
<string>mediaSkipForward:</string>
|
<string>mediaSkipForward:</string>
|
||||||
<string>toggleMediaPlay:</string>
|
<string>toggleMediaPlay:</string>
|
||||||
|
@ -2405,6 +2433,10 @@
|
||||||
<string key="name">exportText:</string>
|
<string key="name">exportText:</string>
|
||||||
<string key="candidateClassName">id</string>
|
<string key="candidateClassName">id</string>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBActionInfo">
|
||||||
|
<string key="name">importText:</string>
|
||||||
|
<string key="candidateClassName">id</string>
|
||||||
|
</object>
|
||||||
<object class="IBActionInfo">
|
<object class="IBActionInfo">
|
||||||
<string key="name">mediaSkipBackward:</string>
|
<string key="name">mediaSkipBackward:</string>
|
||||||
<string key="candidateClassName">id</string>
|
<string key="candidateClassName">id</string>
|
||||||
|
@ -2428,6 +2460,7 @@
|
||||||
<string>mediaController</string>
|
<string>mediaController</string>
|
||||||
<string>mediaTable</string>
|
<string>mediaTable</string>
|
||||||
<string>movieView</string>
|
<string>movieView</string>
|
||||||
|
<string>textExportAccessoryView</string>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableArray" key="dict.values">
|
<object class="NSMutableArray" key="dict.values">
|
||||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||||
|
@ -2436,6 +2469,7 @@
|
||||||
<string>NSArrayController</string>
|
<string>NSArrayController</string>
|
||||||
<string>NSTableView</string>
|
<string>NSTableView</string>
|
||||||
<string>QTMovieView</string>
|
<string>QTMovieView</string>
|
||||||
|
<string>NSView</string>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
||||||
|
@ -2447,6 +2481,7 @@
|
||||||
<string>mediaController</string>
|
<string>mediaController</string>
|
||||||
<string>mediaTable</string>
|
<string>mediaTable</string>
|
||||||
<string>movieView</string>
|
<string>movieView</string>
|
||||||
|
<string>textExportAccessoryView</string>
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMutableArray" key="dict.values">
|
<object class="NSMutableArray" key="dict.values">
|
||||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||||
|
@ -2470,6 +2505,10 @@
|
||||||
<string key="name">movieView</string>
|
<string key="name">movieView</string>
|
||||||
<string key="candidateClassName">QTMovieView</string>
|
<string key="candidateClassName">QTMovieView</string>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="IBToOneOutletInfo">
|
||||||
|
<string key="name">textExportAccessoryView</string>
|
||||||
|
<string key="candidateClassName">NSView</string>
|
||||||
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user