undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoStudio::core::RecentFiles Class Reference

Which files were opened recently. More...

#include <RecentFiles.hpp>

Collaboration diagram for undoStudio::core::RecentFiles:
Collaboration graph

Public Member Functions

void rememberFile (const std::string &filePath)
 Record that a file was opened.
 
void forgetFile (const std::string &filePath)
 Forget one file.
 
void renameFile (const std::string &oldPath, const std::string &newPath)
 Point a remembered file at where it moved to.
 
void clearRecentFiles ()
 Empty the list.
 
const std::vector< std::string > & recentFiles () const
 The files opened recently, newest first.
 
size_t maxRecentFiles () const
 How many files to remember.
 
void setMaxRecentFiles (size_t count)
 Set how many files to remember, trimming the list at once.
 

Static Public Member Functions

static RecentFiles & getInstance ()
 The one instance.
 

Static Public Attributes

static constexpr size_t kMinRecentLimit = 1
 The smallest limit that may be stored.
 
static constexpr size_t kMaxRecentLimit = 100
 The largest limit that may be stored.
 

Private Member Functions

 RecentFiles ()=default
 
void loadRecents () const
 

Static Private Member Functions

static std::string canonicalOrAsGiven (const std::string &filePath)
 Read the list from disk unless it has been read already.
 

Private Attributes

std::vector< std::string > m_recentFiles
 Remembered files, newest first. Mutable because reading the list fills it.
 
bool m_recentsLoaded = false
 Whether the list has been read from disk in this process.
 

Detailed Description

Which files were opened recently.

A singleton, because the list belongs to the IDE and not to any one undoApp: the menu that shows it is the core's, and a plugin that kept its own copy would write a list that the menu could not see.

Constructor & Destructor Documentation

◆ RecentFiles()

undoStudio::core::RecentFiles::RecentFiles ( )
privatedefault

Member Function Documentation

◆ canonicalOrAsGiven()

std::string undoStudio::core::RecentFiles::canonicalOrAsGiven ( const std::string &  filePath)
staticprivate

Read the list from disk unless it has been read already.

Canonical path, or the one as given when it does not resolve

◆ clearRecentFiles()

void undoStudio::core::RecentFiles::clearRecentFiles ( )

Empty the list.

◆ forgetFile()

void undoStudio::core::RecentFiles::forgetFile ( const std::string &  filePath)

Forget one file.

Parameters
filePathPath to drop from the list

◆ getInstance()

RecentFiles & undoStudio::core::RecentFiles::getInstance ( )
static

The one instance.

◆ loadRecents()

void undoStudio::core::RecentFiles::loadRecents ( ) const
private

◆ maxRecentFiles()

size_t undoStudio::core::RecentFiles::maxRecentFiles ( ) const

How many files to remember.

Returns
The limit, never below one and never above the maximum

◆ recentFiles()

const std::vector< std::string > & undoStudio::core::RecentFiles::recentFiles ( ) const

The files opened recently, newest first.

Loads the list from the state file the first time it is asked for, so a fresh process sees the entries a previous one left. Reading is const and mutates the cache, which is why the cache is mutable and why the flag saying whether it is loaded is too.

Returns
The remembered paths, possibly empty

◆ rememberFile()

void undoStudio::core::RecentFiles::rememberFile ( const std::string &  filePath)

Record that a file was opened.

Moves rather than repeats: the list is ordered by when a file was last looked at, and an entry appearing twice is the first thing a user notices about it.

The path is canonicalised so that one file reached by two routes is one entry. A path that does not resolve — a file deleted between being listed and being opened — is recorded as it was given rather than dropped: the list is a history, and refusing to remember something is a worse answer than remembering it in a form that no longer opens.

Parameters
filePathAbsolute path of the file that was opened

◆ renameFile()

void undoStudio::core::RecentFiles::renameFile ( const std::string &  oldPath,
const std::string &  newPath 
)

Point a remembered file at where it moved to.

In place, keeping its position, so a rename does not make an old file the newest thing in the list. A deleted file is left alone instead: the list is a history, and the missing mark is the honest answer for one that is gone.

Parameters
oldPathThe path the entry was recorded under
newPathWhere the file now is

◆ setMaxRecentFiles()

void undoStudio::core::RecentFiles::setMaxRecentFiles ( size_t  count)

Set how many files to remember, trimming the list at once.

Trimmed here rather than at the next rememberFile(), because a limit lowered from fifty to five should leave five entries rather than fifty of which forty-five appear in no list and go on being written to the file.

Parameters
countThe limit to store, clamped to the allowed range

Member Data Documentation

◆ kMaxRecentLimit

constexpr size_t undoStudio::core::RecentFiles::kMaxRecentLimit = 100
staticconstexpr

The largest limit that may be stored.

◆ kMinRecentLimit

constexpr size_t undoStudio::core::RecentFiles::kMinRecentLimit = 1
staticconstexpr

The smallest limit that may be stored.

◆ m_recentFiles

std::vector<std::string> undoStudio::core::RecentFiles::m_recentFiles
mutableprivate

Remembered files, newest first. Mutable because reading the list fills it.

◆ m_recentsLoaded

bool undoStudio::core::RecentFiles::m_recentsLoaded = false
mutableprivate

Whether the list has been read from disk in this process.


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