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.

93 lines
3.4KB

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