diff options
-rw-r--r-- | Source/SPFieldEditorController.h | 4 | ||||
-rw-r--r-- | Source/SPFieldEditorController.m | 101 |
2 files changed, 82 insertions, 23 deletions
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h index e3877a2d..ba44469e 100644 --- a/Source/SPFieldEditorController.h +++ b/Source/SPFieldEditorController.h @@ -140,8 +140,6 @@ BOOL wasCutPaste; BOOL selectionChanged; - NSArray *bitSheetBitButtonsArray; - NSUserDefaults *prefs; NSDictionary *qlTypes; @@ -163,7 +161,7 @@ - (IBAction)bitSheetSelectBit0:(id)sender; - (IBAction)bitSheetBitButtonWasClicked:(id)sender; - (IBAction)bitSheetOperatorButtonWasClicked:(id)sender; - +- (void)updateBitSheet; - (id)editWithObject:(id)data fieldName:(NSString*)fieldName usingEncoding:(NSStringEncoding)anEncoding isObjectBlob:(BOOL)isFieldBlob isEditable:(BOOL)isEditable withWindow:(NSWindow *)theWindow; diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index fa3029e1..fe3ae80f 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -109,7 +109,6 @@ qlTypes = [NSDictionary dictionaryWithObject:qlTypesItems forKey:SPQuickLookTypes]; [qlTypesItems release]; - bitSheetBitButtonsArray = nil; fieldType = @""; fieldEncoding = @""; @@ -157,6 +156,16 @@ if(NO && [fieldType length] && [fieldType isEqualToString:@"BIT"]) { + sheetEditData = [(NSString*)data retain]; + + NSInteger i = 0; + NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength; + 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]; + usedSheet = bitSheet; [NSApp beginSheet:usedSheet modalForWindow:theWindow modalDelegate:self didEndSelector:nil contextInfo:nil]; @@ -398,25 +407,6 @@ wasCutPaste = YES; } -- (IBAction)closeBitSheet:(id)sender -{ - - editSheetReturnCode = 0; - - if(sender == bitSheetOkButton && _isEditable) { - [NSApp stopModal]; - editSheetReturnCode = 1; - } - - [NSApp abortModal]; - -} - -- (IBAction)bitSheetOperatorButtonWasClicked:(id)sender -{ - -} - - (IBAction)closeEditSheet:(id)sender { @@ -909,6 +899,65 @@ #pragma mark - #pragma mark BIT Field Sheet +- (void)updateBitSheet +{ + NSInteger i = 0; + NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength; + + NSMutableString *bitString = [NSMutableString string]; + [bitString setString:@""]; + + for(i=0; i<maxBit; i++) { + if([[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] state] == NSOnState) { + [bitString appendString:@"1"]; + } else { + [bitString appendString:@"0"]; + } + } + + // free old data + if ( sheetEditData != nil ) { + [sheetEditData release]; + } + + // set edit data to text + sheetEditData = [[NSString stringWithString:bitString] retain]; + +} + +- (IBAction)closeBitSheet:(id)sender +{ + + editSheetReturnCode = 0; + + if(sender == bitSheetOkButton && _isEditable) { + [NSApp stopModal]; + editSheetReturnCode = 1; + } + + [NSApp abortModal]; + +} + +- (IBAction)bitSheetOperatorButtonWasClicked:(id)sender +{ + + NSInteger i = 0; + NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength; + + switch([sender tag]) { + case 0: + for(i=0; i<maxBit; i++) + [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOnState]; + break; + case 1: + for(i=0; i<maxBit; i++) + [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOffState]; + break; + } + [self updateBitSheet]; +} + - (IBAction)bitSheetSelectBit0:(id)sender { @@ -917,6 +966,18 @@ - (IBAction)bitSheetBitButtonWasClicked:(id)sender { + NSMutableString *bitString = [NSMutableString string]; + [bitString setString:sheetEditData]; + [bitString replaceCharactersInRange:NSMakeRange(maxTextLength-[sender tag]-1,1) withString:([sender state] == NSOnState) ? @"1" : @"0"]; + + // free old data + if ( sheetEditData != nil ) { + [sheetEditData release]; + } + + // set edit data to text + sheetEditData = [[NSString stringWithString:bitString] retain]; + } #pragma mark - |