On Jul 12, 2004, at 8:59 PM, Thilo Planz wrote:

Hi,


Does anyone have a good snippet of example code for calling NSOpenPanel with CamelBones?

I am not certain what the syntax should be and there are few examples I can find.

Did you check Apple's Cocoa Documentation?
Since CamelBones just wraps around the Objective-C functions, you can use the documentation for that.

Sometimes that works, sometimes it does not. It seems that a lot of trial and error is involved.

For starters, you can do something like this:

my $panel = NSOpenPanel->openPanel;
if ($panel->runModal) {
        # user clicked "Open"
        my $files = $panel->filenames;
        # get only one file here
         my $file = $files->lastObject;
        
        # .. do something with $file (the file name)
}
else{
        # user clicked cancel

}

There is also NSSavePanel to save files (rather than open them).

BTW, this example is much more to the point than those in the example programs. Much more commented as well. (The examples assume that you are already proficient at Cocoa and Objective-C.)

If you want to filter for specific files types you can do:


 my $types = NSMutableArray->alloc->init;
    $types->addObject('pod');
    $types->addObject('pm');
    $types->addObject('pl');

    my $panel = NSOpenPanel->openPanel;

if ($panel->runModalForTypes($types)) {


How do I get the open and/or save dialog to open at a specific directory? What I have tried has not worked.




Reply via email to