From 902695800b7a760c138bc84ae982d5c5b826a437 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 16 Sep 2010 12:09:35 +0000 Subject: =?UTF-8?q?=E2=80=A2=20BIT=20Field=20Sheet=20Editor=20now=20can=20?= =?UTF-8?q?handle=20NULL=20values=20=E2=80=A2=20Field=20Editor=20Sheet=20f?= =?UTF-8?q?ield=20name=20label=20also=20displays=20NOT=20NULL=20if=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/FieldEditorSheet.xib | 107 +++++++++++++++++++++++--- Source/SPCustomQuery.m | 5 ++ Source/SPFieldEditorController.h | 4 + Source/SPFieldEditorController.m | 65 +++++++++++++++- Source/SPTableContent.m | 5 ++ 5 files changed, 172 insertions(+), 14 deletions(-) diff --git a/Interfaces/English.lproj/FieldEditorSheet.xib b/Interfaces/English.lproj/FieldEditorSheet.xib index 8e440290..cb389882 100644 --- a/Interfaces/English.lproj/FieldEditorSheet.xib +++ b/Interfaces/English.lproj/FieldEditorSheet.xib @@ -12,8 +12,8 @@ YES - + YES @@ -2719,6 +2719,27 @@ 75 + + + 268 + {{337, 66}, {39, 15}} + + 7 + YES + + -2080244224 + 134479872 + NULL + + + -1232846593 + 268435619 + + N + 400 + 75 + + 268 @@ -3872,14 +3893,6 @@ 395 - - - nextKeyView - - - - 396 - nextKeyView @@ -4848,6 +4861,38 @@ 519 + + + bitSheetNULLButton + + + + 524 + + + + nextKeyView + + + + 525 + + + + nextKeyView + + + + 526 + + + + setToNull: + + + + 528 + @@ -5228,6 +5273,7 @@ + @@ -6529,6 +6575,20 @@ + + 520 + + + YES + + + + + + 521 + + + @@ -6757,6 +6817,9 @@ 4.IBPluginDependency 5.IBPluginDependency 5.ImportedFromIB2 + 520.IBAttributePlaceholdersKey + 520.IBPluginDependency + 521.IBPluginDependency 6.IBPluginDependency 6.ImportedFromIB2 7.CustomClassName @@ -7080,6 +7143,16 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Set to NULL (⇧⌘N) + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin SPImageView @@ -7175,7 +7248,7 @@ - 519 + 528 @@ -7588,6 +7661,7 @@ quickLookFormatButton: saveEditSheet: segmentControllerChanged: + setToNull: YES @@ -7601,6 +7675,7 @@ id id id + id @@ -7617,6 +7692,7 @@ quickLookFormatButton: saveEditSheet: segmentControllerChanged: + setToNull: YES @@ -7660,6 +7736,10 @@ segmentControllerChanged: id + + setToNull: + id + @@ -7743,6 +7823,7 @@ bitSheetFieldName bitSheetHexTextField bitSheetIntegerTextField + bitSheetNULLButton bitSheetOctalTextField bitSheetOkButton editImage @@ -7840,6 +7921,7 @@ NSTextField NSTextField NSTextField + NSButton NSTextField NSButton id @@ -7940,6 +8022,7 @@ bitSheetFieldName bitSheetHexTextField bitSheetIntegerTextField + bitSheetNULLButton bitSheetOctalTextField bitSheetOkButton editImage @@ -8268,6 +8351,10 @@ bitSheetIntegerTextField NSTextField + + bitSheetNULLButton + NSButton + bitSheetOctalTextField NSTextField diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 2a805da2..ae1b01c0 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -2262,16 +2262,21 @@ NSString *fieldType = nil; NSUInteger *fieldLength = 0; NSString *fieldEncoding = nil; + BOOL allowNULL = YES; + // Retrieve the column defintion fieldType = [columnDefinition objectForKey:@"type"]; if([columnDefinition objectForKey:@"char_length"]) fieldLength = [[columnDefinition objectForKey:@"char_length"] integerValue]; if([columnDefinition objectForKey:@"charset_name"] && ![[columnDefinition objectForKey:@"charset_name"] isEqualToString:@"binary"]) fieldEncoding = [columnDefinition objectForKey:@"charset_name"]; + if([columnDefinition objectForKey:@"null"]) + allowNULL = (![[columnDefinition objectForKey:@"null"] integerValue]); [fieldEditor setTextMaxLength:fieldLength]; [fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType]; [fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding]; + [fieldEditor setAllowNULL:allowNULL]; id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]]; if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h index ba44469e..7c5c6c9a 100644 --- a/Source/SPFieldEditorController.h +++ b/Source/SPFieldEditorController.h @@ -48,6 +48,7 @@ IBOutlet NSTextField *bitSheetOctalTextField; IBOutlet NSButton *bitSheetOkButton; IBOutlet NSButton *bitSheetCloseButton; + IBOutlet NSButton *bitSheetNULLButton; IBOutlet NSButton *bitSheetBitButton0; IBOutlet NSButton *bitSheetBitButton1; IBOutlet NSButton *bitSheetBitButton2; @@ -125,6 +126,7 @@ BOOL editSheetWillBeInitialized; BOOL _isBlob; BOOL _isEditable; + BOOL _allowNULL; NSInteger quickLookCloseMarker; NSStringEncoding encoding; NSString *fieldType; @@ -161,6 +163,7 @@ - (IBAction)bitSheetSelectBit0:(id)sender; - (IBAction)bitSheetBitButtonWasClicked:(id)sender; - (IBAction)bitSheetOperatorButtonWasClicked:(id)sender; +- (IBAction)setToNull:(id)sender; - (void)updateBitSheet; - (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding @@ -169,6 +172,7 @@ - (void)setTextMaxLength:(unsigned long long)length; - (void)setFieldType:(NSString*)aType; - (void)setFieldEncoding:(NSString*)aEncoding; +- (void)setAllowNULL:(BOOL)allowNULL; - (void)processPasteImageData; - (void)processUpdatedImageData:(NSData *)data; 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 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 64) ? 64 : maxTextLength; + + if([sender state] == NSOnState) { + for(i=0; i