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.

88 lines
3.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A component that displays the files in a directory as a listbox.
  18. This implements the DirectoryContentsDisplayComponent base class so that
  19. it can be used in a FileBrowserComponent.
  20. To attach a listener to it, use its DirectoryContentsDisplayComponent base
  21. class and the FileBrowserListener class.
  22. @see DirectoryContentsList, FileTreeComponent
  23. @tags{GUI}
  24. */
  25. class JUCE_API FileListComponent : public ListBox,
  26. public DirectoryContentsDisplayComponent,
  27. private ListBoxModel,
  28. private ChangeListener
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a listbox to show the contents of a specified directory. */
  33. FileListComponent (DirectoryContentsList& listToShow);
  34. /** Destructor. */
  35. ~FileListComponent() override;
  36. //==============================================================================
  37. /** Returns the number of files the user has got selected.
  38. @see getSelectedFile
  39. */
  40. int getNumSelectedFiles() const override;
  41. /** Returns one of the files that the user has currently selected.
  42. The index should be in the range 0 to (getNumSelectedFiles() - 1).
  43. @see getNumSelectedFiles
  44. */
  45. File getSelectedFile (int index = 0) const override;
  46. /** Deselects any files that are currently selected. */
  47. void deselectAllFiles() override;
  48. /** Scrolls to the top of the list. */
  49. void scrollToTop() override;
  50. /** If the specified file is in the list, it will become the only selected item
  51. (and if the file isn't in the list, all other items will be deselected). */
  52. void setSelectedFile (const File&) override;
  53. private:
  54. //==============================================================================
  55. File lastDirectory, fileWaitingToBeSelected;
  56. class ItemComponent;
  57. void changeListenerCallback (ChangeBroadcaster*) override;
  58. int getNumRows() override;
  59. void paintListBoxItem (int, Graphics&, int, int, bool) override;
  60. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component*) override;
  61. void selectedRowsChanged (int row) override;
  62. void deleteKeyPressed (int currentSelectedRow) override;
  63. void returnKeyPressed (int currentSelectedRow) override;
  64. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileListComponent)
  65. };
  66. } // namespace juce