aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPDataCellFormatter.h4
-rw-r--r--Source/SPDataCellFormatter.m18
-rw-r--r--Source/TableContent.m15
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.