Copyright ©1995 by NeXT Computer, Inc.  All Rights Reserved.


Inherits From: SavePanel : Panel : Window : Responder : Object
Declared In: appkit/OpenPanel.h

Class Description

The OpenPanel provides a convenient way for an application to query the user for the name of a file to open.  It can only be run modally.  (The user should use the directory browser in the Workspace for non-modal opens.)  It allows you to specify the types of candidate files whose names will appear in the OpenPanel, and then to filter-out unwanted file types.

Every application has one and only one OpenPanel, and the new method returns a pointer to it.  Do not attempt to create a new OpenPanel using the methods alloc or allocFromZone; these methods are inherited from SavePanel, which overrides them to return errors if used.

See the class description for SavePanel for more information.

Instance Variables

char **filterTypes;

filterTypes File types allowed to open

Method Types

Creating and Freeing an OpenPanel
+ new
+ newContent:style:backing:buttonMask:defer:
Setting the OpenPanel class + setOpenPanelFactory:
Filtering files allowMultipleFiles:
Querying the chosen files filenames
Choosing directories chooseDirectories:
Running the OpenPanel runModalForDirectory:file:

Class Methods

+ new

Creates, if necessary, and returns the shared instance of OpenPanel.  Each application has just one instance of OpenPanel.  This method is implemented to override the inherited new method to assure that only one instance of OpenPanel is created in an application.

+ newContent:(const NXRect *)contentRect

Don't use this method, invoke new instead.  This method is implemented to override the newContent:style:backing:buttonMask:defer: method inherited from SavePanel.  Returns self.

See also:  + new

+ setOpenPanelFactory:class

Sets the class from which OpenPanel will be instantiated.  class should be a subclass of OpenPanel.  An application must invoke this method before it creates the shared instance of OpenPanel.  When the new method is invoked, the object it returns will belong to class.

See also:  + newContent:style:backing:buttonMask:defer:

Instance Methods


If flag is YES, then the user can select more than one file in the browser.  If multiple files are allowed, then the filename method--inherited from SavePanel--returns a non-NULL value only if one and only one file is selected.  By contrast, OpenPanel's filenames method always returns the selected files, even if only one file is selected.  A further distinction between the two methods is that the inherited filename method always returns a fully-specified path, while the filenames method doesn't; the names it returns are always relative to the path returned by directory.  Returns self.

See also:  directory, filename (SavePanel), filenames


Sets the OpenPanel to get directory names from the user.  Invoke this method before running the panel.  If flag is YES, the OpenPanel's filterTypes are ignored and only directories will appear in the OpenPanel file browser.  If flag is NO (the default), the OpenPanel allows the user to select files or directories, and filterTypes are used.

See also:  runModalForDirectory:file:types:

(const char *const *)filenames

Returns a NULL terminated list of files (relative to the path returned by directory).  This list will be valid even if allowMultipleFiles is NO, in which case this method returns a single entry.  This is the preferred method to get the name or names of any files that the user has chosen.

See also:  directory, filename (SavePanel)


Frees the storage used by the shared OpenPanel object and returns nil.  The next time new is sent to the OpenPanel, it will be recreated.  You probably never need to invoke this method since there is one shared instance of the OpenPanel.

See also:  + new

(int)runModalForDirectory:(const char *)path file:(const char *)filename

Initializes the panel to the file specified by path and filename, then displays it and begins its modal event loop.  Invokes the superclass's corresponding method, which invokes Application's runModalFor: method with self as the argument.  Returns NX_OKTAG (if the user clicks the OK button) or NX_CANCELTAG (if the user clicks the Cancel button).

See also:  runModalFor: (Application), runModalForDirectory:file: (SavePanel)

(int)runModalForDirectory:(const char *)path
file:(const char *)filename
types:(const char *const *)fileTypes

Loads the directory specified in path and optionally sets filename as the default file to open.  If filename is NULL, no default file is set.  fileTypes is a NULL-terminated list of extensions (not including the period) to be used to filter candidate files.  If the first item in the list is a NULL, then all ASCII files will be included.

Invokes the runModalForDirectory:file: method and returns the value returned by that method.

See also:  runModalForDirectory:file:

(int)runModalForTypes:(const char *const *)fileTypes

Invokes the runModalForDirectory:file:types: method, using the last directory from which a file was chosen as the path argument.  Returns the value returned by that method.

See also:  runModalForDirectory:file:types: