1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a public member DirectoryContentsDisplayComponent::directoryContentsList

This commit is contained in:
jules 2017-06-06 10:21:44 +01:00
parent dfcc6780dd
commit b6478be22c
4 changed files with 26 additions and 35 deletions

View file

@ -24,8 +24,8 @@
==============================================================================
*/
DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
: fileList (listToShow)
DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& l)
: directoryContentsList (l)
{
}
@ -38,15 +38,8 @@ FileBrowserListener::~FileBrowserListener()
{
}
void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
{
listeners.add (listener);
}
void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
{
listeners.remove (listener);
}
void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* l) { listeners.add (l); }
void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* l) { listeners.remove (l); }
void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
{
@ -56,7 +49,7 @@ void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
{
if (fileList.getDirectory().exists())
if (directoryContentsList.getDirectory().exists())
{
Component::BailOutChecker checker (dynamic_cast<Component*> (this));
listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
@ -65,7 +58,7 @@ void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file,
void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
{
if (fileList.getDirectory().exists())
if (directoryContentsList.getDirectory().exists())
{
Component::BailOutChecker checker (dynamic_cast<Component*> (this));
listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);

View file

@ -43,6 +43,10 @@ public:
/** Destructor. */
virtual ~DirectoryContentsDisplayComponent();
//==============================================================================
/** The list that this component is displaying */
DirectoryContentsList& directoryContentsList;
//==============================================================================
/** Returns the number of files the user has got selected.
@see getSelectedFile
@ -95,14 +99,13 @@ public:
/** @internal */
void sendSelectionChangeMessage();
/** @internal */
void sendDoubleClickMessage (const File& file);
void sendDoubleClickMessage (const File&);
/** @internal */
void sendMouseClickMessage (const File& file, const MouseEvent& e);
void sendMouseClickMessage (const File&, const MouseEvent&);
protected:
//==============================================================================
DirectoryContentsList& fileList;
ListenerList <FileBrowserListener> listeners;
ListenerList<FileBrowserListener> listeners;
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectoryContentsDisplayComponent)

View file

@ -29,7 +29,7 @@ Image juce_createIconForFile (const File& file);
//==============================================================================
FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
: ListBox (String(), nullptr),
: ListBox ({}, nullptr),
DirectoryContentsDisplayComponent (listToShow)
{
setModel (this);
@ -94,7 +94,7 @@ class FileListComponent::ItemComponent : public Component,
{
public:
ItemComponent (FileListComponent& fc, TimeSliceThread& t)
: owner (fc), thread (t), index (0), highlighted (false)
: owner (fc), thread (t)
{
}
@ -124,17 +124,15 @@ public:
owner.sendDoubleClickMessage (file);
}
void update (const File& root,
const DirectoryContentsList::FileInfo* const fileInfo,
const int index_,
const bool highlighted_)
void update (const File& root, const DirectoryContentsList::FileInfo* fileInfo,
int newIndex, bool nowHighlighted)
{
thread.removeTimeSliceClient (this);
if (highlighted_ != highlighted || index_ != index)
if (nowHighlighted != highlighted || newIndex != index)
{
index = index_;
highlighted = highlighted_;
index = newIndex;
highlighted = nowHighlighted;
repaint();
}
@ -188,15 +186,15 @@ private:
File file;
String fileSize, modTime;
Image icon;
int index;
bool highlighted, isDirectory;
int index = 0;
bool highlighted = false, isDirectory = false;
void updateIcon (const bool onlyUpdateIfCached)
{
if (icon.isNull())
{
const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
Image im (ImageCache::getFromHashCode (hashCode));
auto hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
auto im = ImageCache::getFromHashCode (hashCode);
if (im.isNull() && ! onlyUpdateIfCached)
{
@ -231,7 +229,7 @@ Component* FileListComponent::refreshComponentForRow (int row, bool isSelected,
{
jassert (existingComponentToUpdate == nullptr || dynamic_cast<ItemComponent*> (existingComponentToUpdate) != nullptr);
ItemComponent* comp = static_cast<ItemComponent*> (existingComponentToUpdate);
auto comp = static_cast<ItemComponent*> (existingComponentToUpdate);
if (comp == nullptr)
comp = new ItemComponent (*this, fileList.getTimeSliceThread());

View file

@ -46,8 +46,7 @@ class JUCE_API FileListComponent : public ListBox,
{
public:
//==============================================================================
/** Creates a listbox to show the contents of a specified directory.
*/
/** Creates a listbox to show the contents of a specified directory. */
FileListComponent (DirectoryContentsList& listToShow);
/** Destructor. */
@ -78,11 +77,9 @@ public:
private:
//==============================================================================
File lastDirectory;
class ItemComponent;
void changeListenerCallback (ChangeBroadcaster*) override;
int getNumRows() override;
void paintListBoxItem (int, Graphics&, int, int, bool) override;
Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component*) override;