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.

182 lines
6.6KB

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