Skip to content

Commit

Permalink
Move setMenuItem call to bottom so that it can consider the state whe…
Browse files Browse the repository at this point in the history
…n seeting up
  • Loading branch information
gcasa committed Nov 27, 2024
1 parent 7855252 commit bb2eab6
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Source/NSPopUpButtonCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ - (NSImage *) _currentArrowImage

if (_pbcFlags.preferredEdge == NSMaxYEdge)
{
NSLog(@"\tDOWN ARROW!!!!!!");
return _pbc_image[1];
}
else if (_pbcFlags.preferredEdge == NSMaxXEdge)
Expand Down Expand Up @@ -1336,16 +1337,17 @@ - (id) initWithCoder: (NSCoder*)aDecoder
[self setMenu: menu];
selectedItem = [aDecoder decodeObject];
decode_NSInteger(aDecoder, &flag);
_pbcFlags.pullsDown = flag;
[self setPullsDown: flag];
decode_NSInteger(aDecoder, &flag);
_pbcFlags.preferredEdge = flag;
[self setPreferredEdge: flag];
decode_NSInteger(aDecoder, &flag);
_pbcFlags.usesItemFromMenu = flag;
[self setUsesItemFromMenu: flag];
decode_NSInteger(aDecoder, &flag);
_pbcFlags.altersStateOfSelectedItem = flag;
[self setAltersStateOfSelectedItem: flag];
decode_NSInteger(aDecoder, &flag);
_pbcFlags.arrowPosition = flag;

[self setArrowPosition: flag];
[self setMenuItem: (NSMenuItem *)selectedItem];

if (version < 2)
{
int i;
Expand All @@ -1371,6 +1373,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

0 comments on commit bb2eab6

Please sign in to comment.