Re: NSPipe / NSTask ls -> Array
Re: NSPipe / NSTask ls -> Array
- Subject: Re: NSPipe / NSTask ls -> Array
- From: Jerry Krinock <email@hidden>
- Date: Sun, 16 Jul 2006 08:52:39 -0700
- Thread-topic: NSPipe / NSTask ls -> Array
on 06/07/16 2:06, email@hidden at email@hidden wrote:
> So maybe the best way in using this list is not letting other users
> review solutions, but rather asking which way the problem is solved in
> best style...
The best way depends on what you know at the time. In this case, you asked
a good question and got some good answers. It worked very well for you.
> So may i ask what's the correct direction here?
This line of code given by Prachi,
> NSArray *devContents = [[NSFileManager defaultManager]
> directoryContentsAtPath:@"/dev"];
will give you an array of all devices (in /dev). That was quite easy. To
populate a popup menu is a little more difficult, but fortunately others
have done that. Here's the function I use. It also gives each menu item a
numeric tag which is handy later in the action method, to tell you which
item was selected. Pass the devContents from above in as argument the last
argument.
void SSPopulatePopUp( NSPopUpButton* button, id target, SEL action, NSArray*
titles)
{
[button removeAllItems] ;
NSMenu* menu = [button menu] ;
[button setFont:[NSFont systemFontOfSize:
[NSFont systemFontSizeForControlSize:NSSmallControlSize]]] ;
NSMenuItem* menuItem ;
int i = 0 ;
NSEnumerator * e = [titles objectEnumerator] ;
NSString* title ;
while ((title = [e nextObject])) {
menuItem = [menu insertItemWithTitle:NSLocalizedString(title, nil)
action:action
keyEquivalent:@""
atIndex:i ] ;
[menuItem setTarget:target] ;
[menuItem setTag:i++] ;
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden