summaryrefslogtreecommitdiffstats
path: root/macosx/HBPreferencesController.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2014-07-11 18:22:43 +0000
committerritsuka <[email protected]>2014-07-11 18:22:43 +0000
commit70f4a8751ea04c69095025394adecff6a2c8edea (patch)
tree58531bf3ae09e2d508b0f85494b8e6fca9b0ed3f /macosx/HBPreferencesController.m
parent2412d4a92123b2f20b43987a65a4fbd645be1443 (diff)
MacGUI: Expanded the auto name feature to make it as powerful as the WinGUI counterpart.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6228 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBPreferencesController.m')
-rw-r--r--macosx/HBPreferencesController.m81
1 files changed, 78 insertions, 3 deletions
diff --git a/macosx/HBPreferencesController.m b/macosx/HBPreferencesController.m
index 544387dee..47bd36113 100644
--- a/macosx/HBPreferencesController.m
+++ b/macosx/HBPreferencesController.m
@@ -20,13 +20,18 @@
* preference settings are added that cannot be handled with Cocoa bindings).
*/
-@interface HBPreferencesController (Private)
+@interface HBPreferencesController () <NSTokenFieldDelegate>
- (void) setPrefView: (id) sender;
- (NSToolbarItem *)toolbarItemWithIdentifier: (NSString *)identifier
label: (NSString *)label
image: (NSImage *)image;
+@property (assign) IBOutlet NSTokenField *formatTokenField;
+@property (assign) IBOutlet NSTokenField *builtInTokenField;
+@property (readonly, nonatomic) NSArray *buildInFormatTokens;
+@property (retain, nonatomic) NSArray *matches;
+
@end
@implementation HBPreferencesController
@@ -64,6 +69,8 @@
@"YES", @"AlertBuiltInPresetUpdate",
@"MetaX", @"SendCompletedEncodeToApp",
@"NO", @"ShowAdvancedOptsForAutoPassthru",
+
+ @[@"{Source}", @" ", @"{Title}"], @"HBAutoNamingFormat",
nil]];
}
@@ -98,6 +105,14 @@
[toolbar setSizeMode: NSToolbarSizeModeRegular];
[[self window] setToolbar: toolbar];
+ // Format token field initialization
+ [self.formatTokenField setTokenizingCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"%%"]];
+ [self.formatTokenField setCompletionDelay:0.2];
+
+ _buildInFormatTokens = [@[@"{Source}", @"{Title}", @"{Date}", @"{Time}", @"{Chapters}", @"{Quality/Bitrate}"] retain];
+ [self.builtInTokenField setTokenizingCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"%%"]];
+ [self.builtInTokenField setStringValue:[self.buildInFormatTokens componentsJoinedByString:@"%%"]];
+
[toolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
[self setPrefView:nil];
}
@@ -192,10 +207,70 @@
}
}
+#pragma mark - Format Token Field Delegate
+
+- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject
+{
+ if ([representedObject rangeOfString: @"{"].location == 0)
+ {
+ return [(NSString *)representedObject substringWithRange:NSMakeRange(1, [(NSString*)representedObject length]-2)];
+ }
+
+ return representedObject;
+}
+
+- (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject
+{
+ if ([representedObject rangeOfString: @"{"].location == 0)
+ {
+ return NSRoundedTokenStyle;
+ }
+ else
+ {
+ return NSPlainTextTokenStyle;
+ }
+}
+
+- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString
+{
+ return editingString;
+}
+
+- (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex
+ indexOfSelectedItem:(NSInteger *)selectedIndex
+{
+ self.matches = [self.buildInFormatTokens filteredArrayUsingPredicate:
+ [NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@", substring]];
+ return self.matches;
+}
+
+- (NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject
+{
+ if ([representedObject rangeOfString: @"{"].location == 0)
+ {
+ return [NSString stringWithFormat:@"%%%@%%", representedObject];
+ }
+ else
+ {
+ return representedObject;
+ }
+}
+
+- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index
+{
+ return tokens;
+}
+
+- (BOOL)tokenField:(NSTokenField *)tokenField writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard
+{
+ NSString *format = [objects componentsJoinedByString:@"%%"];
+ [pboard setString:format forType:NSPasteboardTypeString];
+
+ return YES;
+}
-@end
-@implementation HBPreferencesController (Private)
+#pragma mark - Private methods
- (void) setPrefView: (id) sender
{