filehistory.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/filehistory.h
  3. // Purpose: wxFileHistory class
  4. // Author: Julian Smart, Vaclav Slavik
  5. // Created: 2010-05-03
  6. // Copyright: (c) Julian Smart, Vaclav Slavik
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_FILEHISTORY_H_
  10. #define _WX_FILEHISTORY_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_FILE_HISTORY
  13. #include "wx/windowid.h"
  14. #include "wx/object.h"
  15. #include "wx/list.h"
  16. #include "wx/string.h"
  17. #include "wx/arrstr.h"
  18. class WXDLLIMPEXP_FWD_CORE wxMenu;
  19. class WXDLLIMPEXP_FWD_BASE wxConfigBase;
  20. class WXDLLIMPEXP_FWD_BASE wxFileName;
  21. // ----------------------------------------------------------------------------
  22. // File history management
  23. // ----------------------------------------------------------------------------
  24. class WXDLLIMPEXP_CORE wxFileHistoryBase : public wxObject
  25. {
  26. public:
  27. wxFileHistoryBase(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
  28. // Operations
  29. virtual void AddFileToHistory(const wxString& file);
  30. virtual void RemoveFileFromHistory(size_t i);
  31. virtual int GetMaxFiles() const { return (int)m_fileMaxFiles; }
  32. virtual void UseMenu(wxMenu *menu);
  33. // Remove menu from the list (MDI child may be closing)
  34. virtual void RemoveMenu(wxMenu *menu);
  35. #if wxUSE_CONFIG
  36. virtual void Load(const wxConfigBase& config);
  37. virtual void Save(wxConfigBase& config);
  38. #endif // wxUSE_CONFIG
  39. virtual void AddFilesToMenu();
  40. virtual void AddFilesToMenu(wxMenu* menu); // Single menu
  41. // Accessors
  42. virtual wxString GetHistoryFile(size_t i) const { return m_fileHistory[i]; }
  43. virtual size_t GetCount() const { return m_fileHistory.GetCount(); }
  44. const wxList& GetMenus() const { return m_fileMenus; }
  45. // Set/get base id
  46. void SetBaseId(wxWindowID baseId) { m_idBase = baseId; }
  47. wxWindowID GetBaseId() const { return m_idBase; }
  48. #if WXWIN_COMPATIBILITY_2_6
  49. // deprecated, use GetCount() instead
  50. wxDEPRECATED( size_t GetNoHistoryFiles() const );
  51. #endif // WXWIN_COMPATIBILITY_2_6
  52. protected:
  53. // Last n files
  54. wxArrayString m_fileHistory;
  55. // Menus to maintain (may need several for an MDI app)
  56. wxList m_fileMenus;
  57. // Max files to maintain
  58. size_t m_fileMaxFiles;
  59. private:
  60. // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
  61. wxWindowID m_idBase;
  62. // Normalize a file name to canonical form. We have a special function for
  63. // this to ensure the same normalization is used everywhere.
  64. static wxString NormalizeFileName(const wxFileName& filename);
  65. wxDECLARE_NO_COPY_CLASS(wxFileHistoryBase);
  66. };
  67. #if WXWIN_COMPATIBILITY_2_6
  68. inline size_t wxFileHistoryBase::GetNoHistoryFiles() const
  69. {
  70. return m_fileHistory.GetCount();
  71. }
  72. #endif // WXWIN_COMPATIBILITY_2_6
  73. #if defined(__WXGTK20__)
  74. #include "wx/gtk/filehistory.h"
  75. #else
  76. // no platform-specific implementation of wxFileHistory yet
  77. class WXDLLIMPEXP_CORE wxFileHistory : public wxFileHistoryBase
  78. {
  79. public:
  80. wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1)
  81. : wxFileHistoryBase(maxFiles, idBase) {}
  82. DECLARE_DYNAMIC_CLASS(wxFileHistory)
  83. };
  84. #endif
  85. #endif // wxUSE_FILE_HISTORY
  86. #endif // _WX_FILEHISTORY_H_