Skip to content

Commit

Permalink
Fix for not being able to add/remove items from main menubar.
Browse files Browse the repository at this point in the history
[cappuccino#72 state:resolved]

Reviewed by rossco.
  • Loading branch information
Francisco Ryan Tolmasky I committed Sep 25, 2008
1 parent 9d5e772 commit 0e26f27
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion AppKit/CPMenu.j
Expand Up @@ -248,7 +248,7 @@ var _CPMenuBarVisible = NO,
[_items removeObjectAtIndex:anIndex];

[[CPNotificationCenter defaultCenter]
postNotificationName:CPMenuDidAddItemNotification
postNotificationName:CPMenuDidRemoveItemNotification
object:self
userInfo:[CPDictionary dictionaryWithObject:anIndex forKey:@"CPMenuItemIndex"]];
}
Expand Down Expand Up @@ -1305,6 +1305,7 @@ var _CPMenuBarWindowBackgroundColor = nil,
{
CPMenu _menu;
CPView _highlightView;
CPArray _menuItemViews;

CPMenuItem _trackingMenuItem;

Expand Down Expand Up @@ -1447,6 +1448,8 @@ var _CPMenuBarWindowBackgroundColor = nil,
object:_menu];
}

_menuItemViews = [];

var contentView = [self contentView],
items = [_menu itemArray],
count = items.length;
Expand All @@ -1455,6 +1458,8 @@ var _CPMenuBarWindowBackgroundColor = nil,
{
var item = items[index],
menuItemView = [item _menuItemView];

_menuItemViews.push(menuItemView);

[menuItemView setShowsStateColumn:NO];
[menuItemView setBelongsToMenuBar:YES];
Expand All @@ -1480,6 +1485,38 @@ var _CPMenuBarWindowBackgroundColor = nil,
[self tile];
}

- (void)menuDidAddItem:(CPNotification)aNotification
{
var index = [[aNotification userInfo] objectForKey:@"CPMenuItemIndex"],
menuItem = [_menu itemAtIndex:index],
menuItemView = [menuItem _menuItemView];

[_menuItemViews insertObject:menuItemView atIndex:index];

[menuItemView setShowsStateColumn:NO];
[menuItemView setBelongsToMenuBar:YES];
[menuItemView setFont:_CPMenuBarWindowFont];
[menuItemView setHidden:[menuItem isHidden]];

[menuItemView synchronizeWithMenuItem];

[[self contentView] addSubview:menuItemView];

[self tile];
}

- (void)menuDidRemoveItem:(CPNotification)aNotification
{
var index = [[aNotification userInfo] objectForKey:@"CPMenuItemIndex"],
menuItemView = [_menuItemViews objectAtIndex:index];

[_menuItemViews removeObjectAtIndex:index];

[menuItemView removeFromSuperview];

[self tile];
}

- (CGRect)frameForMenuItem:(CPMenuItem)aMenuItem
{
var frame = [[aMenuItem _menuItemView] frame];
Expand Down

0 comments on commit 0e26f27

Please sign in to comment.