juce_FileListComponent.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #ifndef JUCE_FILELISTCOMPONENT_H_INCLUDED
  18. #define JUCE_FILELISTCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A component that displays the files in a directory as a listbox.
  22. This implements the DirectoryContentsDisplayComponent base class so that
  23. it can be used in a FileBrowserComponent.
  24. To attach a listener to it, use its DirectoryContentsDisplayComponent base
  25. class and the FileBrowserListener class.
  26. @see DirectoryContentsList, FileTreeComponent
  27. */
  28. class JUCE_API FileListComponent : public ListBox,
  29. public DirectoryContentsDisplayComponent,
  30. private ListBoxModel,
  31. private ChangeListener
  32. {
  33. public:
  34. //==============================================================================
  35. /** Creates a listbox to show the contents of a specified directory.
  36. */
  37. FileListComponent (DirectoryContentsList& listToShow);
  38. /** Destructor. */
  39. ~FileListComponent();
  40. //==============================================================================
  41. /** Returns the number of files the user has got selected.
  42. @see getSelectedFile
  43. */
  44. int getNumSelectedFiles() const override;
  45. /** Returns one of the files that the user has currently selected.
  46. The index should be in the range 0 to (getNumSelectedFiles() - 1).
  47. @see getNumSelectedFiles
  48. */
  49. File getSelectedFile (int index = 0) const override;
  50. /** Deselects any files that are currently selected. */
  51. void deselectAllFiles() override;
  52. /** Scrolls to the top of the list. */
  53. void scrollToTop() override;
  54. /** If the specified file is in the list, it will become the only selected item
  55. (and if the file isn't in the list, all other items will be deselected). */
  56. void setSelectedFile (const File&) override;
  57. private:
  58. //==============================================================================
  59. File lastDirectory;
  60. class ItemComponent;
  61. void changeListenerCallback (ChangeBroadcaster*) override;
  62. int getNumRows() override;
  63. void paintListBoxItem (int, Graphics&, int, int, bool) override;
  64. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component*) override;
  65. void selectedRowsChanged (int row) override;
  66. void deleteKeyPressed (int currentSelectedRow) override;
  67. void returnKeyPressed (int currentSelectedRow) override;
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileListComponent)
  69. };
  70. #endif // JUCE_FILELISTCOMPONENT_H_INCLUDED