Browse Source

Updated FileBrowserComponent to refresh its list if the user switches to another app and then returns.

tags/2021-05-28
jules 9 years ago
parent
commit
6baf778e41
2 changed files with 30 additions and 17 deletions
  1. +21
    -6
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp
  2. +9
    -11
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h

+ 21
- 6
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.cpp View File

@@ -32,7 +32,8 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
previewComp (previewComp_),
currentPathBox ("path"),
fileLabel ("f", TRANS ("file:")),
thread ("Juce FileBrowser")
thread ("Juce FileBrowser"),
wasProcessActive (false)
{
// You need to specify one or other of the open/save flags..
jassert ((flags & (saveMode | openMode)) != 0);
@@ -109,6 +110,8 @@ FileBrowserComponent::FileBrowserComponent (int flags_,
setRoot (currentRoot);
thread.startThread (4);
startTimer (2000);
}
FileBrowserComponent::~FileBrowserComponent()
@@ -178,7 +181,7 @@ void FileBrowserComponent::deselectAllFiles()
bool FileBrowserComponent::isFileSuitable (const File& file) const
{
return (flags & canSelectFiles) != 0
&& (fileFilter == nullptr || fileFilter->isFileSuitable (file));
&& (fileFilter == nullptr || fileFilter->isFileSuitable (file));
}
bool FileBrowserComponent::isDirectorySuitable (const File&) const
@@ -190,10 +193,10 @@ bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
{
if (f.isDirectory())
return (flags & canSelectDirectories) != 0
&& (fileFilter == nullptr || fileFilter->isDirectorySuitable (f));
&& (fileFilter == nullptr || fileFilter->isDirectorySuitable (f));
return (flags & canSelectFiles) != 0 && f.exists()
&& (fileFilter == nullptr || fileFilter->isFileSuitable (f));
&& (fileFilter == nullptr || fileFilter->isFileSuitable (f));
}
//==============================================================================
@@ -401,8 +404,6 @@ void FileBrowserComponent::browserRootChanged (const File&) {}
bool FileBrowserComponent::keyPressed (const KeyPress& key)
{
(void) key;
#if JUCE_LINUX || JUCE_WINDOWS
if (key.getModifiers().isCommandDown()
&& (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
@@ -413,6 +414,7 @@ bool FileBrowserComponent::keyPressed (const KeyPress& key)
}
#endif
ignoreUnused (key);
return false;
}
@@ -589,3 +591,16 @@ void FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPa
{
getDefaultRoots (rootNames, rootPaths);
}
void FileBrowserComponent::timerCallback()
{
const bool isProcessActive = Process::isForegroundProcess();
if (wasProcessActive != isProcessActive)
{
wasProcessActive = isProcessActive;
if (isProcessActive && fileList != nullptr)
refresh();
}
}

+ 9
- 11
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h View File

@@ -41,7 +41,8 @@ class JUCE_API FileBrowserComponent : public Component,
private TextEditorListener,
private ButtonListener,
private ComboBoxListener, // (can't use ComboBox::Listener due to idiotic VC2005 bug)
private FileFilter
private FileFilter,
private Timer
{
public:
//==============================================================================
@@ -103,8 +104,7 @@ public:
*/
File getSelectedFile (int index) const noexcept;
/** Deselects any files that are currently selected.
*/
/** Deselects any files that are currently selected. */
void deselectAllFiles();
/** Returns true if the currently selected file(s) are usable.
@@ -150,8 +150,7 @@ public:
*/
virtual String getActionVerb() const;
/** Returns true if the saveMode flag was set when this component was created.
*/
/** Returns true if the saveMode flag was set when this component was created. */
bool isSaveMode() const noexcept;
/** Sets the label that will be displayed next to the filename entry box.
@@ -243,10 +242,8 @@ public:
bool isFileSuitable (const File&) const override;
/** @internal */
bool isDirectorySuitable (const File&) const override;
/** @internal */
FilePreviewComponent* getPreviewComponent() const noexcept;
/** @internal */
DirectoryContentsDisplayComponent* getDisplayComponent() const noexcept;
@@ -263,13 +260,13 @@ protected:
private:
//==============================================================================
ScopedPointer <DirectoryContentsList> fileList;
ScopedPointer<DirectoryContentsList> fileList;
const FileFilter* fileFilter;
int flags;
File currentRoot;
Array<File> chosenFiles;
ListenerList <FileBrowserListener> listeners;
ListenerList<FileBrowserListener> listeners;
ScopedPointer<DirectoryContentsDisplayComponent> fileListComponent;
FilePreviewComponent* previewComp;
@@ -277,11 +274,12 @@ private:
TextEditor filenameBox;
Label fileLabel;
ScopedPointer<Button> goUpButton;
TimeSliceThread thread;
bool wasProcessActive;
void timerCallback() override;
void sendListenerChangeMessage();
bool isFileOrDirSuitable (const File& f) const;
bool isFileOrDirSuitable (const File&) const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileBrowserComponent)
};


Loading…
Cancel
Save