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.

101 lines
3.8KB

  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 treeview.
  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, FileListComponent
  26. */
  27. class JUCE_API FileTreeComponent : public TreeView,
  28. public DirectoryContentsDisplayComponent
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a listbox to show the contents of a specified directory.
  33. */
  34. FileTreeComponent (DirectoryContentsList& listToShow);
  35. /** Destructor. */
  36. ~FileTreeComponent();
  37. //==============================================================================
  38. /** Returns the number of files the user has got selected.
  39. @see getSelectedFile
  40. */
  41. int getNumSelectedFiles() const override { return TreeView::getNumSelectedItems(); }
  42. /** Returns one of the files that the user has currently selected.
  43. The index should be in the range 0 to (getNumSelectedFiles() - 1).
  44. @see getNumSelectedFiles
  45. */
  46. File getSelectedFile (int index = 0) const override;
  47. /** Deselects any files that are currently selected. */
  48. void deselectAllFiles() override;
  49. /** Scrolls the list to the top. */
  50. void scrollToTop() override;
  51. /** If the specified file is in the list, it will become the only selected item
  52. (and if the file isn't in the list, all other items will be deselected). */
  53. void setSelectedFile (const File&) override;
  54. /** Updates the files in the list. */
  55. void refresh();
  56. /** Setting a name for this allows tree items to be dragged.
  57. The string that you pass in here will be returned by the getDragSourceDescription()
  58. of the items in the tree. For more info, see TreeViewItem::getDragSourceDescription().
  59. */
  60. void setDragAndDropDescription (const String& description);
  61. /** Returns the last value that was set by setDragAndDropDescription().
  62. */
  63. const String& getDragAndDropDescription() const noexcept { return dragAndDropDescription; }
  64. /** Changes the height of the treeview items. */
  65. void setItemHeight (int newHeight);
  66. /** Returns the height of the treeview items. */
  67. int getItemHeight() const noexcept { return itemHeight; }
  68. private:
  69. //==============================================================================
  70. String dragAndDropDescription;
  71. int itemHeight;
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileTreeComponent)
  73. };