weird side effect with setSubmenu in Main menu
weird side effect with setSubmenu in Main menu
- Subject: weird side effect with setSubmenu in Main menu
- From: jerome LAURENS <email@hidden>
- Date: Wed, 17 Apr 2002 19:29:59 +0200
Hi all,
I have a menu item of the main menu which gives access to the contents
of a whole directory (with submenus a la bihierarchic...) As it is
dynamically created at startup, it takes a very long time for my app to
launch, due to the fact that the listed folder contains thousands of
files. So i decided to create the list menu in a separate thread, then
connect the submenu at the right location in the main menu.
It kind of works, the first visible thing is that i can now use the main
menu without waiting. In fact,
when i launch my app and wait for a while, nothing weird occurs, but my
multithreaded strategy is a nonsense.
But, when i launch my app and do not wait, making the main menu to pop
very early (opening for example a recent doc), When my app tries to
insert the list menu in the main menu, all the items of the list menu
become disabled, even those with submenus!!! So I used something to
force enabling the menu items like
@implementation NSMenu(foo)
- (void) deepEnableItems;
{
NSEnumerator * E = [[self array] objectEnumerator];
NSMenuItem * MI;
while(MI = [E nextObject])
{
if([MI hasSubmenu])
{
[[MI submenu] deepEnableItems];
}
else if([MI action] != NULL])
{
[MI setEnabled: YES];
if(! [MI isEnabled])
{
[MI setEnabled: YES];
NSLog(@"%@ %@", MI, ([MI isEnabled]? @"YES": "NO"));
}
}
}
}
@end
calling
[myMenu deepEnableItems];/* nothing is logged */
[myMenuItem setSubmenu: myMenu];
[myMenu deepEnableItems];/* thousands of NO appear.... only if i pop the
main menu before this call*/
What a nonsense!
How could i manage that?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.