diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-09-16 12:09:35 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-09-16 12:09:35 +0000 |
commit | 902695800b7a760c138bc84ae982d5c5b826a437 (patch) | |
tree | 121268fec3959566785809c4e095a3b94fea8c53 /Source/SPFieldEditorController.m | |
parent | 11f9f5a153ca055e4f104dc6494745e1c4f38518 (diff) | |
download | sequelpro-902695800b7a760c138bc84ae982d5c5b826a437.tar.gz sequelpro-902695800b7a760c138bc84ae982d5c5b826a437.tar.bz2 sequelpro-902695800b7a760c138bc84ae982d5c5b826a437.zip |
• BIT Field Sheet Editor now can handle NULL values
• Field Editor Sheet field name label also displays NOT NULL if set
Diffstat (limited to 'Source/SPFieldEditorController.m')
-rw-r--r-- | Source/SPFieldEditorController.m | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index fc3f6eec..b8959ec8 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -46,6 +46,7 @@ stringValue = nil; _isEditable = NO; _isBlob = NO; + _allowNULL = YES; prefs = [NSUserDefaults standardUserDefaults]; @@ -146,6 +147,11 @@ fieldEncoding = aEncoding; } +- (void)setAllowNULL:(BOOL)allowNULL +{ + _allowNULL = allowNULL; +} + - (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)theWindow { @@ -157,12 +163,14 @@ // Set field label NSMutableString *label = [NSMutableString string]; [label appendFormat:@"“%@”", fieldName]; - if([fieldType length] || maxTextLength > 0 || [fieldEncoding length]) + if([fieldType length] || maxTextLength > 0 || [fieldEncoding length] || !_allowNULL) [label appendString:@" – "]; if([fieldType length]) [label appendString:fieldType]; if(maxTextLength > 0) [label appendFormat:@"(%ld) ", maxTextLength]; + if(!_allowNULL) + [label appendString:@"NOT NULL "]; if([fieldEncoding length]) [label appendString:fieldEncoding]; @@ -170,14 +178,25 @@ sheetEditData = [(NSString*)data retain]; + [bitSheetNULLButton setEnabled:_allowNULL]; + + // Check for NULL + if([sheetEditData isEqualToString:[prefs objectForKey:SPNullValue]]) { + [bitSheetNULLButton setState:NSOnState]; + [self setToNull:bitSheetNULLButton]; + } else { + [bitSheetNULLButton setState:NSOffState]; + } + [bitSheetFieldName setStringValue:label]; // Init according bit check boxes NSInteger i = 0; NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength; - for(i=0; i<maxBit; i++) - [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] - setState:([sheetEditData characterAtIndex:(maxBit-i-1)] == '1') ? NSOnState : NSOffState]; + if([bitSheetNULLButton state] == NSOffState) + for(i=0; i<maxBit; i++) + [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] + setState:([sheetEditData characterAtIndex:(maxBit-i-1)] == '1') ? NSOnState : NSOffState]; for(i=maxBit; i<64; i++) [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:NO]; @@ -909,6 +928,20 @@ NSInteger i = 0; NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength; + + if([bitSheetNULLButton state] == NSOnState) { + if ( sheetEditData != nil ) { + [sheetEditData release]; + } + + NSString *nullString = [prefs objectForKey:SPNullValue]; + sheetEditData = [[NSString stringWithString:nullString] retain]; + [bitSheetIntegerTextField setStringValue:nullString]; + [bitSheetHexTextField setStringValue:nullString]; + [bitSheetOctalTextField setStringValue:nullString]; + return; + } + NSMutableString *bitString = [NSMutableString string]; [bitString setString:@""]; for(i=0; i<maxBit; i++) [bitString appendString:@"0"]; @@ -1005,6 +1038,30 @@ [[self window] makeFirstResponder:[self valueForKeyPath:@"bitSheetBitButton0"]]; } +- (IBAction)setToNull:(id)sender +{ + + NSInteger i; + NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength; + + if([sender state] == NSOnState) { + for(i=0; i<maxBit; i++) + [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:NO]; + [bitSheetHexTextField setEnabled:NO]; + [bitSheetIntegerTextField setEnabled:NO]; + [bitSheetOctalTextField setEnabled:NO]; + } else { + for(i=0; i<maxBit; i++) + [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:YES]; + [bitSheetHexTextField setEnabled:YES]; + [bitSheetIntegerTextField setEnabled:YES]; + [bitSheetOctalTextField setEnabled:YES]; + } + + [self updateBitSheet]; + +} + - (IBAction)bitSheetBitButtonWasClicked:(id)sender { |