Commit f7a9144d authored by David Fuhrmann's avatar David Fuhrmann

macosx: add custom numberformatter to goto time field to only allow digits and :

This fixes wrong default formatting (with thousand separator) which
subsequently failed to parse the value correctly.
parent d1365819
......@@ -37,6 +37,7 @@
#import "playlist.h"
#import "MainMenu.h"
#import "CoreInteraction.h"
#import "misc.h"
#import <vlc_keys.h>
#pragma mark -
......@@ -54,6 +55,8 @@
[o_specificTime_ok_btn setTitle: _NS("OK")];
[o_specificTime_sec_lbl setStringValue: _NS("sec.")];
[o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
[o_specificTime_enter_fld setFormatter:[[[PositionFormatter alloc] init] autorelease]];
}
- (void)dealloc
......
......@@ -189,3 +189,20 @@
@interface VLCThreePartDropView : VLCThreePartImageView
@end
/*****************************************************************************
* PositionFormatter interface
*
* Formats a text field to only accept decimals and :
*****************************************************************************/
@interface PositionFormatter : NSFormatter
{
NSCharacterSet *o_forbidden_characters;
}
- (NSString*)stringForObjectValue:(id)obj;
- (BOOL)getObjectValue:(id*)obj forString:(NSString*)string errorDescription:(NSString**)error;
- (bool)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error;
@end
......@@ -786,4 +786,39 @@ void _drawFrameInRect(NSRect frameRect)
[self setNeedsDisplay:YES];
}
@end
@implementation PositionFormatter
- (id)init
{
self = [super init];
NSMutableCharacterSet *nonNumbers = [[[NSCharacterSet decimalDigitCharacterSet] invertedSet] mutableCopy];
[nonNumbers removeCharactersInString:@":"];
o_forbidden_characters = [nonNumbers copy];
return self;
}
- (NSString*)stringForObjectValue:(id)obj
{
return obj;
}
- (BOOL)getObjectValue:(id*)obj forString:(NSString*)string errorDescription:(NSString**)error
{
*obj = [[string copy] autorelease];
return YES;
}
- (bool)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
{
if ([partialString rangeOfCharacterFromSet:o_forbidden_characters options:NSLiteralSearch].location != NSNotFound) {
return NO;
} else {
return YES;
}
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment