mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
FileChooser: Show desktop folder if requested folder does not exist
This change affects the PostVista version of the Windows FileChooser.
This commit is contained in:
parent
e403e330ef
commit
41ec486dd0
1 changed files with 17 additions and 7 deletions
|
|
@ -167,6 +167,11 @@ private:
|
|||
Atomic<HWND> nativeDialogRef;
|
||||
Atomic<int> shouldCancel;
|
||||
|
||||
struct FreeLPWSTR
|
||||
{
|
||||
void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
|
||||
};
|
||||
|
||||
bool showDialog (IFileDialog& dialog, bool async) const
|
||||
{
|
||||
FILEOPENDIALOGOPTIONS flags = {};
|
||||
|
|
@ -193,7 +198,17 @@ private:
|
|||
PIDLIST_ABSOLUTE pidl = {};
|
||||
|
||||
if (FAILED (SHParseDisplayName (initialPath.toWideCharPointer(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
|
||||
return false;
|
||||
{
|
||||
LPWSTR ptr = nullptr;
|
||||
auto result = SHGetKnownFolderPath (FOLDERID_Desktop, 0, nullptr, &ptr);
|
||||
std::unique_ptr<WCHAR, FreeLPWSTR> desktopPath (ptr);
|
||||
|
||||
if (FAILED (result))
|
||||
return false;
|
||||
|
||||
if (FAILED (SHParseDisplayName (desktopPath.get(), nullptr, &pidl, SFGAO_FOLDER, nullptr)))
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto item = [&]
|
||||
{
|
||||
|
|
@ -228,17 +243,12 @@ private:
|
|||
{
|
||||
const auto getUrl = [] (IShellItem& item)
|
||||
{
|
||||
struct Free
|
||||
{
|
||||
void operator() (LPWSTR ptr) const noexcept { CoTaskMemFree (ptr); }
|
||||
};
|
||||
|
||||
LPWSTR ptr = nullptr;
|
||||
|
||||
if (item.GetDisplayName (SIGDN_FILESYSPATH, &ptr) != S_OK)
|
||||
return URL();
|
||||
|
||||
const auto path = std::unique_ptr<WCHAR, Free> { ptr };
|
||||
const auto path = std::unique_ptr<WCHAR, FreeLPWSTR> { ptr };
|
||||
return URL (File (String (path.get())));
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue