cf pip below to reproduce.
That does not work because the comparison to File() is always failing here:
File FilenameComponent::getLocationToBrowse()
{
return getCurrentFile() == File() ? defaultBrowseFile
: getCurrentFile();
}
Because getCurrentFile() returns the current working dir :
File FilenameComponent::getCurrentFile() const
{
auto f = File::getCurrentWorkingDirectory().getChildFile (getCurrentFileText());
if (enforcedSuffix.isNotEmpty())
f = f.withFileExtension (enforcedSuffix);
return f;
}
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;
File currentFile (File::getSpecialLocation (File::userDesktopDirectory));
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));
filenameComponent->setDefaultBrowseTarget (currentFile);
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)
};