Audacity  2.2.2
Public Member Functions | Private Attributes | List of all members
FileHistory Class Reference

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

#include <FileHistory.h>

Public Member Functions

 FileHistory (size_t maxfiles=12, wxWindowID idbase=wxID_FILE)
 
virtual ~FileHistory ()
 
void AddFileToHistory (const wxString &file, bool update=true)
 
void RemoveFileFromHistory (size_t i, bool update=true)
 
void Clear ()
 
void UseMenu (wxMenu *menu)
 
void RemoveMenu (wxMenu *menu)
 
void Load (wxConfigBase &config, const wxString &group)
 
void Save (wxConfigBase &config, const wxString &group)
 
void AddFilesToMenu ()
 
void AddFilesToMenu (wxMenu *menu)
 
size_t GetCount ()
 
const wxString & GetHistoryFile (size_t i) const
 

Private Attributes

size_t mMaxFiles
 
wxWindowID mIDBase
 
std::vector< wxMenu * > mMenus
 
wxArrayString mHistory
 

Detailed Description

Similar to FileHistory, but customized to our needs.

Definition at line 23 of file FileHistory.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file FileHistory.cpp.

References mIDBase, and mMaxFiles.

26 {
27  mMaxFiles = maxfiles;
28  mIDBase = base;
29 }
size_t mMaxFiles
Definition: FileHistory.h:44
wxWindowID mIDBase
Definition: FileHistory.h:45
FileHistory::~FileHistory ( )
virtual

Definition at line 31 of file FileHistory.cpp.

32 {
33 }

Member Function Documentation

void FileHistory::AddFilesToMenu ( )

Definition at line 161 of file FileHistory.cpp.

References mMenus.

Referenced by AddFileToHistory(), Clear(), AudacityProject::CreateRecentFilesMenu(), Load(), and RemoveFileFromHistory().

162 {
163  for (auto pMenu : mMenus)
164  AddFilesToMenu(pMenu);
165 }
std::vector< wxMenu * > mMenus
Definition: FileHistory.h:47
void AddFilesToMenu()
void FileHistory::AddFilesToMenu ( wxMenu *  menu)

Definition at line 167 of file FileHistory.cpp.

References _(), mHistory, and mIDBase.

168 {
169  wxMenuItemList items = menu->GetMenuItems();
170  for (auto end = items.end(), iter = items.begin(); iter != end;)
171  menu->Destroy(*iter++);
172 
173  for (size_t i = 0; i < mHistory.GetCount(); i++) {
174  wxString item = mHistory[i];
175  item.Replace( "&", "&&" );
176  menu->Append(mIDBase + 1 + i,item);
177  }
178 
179  if (mHistory.GetCount() > 0) {
180  menu->AppendSeparator();
181  }
182  menu->Append(mIDBase, _("&Clear"));
183  menu->Enable(mIDBase, mHistory.GetCount() > 0);
184 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxArrayString mHistory
Definition: FileHistory.h:48
wxWindowID mIDBase
Definition: FileHistory.h:45
void FileHistory::AddFileToHistory ( const wxString &  file,
bool  update = true 
)

Definition at line 36 of file FileHistory.cpp.

References AddFilesToMenu(), mHistory, and mMaxFiles.

Referenced by Load(), and ExportCLOptions::TransferDataFromWindow().

37 {
38  // Needed to transition from wxFileHistory to FileHistory since there
39  // can be empty history "slots".
40  if (file.IsEmpty()) {
41  return;
42  }
43 
44 #if defined(__WXMSW__)
45  int i = mHistory.Index(file, false);
46 #else
47  int i = mHistory.Index(file, true);
48 #endif
49 
50  if (i != wxNOT_FOUND) {
51  mHistory.RemoveAt(i);
52  }
53 
54  if (mMaxFiles == mHistory.GetCount()) {
55  mHistory.RemoveAt(mHistory.GetCount() - 1);
56  }
57 
58  mHistory.Insert(file, 0);
59 
60  if (update) {
62  }
63 }
size_t mMaxFiles
Definition: FileHistory.h:44
void AddFilesToMenu()
wxArrayString mHistory
Definition: FileHistory.h:48
void FileHistory::Clear ( )

Definition at line 78 of file FileHistory.cpp.

References AddFilesToMenu(), and mHistory.

79 {
80  mHistory.Clear();
81 
83 }
void AddFilesToMenu()
wxArrayString mHistory
Definition: FileHistory.h:48
size_t FileHistory::GetCount ( )

Definition at line 97 of file FileHistory.cpp.

References mHistory.

Referenced by ExportCLOptions::PopulateOrExchange().

98 {
99  return mHistory.GetCount();
100 }
wxArrayString mHistory
Definition: FileHistory.h:48
const wxString & FileHistory::GetHistoryFile ( size_t  i) const

Definition at line 85 of file FileHistory.cpp.

References mHistory.

Referenced by ExportCLOptions::PopulateOrExchange().

86 {
87  wxASSERT(i < mHistory.GetCount());
88 
89  if (i < mHistory.GetCount()) {
90  return mHistory[i];
91  }
92 
93  static const wxString empty;
94  return empty;
95 }
wxArrayString mHistory
Definition: FileHistory.h:48
void FileHistory::Load ( wxConfigBase &  config,
const wxString &  group 
)

Definition at line 128 of file FileHistory.cpp.

References AddFilesToMenu(), AddFileToHistory(), and mHistory.

129 {
130  mHistory.Clear();
131 
132  config.SetPath(group);
133 
134  wxString file;
135  long ndx;
136  bool got = config.GetFirstEntry(file, ndx);
137  while (got) {
138  AddFileToHistory(config.Read(file), false);
139  got = config.GetNextEntry(file, ndx);
140  }
141 
142  config.SetPath(wxT(".."));
143 
144  AddFilesToMenu();
145 }
void AddFilesToMenu()
wxArrayString mHistory
Definition: FileHistory.h:48
void AddFileToHistory(const wxString &file, bool update=true)
Definition: FileHistory.cpp:36
void FileHistory::RemoveFileFromHistory ( size_t  i,
bool  update = true 
)

Definition at line 65 of file FileHistory.cpp.

References AddFilesToMenu(), and mHistory.

66 {
67  wxASSERT(i < mHistory.GetCount());
68 
69  if (i < mHistory.GetCount()) {
70  mHistory.RemoveAt(i);
71 
72  if (update) {
74  }
75  }
76 }
void AddFilesToMenu()
wxArrayString mHistory
Definition: FileHistory.h:48
void FileHistory::RemoveMenu ( wxMenu *  menu)

Definition at line 115 of file FileHistory.cpp.

References mMenus.

Referenced by AudacityProject::RebuildMenuBar(), and AudacityProject::~AudacityProject().

116 {
117  auto end = mMenus.end();
118  auto iter = std::find(mMenus.begin(), end, menu);
119  auto found = (iter != end);
120 
121  if (found)
122  mMenus.erase(iter);
123  else {
124  wxASSERT(false);
125  }
126 }
std::vector< wxMenu * > mMenus
Definition: FileHistory.h:47
void FileHistory::Save ( wxConfigBase &  config,
const wxString &  group 
)

Definition at line 147 of file FileHistory.cpp.

References mHistory.

Referenced by ExportCLOptions::TransferDataFromWindow().

148 {
149  config.DeleteGroup(group);
150  config.SetPath(group);
151 
152  // Stored in reverse order
153  int n = mHistory.GetCount() - 1;
154  for (size_t i = 1; i <= mHistory.GetCount(); i++) {
155  config.Write(wxString::Format(wxT("file%02d"), (int)i), mHistory[n--]);
156  }
157 
158  config.SetPath(wxT(".."));
159 }
wxArrayString mHistory
Definition: FileHistory.h:48
void FileHistory::UseMenu ( wxMenu *  menu)

Definition at line 102 of file FileHistory.cpp.

References mMenus.

Referenced by AudacityProject::CreateRecentFilesMenu().

103 {
104  auto end = mMenus.end();
105  auto iter = std::find(mMenus.begin(), end, menu);
106  auto found = (iter != end);
107 
108  if (!found)
109  mMenus.push_back(menu);
110  else {
111  wxASSERT(false);
112  }
113 }
std::vector< wxMenu * > mMenus
Definition: FileHistory.h:47

Member Data Documentation

wxArrayString FileHistory::mHistory
private
wxWindowID FileHistory::mIDBase
private

Definition at line 45 of file FileHistory.h.

Referenced by AddFilesToMenu(), and FileHistory().

size_t FileHistory::mMaxFiles
private

Definition at line 44 of file FileHistory.h.

Referenced by AddFileToHistory(), and FileHistory().

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

Definition at line 47 of file FileHistory.h.

Referenced by AddFilesToMenu(), RemoveMenu(), and UseMenu().


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