protect changedMessagesEnabled flag; update menus after modal session, key or main window change

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29891 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2010-03-09 23:11:40 +00:00
parent 8dd7827584
commit ce29b8d726
3 changed files with 77 additions and 57 deletions

View file

@ -1,3 +1,10 @@
2005-03-09 Doug Simons <doug.simons@testplant.com>
* Source/NSMenu.m: Protect changedMessagesEnabled flag against getting
stuck off if exceptions occur during update.
* Source/NSApplication.m: Update menu after modal session, and when
the key or main window has changed.
2005-03-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSAlert.m: Cope gracefully with being called from an non-gui

View file

@ -1696,6 +1696,10 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
}
}
}
else
{
[_main_menu update];
}
}
/**
@ -3883,6 +3887,7 @@ struct _DelegateWrapper
if (_key_window == nil && [obj isKindOfClass: [NSWindow class]])
{
_key_window = obj;
[_main_menu update];
}
else if (_key_window != obj)
{
@ -3897,6 +3902,7 @@ struct _DelegateWrapper
if (_main_window == nil && [obj isKindOfClass: [NSWindow class]])
{
_main_window = obj;
[_main_menu update];
}
else if (_main_window != obj)
{

View file

@ -1124,68 +1124,75 @@ static BOOL menuBarVisible = YES;
// Temporary disable automatic displaying of menu.
[self setMenuChangedMessagesEnabled: NO];
for (i = 0; i < count; i++)
NS_DURING
{
NSMenuItem *item = [_items objectAtIndex: i];
SEL action = [item action];
id validator = nil;
BOOL wasEnabled = [item isEnabled];
BOOL shouldBeEnabled;
// Update the submenu items if any.
if ([item hasSubmenu])
[[item submenu] update];
// If there is no action - there can be no validator for the item.
if (action)
for (i = 0; i < count; i++)
{
validator = [NSApp targetForAction: action
to: [item target]
from: item];
}
else if (_popUpButtonCell != nil)
{
if (NULL != (action = [_popUpButtonCell action]))
NSMenuItem *item = [_items objectAtIndex: i];
SEL action = [item action];
id validator = nil;
BOOL wasEnabled = [item isEnabled];
BOOL shouldBeEnabled;
// Update the submenu items if any.
if ([item hasSubmenu])
[[item submenu] update];
// If there is no action - there can be no validator for the item.
if (action)
{
validator = [NSApp targetForAction: action
to: [_popUpButtonCell target]
from: [_popUpButtonCell controlView]];
}
}
validator = [NSApp targetForAction: action
to: [item target]
from: item];
}
else if (_popUpButtonCell != nil)
{
if (NULL != (action = [_popUpButtonCell action]))
{
validator = [NSApp targetForAction: action
to: [_popUpButtonCell target]
from: [_popUpButtonCell controlView]];
}
}
if (validator == nil)
{
if ((action == NULL) && (_popUpButtonCell != nil))
{
shouldBeEnabled = YES;
}
else
{
shouldBeEnabled = NO;
}
}
else if ([validator
respondsToSelector: @selector(validateMenuItem:)])
{
shouldBeEnabled = [validator validateMenuItem: item];
}
else if ([validator
respondsToSelector: @selector(validateUserInterfaceItem:)])
{
shouldBeEnabled = [validator validateUserInterfaceItem: item];
}
else
{
shouldBeEnabled = YES;
}
if (validator == nil)
{
if ((action == NULL) && (_popUpButtonCell != nil))
{
shouldBeEnabled = YES;
}
else
{
shouldBeEnabled = NO;
}
}
else if ([validator
respondsToSelector: @selector(validateMenuItem:)])
{
shouldBeEnabled = [validator validateMenuItem: item];
}
else if ([validator
respondsToSelector: @selector(validateUserInterfaceItem:)])
{
shouldBeEnabled = [validator validateUserInterfaceItem: item];
}
else
{
shouldBeEnabled = YES;
}
if (shouldBeEnabled != wasEnabled)
{
[item setEnabled: shouldBeEnabled];
if (shouldBeEnabled != wasEnabled)
{
[item setEnabled: shouldBeEnabled];
}
}
}
}
NS_HANDLER
{
NSLog(@"Error Occurred While Updating Menu %@: %@", [self title], localException);
}
NS_ENDHANDLER
// Reenable displaying of menus
[self setMenuChangedMessagesEnabled: YES];
}
@ -1209,7 +1216,7 @@ static BOOL menuBarVisible = YES;
NSEventType type = [theEvent type];
unsigned modifiers = [theEvent modifierFlags];
NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
if (type != NSKeyDown && type != NSKeyUp)
return NO;