NSPathControl Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.5 and later.
Declared in
NSPathControl.h
Related sample code

Overview

NSPathControl is a subclass of NSControl that represents a file system path or virtual path.

The NSPathControl class uses NSPathCell to implement its user interface. NSPathControl provides cover methods for most NSPathCell methods—the cover method simply invokes the corresponding cell method. See also NSPathComponentCell, which represents individual components of the path, and two associated protocols: NSPathCellDelegate and NSPathControlDelegate.

NSPathControl has three styles represented by the NSPathStyle enumeration constants NSPathStyleStandard, NSPathStyleNavigationBar, and NSPathStylePopUp. The represented path can be a file system path or any other type of path leading through a sequence of nodes or components, as defined by the programmer.

NSPathControl automatically supports drag and drop, which can be further customized via delegate methods. To accept drag and drop, NSPathControl calls registerForDraggedTypes: with NSFilenamesPboardType and NSURLPboardType. When the URL value in the NSPathControl object changes because of an automatic drag and drop operation or the user selecting a new path via the open panel, the action is sent. On OS X v10.5 the value returned by clickedPathComponentCell is nil, on OS X v10.6 and later, clickedPathComponentCell returns the clicked cell.

Tasks

Setting the Control Style

Setting the Background Color

Managing Path Components

Setting the Double-Click Action

Setting the Path

Setting the Delegate

Setting the Drag Operation Mask

Setting Popup Menu

Instance Methods

backgroundColor

Returns the current background color of the receiver.

- (NSColor *)backgroundColor
Return Value

The background color.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

clickedPathComponentCell

Returns the clicked cell.

- (NSPathComponentCell *)clickedPathComponentCell
Return Value

The component cell that was clicked.

Discussion

The value returned is generally valid only when the action or double action is being sent.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSPathControl.h

delegate

Returns the receiver’s delegate.

- (id < NSPathControlDelegate >)delegate
Return Value

The receiver’s delegate.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

doubleAction

Returns the receiver’s double-click action method.

- (SEL)doubleAction
Return Value

The action method invoked when the user double-clicks the receiver.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

menu

Returns the menu that is used for the path control’s cells.

- (NSMenu *)menu
Return Value

An instance of NSMenu.

Discussion

This method overrides the NSView implementation of menu and forwards the message to the NSPathControlCell.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSPathControl.h

pathComponentCells

Returns an array of the NSPathComponentCell objects currently being displayed.

- (NSArray *)pathComponentCells
Return Value

The array of NSPathComponentCell objects.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

pathStyle

Returns the receiver’s path style.

- (NSPathStyle)pathStyle
Return Value

The style of the path control.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setBackgroundColor:

Sets the receiver’s background color.

- (void)setBackgroundColor:(NSColor *)color
Parameters
color

The color to draw.

Discussion

By default, the background is set to a light blue color for NSPathStyleStandard and nil for the other styles. You can use [NSColor clearColor] to make the background transparent.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setDelegate:

Sets the receiver’s delegate.

- (void)setDelegate:(id < NSPathControlDelegate >)delegate
Parameters
delegate

The object to set as the receiver’s delegate.

Availability
  • Available in OS X v10.5 and later.
See Also
Declared In
NSPathControl.h

setDoubleAction:

Sets the receiver’s double-click action.

- (void)setDoubleAction:(SEL)action
Parameters
action

The action method to invoke when the receiver is double-clicked.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setDraggingSourceOperationMask:forLocal:

Configures the default value returned from draggingSourceOperationMaskForLocal:.

- (void)setDraggingSourceOperationMask:(NSDragOperation)mask forLocal:(BOOL)isLocal
Parameters
mask

The types of drag operations allowed.

isLocal

If YES, mask applies when the drag destination object is in the same application as the receiver; if NO, mask applies when the destination object is outside the receiver’s application.

Discussion

By default, draggingSourceOperationMaskForLocal: returns NSDragOperationEvery when isLocal is YES and NSDragOperationNone when isLocal is NO.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setMenu:

Sets the menu used for the path control’s cells.

- (void)setMenu:(NSMenu *)menu
Parameters
menu

An instance of NSMenu.

Discussion

This method overrides the NSView implementation of setMenu: and forwards the message to the NSPathControlCell.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSPathControl.h

setPathComponentCells:

Sets the array of NSPathComponentCell objects currently being displayed.

- (void)setPathComponentCells:(NSArray *)cells
Parameters
cells

An array of NSPathComponentCell objects.

Discussion

Each item in the array must be an instance of NSPathComponentCell or a subclass thereof. You cannot set this value to nil, but you can set it to an empty array using, for example, [NSArray array].

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setPathStyle:

Sets the receiver’s path style.

- (void)setPathStyle:(NSPathStyle)style
Parameters
style

The new path style.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSPathControl.h

setURL:

Sets the path value displayed by the receiver.

- (void)setURL:(NSURL *)url
Parameters
url

The new path value to display.

Discussion

When setting, an array of NSPathComponentCell objects is automatically set based on the path in url. If url is a file URL (returns YES from isFileURL), the images are automatically filled with file icons, if the path exists. The URL value itself is stored in the objectValue property of the cell.

Availability
  • Available in OS X v10.5 and later.
See Also
Declared In
NSPathControl.h

URL

Returns the path value displayed by the receiver.

- (NSURL *)URL
Return Value

The path value.

Availability
  • Available in OS X v10.5 and later.
See Also
Declared In
NSPathControl.h