diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-08-10 16:38:54 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-08-10 16:38:54 +0000 |
commit | 2c7f2098004f5fe90189c536affc73dfe67393e9 (patch) | |
tree | 0e9c2de229d366c07311a536249757696a138423 /Source/SPFieldEditorController.m | |
parent | f083576763c6c97b03943e335a6948411e7214ef (diff) | |
download | sequelpro-2c7f2098004f5fe90189c536affc73dfe67393e9.tar.gz sequelpro-2c7f2098004f5fe90189c536affc73dfe67393e9.tar.bz2 sequelpro-2c7f2098004f5fe90189c536affc73dfe67393e9.zip |
• added to the FieldEditorSheet a max text length validation
• added the max text length validation for the TableContent while editing in the FieldEditorSheet
• reinvoked the validation of the max text length for TableContent editing while editing in a cell
• fixed in TableContent: prevent the editing of data cells in gray if the cell displays the gray NULL value
Diffstat (limited to 'Source/SPFieldEditorController.m')
-rw-r--r-- | Source/SPFieldEditorController.m | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 7b05c5fa..230a3861 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -28,6 +28,7 @@ #import "SPTextViewAdditions.h" #import "SPDataAdditions.h" #import "QLPreviewPanel.h" +#import "SPDataCellFormatter.h" @implementation SPFieldEditorController @@ -37,6 +38,7 @@ // force the nib to be loaded (void) [self window]; counter = 0; + maxTextLength = 0; // Allow the user to enter cmd+return to close the edit sheet in addition to fn+return [editSheetOkButton setKeyEquivalentModifierMask:NSCommandKeyMask]; @@ -51,6 +53,11 @@ [super dealloc]; } +- (void)setTextMaxLength:(unsigned long long)length +{ + maxTextLength = length; +} + - (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)tableWindow { @@ -594,12 +601,51 @@ } } +#pragma mark - +#pragma mark Delegates + +/* + Validate editTextView for max text length + */ +- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)r replacementString:(NSString *)replacementString +{ + if(textView == editTextView && maxTextLength > 0) { + + int newLength; + + // Pure attribute changes are ok. + if (!replacementString) return YES; + + // The exact change isn't known. Disallow the change to be safe. + if (r.location==NSNotFound) return NO; + + // Calculate the length of the text after the change. + newLength=[[textView textStorage] length]+[replacementString length]-r.length; + + // If it's too long, disallow the change. + // If the user pastes something into insert it partially to maxTextLength. + if (newLength>maxTextLength) { + + if(maxTextLength-[[textView textStorage] length] < [replacementString length]) { + [textView insertText:[replacementString substringToIndex:maxTextLength-[[textView textStorage] length]]]; + } + NSBeep(); + return NO; + } + + // Otherwise, allow it. + return YES; + + } + return YES; +} + /* invoked when the user changes the string in the editSheet */ - (void)textViewDidChangeSelection:(NSNotification *)notification { - + // Do nothing if user really didn't changed text (e.g. for font size changing return) if(editSheetWillBeInitialized || ([[[notification object] textStorage] changeInLength]==0)) return; |