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 (audacity::BasicSettings &config, const wxString &group=wxEmptyString)
 
void Save (audacity::BasicSettings &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 29 of file FileHistory.h.

Member Typedef Documentation

◆ const_iterator

using FileHistory::const_iterator = FilePaths::const_iterator

Definition at line 59 of file FileHistory.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ID_RECENT_CLEAR 
ID_RECENT_FIRST 
ID_RECENT_LAST 

Definition at line 38 of file FileHistory.h.

38 {
39 ID_RECENT_CLEAR = 6100,
40 ID_RECENT_FIRST = 6101,
41 ID_RECENT_LAST = 6112
42 };

Constructor & Destructor Documentation

◆ FileHistory() [1/2]

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

Definition at line 29 of file FileHistory.cpp.

30{
31 mMaxFiles = maxfiles;
32 mIDBase = base;
33}
wxWindowID mIDBase
Definition: FileHistory.h:73
size_t mMaxFiles
Definition: FileHistory.h:72

References mIDBase, and mMaxFiles.

◆ ~FileHistory()

FileHistory::~FileHistory ( )
virtual

Definition at line 35 of file FileHistory.cpp.

36{
37}

◆ FileHistory() [2/2]

FileHistory::FileHistory ( const FileHistory )
delete

Member Function Documentation

◆ AddFileToHistory()

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

Definition at line 53 of file FileHistory.cpp.

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

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

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

Here is the caller graph for this function:

◆ begin()

const_iterator FileHistory::begin ( ) const
inline

Definition at line 60 of file FileHistory.h.

60{ return mHistory.begin(); }

Referenced by ExportOptionsCLEditor::PopulateUI().

Here is the caller graph for this function:

◆ Clear()

void FileHistory::Clear ( )

Definition at line 92 of file FileHistory.cpp.

93{
94 mHistory.clear();
95
97}

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 171 of file FileHistory.cpp.

172{
173 // Clear up expired weak pointers
174 auto end = mMenus.end();
175 mMenus.erase(
176 std::remove_if( mMenus.begin(), end,
177 [](wxWeakRef<wxMenu> &pMenu){ return !pMenu; } ),
178 end
179 );
180}
const_iterator end() const
Definition: FileHistory.h:61
std::vector< wxWeakRef< wxMenu > > mMenus
Definition: FileHistory.h:75

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 63 of file FileHistory.h.

63{ return mHistory.empty(); }

Referenced by ExportOptionsCLEditor::PopulateUI().

Here is the caller graph for this function:

◆ end()

const_iterator FileHistory::end ( ) const
inline

Definition at line 61 of file FileHistory.h.

61{ return mHistory.end(); }

Referenced by Compress(), NotifyMenu(), ExportOptionsCLEditor::PopulateUI(), and UseMenu().

Here is the caller graph for this function:

◆ Global()

FileHistory & FileHistory::Global ( )
static

Definition at line 39 of file FileHistory.cpp.

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

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

Referenced by anonymous_namespace{FileMenus.cpp}::DoExport(), anonymous_namespace{ImportMIDI.cpp}::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 ( audacity::BasicSettings config,
const wxString &  group = wxEmptyString 
)

Definition at line 116 of file FileHistory.cpp.

117{
118 mHistory.clear();
119 mGroup = group.empty()
120 ? wxString{ "RecentFiles" }
121 : group;
122
123 const auto localGroup = settings.BeginGroup(mGroup);
124 for(const auto& key : settings.GetChildKeys())
125 AddFileToHistory(settings.Read(key), false);
126
127 NotifyMenus();
128}
static const AudacityProject::AttachedObjects::RegisteredFactory key
static Settings & settings()
Definition: TrackInfo.cpp:69
wxString mGroup
Definition: FileHistory.h:78

References AddFileToHistory(), key, mGroup, mHistory, NotifyMenus(), and settings().

Referenced by ExportOptionsCLEditor::PopulateUI().

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

◆ NotifyMenu()

void FileHistory::NotifyMenu ( wxMenu *  menu)
private

Definition at line 152 of file FileHistory.cpp.

153{
154 wxMenuItemList items = menu->GetMenuItems();
155 for (auto end = items.end(), iter = items.begin(); iter != end;)
156 menu->Destroy(*iter++);
157
158 for (size_t i = 0; i < mHistory.size(); i++) {
159 wxString item = mHistory[i];
160 item.Replace( "&", "&&" );
161 menu->Append(mIDBase + 1 + i,item);
162 }
163
164 if (mHistory.size() > 0) {
165 menu->AppendSeparator();
166 }
167 menu->Append(mIDBase, _("&Clear"));
168 menu->Enable(mIDBase, mHistory.size() > 0);
169}
#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 143 of file FileHistory.cpp.

144{
145 Compress();
146 for (auto pMenu : mMenus)
147 if (pMenu)
148 NotifyMenu(pMenu);
149 Save(*gPrefs);
150}
void NotifyMenu(wxMenu *menu)
void Compress()
void Save(audacity::BasicSettings &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 62 of file FileHistory.h.

62{ return mHistory[ ii ]; }

◆ Remove()

void FileHistory::Remove ( size_t  i)

Definition at line 81 of file FileHistory.cpp.

82{
83 wxASSERT(i < mHistory.size());
84
85 if (i < mHistory.size()) {
86 mHistory.erase( mHistory.begin() + i );
87
89 }
90}

References mHistory, and NotifyMenus().

Here is the call graph for this function:

◆ Save()

void FileHistory::Save ( audacity::BasicSettings config)

Definition at line 130 of file FileHistory.cpp.

131{
132 auto group = settings.BeginGroup(mGroup);
133 settings.Remove({});
134
135 // Stored in reverse order
136 int n = mHistory.size() - 1;
137 for (size_t i = 1; i <= mHistory.size(); i++) {
138 settings.Write(wxString::Format(wxT("file%02d"), (int)i), mHistory[n--]);
139 }
140 settings.Flush();
141}

References mGroup, mHistory, settings(), and wxT().

Referenced by NotifyMenus(), AudacityApp::OnExit(), and ExportOptionsCLEditor::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 99 of file FileHistory.cpp.

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

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 78 of file FileHistory.h.

Referenced by Load(), and Save().

◆ mHistory

FilePaths FileHistory::mHistory
private

Definition at line 76 of file FileHistory.h.

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

◆ mIDBase

wxWindowID FileHistory::mIDBase
private

Definition at line 73 of file FileHistory.h.

Referenced by FileHistory(), and NotifyMenu().

◆ mMaxFiles

size_t FileHistory::mMaxFiles
private

Definition at line 72 of file FileHistory.h.

Referenced by AddFileToHistory(), and FileHistory().

◆ mMenus

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

Definition at line 75 of file FileHistory.h.

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


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