FilenameComponent::setRecentlyUsedFilenames()
clears the filenameBox
and messes up with the current file.
here below is a pip to reproduce that just :
- set the current file to the desktop
- set some recently used files
unexpected result : the current file of the filenameComponent is set to the “location to browse”
PIP
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: MyComponentPIP
dependencies: juce_core, juce_data_structures, juce_events, juce_graphics, juce_gui_basics
exporters: xcode_mac
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: MyComponent
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
//==============================================================================
class MyComponent : public Component
{
public:
//==============================================================================
MyComponent()
{
String name;
bool canEditFilename = false;
bool isDirectory = true;
bool isForSaving = false;
String fileBrowserWildcard;
String enforcedSuffix;
String textWhenNothingSelected;
filenameComponent.reset (new FilenameComponent (name, {},
canEditFilename, isDirectory, isForSaving,
fileBrowserWildcard, enforcedSuffix, textWhenNothingSelected));
// set the current file to desktop
File currentFile (File::getSpecialLocation (File::userDesktopDirectory));
filenameComponent->setCurrentFile (currentFile, false);
// set the recent files
File musicDirectory (File::getSpecialLocation (File::userMusicDirectory));
StringArray previousFiles { musicDirectory.getFullPathName() };
filenameComponent->setRecentlyUsedFilenames (previousFiles);
// the current file is now filenameComponent->getLocationToBrowse()
// while I expect it to be userDesktopDirectory
DBG ("current file " << filenameComponent->getCurrentFile().getFullPathName());
addAndMakeVisible (*filenameComponent);
setSize (600, 400);
}
void paint (Graphics& g) override
{
g.fillAll (Colours::white);
}
void resized() override
{
filenameComponent->setBounds (getLocalBounds().removeFromTop (40));
}
private:
//==============================================================================
std::unique_ptr<FilenameComponent> filenameComponent;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyComponent)
};