1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 5 FileHistory.h 6 7 Leland Lucius 8 9 **********************************************************************/ 10 11 #ifndef __AUDACITY_WIDGETS_FILEHISTORY__ 12 #define __AUDACITY_WIDGETS_FILEHISTORY__ 13 14 #include <vector> 15 #include <algorithm> 16 #include <wx/defs.h> 17 #include <wx/weakref.h> // member variable 18 19 #include "Identifier.h" 20 #include "wxArrayStringEx.h" 21 22 class wxConfigBase; 23 class wxMenu; 24 25 class AUDACITY_DLL_API FileHistory 26 { 27 public: 28 FileHistory(size_t maxfiles = 12, wxWindowID idbase = wxID_FILE); 29 virtual ~FileHistory(); 30 FileHistory( const FileHistory& ) = delete; 31 FileHistory &operator =( const FileHistory & ) = delete; 32 33 // These constants define the range of IDs reserved by the global file history 34 enum { 35 ID_RECENT_CLEAR = 6100, 36 ID_RECENT_FIRST = 6101, 37 ID_RECENT_LAST = 6112 38 }; 39 40 static FileHistory &Global(); 41 Append(const FilePath & file)42 void Append( const FilePath &file ) 43 { AddFileToHistory( file, true ); } 44 void Remove( size_t i ); 45 void Clear(); 46 47 // Causes this menu to reflect the contents of this FileHistory, now and 48 // also whenever the history changes. 49 void UseMenu(wxMenu *menu); 50 51 void Load(wxConfigBase& config, const wxString & group = wxEmptyString); 52 void Save(wxConfigBase& config); 53 54 // stl-style accessors 55 using const_iterator = FilePaths::const_iterator; begin()56 const_iterator begin() const { return mHistory.begin(); } end()57 const_iterator end() const { return mHistory.end(); } 58 const FilePath &operator[] ( size_t ii ) const { return mHistory[ ii ]; } empty()59 bool empty() const { return mHistory.empty(); } 60 61 private: 62 void AddFileToHistory(const FilePath & file, bool update); 63 void NotifyMenus(); 64 void NotifyMenu(wxMenu *menu); 65 66 void Compress(); 67 68 size_t mMaxFiles; 69 wxWindowID mIDBase; 70 71 std::vector< wxWeakRef< wxMenu > > mMenus; 72 FilePaths mHistory; 73 74 wxString mGroup; 75 }; 76 77 #endif 78