JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_FileListComponent.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
31 : ListBox ({}, this),
33 lastDirectory (listToShow.getDirectory())
34{
35 setTitle ("Files");
36 directoryContentsList.addChangeListener (this);
37}
38
43
48
53
58
63
65{
67 {
68 for (int i = directoryContentsList.getNumFiles(); --i >= 0;)
69 {
70 if (directoryContentsList.getFile (i) == f)
71 {
72 fileWaitingToBeSelected = File();
73
75 selectRow (i);
76 return;
77 }
78 }
79 }
80
82 fileWaitingToBeSelected = f;
83}
84
85//==============================================================================
86void FileListComponent::changeListenerCallback (ChangeBroadcaster*)
87{
89
90 if (lastDirectory != directoryContentsList.getDirectory())
91 {
92 fileWaitingToBeSelected = File();
93 lastDirectory = directoryContentsList.getDirectory();
95 }
96
97 if (fileWaitingToBeSelected != File())
98 setSelectedFile (fileWaitingToBeSelected);
99}
100
101//==============================================================================
103 public TooltipClient,
104 private TimeSliceClient,
105 private AsyncUpdater
106{
107public:
109 : owner (fc), thread (t)
110 {
111 }
112
113 ~ItemComponent() override
114 {
115 thread.removeTimeSliceClient (this);
116 }
117
118 //==============================================================================
119 void paint (Graphics& g) override
120 {
121 getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
122 file, file.getFileName(),
123 &icon, fileSize, modTime,
124 isDirectory, highlighted,
125 index, owner);
126 }
127
128 void mouseDown (const MouseEvent& e) override
129 {
130 owner.selectRowsBasedOnModifierKeys (index, e.mods, true);
131 owner.sendMouseClickMessage (file, e);
132 }
133
134 void mouseDoubleClick (const MouseEvent&) override
135 {
136 owner.sendDoubleClickMessage (file);
137 }
138
139 void update (const File& root, const DirectoryContentsList::FileInfo* fileInfo,
140 int newIndex, bool nowHighlighted)
141 {
142 thread.removeTimeSliceClient (this);
143
144 if (nowHighlighted != highlighted || newIndex != index)
145 {
146 index = newIndex;
147 highlighted = nowHighlighted;
148 repaint();
149 }
150
153
154 if (fileInfo != nullptr)
155 {
156 newFile = root.getChildFile (fileInfo->filename);
158 newModTime = fileInfo->modificationTime.formatted ("%d %b '%y %H:%M");
159 }
160
161 if (newFile != file
162 || fileSize != newFileSize
163 || modTime != newModTime)
164 {
165 file = newFile;
166 fileSize = newFileSize;
167 modTime = newModTime;
168 icon = Image();
169 isDirectory = fileInfo != nullptr && fileInfo->isDirectory;
170
171 repaint();
172 }
173
174 if (file != File() && icon.isNull() && ! isDirectory)
175 {
176 updateIcon (true);
177
178 if (! icon.isValid())
179 thread.addTimeSliceClient (this);
180 }
181 }
182
183 int useTimeSlice() override
184 {
185 updateIcon (false);
186 return -1;
187 }
188
189 void handleAsyncUpdate() override
190 {
191 repaint();
192 }
193
195 {
196 return owner.getTooltipForRow (index);
197 }
198
199private:
200 //==============================================================================
201 FileListComponent& owner;
202 TimeSliceThread& thread;
203 File file;
204 String fileSize, modTime;
205 Image icon;
206 int index = 0;
207 bool highlighted = false, isDirectory = false;
208
209 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override
210 {
212 }
213
214 void updateIcon (const bool onlyUpdateIfCached)
215 {
216 if (icon.isNull())
217 {
218 auto hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
219 auto im = ImageCache::getFromHashCode (hashCode);
220
221 if (im.isNull() && ! onlyUpdateIfCached)
222 {
223 im = detail::WindowingHelpers::createIconForFile (file);
224
225 if (im.isValid())
227 }
228
229 if (im.isValid())
230 {
231 icon = im;
233 }
234 }
235 }
236
238};
239
240//==============================================================================
241int FileListComponent::getNumRows()
242{
244}
245
246String FileListComponent::getNameForRow (int rowNumber)
247{
249}
250
251void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
252{
253}
254
255Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
256{
257 jassert (existingComponentToUpdate == nullptr || dynamic_cast<ItemComponent*> (existingComponentToUpdate) != nullptr);
258
259 auto comp = static_cast<ItemComponent*> (existingComponentToUpdate);
260
261 if (comp == nullptr)
262 comp = new ItemComponent (*this, directoryContentsList.getTimeSliceThread());
263
264 DirectoryContentsList::FileInfo fileInfo;
265 comp->update (directoryContentsList.getDirectory(),
267 row, isSelected);
268
269 return comp;
270}
271
272void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
273{
274 sendSelectionChangeMessage();
275}
276
277void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
278{
279}
280
281void FileListComponent::returnKeyPressed (int currentSelectedRow)
282{
283 sendDoubleClickMessage (directoryContentsList.getFile (currentSelectedRow));
284}
285
286} // namespace juce
Has a callback method that is triggered asynchronously.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
Holds a list of ChangeListeners, and sends messages to them when instructed.
void removeChangeListener(ChangeListener *listener)
Unregisters a listener from the list.
The base class for all JUCE user-interface objects.
int getHeight() const noexcept
Returns the component's height in pixels.
void repaint()
Marks the whole component as needing to be redrawn.
int getWidth() const noexcept
Returns the component's width in pixels.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
A base class for components that display a list of the files in a directory.
DirectoryContentsList & directoryContentsList
The list that this component is displaying.
A class to asynchronously scan for details about the files in a directory.
const File & getDirectory() const noexcept
Returns the directory that's currently being used.
bool getFileInfo(int index, FileInfo &resultInfo) const
Returns the cached information about one of the files in the list.
bool isStillLoading() const
True if the background thread hasn't yet finished scanning for files.
int getNumFiles() const noexcept
Returns the number of files currently available in the list.
File getFile(int index) const
Returns one of the files in the list.
Contains cached information about one of the files in a DirectoryContentsList.
int useTimeSlice() override
Called back by a TimeSliceThread.
void mouseDoubleClick(const MouseEvent &) override
Called when a mouse button has been double-clicked on a component.
String getTooltip() override
Returns the string that this object wants to show as its tooltip.
void handleAsyncUpdate() override
Called back to do whatever your class needs to do.
void mouseDown(const MouseEvent &e) override
Called when a mouse button is pressed.
void paint(Graphics &g) override
Components can override this method to draw their content.
A component that displays the files in a directory as a listbox.
FileListComponent(DirectoryContentsList &listToShow)
Creates a listbox to show the contents of a specified directory.
void deselectAllFiles() override
Deselects any files that are currently selected.
void setSelectedFile(const File &) override
If the specified file is in the list, it will become the only selected item (and if the file isn't in...
~FileListComponent() override
Destructor.
void scrollToTop() override
Scrolls to the top of the list.
File getSelectedFile(int index=0) const override
Returns one of the files that the user has currently selected.
int getNumSelectedFiles() const override
Returns the number of files the user has got selected.
Represents a local file or directory.
Definition juce_File.h:45
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
Definition juce_File.h:153
String getFileName() const
Returns the last section of the pathname.
File getChildFile(StringRef relativeOrAbsolutePath) const
Returns a file that represents a relative (or absolute) sub-path of the current one.
static String descriptionOfSizeInBytes(int64 bytes)
Utility function to convert a file size in bytes to a neat string description.
A graphics context, used for drawing a component or image.
static void addImageToCache(const Image &image, int64 hashCode)
Adds an image to the cache with a user-defined hash-code.
static Image getFromHashCode(int64 hashCode)
Checks the cache for an image with a particular hashcode.
Holds a fixed-size bitmap.
Definition juce_Image.h:58
bool isNull() const noexcept
Returns true if this image is not valid.
Definition juce_Image.h:155
bool isValid() const noexcept
Returns true if this image isn't null.
Definition juce_Image.h:147
A list of items that can be scrolled vertically.
void deselectAllRows()
Deselects any currently selected rows.
int getSelectedRow(int index=0) const
Returns the row number of a selected row.
ScrollBar & getVerticalScrollBar() const noexcept
Returns a reference to the vertical scrollbar.
void updateContent()
Causes the list to refresh its content.
int getNumSelectedRows() const
Returns the number of rows that are currently selected.
void selectRow(int rowNumber, bool dontScrollToShowThisRow=false, bool deselectOthersFirst=true)
Selects a row.
void selectRowsBasedOnModifierKeys(int rowThatWasClickedOn, ModifierKeys modifiers, bool isMouseUpEvent)
Multiply-selects rows based on the modifier keys.
Contains position and status information about a mouse event.
const ModifierKeys mods
The key modifiers associated with the event.
void setCurrentRangeStart(double newStart, NotificationType notification=sendNotificationAsync)
Moves the bar's thumb position.
The JUCE String class!
Definition juce_String.h:53
Used by the TimeSliceThread class.
A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run so...
void removeTimeSliceClient(TimeSliceClient *clientToRemove)
Removes a client from the list.
void addTimeSliceClient(TimeSliceClient *clientToAdd, int millisecondsBeforeStarting=0)
Adds a client to the list.
Components that want to use pop-up tooltips should implement this interface.
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88