mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-17 08:01:27 +00:00
Better handling of submenu actions.
Reviewed by me.
This commit is contained in:
+22
-17
@@ -691,12 +691,28 @@ var aFont = nil;
|
||||
[delegate menuWillOpen:aMenu];
|
||||
|
||||
[menuWindow orderFront:self];
|
||||
[menuWindow beginTrackingWithEvent:[CPApp currentEvent] callback:function(aMenuWindow, aMenu)
|
||||
[menuWindow
|
||||
beginTrackingWithEvent:[CPApp currentEvent]
|
||||
callback:[CPMenu trackingCallbackWithCallback:aCallback]];
|
||||
}
|
||||
|
||||
+ (Function)trackingCallbackWithCallback:(Function)aCallback
|
||||
{
|
||||
return function(aMenuWindow, aMenu)
|
||||
{
|
||||
[_CPMenuWindow poolMenuWindow:aMenuWindow];
|
||||
|
||||
aCallback(aMenu);
|
||||
}];
|
||||
if (aCallback)
|
||||
aCallback(aMenu);
|
||||
|
||||
var highlightedItem = [aMenu highlightedItem];
|
||||
|
||||
while ([highlightedItem submenu] && [highlightedItem action] === @selector(submenuAction:))
|
||||
highlightedItem = [[highlightedItem submenu] highlightedItem];
|
||||
|
||||
if (highlightedItem)
|
||||
[CPApp sendAction:[highlightedItem action] to:[highlightedItem target] from:highlightedItem];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView
|
||||
@@ -729,20 +745,9 @@ var aFont = nil;
|
||||
[menuWindow setFrameOrigin:[[anEvent window] convertBaseToGlobal:[anEvent locationInWindow]]];
|
||||
|
||||
[menuWindow orderFront:self];
|
||||
[menuWindow beginTrackingWithEvent:anEvent callback:function(aMenuWindow, aMenu)
|
||||
{
|
||||
[_CPMenuWindow poolMenuWindow:aMenuWindow];
|
||||
|
||||
aCallback(aMenu);
|
||||
|
||||
var highlightedItem = [aMenu highlightedItem];
|
||||
|
||||
while ([highlightedItem submenu] && [highlightedItem action] === @selector(submenuAction:))
|
||||
highlightedItem = [[highlightedItem submenu] highlightedItem];
|
||||
|
||||
if (highlightedItem)
|
||||
[CPApp sendAction:[highlightedItem action] to:[highlightedItem target] from:highlightedItem];
|
||||
}];
|
||||
[menuWindow
|
||||
beginTrackingWithEvent:anEvent
|
||||
callback:[CPMenu trackingCallbackWithCallback:nil]];
|
||||
}
|
||||
|
||||
// Managing Display of State Column
|
||||
|
||||
@@ -450,19 +450,31 @@ CPOffState
|
||||
- (void)setSubmenu:(CPMenu)aMenu
|
||||
{
|
||||
var supermenu = [_submenu supermenu];
|
||||
|
||||
if (supermenu == self)
|
||||
|
||||
if (supermenu === self)
|
||||
return;
|
||||
|
||||
|
||||
if (supermenu)
|
||||
return alert("bad");
|
||||
|
||||
[_submenu setSupermenu:_menu];
|
||||
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason: @"Can't add submenu \"" + [aMenu title] + "\" to item \"" + [self title] + "\", because it is already submenu of \"" + [[aMenu supermenu] title] + "\""];
|
||||
|
||||
_submenu = aMenu;
|
||||
|
||||
|
||||
if (_submenu)
|
||||
{
|
||||
[_submenu setSupermenu:_menu];
|
||||
|
||||
[self setTarget:_menu];
|
||||
[self setAction:@selector(submenuAction:)];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setTarget:nil];
|
||||
[self setAction:NULL];
|
||||
}
|
||||
|
||||
[_menuItemView setDirty];
|
||||
|
||||
|
||||
[_menu itemChanged:self];
|
||||
}
|
||||
|
||||
@@ -762,6 +774,11 @@ CPControlKeyMask
|
||||
return _menuItemView;
|
||||
}
|
||||
|
||||
- (BOOL)_isSelectable
|
||||
{
|
||||
return ![self submenu] || [self action] !== @selector(submenuAction:) || [self target] !== [self menu];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
|
||||
@@ -824,8 +841,9 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
|
||||
// CPImage _offStateImage;
|
||||
// CPImage _mixedStateImage;
|
||||
|
||||
_submenu = DEFAULT_VALUE(CPMenuItemSubmenuKey, nil);
|
||||
// This order matters because setSubmenu: needs _menu to be around.
|
||||
_menu = DEFAULT_VALUE(CPMenuItemMenuKey, nil);
|
||||
[self setSubmenu:DEFAULT_VALUE(CPMenuItemSubmenuKey, nil)];
|
||||
|
||||
_keyEquivalent = [aCoder decodeObjectForKey:CPMenuItemKeyEquivalentKey] || @"";
|
||||
_keyEquivalentModifierMask = [aCoder decodeObjectForKey:CPMenuItemKeyEquivalentModifierMaskKey] || 0;
|
||||
|
||||
@@ -664,14 +664,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
||||
|
||||
var highlightedItem = [aMenu highlightedItem];
|
||||
|
||||
while ([highlightedItem submenu] && [highlightedItem action] === @selector(submenuAction:))
|
||||
highlightedItem = [[highlightedItem submenu] highlightedItem];
|
||||
|
||||
if ([highlightedItem menu] === [self menu])
|
||||
if ([highlightedItem _isSelectable])
|
||||
[self selectItem:highlightedItem];
|
||||
|
||||
if (highlightedItem)
|
||||
[CPApp sendAction:[highlightedItem action] to:[highlightedItem target] from:highlightedItem];
|
||||
}];
|
||||
/*
|
||||
var menu = [self menu],
|
||||
|
||||
Reference in New Issue
Block a user