aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-09-15 23:12:32 +0000
committerBibiko <bibiko@eva.mpg.de>2010-09-15 23:12:32 +0000
commitcbb150b07fcb3a96db460a22c4eb5280d8bf9e08 (patch)
treee296d46cf2c2c84e9b2974dd0b2d8ae746467a28
parente9e2c969af896c025fd8daba7612751a8afe096f (diff)
downloadsequelpro-cbb150b07fcb3a96db460a22c4eb5280d8bf9e08.tar.gz
sequelpro-cbb150b07fcb3a96db460a22c4eb5280d8bf9e08.tar.bz2
sequelpro-cbb150b07fcb3a96db460a22c4eb5280d8bf9e08.zip
• further progress on the BIT field sheet editor
-rw-r--r--Source/SPFieldEditorController.h4
-rw-r--r--Source/SPFieldEditorController.m101
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 -