diff --git a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp index bd19fd3cd4..f92b28647e 100644 --- a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp @@ -95,7 +95,12 @@ MultiDocumentPanel::MultiDocumentPanel() setOpaque (true); } -MultiDocumentPanel::~MultiDocumentPanel() = default; +MultiDocumentPanel::~MultiDocumentPanel() +{ + for (int i = components.size(); --i >= 0;) + if (auto* component = components[i]) + closeDocumentInternal (component); +} //============================================================================== namespace MultiDocHelpers @@ -407,6 +412,8 @@ void MultiDocumentPanel::closeDocumentAsync (Component* component, return; } + + closeDocumentInternal (component); } else { diff --git a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h index 302380099f..f208e7736c 100644 --- a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h +++ b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h @@ -100,10 +100,11 @@ public: /** Destructor. - When deleted, this will call closeAllDocuments (false) to make sure all its + When deleted, this will call close all open documents to make sure all its components are deleted. If you need to make sure all documents are saved - before closing, then you should call closeAllDocuments (true) and check that - it returns true before deleting the panel. + before closing, then you should call closeAllDocumentsAsync() with + checkItsOkToCloseFirst == true and check the provided callback result is true + before deleting the panel. */ ~MultiDocumentPanel() override; @@ -133,7 +134,7 @@ public: If checkItsOkToCloseFirst is false, then all documents will be closed unconditionally. - @see closeDocument + @see closeDocumentAsync */ void closeAllDocumentsAsync (bool checkItsOkToCloseFirst, std::function callback); @@ -151,8 +152,8 @@ public: @param component the component to add @param backgroundColour the background colour to use to fill the component's window or tab - @param deleteWhenRemoved if true, then when the component is removed by closeDocument() - or closeAllDocuments(), then it will be deleted. If false, then + @param deleteWhenRemoved if true, then when the component is removed by closeDocumentAsync() + or closeAllDocumentsAsync(), then it will be deleted. If false, then the caller must handle the component's deletion */ bool addDocument (Component* component, @@ -190,7 +191,7 @@ public: The component will be deleted if the deleteWhenRemoved parameter was set to true when it was added with addDocument. - @see addDocument, closeAllDocuments + @see addDocument, closeAllDocumentsAsync */ void closeDocumentAsync (Component* component, bool checkItsOkToCloseFirst,