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.

139 lines
4.1KB

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