Re: NSOpenPanel obsolete method?
Re: NSOpenPanel obsolete method?
- Subject: Re: NSOpenPanel obsolete method?
- From: Ali Ozer <email@hidden>
- Date: Mon, 2 Jul 2001 19:34:33 -0700
>
Is this "new Class[]" thing a Java thing? I can only tell you that my
>
(Objective-C) code looks like this.
Yup. For reference, here's Cocoa/Java code to bring up the sheet (and to
process it when torn down). The new Class[] thing is part of the
NSSelector creation --- you are creating an array of Classes, and
putting one class --- the class of the receiver of the selector --- in
it. Also note the syntax for the selector itself. The contextInfo is
your optional user data; in ObjC it can be anything; in Java it has to
be an object (and null is OK).
Ali
public void openMenu(NSMenuItem sender) {
NSOpenPanel op = new NSOpenPanel();
op.setAllowsMultipleSelection(false);
op.setCanChooseDirectories(false);
op.setCanChooseFiles(true);
op.beginSheetForDirectory(
directoryName, // dir name
null, // file name
null, // file types
window, // window to attach sheet to
this, // callback object
new NSSelector("done::", new Class[]
{getClass()}), // callback
null); // context info (to be passed to the callback)
}
public void done(NSOpenPanel sheet, int returnCode, Object
contextInfo) {
NSSystem.log("called callback");
if (returnCode == NSAlertPanel.DefaultReturn) {
NSSystem.log("Success! file name is " + sheet.filename());
}
}