Hi,
Here is a patch to fix NSSearchFieldCell archiving and keyed archiving.
Non-keyed archiving was crashing because _max_recents ivar was declared as
an unsigned char and encoded/decoded as an unsigned int. Keyed archiving was
not crashing because keyed decoding was not implemented. The patch adds
keyed encoding to -encodeWithCoder:.
In a nib (a xib precisely), NSMaximumRecents is encoded as an int, so I
switched to int as the encoded type (rather than unsigned int).
I also changed the ivar from unsigned char to int to keep the
encoding/decoding as simple as possible. I doubt any application has more
than 4 or 5 search fields in use at the same time so it doesn't seem worth
to save some memory.
Cheers,
Quentin.
Index: Headers/AppKit/NSSearchFieldCell.h
===================================================================
--- Headers/AppKit/NSSearchFieldCell.h (revision 28600)
+++ Headers/AppKit/NSSearchFieldCell.h (working copy)
@@ -52,7 +52,7 @@
NSMenu *_menu_template;
BOOL _sends_whole_search_string;
BOOL _sends_search_string_immediatly;
- unsigned char _max_recents;
+ int _max_recents;
}
// Managing button cells
Index: Source/NSSearchFieldCell.m
===================================================================
--- Source/NSSearchFieldCell.m (revision 28600)
+++ Source/NSSearchFieldCell.m (working copy)
@@ -443,35 +443,56 @@
[self searchButtonRectForBounds: [_control_view bounds]]
inView: _control_view];
}
+
//
// NSCoding protocol
//
+
+
+static NSString *NSSearchButtonCell = @"NSSearchButtonCell";
+static NSString *NSCancelButtonCell = @"NSCancelButtonCell";
+static NSString *NSRecentsAutosaveName = @"NSRecentsAutosaveName";
+static NSString *NSSendsWholeSearchString = @"NSSendsWholeSearchString";
+static NSString *NSMaximumRecents = @"NSMaximumRecents";
+
+
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
- [aCoder encodeObject: _search_button_cell];
- [aCoder encodeObject: _cancel_button_cell];
- [aCoder encodeObject: _recents_autosave_name];
- [aCoder encodeValueOfObjCType: @encode(BOOL)
- at: &_sends_whole_search_string];
- [aCoder encodeValueOfObjCType: @encode(unsigned int)
- at: &_max_recents];
+ if ([aCoder allowsKeyedCoding])
+ {
+ [aCoder encodeObject: _search_button_cell forKey: NSSearchButtonCell];
+ [aCoder encodeObject: _cancel_button_cell forKey: NSCancelButtonCell];
+ [aCoder encodeObject: _recents_autosave_name forKey: NSRecentsAutosaveName];
+ [aCoder encodeBool: _sends_whole_search_string forKey: NSSendsWholeSearchString];
+ [aCoder encodeInt: _max_recents forKey: NSMaximumRecents];
+ }
+ else
+ {
+ [aCoder encodeObject: _search_button_cell];
+ [aCoder encodeObject: _cancel_button_cell];
+ [aCoder encodeObject: _recents_autosave_name];
+ [aCoder encodeValueOfObjCType: @encode(BOOL)
+ at: &_sends_whole_search_string];
+ [aCoder encodeValueOfObjCType: @encode(int)
+ at: &_max_recents];
+ }
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
self = [super initWithCoder: aDecoder];
- if(self != nil)
+ if (self != nil)
{
if ([aDecoder allowsKeyedCoding])
{
- [self setSearchButtonCell: [aDecoder decodeObjectForKey: @"NSSearchButtonCell"]];
- [self setCancelButtonCell: [aDecoder decodeObjectForKey: @"NSCancelButtonCell"]];
- [self setRecentsAutosaveName: [aDecoder decodeObjectForKey: @"NSRecentsAutosaveName"]];
- [self setSendsWholeSearchString: [aDecoder decodeBoolForKey: @"NSSendsWholeSearchString"]];
- [self setMaximumRecents: [aDecoder decodeIntForKey: @"NSMaximumRecents"]];
+ [self setSearchButtonCell: [aDecoder decodeObjectForKey: NSSearchButtonCell]];
+ [self setCancelButtonCell: [aDecoder decodeObjectForKey: NSCancelButtonCell]];
+ [self setRecentsAutosaveName: [aDecoder decodeObjectForKey: NSRecentsAutosaveName]];
+ [self setSendsWholeSearchString: [aDecoder decodeBoolForKey: NSSendsWholeSearchString]];
+ [self setMaximumRecents: [aDecoder decodeIntForKey: NSMaximumRecents]];
}
else
{
@@ -479,7 +500,7 @@
[self setCancelButtonCell: [aDecoder decodeObject]];
[self setRecentsAutosaveName: [aDecoder decodeObject]];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_sends_whole_search_string];
- [aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &_max_recents];
+ [aDecoder decodeValueOfObjCType: @encode(int) at: &_max_recents];
}
[self resetCancelButtonCell];
_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev