Browse Source

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".
v7.0.9
reuk 2 years ago
parent
commit
8942f22a9b
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      modules/juce_gui_basics/native/juce_win32_FileChooser.cpp

+ 11
- 10
modules/juce_gui_basics/native/juce_win32_FileChooser.cpp 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();
if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
return tokens[0].fromFirstOccurrenceOf (".", false, false);
return extension;
return {};
}
//==============================================================================


Loading…
Cancel
Save