The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
6.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  19. #define __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Manages a set of files for use as a list of recently-opened documents.
  23. This is a handy class for holding your list of recently-opened documents, with
  24. helpful methods for things like purging any non-existent files, automatically
  25. adding them to a menu, and making persistence easy.
  26. @see File, FileBasedDocument
  27. */
  28. class JUCE_API RecentlyOpenedFilesList
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates an empty list.
  33. */
  34. RecentlyOpenedFilesList();
  35. /** Destructor. */
  36. ~RecentlyOpenedFilesList();
  37. //==============================================================================
  38. /** Sets a limit for the number of files that will be stored in the list.
  39. When addFile() is called, then if there is no more space in the list, the
  40. least-recently added file will be dropped.
  41. @see getMaxNumberOfItems
  42. */
  43. void setMaxNumberOfItems (int newMaxNumber);
  44. /** Returns the number of items that this list will store.
  45. @see setMaxNumberOfItems
  46. */
  47. int getMaxNumberOfItems() const noexcept { return maxNumberOfItems; }
  48. /** Returns the number of files in the list.
  49. The most recently added file is always at index 0.
  50. */
  51. int getNumFiles() const;
  52. /** Returns one of the files in the list.
  53. The most recently added file is always at index 0.
  54. */
  55. File getFile (int index) const;
  56. /** Returns an array of all the absolute pathnames in the list.
  57. */
  58. const StringArray& getAllFilenames() const noexcept { return files; }
  59. /** Clears all the files from the list. */
  60. void clear();
  61. /** Adds a file to the list.
  62. The file will be added at index 0. If this file is already in the list, it will
  63. be moved up to index 0, but a file can only appear once in the list.
  64. If the list already contains the maximum number of items that is permitted, the
  65. least-recently added file will be dropped from the end.
  66. */
  67. void addFile (const File& file);
  68. /** Removes a file from the list. */
  69. void removeFile (const File& file);
  70. /** Checks each of the files in the list, removing any that don't exist.
  71. You might want to call this after reloading a list of files, or before putting them
  72. on a menu.
  73. */
  74. void removeNonExistentFiles();
  75. //==============================================================================
  76. /** Adds entries to a menu, representing each of the files in the list.
  77. This is handy for creating an "open recent file..." menu in your app. The
  78. menu items are numbered consecutively starting with the baseItemId value,
  79. and can either be added as complete pathnames, or just the last part of the
  80. filename.
  81. If dontAddNonExistentFiles is true, then each file will be checked and only those
  82. that exist will be added.
  83. If filesToAvoid is non-zero, then it is considered to be a zero-terminated array of
  84. pointers to file objects. Any files that appear in this list will not be added to the
  85. menu - the reason for this is that you might have a number of files already open, so
  86. might not want these to be shown in the menu.
  87. It returns the number of items that were added.
  88. */
  89. int createPopupMenuItems (PopupMenu& menuToAddItemsTo,
  90. int baseItemId,
  91. bool showFullPaths,
  92. bool dontAddNonExistentFiles,
  93. const File** filesToAvoid = nullptr);
  94. //==============================================================================
  95. /** Returns a string that encapsulates all the files in the list.
  96. The string that is returned can later be passed into restoreFromString() in
  97. order to recreate the list. This is handy for persisting your list, e.g. in
  98. a PropertiesFile object.
  99. @see restoreFromString
  100. */
  101. String toString() const;
  102. /** Restores the list from a previously stringified version of the list.
  103. Pass in a stringified version created with toString() in order to persist/restore
  104. your list.
  105. @see toString
  106. */
  107. void restoreFromString (const String& stringifiedVersion);
  108. private:
  109. //==============================================================================
  110. StringArray files;
  111. int maxNumberOfItems;
  112. JUCE_LEAK_DETECTOR (RecentlyOpenedFilesList);
  113. };
  114. #endif // __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__