juce_FileTreeComponent.h 3.9 KB

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