Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with non-keyed encoding/decoding of NSPopUpButton #322

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions Source/NSPopUpButtonCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,10 @@ - (NSImage *) _currentArrowImage
return nil;
}

NSLog(@"Arrow position = %d", [self arrowPosition]);
if (_pbcFlags.preferredEdge == NSMaxYEdge)
{
NSLog(@"\tDOWN ARROW!!!!!! %d", [self arrowPosition]);
return _pbc_image[1];
}
else if (_pbcFlags.preferredEdge == NSMaxXEdge)
Expand Down Expand Up @@ -653,7 +655,6 @@ - (void) setMenuItem: (NSMenuItem *)item
[_menuItem setImage: nil];
}

//[super setMenuItem: item];
ASSIGN(_menuItem, item);

if ([_menuItem image] == nil)
Expand Down Expand Up @@ -1345,7 +1346,28 @@ - (id) initWithCoder: (NSCoder*)aDecoder
_pbcFlags.altersStateOfSelectedItem = flag;
decode_NSInteger(aDecoder, &flag);
_pbcFlags.arrowPosition = flag;

/*
selectedItem = [aDecoder decodeObject];
decode_NSInteger(aDecoder, &pullsDown);
decode_NSInteger(aDecoder, &flag);
[self setPreferredEdge: flag];
decode_NSInteger(aDecoder, &flag);
[self setUsesItemFromMenu: flag];
decode_NSInteger(aDecoder, &flag);
[self setAltersStateOfSelectedItem: flag];
decode_NSInteger(aDecoder, &flag);
[self setArrowPosition: flag];
*/
/*
if (_pbcFlags.pullsDown)
{
[self setPreferredEdge: NSMinYEdge];
}
*/
// [self setMenuItem: nil];
[self setMenuItem: (NSMenuItem *)selectedItem];
// [self setPullsDown: pullsDown];

if (version < 2)
{
int i;
Expand All @@ -1371,6 +1393,22 @@ - (id) initWithCoder: (NSCoder*)aDecoder
[self setArrowPosition: NSPopUpArrowAtCenter];
}
[self selectItem: selectedItem];

NSEnumerator *menuItemEnumerator;
NSMenuItem *menuItem;

// FIXME: This special handling is needed bacause the NSClassSwapper
// might have replaced the cell, but the items still refere to it.
menuItemEnumerator = [[menu itemArray] objectEnumerator];

while ((menuItem = [menuItemEnumerator nextObject]) != nil)
{
if (sel_isEqual([menuItem action], @selector(_popUpItemAction:))
&& ([menuItem target] != self))
{
[menuItem setTarget: self];
}
}
}

return self;
Expand Down
Loading