Skip to content

Commit

Permalink
FileChooser: Hide chooser when it leaves scope on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed Mar 2, 2021
1 parent e813531 commit 45409bb
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 94 deletions.
2 changes: 1 addition & 1 deletion extras/Build/juceaide/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ int main (int argc, char** argv)
std::transform (argv, argv + argc, std::back_inserter (arguments), getString);

juce::ArgumentList argumentList { arguments.front(),
juce::StringArray (arguments.data() + 1, arguments.size() - 1) };
juce::StringArray (arguments.data() + 1, (int) arguments.size() - 1) };

using Fn = typename std::add_lvalue_reference<decltype (writeBinaryData)>::type;

Expand Down
5 changes: 1 addition & 4 deletions modules/juce_gui_basics/components/juce_Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -2179,10 +2179,7 @@ class JUCE_API Component : public MouseListener
operator ComponentType*() const noexcept { return getComponent(); }

/** Returns the component that this pointer refers to, or null if the component no longer exists. */
ComponentType* operator->() noexcept { return getComponent(); }

/** Returns the component that this pointer refers to, or null if the component no longer exists. */
const ComponentType* operator->() const noexcept { return getComponent(); }
ComponentType* operator->() const noexcept { return getComponent(); }

/** If the component is valid, this deletes it and sets this pointer to null. */
void deleteAndZero() { delete getComponent(); }
Expand Down
12 changes: 5 additions & 7 deletions modules/juce_gui_basics/filebrowser/juce_FileChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool FileChooser::showDialog (const int flags, FilePreviewComponent* const previ
{
FocusRestorer focusRestorer;

pimpl.reset (createPimpl (flags, previewComp));
pimpl = createPimpl (flags, previewComp);
pimpl->runModally();

// ensure that the finished function was invoked
Expand All @@ -179,12 +179,12 @@ void FileChooser::launchAsync (int flags, std::function<void (const FileChooser&

asyncCallback = std::move (callback);

pimpl.reset (createPimpl (flags, previewComp));
pimpl = createPimpl (flags, previewComp);
pimpl->launch();
}


FileChooser::Pimpl* FileChooser::createPimpl (int flags, FilePreviewComponent* previewComp)
std::unique_ptr<FileChooser::Pimpl> FileChooser::createPimpl (int flags, FilePreviewComponent* previewComp)
{
results.clear();

Expand Down Expand Up @@ -214,10 +214,8 @@ FileChooser::Pimpl* FileChooser::createPimpl (int flags, FilePreviewComponent* p
{
return showPlatformDialog (*this, flags, previewComp);
}
else
{
return new NonNative (*this, flags, previewComp);
}

return std::make_unique<NonNative> (*this, flags, previewComp);
}

Array<File> FileChooser::getResults() const noexcept
Expand Down
7 changes: 3 additions & 4 deletions modules/juce_gui_basics/filebrowser/juce_FileChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,11 @@ class JUCE_API FileChooser
virtual void runModally() = 0;
};

std::unique_ptr<Pimpl> pimpl;
std::shared_ptr<Pimpl> pimpl;

//==============================================================================
Pimpl* createPimpl (int, FilePreviewComponent*);
static Pimpl* showPlatformDialog (FileChooser&, int,
FilePreviewComponent*);
std::unique_ptr<Pimpl> createPimpl (int, FilePreviewComponent*);
static std::unique_ptr<Pimpl> showPlatformDialog (FileChooser&, int, FilePreviewComponent*);

class NonNative;
friend class NonNative;
Expand Down
6 changes: 3 additions & 3 deletions modules/juce_gui_basics/native/juce_android_FileChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ class FileChooser::Native : public FileChooser::Pimpl

FileChooser::Native* FileChooser::Native::currentFileChooser = nullptr;

FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent*)
std::unique_ptr<FileChooser::Pimpl> FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent*)
{
if (FileChooser::Native::currentFileChooser == nullptr)
return new FileChooser::Native (owner, flags);
return std::make_unique<FileChooser::Native> (owner, flags);

// there can only be one file chooser on Android at a once
jassertfalse;
Expand Down
6 changes: 3 additions & 3 deletions modules/juce_gui_basics/native/juce_ios_FileChooser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ static void viewDidDisappear (id self, SEL, BOOL animated)
#endif
}

FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent*)
std::unique_ptr<FileChooser::Pimpl> FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent*)
{
return new FileChooser::Native (owner, flags);
return std::make_unique<FileChooser::Native> (owner, flags);
}

#if JUCE_DEPRECATION_IGNORED
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_gui_basics/native/juce_linux_FileChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ bool FileChooser::isPlatformDialogAvailable()
#endif
}

FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags, FilePreviewComponent*)
std::unique_ptr<FileChooser::Pimpl> FileChooser::showPlatformDialog (FileChooser& owner, int flags, FilePreviewComponent*)
{
return new Native (owner, flags);
return std::make_unique<Native> (owner, flags);
}

} // namespace juce
6 changes: 3 additions & 3 deletions modules/juce_gui_basics/native/juce_mac_FileChooser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ static void panelSelectionDidChange (id self, SEL, id sender)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Native)
};

FileChooser::Pimpl* FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent* preview)
std::unique_ptr<FileChooser::Pimpl> FileChooser::showPlatformDialog (FileChooser& owner, int flags,
FilePreviewComponent* preview)
{
return new FileChooser::Native (owner, flags, preview);
return std::make_unique<FileChooser::Native> (owner, flags, preview);
}

bool FileChooser::isPlatformDialogAvailable()
Expand Down
Loading

0 comments on commit 45409bb

Please sign in to comment.