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.

147 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  18. : maxNumberOfItems (10)
  19. {
  20. }
  21. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  22. {
  23. }
  24. //==============================================================================
  25. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  26. {
  27. maxNumberOfItems = jmax (1, newMaxNumber);
  28. files.removeRange (maxNumberOfItems, getNumFiles());
  29. }
  30. int RecentlyOpenedFilesList::getNumFiles() const
  31. {
  32. return files.size();
  33. }
  34. File RecentlyOpenedFilesList::getFile (const int index) const
  35. {
  36. return File (files [index]);
  37. }
  38. void RecentlyOpenedFilesList::clear()
  39. {
  40. files.clear();
  41. }
  42. void RecentlyOpenedFilesList::addFile (const File& file)
  43. {
  44. removeFile (file);
  45. files.insert (0, file.getFullPathName());
  46. setMaxNumberOfItems (maxNumberOfItems);
  47. }
  48. void RecentlyOpenedFilesList::removeFile (const File& file)
  49. {
  50. files.removeString (file.getFullPathName());
  51. }
  52. void RecentlyOpenedFilesList::removeNonExistentFiles()
  53. {
  54. for (int i = getNumFiles(); --i >= 0;)
  55. if (! getFile(i).exists())
  56. files.remove (i);
  57. }
  58. //==============================================================================
  59. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  60. const int baseItemId,
  61. const bool showFullPaths,
  62. const bool dontAddNonExistentFiles,
  63. const File** filesToAvoid)
  64. {
  65. int num = 0;
  66. for (int i = 0; i < getNumFiles(); ++i)
  67. {
  68. const File f (getFile(i));
  69. if ((! dontAddNonExistentFiles) || f.exists())
  70. {
  71. bool needsAvoiding = false;
  72. if (filesToAvoid != nullptr)
  73. {
  74. for (const File** avoid = filesToAvoid; *avoid != nullptr; ++avoid)
  75. {
  76. if (f == **avoid)
  77. {
  78. needsAvoiding = true;
  79. break;
  80. }
  81. }
  82. }
  83. if (! needsAvoiding)
  84. {
  85. menuToAddTo.addItem (baseItemId + i,
  86. showFullPaths ? f.getFullPathName()
  87. : f.getFileName());
  88. ++num;
  89. }
  90. }
  91. }
  92. return num;
  93. }
  94. //==============================================================================
  95. String RecentlyOpenedFilesList::toString() const
  96. {
  97. return files.joinIntoString ("\n");
  98. }
  99. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  100. {
  101. clear();
  102. files.addLines (stringifiedVersion);
  103. setMaxNumberOfItems (maxNumberOfItems);
  104. }
  105. //==============================================================================
  106. void RecentlyOpenedFilesList::registerRecentFileNatively (const File& file)
  107. {
  108. #if JUCE_MAC
  109. JUCE_AUTORELEASEPOOL
  110. {
  111. [[NSDocumentController sharedDocumentController]
  112. noteNewRecentDocumentURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  113. }
  114. #else
  115. (void) file;
  116. #endif
  117. }