[vlc-commits] macosx: add custom numberformatter to goto time field to only allow digits and :

David Fuhrmann git at videolan.org
Tue Apr 30 23:13:17 CEST 2013


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Tue Apr 30 23:11:06 2013 +0200| [f7a9144dc0d0e5449b14b1333ac7f1fcc1673a76] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f7a9144dc0d0e5449b14b1333ac7f1fcc1673a76
---

 modules/gui/macosx/controls.m |    3 +++
 modules/gui/macosx/misc.h     |   17 +++++++++++++++++
 modules/gui/macosx/misc.m     |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/controls.m
index cab73ba..1a1b4a0 100644
--- a/modules/gui/macosx/controls.m
+++ b/modules/gui/macosx/controls.m
@@ -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
diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h
index 6855c05..4859611 100644
--- a/modules/gui/macosx/misc.h
+++ b/modules/gui/macosx/misc.h
@@ -189,3 +189,20 @@
 @interface VLCThreePartDropView : VLCThreePartImageView
 
 @end
+
+/*****************************************************************************
+ * PositionFormatter interface
+ *
+ * Formats a text field to only accept decimals and :
+ *****************************************************************************/
+ at 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;
+
+ at end
diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index 5fea88d..3a9bfde 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -787,3 +787,38 @@ void _drawFrameInRect(NSRect frameRect)
 }
 
 @end
+
+ at 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;
+    }
+}
+
+
+ at end



More information about the vlc-commits mailing list