aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/FieldEditorSheet.xib38
-rw-r--r--Source/SPFieldEditorController.m192
2 files changed, 160 insertions, 70 deletions
diff --git a/Interfaces/English.lproj/FieldEditorSheet.xib b/Interfaces/English.lproj/FieldEditorSheet.xib
index 07dcbe45..8e440290 100644
--- a/Interfaces/English.lproj/FieldEditorSheet.xib
+++ b/Interfaces/English.lproj/FieldEditorSheet.xib
@@ -13,7 +13,7 @@
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="2"/>
- <integer value="80"/>
+ <integer value="81"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -2241,7 +2241,7 @@
<object class="NSTextField" id="972404924">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">266</int>
- <string key="NSFrame">{{19, 104}, {82, 14}}</string>
+ <string key="NSFrame">{{5, 104}, {90, 14}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="48849739">
@@ -2257,7 +2257,7 @@
<object class="NSTextField" id="875052373">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">266</int>
- <string key="NSFrame">{{20, 85}, {82, 14}}</string>
+ <string key="NSFrame">{{5, 85}, {91, 14}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="339711087">
@@ -2273,12 +2273,12 @@
<object class="NSTextField" id="737055137">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{106, 102}, {96, 16}}</string>
+ <string key="NSFrame">{{96, 102}, {138, 16}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="838692428">
<int key="NSCellFlags">-1804468671</int>
- <int key="NSCellFlags2">272892928</int>
+ <int key="NSCellFlags2">71566336</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="22"/>
<reference key="NSControlView" ref="737055137"/>
@@ -2295,12 +2295,12 @@
<object class="NSTextField" id="1069681827">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{106, 84}, {96, 16}}</string>
+ <string key="NSFrame">{{96, 84}, {138, 16}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="578793622">
- <int key="NSCellFlags">-1804468671</int>
- <int key="NSCellFlags2">272892928</int>
+ <int key="NSCellFlags">-1803944383</int>
+ <int key="NSCellFlags2">71566336</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="22"/>
<reference key="NSControlView" ref="1069681827"/>
@@ -2312,7 +2312,7 @@
<object class="NSTextField" id="586956008">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">266</int>
- <string key="NSFrame">{{20, 67}, {82, 14}}</string>
+ <string key="NSFrame">{{5, 67}, {91, 14}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="1016233566">
@@ -2328,12 +2328,12 @@
<object class="NSTextField" id="818873877">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{106, 66}, {96, 16}}</string>
+ <string key="NSFrame">{{96, 66}, {138, 16}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="683860128">
- <int key="NSCellFlags">-1804468671</int>
- <int key="NSCellFlags2">272892928</int>
+ <int key="NSCellFlags">-2075001280</int>
+ <int key="NSCellFlags2">71566336</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="22"/>
<reference key="NSControlView" ref="818873877"/>
@@ -2597,7 +2597,7 @@
<object class="NSButton" id="912777084">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{230, 103}, {39, 15}}</string>
+ <string key="NSFrame">{{245, 103}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="421399648">
@@ -2617,7 +2617,7 @@
<object class="NSButton" id="317620485">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{322, 103}, {39, 15}}</string>
+ <string key="NSFrame">{{337, 103}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">4</int>
<bool key="NSEnabled">YES</bool>
@@ -2638,7 +2638,7 @@
<object class="NSButton" id="496168724">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{276, 103}, {39, 15}}</string>
+ <string key="NSFrame">{{291, 103}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">3</int>
<bool key="NSEnabled">YES</bool>
@@ -2659,7 +2659,7 @@
<object class="NSButton" id="293046073">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{230, 85}, {39, 15}}</string>
+ <string key="NSFrame">{{245, 85}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">1</int>
<bool key="NSEnabled">YES</bool>
@@ -2680,7 +2680,7 @@
<object class="NSButton" id="45609934">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{230, 67}, {39, 15}}</string>
+ <string key="NSFrame">{{245, 67}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">2</int>
<bool key="NSEnabled">YES</bool>
@@ -2701,7 +2701,7 @@
<object class="NSButton" id="817754450">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{322, 85}, {39, 15}}</string>
+ <string key="NSFrame">{{337, 85}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">6</int>
<bool key="NSEnabled">YES</bool>
@@ -2722,7 +2722,7 @@
<object class="NSButton" id="557422946">
<reference key="NSNextResponder" ref="539487490"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{276, 85}, {39, 15}}</string>
+ <string key="NSFrame">{{291, 85}, {39, 15}}</string>
<reference key="NSSuperview" ref="539487490"/>
<int key="NSTag">5</int>
<bool key="NSEnabled">YES</bool>
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index fe3ae80f..fc3f6eec 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -154,18 +154,35 @@
_isEditable = isEditable;
- if(NO && [fieldType length] && [fieldType isEqualToString:@"BIT"]) {
+ // Set field label
+ NSMutableString *label = [NSMutableString string];
+ [label appendFormat:@"“%@”", fieldName];
+ if([fieldType length] || maxTextLength > 0 || [fieldEncoding length])
+ [label appendString:@" – "];
+ if([fieldType length])
+ [label appendString:fieldType];
+ if(maxTextLength > 0)
+ [label appendFormat:@"(%ld) ", maxTextLength];
+ if([fieldEncoding length])
+ [label appendString:fieldEncoding];
+
+ if([fieldType length] && [fieldType isEqualToString:@"BIT"]) {
sheetEditData = [(NSString*)data retain];
+ [bitSheetFieldName setStringValue:label];
+
+ // Init according bit check boxes
NSInteger i = 0;
- NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength;
+ 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];
for(i=maxBit; i<64; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setEnabled:NO];
+ [self updateBitSheet];
+
usedSheet = bitSheet;
[NSApp beginSheet:usedSheet modalForWindow:theWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
@@ -186,18 +203,6 @@
[hexTextView setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]];
- // Set field label
- NSMutableString *label = [NSMutableString string];
- [label appendFormat:@"“%@”", fieldName];
- if([fieldType length] || maxTextLength > 0 || [fieldEncoding length])
- [label appendString:@" – "];
- if([fieldType length])
- [label appendString:fieldType];
- if(maxTextLength > 0)
- [label appendFormat:@"(%ld) ", maxTextLength];
- if([fieldEncoding length])
- [label appendString:fieldEncoding];
-
[editSheetFieldName setStringValue:[NSString stringWithFormat:@"%@: %@%", NSLocalizedString(@"Field", @"Field"), label]];
// hide all views in editSheet
@@ -902,19 +907,25 @@
- (void)updateBitSheet
{
NSInteger i = 0;
- NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength;
+ NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
NSMutableString *bitString = [NSMutableString string];
[bitString setString:@""];
+ for(i=0; i<maxBit; i++) [bitString appendString:@"0"];
+
+ NSUInteger intValue = 0;
+ NSUInteger bitValue = 0x1;
for(i=0; i<maxBit; i++) {
if([[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] state] == NSOnState) {
- [bitString appendString:@"1"];
- } else {
- [bitString appendString:@"0"];
+ intValue += bitValue;
+ [bitString replaceCharactersInRange:NSMakeRange(maxTextLength-i-1, 1) withString:@"1"];
}
+ bitValue <<= 1;
}
-
+ [bitSheetIntegerTextField setStringValue:[[NSNumber numberWithUnsignedLongLong:intValue] stringValue]];
+ [bitSheetHexTextField setStringValue:[NSString stringWithFormat:@"%qX", intValue]];
+ [bitSheetOctalTextField setStringValue:[NSString stringWithFormat:@"%jO", intValue]];
// free old data
if ( sheetEditData != nil ) {
[sheetEditData release];
@@ -943,46 +954,123 @@
{
NSInteger i = 0;
- NSInteger maxBit = (maxTextLength > 63) ? 63 : maxTextLength;
+ NSInteger aBit;
+ NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
switch([sender tag]) {
- case 0:
+ case 0: // all to 1
for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOnState];
break;
- case 1:
+ case 1: // all to 0
for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOffState];
break;
+ case 2: // negate
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:![[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] state]];
+ break;
+ case 3: // shift left
+ for(i=maxBit-1; i>0; i--) {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i-1]] state]];
+ }
+ [[self valueForKeyPath:@"bitSheetBitButton0"] setState:NSOffState];
+ break;
+ case 4: // shift right
+ for(i=0; i<maxBit-1; i++) {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i+1]] state]];
+ }
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", maxBit-1]] setState:NSOffState];
+ break;
+ case 5: // rotate left
+ aBit = [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", maxBit-1]] state];
+ for(i=maxBit-1; i>0; i--) {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i-1]] state]];
+ }
+ [[self valueForKeyPath:@"bitSheetBitButton0"] setState:aBit];
+ break;
+ case 6: // rotate right
+ aBit = [[self valueForKeyPath:@"bitSheetBitButton0"] state];
+ for(i=0; i<maxBit-1; i++) {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i+1]] state]];
+ }
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", maxBit-1]] setState:aBit];
+ break;
}
[self updateBitSheet];
}
- (IBAction)bitSheetSelectBit0:(id)sender
{
-
+ [[self window] makeFirstResponder:[self valueForKeyPath:@"bitSheetBitButton0"]];
}
- (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];
+ [self updateBitSheet];
}
#pragma mark -
#pragma mark Delegates
+/**
+ * Performs interface validation for various controls.
+ */
+- (void)controlTextDidChange:(NSNotification *)notification
+{
+ id object = [notification object];
+
+ if (object == bitSheetIntegerTextField) {
+
+ NSInteger i = 0;
+ NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
+
+ NSUInteger intValue = strtoull([[bitSheetIntegerTextField stringValue] UTF8String], NULL, 0);
+
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOffState];
+
+ [bitSheetHexTextField setStringValue:[NSString stringWithFormat:@"%qX", intValue]];
+ [bitSheetOctalTextField setStringValue:[NSString stringWithFormat:@"%jO", intValue]];
+
+ i = 0;
+ while( intValue && i < maxBit )
+ {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
+ intValue >>= 1;
+ i++;
+ }
+ [self updateBitSheet];
+ }
+ else if (object == bitSheetHexTextField) {
+
+ NSInteger i = 0;
+ NSInteger maxBit = (maxTextLength > 64) ? 64 : maxTextLength;
+
+ NSUInteger intValue;
+
+ [[NSScanner scannerWithString:[bitSheetHexTextField stringValue]] scanHexLongLong: &intValue];
+
+ for(i=0; i<maxBit; i++)
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:NSOffState];
+
+ [bitSheetHexTextField setStringValue:[NSString stringWithFormat:@"%qX", intValue]];
+ [bitSheetOctalTextField setStringValue:[NSString stringWithFormat:@"%jO", intValue]];
+
+ i = 0;
+ while( intValue && i < maxBit )
+ {
+ [[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
+ intValue >>= 1;
+ i++;
+ }
+ [self updateBitSheet];
+ }
+
+}
+
/*
Validate editTextView for max text length except for NULL value string
*/
@@ -1053,26 +1141,28 @@
- (void)textViewDidChangeSelection:(NSNotification *)notification
{
- // Do nothing if user really didn't changed text (e.g. for font size changing return)
- if(!editTextViewWasChanged && (editSheetWillBeInitialized
- || (([[[notification object] textStorage] editedRange].length == 0)
- && ([[[notification object] textStorage] changeInLength] == 0)))) {
- // Inform the undo-grouping about the caret movement
- selectionChanged = YES;
- return;
- }
+ if([notification object] == editTextView) {
+ // Do nothing if user really didn't changed text (e.g. for font size changing return)
+ if(!editTextViewWasChanged && (editSheetWillBeInitialized
+ || (([[[notification object] textStorage] editedRange].length == 0)
+ && ([[[notification object] textStorage] changeInLength] == 0)))) {
+ // Inform the undo-grouping about the caret movement
+ selectionChanged = YES;
+ return;
+ }
- // clear the image and hex (since i doubt someone can "type" a gif)
- [editImage setImage:nil];
- [hexTextView setString:@""];
+ // clear the image and hex (since i doubt someone can "type" a gif)
+ [editImage setImage:nil];
+ [hexTextView setString:@""];
- // free old data
- if ( sheetEditData != nil ) {
- [sheetEditData release];
- }
+ // free old data
+ if ( sheetEditData != nil ) {
+ [sheetEditData release];
+ }
- // set edit data to text
- sheetEditData = [[NSString stringWithString:[editTextView string]] retain];
+ // set edit data to text
+ sheetEditData = [[NSString stringWithString:[editTextView string]] retain];
+ }
}