diff options
author | avenjamin <avenjamin@gmail.com> | 2009-02-27 01:37:27 +0000 |
---|---|---|
committer | avenjamin <avenjamin@gmail.com> | 2009-02-27 01:37:27 +0000 |
commit | 51b094e48b68420cd53be08648eab7b671ce1639 (patch) | |
tree | 6df11a0bbc1a8528ba43ad05d6f6533e6b37fb7a /Source | |
parent | 10a7c5a32983070158a736e479b2c6200ecd70fd (diff) | |
download | sequelpro-51b094e48b68420cd53be08648eab7b671ce1639.tar.gz sequelpro-51b094e48b68420cd53be08648eab7b671ce1639.tar.bz2 sequelpro-51b094e48b68420cd53be08648eab7b671ce1639.zip |
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.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPDataCellFormatter.h | 4 | ||||
-rw-r--r-- | Source/SPDataCellFormatter.m | 18 | ||||
-rw-r--r-- | Source/TableContent.m | 15 |
3 files changed, 36 insertions, 1 deletions
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. |