Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
FileHistory Class Reference

Similar to wxFileHistory, but customized to our needs. More...

#include <FileHistory.h>

Collaboration diagram for FileHistory:
[legend]

Public Types

enum  { ID_RECENT_CLEAR = 6100 , ID_RECENT_FIRST = 6101 , ID_RECENT_LAST = 6112 }
 
using const_iterator = FilePaths::const_iterator
 

Public Member Functions

 FileHistory (size_t maxfiles=12, wxWindowID idbase=wxID_FILE)
 
virtual ~FileHistory ()
 
 FileHistory (const FileHistory &)=delete
 
FileHistoryoperator= (const FileHistory &)=delete
 
void Append (const FilePath &file)
 
void Remove (size_t i)
 
void Clear ()
 
void UseMenu (wxMenu *menu)
 
void Load (wxConfigBase &config, const wxString &group=wxEmptyString)
 
void Save (wxConfigBase &config)
 
const_iterator begin () const
 
const_iterator end () const
 
const FilePathoperator[] (size_t ii) const
 
bool empty () const
 

Static Public Member Functions

static FileHistoryGlobal ()
 

Private Member Functions

void AddFileToHistory (const FilePath &file, bool update)
 
void NotifyMenus ()
 
void NotifyMenu (wxMenu *menu)
 
void Compress ()
 

Private Attributes

size_t mMaxFiles
 
wxWindowID mIDBase
 
std::vector< wxWeakRef< wxMenu > > mMenus
 
FilePaths mHistory
 
wxString mGroup
 

Detailed Description

Similar to wxFileHistory, but customized to our needs.

Definition at line 25 of file FileHistory.h.

Member Typedef Documentation

◆ const_iterator

using FileHistory::const_iterator = FilePaths::const_iterator

Definition at line 55 of file FileHistory.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ID_RECENT_CLEAR 
ID_RECENT_FIRST 
ID_RECENT_LAST 

Definition at line 34 of file FileHistory.h.

34 {
35 ID_RECENT_CLEAR = 6100,
36 ID_RECENT_FIRST = 6101,
37 ID_RECENT_LAST = 6112
38 };

Constructor & Destructor Documentation

◆ FileHistory() [1/2]

FileHistory::FileHistory ( size_t  maxfiles = 12,
wxWindowID  idbase = wxID_FILE 
)

Definition at line 27 of file FileHistory.cpp.

28{
29 mMaxFiles = maxfiles;
30 mIDBase = base;
31}
wxWindowID mIDBase
Definition: FileHistory.h:69
size_t mMaxFiles
Definition: FileHistory.h:68

References mIDBase, and mMaxFiles.

◆ ~FileHistory()

FileHistory::~FileHistory ( )
virtual

Definition at line 33 of file FileHistory.cpp.

34{
35}

◆ FileHistory() [2/2]

FileHistory::FileHistory ( const FileHistory )
delete

Member Function Documentation

◆ AddFileToHistory()

void FileHistory::AddFileToHistory ( const FilePath file,
bool  update 
)
private

Definition at line 51 of file FileHistory.cpp.

52{
53 // Needed to transition from wxFileHistory to FileHistory since there
54 // can be empty history "slots".
55 if (file.empty()) {
56 return;
57 }
58
59#if defined(__WXMSW__)
60 int i = mHistory.Index(file, false);
61#else
62 int i = mHistory.Index(file, true);
63#endif
64
65 if (i != wxNOT_FOUND) {
66 mHistory.erase( mHistory.begin() + i );
67 }
68
69 if (mMaxFiles > 0 && mMaxFiles == mHistory.size()) {
70 mHistory.erase( mHistory.end() - 1 );
71 }
72
73 mHistory.insert(mHistory.begin(), file);
74
75 if (update)
77}
FilePaths mHistory
Definition: FileHistory.h:72
void NotifyMenus()
iterator insert(const_iterator pos, std::initializer_list< T > items)

References wxArrayStringEx::insert(), mHistory, mMaxFiles, and NotifyMenus().

Referenced by Load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Append()

void FileHistory::Append ( const FilePath file)
inline

Definition at line 42 of file FileHistory.h.

43 { AddFileToHistory( file, true ); }
void AddFileToHistory(const FilePath &file, bool update)
Definition: FileHistory.cpp:51

Referenced by anonymous_namespace{FileMenus.cpp}::DoExport(), DoImportMIDI(), ProjectFileManager::Import(), ProjectFileManager::OpenProjectFile(), ProjectFileManager::SaveAs(), ProjectFileManager::SaveFromTimerRecording(), and ExportCLOptions::TransferDataFromWindow().

Here is the caller graph for this function:

◆ begin()

const_iterator FileHistory::begin ( ) const
inline

Definition at line 56 of file FileHistory.h.

56{ return mHistory.begin(); }

Referenced by ExportCLOptions::PopulateOrExchange().

Here is the caller graph for this function:

◆ Clear()

void FileHistory::Clear ( )

Definition at line 90 of file FileHistory.cpp.

91{
92 mHistory.clear();
93
95}

References mHistory, and NotifyMenus().

Referenced by AudacityApp::OnMRUClear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Compress()

void FileHistory::Compress ( )
private

Definition at line 181 of file FileHistory.cpp.

182{
183 // Clear up expired weak pointers
184 auto end = mMenus.end();
185 mMenus.erase(
186 std::remove_if( mMenus.begin(), end,
187 [](wxWeakRef<wxMenu> &pMenu){ return !pMenu; } ),
188 end
189 );
190}
const_iterator end() const
Definition: FileHistory.h:57
std::vector< wxWeakRef< wxMenu > > mMenus
Definition: FileHistory.h:71

References end(), and mMenus.

Referenced by NotifyMenus(), and UseMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool FileHistory::empty ( ) const
inline

Definition at line 59 of file FileHistory.h.

59{ return mHistory.empty(); }

◆ end()

const_iterator FileHistory::end ( ) const
inline

Definition at line 57 of file FileHistory.h.

57{ return mHistory.end(); }

Referenced by Compress(), NotifyMenu(), ExportCLOptions::PopulateOrExchange(), and UseMenu().

Here is the caller graph for this function:

◆ Global()

FileHistory & FileHistory::Global ( )
static

Definition at line 37 of file FileHistory.cpp.

38{
39 // TODO - read the number of files to store in history from preferences
40 static FileHistory history{
42 static std::once_flag flag;
43 std::call_once( flag, [&]{
44 history.Load(*gPrefs, wxT("RecentFiles"));
45 });
46
47 return history;
48}
wxT("CloseDown"))
FileConfig * gPrefs
Definition: Prefs.cpp:70
static std::once_flag flag
Similar to wxFileHistory, but customized to our needs.
Definition: FileHistory.h:26

References flag, gPrefs, ID_RECENT_CLEAR, ID_RECENT_FIRST, ID_RECENT_LAST, and wxT().

Referenced by anonymous_namespace{FileMenus.cpp}::DoExport(), DoImportMIDI(), anonymous_namespace{FileMenus.cpp}::FileMenu(), ProjectFileManager::Import(), AudacityApp::InitPart2(), AudacityApp::OnExit(), AudacityApp::OnMRUClear(), AudacityApp::OnMRUFile(), ProjectFileManager::OpenProjectFile(), ProjectFileManager::SaveAs(), and ProjectFileManager::SaveFromTimerRecording().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Load()

void FileHistory::Load ( wxConfigBase &  config,
const wxString &  group = wxEmptyString 
)

Definition at line 114 of file FileHistory.cpp.

115{
116 mHistory.clear();
117 mGroup = group.empty()
118 ? wxString{ "RecentFiles" }
119 : group;
120
121 config.SetPath(mGroup);
122
123 wxString file;
124 long ndx;
125 bool got = config.GetFirstEntry(file, ndx);
126 while (got) {
127 AddFileToHistory(config.Read(file), false);
128 got = config.GetNextEntry(file, ndx);
129 }
130
131 config.SetPath(wxT(".."));
132
133 NotifyMenus();
134}
wxString mGroup
Definition: FileHistory.h:74

References AddFileToHistory(), mGroup, mHistory, NotifyMenus(), and wxT().

Here is the call graph for this function:

◆ NotifyMenu()

void FileHistory::NotifyMenu ( wxMenu *  menu)
private

Definition at line 162 of file FileHistory.cpp.

163{
164 wxMenuItemList items = menu->GetMenuItems();
165 for (auto end = items.end(), iter = items.begin(); iter != end;)
166 menu->Destroy(*iter++);
167
168 for (size_t i = 0; i < mHistory.size(); i++) {
169 wxString item = mHistory[i];
170 item.Replace( "&", "&&" );
171 menu->Append(mIDBase + 1 + i,item);
172 }
173
174 if (mHistory.size() > 0) {
175 menu->AppendSeparator();
176 }
177 menu->Append(mIDBase, _("&Clear"));
178 menu->Enable(mIDBase, mHistory.size() > 0);
179}
#define _(s)
Definition: Internat.h:73

References _, end(), mHistory, and mIDBase.

Referenced by NotifyMenus(), and UseMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NotifyMenus()

void FileHistory::NotifyMenus ( )
private

Definition at line 153 of file FileHistory.cpp.

154{
155 Compress();
156 for (auto pMenu : mMenus)
157 if (pMenu)
158 NotifyMenu(pMenu);
159 Save(*gPrefs);
160}
void NotifyMenu(wxMenu *menu)
void Compress()
void Save(wxConfigBase &config)

References Compress(), gPrefs, mMenus, NotifyMenu(), and Save().

Referenced by AddFileToHistory(), Clear(), Load(), and Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

FileHistory & FileHistory::operator= ( const FileHistory )
delete

◆ operator[]()

const FilePath & FileHistory::operator[] ( size_t  ii) const
inline

Definition at line 58 of file FileHistory.h.

58{ return mHistory[ ii ]; }

◆ Remove()

void FileHistory::Remove ( size_t  i)

Definition at line 79 of file FileHistory.cpp.

80{
81 wxASSERT(i < mHistory.size());
82
83 if (i < mHistory.size()) {
84 mHistory.erase( mHistory.begin() + i );
85
87 }
88}

References mHistory, and NotifyMenus().

Here is the call graph for this function:

◆ Save()

void FileHistory::Save ( wxConfigBase &  config)

Definition at line 136 of file FileHistory.cpp.

137{
138 config.SetPath(wxT(""));
139 config.DeleteGroup(mGroup);
140 config.SetPath(mGroup);
141
142 // Stored in reverse order
143 int n = mHistory.size() - 1;
144 for (size_t i = 1; i <= mHistory.size(); i++) {
145 config.Write(wxString::Format(wxT("file%02d"), (int)i), mHistory[n--]);
146 }
147
148 config.SetPath(wxT(""));
149
150 config.Flush();
151}

References mGroup, mHistory, and wxT().

Referenced by NotifyMenus(), AudacityApp::OnExit(), and ExportCLOptions::TransferDataFromWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UseMenu()

void FileHistory::UseMenu ( wxMenu *  menu)

Definition at line 97 of file FileHistory.cpp.

98{
99 Compress();
100
101 auto end = mMenus.end();
102 auto iter = std::find(mMenus.begin(), end, menu);
103 auto found = (iter != end);
104
105 if (!found)
106 mMenus.push_back(menu);
107 else {
108 wxASSERT(false);
109 }
110
111 NotifyMenu( menu );
112}

References Compress(), end(), mMenus, and NotifyMenu().

Here is the call graph for this function:

Member Data Documentation

◆ mGroup

wxString FileHistory::mGroup
private

Definition at line 74 of file FileHistory.h.

Referenced by Load(), and Save().

◆ mHistory

FilePaths FileHistory::mHistory
private

Definition at line 72 of file FileHistory.h.

Referenced by AddFileToHistory(), Clear(), Load(), NotifyMenu(), Remove(), and Save().

◆ mIDBase

wxWindowID FileHistory::mIDBase
private

Definition at line 69 of file FileHistory.h.

Referenced by FileHistory(), and NotifyMenu().

◆ mMaxFiles

size_t FileHistory::mMaxFiles
private

Definition at line 68 of file FileHistory.h.

Referenced by AddFileToHistory(), and FileHistory().

◆ mMenus

std::vector< wxWeakRef< wxMenu > > FileHistory::mMenus
private

Definition at line 71 of file FileHistory.h.

Referenced by Compress(), NotifyMenus(), and UseMenu().


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