JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::RecentlyOpenedFilesList Class Reference

Manages a set of files for use as a list of recently-opened documents. More...

#include <juce_RecentlyOpenedFilesList.h>

Collaboration diagram for juce::RecentlyOpenedFilesList:

Public Member Functions

 RecentlyOpenedFilesList ()
 Creates an empty list. More...
 
void addFile (const File &file)
 Adds a file to the list. More...
 
void clear ()
 Clears all the files from the list. More...
 
int createPopupMenuItems (PopupMenu &menuToAddItemsTo, int baseItemId, bool showFullPaths, bool dontAddNonExistentFiles, const File **filesToAvoid=nullptr)
 Adds entries to a menu, representing each of the files in the list. More...
 
const StringArraygetAllFilenames () const noexcept
 Returns an array of all the absolute pathnames in the list. More...
 
File getFile (int index) const
 Returns one of the files in the list. More...
 
int getMaxNumberOfItems () const noexcept
 Returns the number of items that this list will store. More...
 
int getNumFiles () const
 Returns the number of files in the list. More...
 
void removeFile (const File &file)
 Removes a file from the list. More...
 
void removeNonExistentFiles ()
 Checks each of the files in the list, removing any that don't exist. More...
 
void restoreFromString (const String &stringifiedVersion)
 Restores the list from a previously stringified version of the list. More...
 
void setMaxNumberOfItems (int newMaxNumber)
 Sets a limit for the number of files that will be stored in the list. More...
 
String toString () const
 Returns a string that encapsulates all the files in the list. More...
 

Static Public Member Functions

static void clearRecentFilesNatively ()
 Tells the OS to clear the OS-managed list of recent documents for this app. More...
 
static void forgetRecentFileNatively (const File &file)
 Tells the OS to remove a file from the OS-managed list of recent documents for this app. More...
 
static void registerRecentFileNatively (const File &file)
 Tells the OS to add a file to the OS-managed list of recent documents for this app. More...
 

Private Attributes

StringArray files
 
int maxNumberOfItems
 

Detailed Description

Manages a set of files for use as a list of recently-opened documents.

This is a handy class for holding your list of recently-opened documents, with helpful methods for things like purging any non-existent files, automatically adding them to a menu, and making persistence easy.

See also
File, FileBasedDocument

@tags{GUI}

Constructor & Destructor Documentation

◆ RecentlyOpenedFilesList()

juce::RecentlyOpenedFilesList::RecentlyOpenedFilesList ( )

Creates an empty list.

Member Function Documentation

◆ addFile()

void juce::RecentlyOpenedFilesList::addFile ( const File file)

Adds a file to the list.

The file will be added at index 0. If this file is already in the list, it will be moved up to index 0, but a file can only appear once in the list.

If the list already contains the maximum number of items that is permitted, the least-recently added file will be dropped from the end.

◆ clear()

void juce::RecentlyOpenedFilesList::clear ( )

Clears all the files from the list.

◆ clearRecentFilesNatively()

static void juce::RecentlyOpenedFilesList::clearRecentFilesNatively ( )
static

Tells the OS to clear the OS-managed list of recent documents for this app.

Not all OSes maintain a list of recent files for an application, so this function will have no effect on some OSes. Currently it's just implemented for OSX.

◆ createPopupMenuItems()

int juce::RecentlyOpenedFilesList::createPopupMenuItems ( PopupMenu menuToAddItemsTo,
int  baseItemId,
bool  showFullPaths,
bool  dontAddNonExistentFiles,
const File **  filesToAvoid = nullptr 
)

Adds entries to a menu, representing each of the files in the list.

This is handy for creating an "open recent file..." menu in your app. The menu items are numbered consecutively starting with the baseItemId value, and can either be added as complete pathnames, or just the last part of the filename.

If dontAddNonExistentFiles is true, then each file will be checked and only those that exist will be added.

If filesToAvoid is not a nullptr, then it is considered to be a zero-terminated array of pointers to file objects. Any files that appear in this list will not be added to the menu - the reason for this is that you might have a number of files already open, so might not want these to be shown in the menu.

It returns the number of items that were added.

◆ forgetRecentFileNatively()

static void juce::RecentlyOpenedFilesList::forgetRecentFileNatively ( const File file)
static

Tells the OS to remove a file from the OS-managed list of recent documents for this app.

Not all OSes maintain a list of recent files for an application, so this function will have no effect on some OSes. Currently it's just implemented for OSX.

◆ getAllFilenames()

const StringArray& juce::RecentlyOpenedFilesList::getAllFilenames ( ) const
inlinenoexcept

Returns an array of all the absolute pathnames in the list.

References juce::UnitTestCategories::files.

◆ getFile()

File juce::RecentlyOpenedFilesList::getFile ( int  index) const

Returns one of the files in the list.

The most recently added file is always at index 0.

◆ getMaxNumberOfItems()

int juce::RecentlyOpenedFilesList::getMaxNumberOfItems ( ) const
inlinenoexcept

Returns the number of items that this list will store.

See also
setMaxNumberOfItems

◆ getNumFiles()

int juce::RecentlyOpenedFilesList::getNumFiles ( ) const

Returns the number of files in the list.

The most recently added file is always at index 0.

◆ registerRecentFileNatively()

static void juce::RecentlyOpenedFilesList::registerRecentFileNatively ( const File file)
static

Tells the OS to add a file to the OS-managed list of recent documents for this app.

Not all OSes maintain a list of recent files for an application, so this function will have no effect on some OSes. Currently it's just implemented for OSX.

◆ removeFile()

void juce::RecentlyOpenedFilesList::removeFile ( const File file)

Removes a file from the list.

◆ removeNonExistentFiles()

void juce::RecentlyOpenedFilesList::removeNonExistentFiles ( )

Checks each of the files in the list, removing any that don't exist.

You might want to call this after reloading a list of files, or before putting them on a menu.

◆ restoreFromString()

void juce::RecentlyOpenedFilesList::restoreFromString ( const String stringifiedVersion)

Restores the list from a previously stringified version of the list.

Pass in a stringified version created with toString() in order to persist/restore your list.

See also
toString

◆ setMaxNumberOfItems()

void juce::RecentlyOpenedFilesList::setMaxNumberOfItems ( int  newMaxNumber)

Sets a limit for the number of files that will be stored in the list.

When addFile() is called, then if there is no more space in the list, the least-recently added file will be dropped.

See also
getMaxNumberOfItems

◆ toString()

String juce::RecentlyOpenedFilesList::toString ( ) const

Returns a string that encapsulates all the files in the list.

The string that is returned can later be passed into restoreFromString() in order to recreate the list. This is handy for persisting your list, e.g. in a PropertiesFile object.

See also
restoreFromString

Member Data Documentation

◆ files

StringArray juce::RecentlyOpenedFilesList::files
private

◆ maxNumberOfItems

int juce::RecentlyOpenedFilesList::maxNumberOfItems
private

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