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.

165 lines
6.1KB

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