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.

166 lines
6.3KB

  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. /** Tells the OS to add a file to the OS-managed list of recent documents for this app.
  76. Not all OSes maintain a list of recent files for an application, so this
  77. function will have no effect on some OSes. Currently it's just implemented for OSX.
  78. */
  79. static void registerRecentFileNatively (const File& file);
  80. //==============================================================================
  81. /** Adds entries to a menu, representing each of the files in the list.
  82. This is handy for creating an "open recent file..." menu in your app. The
  83. menu items are numbered consecutively starting with the baseItemId value,
  84. and can either be added as complete pathnames, or just the last part of the
  85. filename.
  86. If dontAddNonExistentFiles is true, then each file will be checked and only those
  87. that exist will be added.
  88. If filesToAvoid is non-zero, then it is considered to be a zero-terminated array of
  89. pointers to file objects. Any files that appear in this list will not be added to the
  90. menu - the reason for this is that you might have a number of files already open, so
  91. might not want these to be shown in the menu.
  92. It returns the number of items that were added.
  93. */
  94. int createPopupMenuItems (PopupMenu& menuToAddItemsTo,
  95. int baseItemId,
  96. bool showFullPaths,
  97. bool dontAddNonExistentFiles,
  98. const File** filesToAvoid = nullptr);
  99. //==============================================================================
  100. /** Returns a string that encapsulates all the files in the list.
  101. The string that is returned can later be passed into restoreFromString() in
  102. order to recreate the list. This is handy for persisting your list, e.g. in
  103. a PropertiesFile object.
  104. @see restoreFromString
  105. */
  106. String toString() const;
  107. /** Restores the list from a previously stringified version of the list.
  108. Pass in a stringified version created with toString() in order to persist/restore
  109. your list.
  110. @see toString
  111. */
  112. void restoreFromString (const String& stringifiedVersion);
  113. private:
  114. //==============================================================================
  115. StringArray files;
  116. int maxNumberOfItems;
  117. JUCE_LEAK_DETECTOR (RecentlyOpenedFilesList);
  118. };
  119. #endif // __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__