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.4KB

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