mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-28 02:30:05 +00:00
Windows: Made the behaviour of the new native FileChooser consistent with the old when saving a file with no extension specified
This commit is contained in:
parent
f9e6030f85
commit
876aceed99
1 changed files with 22 additions and 11 deletions
|
|
@ -154,7 +154,7 @@ private:
|
|||
Component::SafePointer<Component> owner;
|
||||
String title, filtersString;
|
||||
std::unique_ptr<CustomComponentHolder> customComponent;
|
||||
String initialPath, returnedString, defaultExtension;
|
||||
String initialPath, returnedString;
|
||||
|
||||
WaitableEvent threadHasReference;
|
||||
CriticalSection deletingDialog;
|
||||
|
|
@ -210,7 +210,7 @@ private:
|
|||
if (FAILED (dialog.SetFileName (filename.toWideCharPointer())))
|
||||
return false;
|
||||
|
||||
const auto extension = filename.fromLastOccurrenceOf (".", false, false);
|
||||
auto extension = getDefaultFileExtension (filename);
|
||||
|
||||
if (extension.isNotEmpty() && FAILED (dialog.SetDefaultExtension (extension.toWideCharPointer())))
|
||||
return false;
|
||||
|
|
@ -367,16 +367,10 @@ private:
|
|||
|
||||
if (isSave)
|
||||
{
|
||||
StringArray tokens;
|
||||
tokens.addTokens (filtersString, ";,", "\"'");
|
||||
tokens.trim();
|
||||
tokens.removeEmptyStrings();
|
||||
auto extension = getDefaultFileExtension (files.getData());
|
||||
|
||||
if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
|
||||
{
|
||||
defaultExtension = tokens[0].fromFirstOccurrenceOf (".", false, false);
|
||||
of.lpstrDefExt = defaultExtension.toWideCharPointer();
|
||||
}
|
||||
if (extension.isNotEmpty())
|
||||
of.lpstrDefExt = extension.toWideCharPointer();
|
||||
|
||||
if (! GetSaveFileName (&of))
|
||||
return {};
|
||||
|
|
@ -482,6 +476,23 @@ private:
|
|||
return ofFlags;
|
||||
}
|
||||
|
||||
String getDefaultFileExtension (const String& filename) const
|
||||
{
|
||||
auto extension = filename.fromLastOccurrenceOf (".", false, false);
|
||||
|
||||
if (extension.isEmpty())
|
||||
{
|
||||
auto tokens = StringArray::fromTokens (filtersString, ";,", "\"'");
|
||||
tokens.trim();
|
||||
tokens.removeEmptyStrings();
|
||||
|
||||
if (tokens.size() == 1 && tokens[0].removeCharacters ("*.").isNotEmpty())
|
||||
extension = tokens[0].fromFirstOccurrenceOf (".", false, false);
|
||||
}
|
||||
|
||||
return extension;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void initialised (HWND hWnd)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue