30 const File& initialFileOrDirectory,
34 fileFilter (fileFilter_),
36 previewComp (previewComp_),
37 currentPathBox (
"path"),
38 fileLabel (
"f",
TRANS (
"file:")),
39 thread (
"JUCE FileBrowser"),
40 wasProcessActive (
true)
44 jassert ((
flags & (saveMode | openMode)) != (saveMode | openMode));
47 jassert ((
flags & (canSelectFiles | canSelectDirectories)) != 0);
51 if (initialFileOrDirectory ==
File())
55 else if (initialFileOrDirectory.isDirectory())
57 currentRoot = initialFileOrDirectory;
61 chosenFiles.add (initialFileOrDirectory);
62 currentRoot = initialFileOrDirectory.getParentDirectory();
63 filename = initialFileOrDirectory.getFileName();
66 fileList.reset (
new DirectoryContentsList (
this, thread));
67 fileList->setDirectory (currentRoot,
true,
true);
69 if ((flags & useTreeView) != 0)
71 auto tree =
new FileTreeComponent (*fileList);
72 fileListComponent.reset (tree);
74 if ((flags & canSelectMultipleItems) != 0)
75 tree->setMultiSelectEnabled (
true);
77 addAndMakeVisible (tree);
81 auto list =
new FileListComponent (*fileList);
82 fileListComponent.reset (list);
83 list->setOutlineThickness (1);
85 if ((flags & canSelectMultipleItems) != 0)
86 list->setMultipleSelectionEnabled (
true);
88 addAndMakeVisible (list);
91 fileListComponent->addListener (
this);
93 addAndMakeVisible (currentPathBox);
94 currentPathBox.setEditableText (
true);
96 currentPathBox.onChange = [
this] { updateSelectedPath(); };
98 addAndMakeVisible (filenameBox);
99 filenameBox.setMultiLine (
false);
100 filenameBox.setSelectAllWhenFocused (
true);
101 filenameBox.setText (
filename,
false);
102 filenameBox.onTextChange = [
this] { sendListenerChangeMessage(); };
103 filenameBox.onReturnKey = [
this] { changeFilename(); };
104 filenameBox.onFocusLost = [
this]
110 filenameBox.setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
112 addAndMakeVisible (fileLabel);
113 fileLabel.attachToComponent (&filenameBox,
true);
115 if (previewComp !=
nullptr)
116 addAndMakeVisible (previewComp);
118 lookAndFeelChanged();
120 setRoot (currentRoot);
125 thread.startThread (4);
134 thread.stopThread (10000);
223 bool callListeners =
false;
227 callListeners =
true;
238 if (! rootPaths.
contains (path,
true))
240 bool alreadyListed =
false;
246 alreadyListed =
true;
262 auto currentRootName =
currentRoot.getFullPathName();
264 if (currentRootName.isEmpty())
293 for (
int i = 0;
i < rootNames.
size(); ++
i)
295 if (rootNames[
i].isEmpty())
361 buttonPtr->onClick = [
this] {
goUp(); };
362 buttonPtr->setTooltip (
TRANS (
"Go up to parent directory"));
393 bool resetChosenFiles =
true;
401 if (resetChosenFiles)
404 resetChosenFiles =
false;
408 newFilenames.
add (
f.getRelativePathFrom (
getRoot()));
412 if (newFilenames.
size() > 0)
444 #if JUCE_LINUX || JUCE_BSD || JUCE_WINDOWS
445 if (
key.getModifiers().isCommandDown()
446 && (
key.getKeyCode() ==
'H' ||
key.getKeyCode() ==
'h'))
492 if (newText.isNotEmpty())
499 if (rootPaths[index].isNotEmpty())
515 if (
f.getParentDirectory() ==
f)
518 f =
f.getParentDirectory();
531 for (
int i = 0;
i < roots.
size(); ++
i)
549 name <<
" [" <<
TRANS(
"CD/DVD drive") <<
']';
569 rootNames.
add (
TRANS(
"Home folder"));
584 if (
volume.isDirectory() && !
volume.getFileName().startsWithChar (
'.'))
586 rootPaths.
add (
volume.getFullPathName());
595 rootNames.
add (
TRANS(
"Home folder"));
614 if (isProcessActive &&
fileList !=
nullptr)
#define noexcept
Definition DistrhoDefines.h:72
static File getCurrentWorkingDirectory()
Definition File.cpp:1395
Definition juce_Array.h:56
int size() const noexcept
Definition juce_Array.h:215
ElementType & getReference(int index) noexcept
Definition juce_Array.h:267
@ arrowColourId
Definition juce_ComboBox.h:360
@ textColourId
Definition juce_ComboBox.h:357
@ backgroundColourId
Definition juce_ComboBox.h:356
Definition juce_Component.h:2331
bool shouldBailOut() const noexcept
Definition juce_Component.cpp:3252
void addAndMakeVisible(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1554
void repaint()
Definition juce_Component.cpp:1917
Colour findColour(int colourID, bool inheritFromParent=false) const
Definition juce_Component.cpp:2219
LookAndFeel & getLookAndFeel() const noexcept
Definition juce_Component.cpp:2173
Definition juce_DirectoryContentsDisplayComponent.h:38
void refresh()
Definition juce_FileBrowserComponent.cpp:309
void updateSelectedPath()
Definition juce_FileBrowserComponent.cpp:488
int flags
Definition juce_FileBrowserComponent.h:272
void resized() override
Definition juce_FileBrowserComponent.cpp:346
static void getDefaultRoots(StringArray &rootNames, StringArray &rootPaths)
Definition juce_FileBrowserComponent.cpp:524
void timerCallback() override
Definition juce_FileBrowserComponent.cpp:606
void sendListenerChangeMessage()
Definition juce_FileBrowserComponent.cpp:377
File getSelectedFile(int index) const noexcept
Definition juce_FileBrowserComponent.cpp:162
@ saveMode
Definition juce_FileBrowserComponent.h:56
@ canSelectFiles
Definition juce_FileBrowserComponent.h:58
@ doNotClearFileNameOnRootChange
Definition juce_FileBrowserComponent.h:66
@ canSelectDirectories
Definition juce_FileBrowserComponent.h:60
void selectionChanged() override
Definition juce_FileBrowserComponent.cpp:390
std::unique_ptr< DirectoryContentsList > fileList
Definition juce_FileBrowserComponent.h:269
ComboBox currentPathBox
Definition juce_FileBrowserComponent.h:279
FileBrowserComponent(int flags, const File &initialFileOrDirectory, const FileFilter *fileFilter, FilePreviewComponent *previewComp)
Definition juce_FileBrowserComponent.cpp:29
File currentRoot
Definition juce_FileBrowserComponent.h:273
bool wasProcessActive
Definition juce_FileBrowserComponent.h:284
Array< File > chosenFiles
Definition juce_FileBrowserComponent.h:274
virtual String getActionVerb() const
Definition juce_FileBrowserComponent.cpp:323
ListenerList< FileBrowserListener > listeners
Definition juce_FileBrowserComponent.h:275
virtual void getRoots(StringArray &rootNames, StringArray &rootPaths)
Definition juce_FileBrowserComponent.cpp:601
bool isFileOrDirSuitable(const File &) const
Definition juce_FileBrowserComponent.cpp:205
void browserRootChanged(const File &) override
Definition juce_FileBrowserComponent.cpp:440
void setFileFilter(const FileFilter *newFileFilter)
Definition juce_FileBrowserComponent.cpp:314
void goUp()
Definition juce_FileBrowserComponent.cpp:304
void fileClicked(const File &, const MouseEvent &) override
Definition juce_FileBrowserComponent.cpp:418
void setFilenameBoxLabel(const String &name)
Definition juce_FileBrowserComponent.cpp:330
void setRoot(const File &newRootDirectory)
Definition juce_FileBrowserComponent.cpp:221
const FileFilter * fileFilter
Definition juce_FileBrowserComponent.h:270
void deselectAllFiles()
Definition juce_FileBrowserComponent.cpp:188
std::unique_ptr< DirectoryContentsDisplayComponent > fileListComponent
Definition juce_FileBrowserComponent.h:277
DirectoryContentsDisplayComponent * getDisplayComponent() const noexcept
Definition juce_FileBrowserComponent.cpp:340
FilePreviewComponent * getPreviewComponent() const noexcept
Definition juce_FileBrowserComponent.cpp:335
void removeListener(FileBrowserListener *listener)
Definition juce_FileBrowserComponent.cpp:143
void lookAndFeelChanged() override
Definition juce_FileBrowserComponent.cpp:354
void setFileName(const String &newName)
Definition juce_FileBrowserComponent.cpp:279
bool isDirectorySuitable(const File &) const override
Definition juce_FileBrowserComponent.cpp:200
std::unique_ptr< Button > goUpButton
Definition juce_FileBrowserComponent.h:282
File getHighlightedFile() const noexcept
Definition juce_FileBrowserComponent.cpp:183
TextEditor filenameBox
Definition juce_FileBrowserComponent.h:280
void changeFilename()
Definition juce_FileBrowserComponent.cpp:459
FilePreviewComponent * previewComp
Definition juce_FileBrowserComponent.h:278
bool isFileSuitable(const File &) const override
Definition juce_FileBrowserComponent.cpp:194
bool isSaveMode() const noexcept
Definition juce_FileBrowserComponent.cpp:149
int getNumSelectedFiles() const noexcept
Definition juce_FileBrowserComponent.cpp:154
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_FileBrowserComponent.cpp:620
const File & getRoot() const
Definition juce_FileBrowserComponent.cpp:216
~FileBrowserComponent() override
Definition juce_FileBrowserComponent.cpp:130
bool currentFileIsValid() const
Definition juce_FileBrowserComponent.cpp:173
@ currentPathBoxTextColourId
Definition juce_FileBrowserComponent.h:226
@ filenameBoxBackgroundColourId
Definition juce_FileBrowserComponent.h:228
@ currentPathBoxBackgroundColourId
Definition juce_FileBrowserComponent.h:225
@ filenameBoxTextColourId
Definition juce_FileBrowserComponent.h:229
@ currentPathBoxArrowColourId
Definition juce_FileBrowserComponent.h:227
TimeSliceThread thread
Definition juce_FileBrowserComponent.h:283
void addListener(FileBrowserListener *listener)
Definition juce_FileBrowserComponent.cpp:138
Label fileLabel
Definition juce_FileBrowserComponent.h:281
bool keyPressed(const KeyPress &) override
Definition juce_FileBrowserComponent.cpp:442
void fileDoubleClicked(const File &) override
Definition juce_FileBrowserComponent.cpp:424
void resetRecentPaths()
Definition juce_FileBrowserComponent.cpp:286
Definition juce_FileBrowserListener.h:38
FileFilter(const String &filterDescription)
Definition juce_FileFilter.cpp:26
Definition juce_File.h:45
bool isOnHardDisk() const
Definition juce_linux_Files.cpp:46
bool isOnCDRomDrive() const
Definition juce_linux_Files.cpp:38
static StringRef getSeparatorString()
Definition juce_posix_SharedCode.h:114
const String & getFullPathName() const noexcept
Definition juce_File.h:153
@ userMusicDirectory
Definition juce_File.h:875
@ userDocumentsDirectory
Definition juce_File.h:869
@ userPicturesDirectory
Definition juce_File.h:881
@ userDesktopDirectory
Definition juce_File.h:872
@ userHomeDirectory
Definition juce_File.h:863
static void findFileSystemRoots(Array< File > &results)
Definition juce_linux_CommonFile.cpp:48
@ findDirectories
Definition juce_File.h:559
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Definition juce_linux_Files.cpp:107
String getVolumeLabel() const
Definition juce_posix_SharedCode.h:676
static juce_wchar getSeparatorChar()
Definition juce_posix_SharedCode.h:113
Definition juce_FilePreviewComponent.h:44
Definition juce_FileTreeComponent.h:45
Definition juce_KeyPress.h:40
Definition juce_MouseEvent.h:39
Definition juce_StringArray.h:35
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Definition juce_StringArray.cpp:289
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Definition juce_StringArray.cpp:189
void clear()
Definition juce_StringArray.cpp:107
int size() const noexcept
Definition juce_StringArray.h:136
void add(String stringToAdd)
Definition juce_StringArray.cpp:136
Definition juce_String.h:53
bool isEmpty() const noexcept
Definition juce_String.h:310
@ backgroundColourId
Definition juce_TextEditor.h:209
* e
Definition inflate.c:1404
int * l
Definition inflate.c:1579
register unsigned i
Definition inflate.c:1575
unsigned f
Definition inflate.c:1572
static char filename[]
Definition features.c:5
static const char * name
Definition pugl.h:1582
#define TRANS(stringLiteral)
Definition juce_LocalisedStrings.h:208
Definition carla_juce.cpp:31
@ dontSendNotification
Definition juce_NotificationType.h:33
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
@ list
Definition juce_AccessibilityRole.h:56
@ tree
Definition juce_AccessibilityRole.h:58
@ group
Definition juce_AccessibilityRole.h:61
static bool isForegroundOrEmbeddedProcess(Component *viewComponent)
Definition juce_gui_basics.cpp:120
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void func jack_client_t const char const char unsigned long flags
Definition juce_linux_JackAudio.cpp:69
static float volume(float level)
Definition nekobee_voice_render.c:99
ZCONST char * key
Definition crypt.c:587
struct zdirent * file
Definition win32.c:1500
#define const
Definition zconf.h:137