include/svx/dialog/ThemeDialog.hxx |    3 ++-
 svx/source/dialog/ThemeDialog.cxx  |   19 ++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

New commits:
commit 5733cdba90b099637805648b193510268def74be
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Aug 15 12:31:22 2023 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Aug 28 08:47:55 2023 +0200

    Theme dialog: fix crash when closing parent first
    
    When we have 'Add' subdialog opened and we close parent
    by clicking 'cancel' - subdialog wasn't closed and we had
    a crash on next interaction with 'Add' subdialog
    
    Change-Id: I5865a725e93d7c11aa933b7566a7c584018740ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155715
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Gülşah Köse <gulsah.k...@collabora.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156157
    Tested-by: Jenkins

diff --git a/include/svx/dialog/ThemeDialog.hxx 
b/include/svx/dialog/ThemeDialog.hxx
index 7003fdebf168..9536bdb38d84 100644
--- a/include/svx/dialog/ThemeDialog.hxx
+++ b/include/svx/dialog/ThemeDialog.hxx
@@ -13,6 +13,7 @@
 #include <vcl/weld.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/theme/IThemeColorChanger.hxx>
+#include <svx/dialog/ThemeColorEditDialog.hxx>
 #include <svx/dialog/ThemeColorValueSet.hxx>
 #include <functional>
 
@@ -30,7 +31,7 @@ class SVX_DLLPUBLIC ThemeDialog final : public 
weld::GenericDialogController
 private:
     weld::Window* mpWindow;
     model::Theme* mpTheme;
-    bool mxSubDialog;
+    std::shared_ptr<svx::ThemeColorEditDialog> mxSubDialog;
     std::vector<model::ColorSet> maColorSets;
 
     std::unique_ptr<svx::ThemeColorValueSet> mxValueSetThemeColors;
diff --git a/svx/source/dialog/ThemeDialog.cxx 
b/svx/source/dialog/ThemeDialog.cxx
index 99e7c3ad466e..e3a206be6cab 100644
--- a/svx/source/dialog/ThemeDialog.cxx
+++ b/svx/source/dialog/ThemeDialog.cxx
@@ -8,7 +8,6 @@
  */
 
 #include <svx/dialog/ThemeDialog.hxx>
-#include <svx/dialog/ThemeColorEditDialog.hxx>
 #include <docmodel/theme/ColorSet.hxx>
 #include <docmodel/theme/Theme.hxx>
 #include <svx/ColorSets.hxx>
@@ -22,7 +21,6 @@ ThemeDialog::ThemeDialog(weld::Window* pParent, model::Theme* 
pTheme)
     : GenericDialogController(pParent, "svx/ui/themedialog.ui", "ThemeDialog")
     , mpWindow(pParent)
     , mpTheme(pTheme)
-    , mxSubDialog(false)
     , mxValueSetThemeColors(new svx::ThemeColorValueSet)
     , mxValueSetThemeColorsWindow(
           new weld::CustomWeld(*m_xBuilder, "valueset_theme_colors", 
*mxValueSetThemeColors))
@@ -45,7 +43,11 @@ ThemeDialog::ThemeDialog(weld::Window* pParent, 
model::Theme* pTheme)
     }
 }
 
-ThemeDialog::~ThemeDialog() = default;
+ThemeDialog::~ThemeDialog()
+{
+    if (mxSubDialog)
+        mxSubDialog->response(RET_CANCEL);
+}
 
 void ThemeDialog::initColorSets()
 {
@@ -89,17 +91,16 @@ void ThemeDialog::runThemeColorEditDialog()
     if (mxSubDialog)
         return;
 
-    auto pDialog = std::make_shared<svx::ThemeColorEditDialog>(mpWindow, 
*mpCurrentColorSet);
-    std::shared_ptr<DialogController> xKeepAlive(shared_from_this());
+    mxSubDialog = std::make_shared<svx::ThemeColorEditDialog>(mpWindow, 
*mpCurrentColorSet);
 
-    mxSubDialog = weld::DialogController::runAsync(pDialog, [this, 
pDialog](sal_uInt32 nResult) {
+    weld::DialogController::runAsync(mxSubDialog, [this](sal_uInt32 nResult) {
         if (nResult != RET_OK)
         {
             mxAdd->set_sensitive(true);
-            mxSubDialog = false;
+            mxSubDialog = nullptr;
             return;
         }
-        auto aColorSet = pDialog->getColorSet();
+        auto aColorSet = mxSubDialog->getColorSet();
         if (!aColorSet.getName().isEmpty())
         {
             ColorSets::get().insert(aColorSet, 
ColorSets::IdenticalNameAction::AutoRename);
@@ -113,7 +114,7 @@ void ThemeDialog::runThemeColorEditDialog()
                 = 
std::make_shared<model::ColorSet>(maColorSets[maColorSets.size() - 1]);
         }
         mxAdd->set_sensitive(true);
-        mxSubDialog = false;
+        mxSubDialog = nullptr;
     });
 }
 

Reply via email to