Releasing Menu Resources?
Releasing Menu Resources?
- Subject: Releasing Menu Resources?
- From: Jerry LeVan <email@hidden>
- Date: Wed, 9 Jun 2004 09:34:53 -0400
I am adding a dynamically generated menu to one of my applications
that creates a menu of all of the sql files in a library folder
with submenus for the subdirectories. I initially create the
"Script" menu in awakeFromNib. ( The result looks like the
Script menu in the right hand side of the menu bar.)
Since users can create/add scripts on the fly I would like to
be able to update the menu on demand (or automagically).
It appears to me that I need to destroy the existing menu
structure and then call the build routine to catch any
changes.
One question is: In order to properly release the menu resources
do I need to walk the "main" menu and recursively release the
submenus and then release the items on the "main" menu?
For what it is worth, here is the build code that I am
using in a mini-app before placing in the main application.
It is initially called with menu set to the Script menu in
the application menubar and thePath set to the path of the
script library folder.
******************************
-(IBAction) buildScriptMenu: (NSMenu*) menu withPath: (NSString*)thePath
{
BOOL isDir;
NSString *dirPath;
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *dirArray = [manager directoryContentsAtPath:thePath];
NSEnumerator *direnum = [dirArray objectEnumerator];
NSString *pname;
while (pname =(NSString*) [direnum nextObject]) {
// Is it a directory?
dirPath = [NSString stringWithFormat:@"%@/%@",thePath,pname];
if( ([manager fileExistsAtPath:dirPath isDirectory:&isDir] && isDir))
{
NSMenuItem *tmp = [menu addItemWithTitle:pname action:nil
keyEquivalent:@""];
NSMenu *newMenu = [[NSMenu alloc] initWithTitle:pname];
[menu setSubmenu:newMenu forItem:tmp];
[self buildScriptMenu: newMenu withPath:dirPath];
}
else
// if ([[pname pathExtension] isEqualToString:@"sql"])
{
if ( [pname characterAtIndex:0] == (unichar)'.') continue; // skip
dot files
NSMenuItem *tmp = [menu addItemWithTitle:pname
action:@selector(loadScript:) keyEquivalent:@""];
[tmp setRepresentedObject:dirPath];
}
}
*****************************
Thanks,
Jerry
_______________________________________________
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.