1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FileChooser: Avoid setting default extension to filename

Fixes a bug on Windows when opening a FileChooser with the following
arguments.

    FileChooser ("",
                 "C:\path\to\file", // filename 'file' doesn't contain '.'
                 "",                // all extensions are allowed
                 true);

The expected behaviour is that the initially-displayed filename is
"file".

The actual behaviour was that the initially-displayed filename was
"file.file".
This commit is contained in:
reuk 2023-03-14 18:19:51 +00:00
parent 95f823ff72
commit 8942f22a9b
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -581,19 +581,20 @@ private:
String getDefaultFileExtension (const String& filename) const
{
auto extension = filename.fromLastOccurrenceOf (".", false, false);
const auto extension = filename.contains (".") ? filename.fromLastOccurrenceOf (".", false, false)
: String();
if (extension.isEmpty())
{
auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'");
tokens.trim();
tokens.removeEmptyStrings();
if (! extension.isEmpty())
return extension;
if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
extension = tokens[0].fromFirstOccurrenceOf (".", false, false);
}
auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'");
tokens.trim();
tokens.removeEmptyStrings();
return extension;
if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
return tokens[0].fromFirstOccurrenceOf (".", false, false);
return {};
}
//==============================================================================