From 51b094e48b68420cd53be08648eab7b671ce1639 Mon Sep 17 00:00:00 2001 From: avenjamin Date: Fri, 27 Feb 2009 01:37:27 +0000 Subject: Added length limits to varchar and char fields. Issue #170 Ideally we should add these limits for other field types depending on their length value. --- Source/SPDataCellFormatter.h | 4 +++- Source/SPDataCellFormatter.m | 18 ++++++++++++++++++ Source/TableContent.m | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPDataCellFormatter.h b/Source/SPDataCellFormatter.h index aafb1b1c..8784898a 100644 --- a/Source/SPDataCellFormatter.h +++ b/Source/SPDataCellFormatter.h @@ -25,7 +25,9 @@ @interface SPDataCellFormatter : NSFormatter { - + NSUInteger textLimit; } +@property NSUInteger textLimit; + @end diff --git a/Source/SPDataCellFormatter.m b/Source/SPDataCellFormatter.m index c23fccf5..051a7ac6 100644 --- a/Source/SPDataCellFormatter.m +++ b/Source/SPDataCellFormatter.m @@ -26,6 +26,8 @@ @implementation SPDataCellFormatter +@synthesize textLimit; + - (NSString *)stringForObjectValue:(id)anObject { @@ -54,4 +56,20 @@ return [[[NSAttributedString alloc] initWithString:[self stringForObjectValue:anObject] attributes:attributes] autorelease]; } + + +- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error +{ + // No limit set + if (textLimit == 0) + return YES; + + if ([partialString length] > textLimit) { + NSBeep(); + newString = [NSString stringWithCharacters:partialString length:textLimit]; + } + + return ([partialString length] <= textLimit); +} + @end diff --git a/Source/TableContent.m b/Source/TableContent.m index 5876141c..fba8a3ed 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -30,6 +30,7 @@ #import "SPDataCellFormatter.h" #import "SPTableData.h" + @implementation TableContent - (id)init @@ -167,6 +168,11 @@ [dataCell setLineBreakMode:NSLineBreakByTruncatingTail]; [dataCell setFormatter:[[SPDataCellFormatter new] autorelease]]; + // Set field length limit if field is a varchar to match varchar length + if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"]) { + [[dataCell formatter] setTextLimit:[[columnDefinition objectForKey:@"length"] intValue]]; + } + // Set the data cell font according to the preferences if ( [prefs boolForKey:@"useMonospacedFonts"] ) { [dataCell setFont:[NSFont fontWithName:@"Monaco" size:10]]; @@ -1860,6 +1866,15 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn #pragma mark - +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + NSString *fieldType; + int row, column, i; + + row = [tableContentView editedRow]; + column = [tableContentView editedColumn]; +} + /* * Trap the enter and escape keys, overriding default behaviour and continuing/ending editing, * only within the current row. -- cgit v1.2.3