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.

149 lines
4.2KB

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