DirectoryContentsList Class Reference
juce_gui_basics » filebrowser

A class to asynchronously scan for details about the files in a directory. More...

Inheritance diagram for DirectoryContentsList:

## Classes

struct | FileInfo
| Contains cached information about one of the files in a DirectoryContentsList. More...

## Public Member Functions

| DirectoryContentsList (const FileFilter *fileFilter, TimeSliceThread &threadToUse)
| Creates a directory list. More...
| ~DirectoryContentsList () override
| Destructor. More...
const File & | getDirectory () const noexcept
| Returns the directory that's currently being used. More...
void | setDirectory (const File &directory, bool includeDirectories, bool includeFiles)
| Sets the directory to look in for files. More...
bool | isFindingDirectories () const noexcept
| Returns true if this list contains directories. More...
bool | isFindingFiles () const noexcept
| Returns true if this list contains files. More...
void | clear ()
| Clears the list, and stops the thread scanning for files. More...
void | refresh ()
| Clears the list and restarts scanning the directory for files. More...
bool | isStillLoading () const
| True if the background thread hasn't yet finished scanning for files. More...
void | setIgnoresHiddenFiles (bool shouldIgnoreHiddenFiles)
| Tells the list whether or not to ignore hidden files. More...
bool | ignoresHiddenFiles () const
| Returns true if hidden files are ignored. More...
void | setFileFilter (const FileFilter *newFileFilter)
| Replaces the current FileFilter. More...
int | getNumFiles () const noexcept
| Returns the number of files currently available in the list. More...
bool | getFileInfo (int index, FileInfo &resultInfo) const
| Returns the cached information about one of the files in the list. More...
File | getFile (int index) const
| Returns one of the files in the list. More...
const FileFilter * | getFilter () const noexcept
| Returns the file filter being used. More...
bool | contains (const File &) const
| Returns true if the list contains the specified file. More...
TimeSliceThread & | getTimeSliceThread () const noexcept
Public Member Functions inherited from ChangeBroadcaster
| ChangeBroadcaster () noexcept
| Creates an ChangeBroadcaster. More...
virtual | ~ChangeBroadcaster ()
| Destructor. More...
void | addChangeListener (ChangeListener *listener)
| Registers a listener to receive change callbacks from this broadcaster. More...
void | removeChangeListener (ChangeListener *listener)
| Unregisters a listener from the list. More...
void | removeAllChangeListeners ()
| Removes all listeners from the list. More...
void | sendChangeMessage ()
| Causes an asynchronous change message to be sent to all the registered listeners. More...
void | sendSynchronousChangeMessage ()
| Sends a synchronous change message to all the registered listeners. More...
void | dispatchPendingMessages ()
| If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately. More...

## Detailed Description

A class to asynchronously scan for details about the files in a directory.

This keeps a list of files and some information about them, using a background thread to scan for more files. As files are found, it broadcasts change messages to tell any listeners.

See also
  FileListComponent, FileBrowserComponent

## Constructor & Destructor Documentation

## DirectoryContentsList()

DirectoryContentsList::DirectoryContentsList | ( | const FileFilter * | fileFilter,
|  | TimeSliceThread & | threadToUse
| ) |  |

Creates a directory list.

To set the directory it should point to, use setDirectory(), which will also start it scanning for files on the background thread.

When the background thread finds and adds new files to this list, the ChangeBroadcaster class will send a change message, so you can register listeners and update them when the list changes.

Parameters

  fileFilter | an optional filter to select which files are included in the list. If this is nullptr, then all files and directories are included. Make sure that the filter doesn't get deleted during the lifetime of this object
  threadToUse | a thread object that this list can use to scan for files as a background task. Make sure that the thread you give it has been started, or you won't get any files!

## ~DirectoryContentsList()

DirectoryContentsList::~DirectoryContentsList | ( |  | ) |

override

Destructor.

## Member Function Documentation

## getDirectory()

const File& DirectoryContentsList::getDirectory | ( |  | ) | const

noexcept

Returns the directory that's currently being used.

## setDirectory()

void DirectoryContentsList::setDirectory | ( | const File & | directory,
|  | bool | includeDirectories,
|  | bool | includeFiles
| ) |  |

Sets the directory to look in for files.

If the directory that's passed in is different to the current one, this will also start the background thread scanning it for files.

## isFindingDirectories()

bool DirectoryContentsList::isFindingDirectories | ( |  | ) | const

noexcept

Returns true if this list contains directories.

See also
  setDirectory

References File::findDirectories.

## isFindingFiles()

bool DirectoryContentsList::isFindingFiles | ( |  | ) | const

noexcept

Returns true if this list contains files.

See also
  setDirectory

References File::findFiles.

## clear()

void DirectoryContentsList::clear | ( |  | ) |

Clears the list, and stops the thread scanning for files.

## refresh()

void DirectoryContentsList::refresh | ( |  | ) |

Clears the list and restarts scanning the directory for files.

## isStillLoading()

bool DirectoryContentsList::isStillLoading | ( |  | ) | const

True if the background thread hasn't yet finished scanning for files.

## setIgnoresHiddenFiles()

void DirectoryContentsList::setIgnoresHiddenFiles | ( | bool | shouldIgnoreHiddenFiles | ) |

Tells the list whether or not to ignore hidden files.

By default these are ignored.

## ignoresHiddenFiles()

bool DirectoryContentsList::ignoresHiddenFiles | ( |  | ) | const

Returns true if hidden files are ignored.

See also
  setIgnoresHiddenFiles

## setFileFilter()

void DirectoryContentsList::setFileFilter | ( | const FileFilter * | newFileFilter | ) |

Replaces the current FileFilter.

This can be nullptr to have no filter. The DirectoryContentList does not take ownership of this object - it just keeps a pointer to it, so you must manage its lifetime. Note that this only replaces the filter, it doesn't refresh the list - you'll probably want to call refresh() after calling this.

## getNumFiles()

int DirectoryContentsList::getNumFiles | ( |  | ) | const

noexcept

Returns the number of files currently available in the list.

The info about one of these files can be retrieved with getFileInfo() or getFile().

Obviously as the background thread runs and scans the directory for files, this number will change.

See also
  getFileInfo, getFile

## getFileInfo()

bool DirectoryContentsList::getFileInfo | ( | int | index,
|  | FileInfo & | resultInfo
| ) |  | const

Returns the cached information about one of the files in the list.

If the index is in-range, this will return true and will copy the file's details to the structure that is passed-in.

If it returns false, then the index wasn't in range, and the structure won't be affected.

See also
  getNumFiles, getFile

## getFile()

File DirectoryContentsList::getFile | ( | int | index | ) | const

Returns one of the files in the list.

Parameters

  index | should be less than getNumFiles(). If this is out-of-range, the return value will be a default File() object

See also
  getNumFiles, getFileInfo

## getFilter()

const FileFilter* DirectoryContentsList::getFilter | ( |  | ) | const

noexcept

Returns the file filter being used.

The filter is specified in the constructor.

## contains()

bool DirectoryContentsList::contains | ( | const File & |  | ) | const

Returns true if the list contains the specified file.

## getTimeSliceThread()

TimeSliceThread& DirectoryContentsList::getTimeSliceThread | ( |  | ) | const

noexcept

The documentation for this class was generated from the following file:

- juce_DirectoryContentsList.h