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.

102 lines
3.7KB

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