chart2/source/controller/main/ChartController.cxx        |   18 -
 chart2/source/controller/main/ChartController_Insert.cxx |  166 +++++++--------
 2 files changed, 97 insertions(+), 87 deletions(-)

New commits:
commit b9a46c1ec295fe3227a5adb864c849e55838e89e
Author:     codewithvk <vivek.jav...@collabora.com>
AuthorDate: Sun Jan 28 13:43:09 2024 +0530
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Feb 6 16:43:43 2024 +0100

    Async Dialogs for Few Chart Properties
    
    Updated the chart properties dialogs to work asynchronously. The changes 
affect the following dialogs:
    
    Chart Type: Accessible by double-clicking on a chart to select it, then 
right-clicking to open the context menu. Selecting 'Chart type...' opens the 
dialog for modifying chart types.
    
    Insert Axes: Triggered by double-clicking on a chart to select it, then 
right-clicking and choosing 'Insert/Delete Axes' from the context menu. This 
dialog allows users to add or remove chart axes.
    
    Insert Titles: Opens when you double-click on a chart, right-click, and 
select 'Insert Titles...' from the context menu. It's used for adding titles to 
the chart and its axes.
    
    Insert Trendline: For column charts, you can double-click on a column, 
right-click, and choose 'Insert trendline..' to open this dialog.
    
    Insert Error Bars: In a column chart, after selecting a column, 
right-clicking and choosing 'Insert X Error Bars..' or 'Insert Y Error Bars..' 
opens the dialog for adding error bars to the chart.
    
    Signed-off-by: codewithvk <vivek.jav...@collabora.com>
    Change-Id: Id7bb8682150f2e3115420d9259c6afd41682641e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162655
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 71a3cfb71dddba8098d74d7bb1dd414e4696914b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162824
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index ae09e6813dd5..29f5d9b6a24d 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -1339,17 +1339,19 @@ void SAL_CALL 
ChartController::releaseContextMenuInterceptor(
 
 void ChartController::executeDispatch_ChartType()
 {
-    UndoLiveUpdateGuard aUndoGuard(
-        SchResId( STR_ACTION_EDIT_CHARTTYPE ), m_xUndoManager );
+    auto aUndoGuard = 
std::make_shared<UndoLiveUpdateGuard>(SchResId(STR_ACTION_EDIT_CHARTTYPE),
+                                                            m_xUndoManager);
 
     SolarMutexGuard aSolarGuard;
     //prepare and open dialog
-    ChartTypeDialog aDlg(GetChartFrame(), getChartModel());
-    if (aDlg.run() == RET_OK)
-    {
-        impl_adaptDataSeriesAutoResize();
-        aUndoGuard.commit();
-    }
+    auto aDlg =  std::make_shared<ChartTypeDialog>(GetChartFrame(), 
getChartModel());
+    weld::DialogController::runAsync(aDlg, [this, aUndoGuard](int nResult) {
+        if (nResult == RET_OK)
+        {
+            impl_adaptDataSeriesAutoResize();
+            aUndoGuard->commit();
+        }
+    });
 }
 
 void ChartController::executeDispatch_SourceData()
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx 
b/chart2/source/controller/main/ChartController_Insert.cxx
index 1038e97943db..adb5b74b67d3 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -90,34 +90,36 @@ namespace chart
 
 void ChartController::executeDispatch_InsertAxes()
 {
-    UndoGuard aUndoGuard(
+    auto aUndoGuard = std::make_shared<UndoGuard>(
         ActionDescriptionProvider::createDescription(
             ActionDescriptionProvider::ActionType::Insert, SchResId( 
STR_OBJECT_AXES )),
         m_xUndoManager );
 
     try
     {
-        InsertAxisOrGridDialogData aDialogInput;
+        auto aDialogInput = std::make_shared<InsertAxisOrGridDialogData>();
         rtl::Reference< Diagram > xDiagram = getFirstDiagram();
-        AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, 
xDiagram );
-        AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, 
xDiagram );
+        AxisHelper::getAxisOrGridExistence( aDialogInput->aExistenceList, 
xDiagram );
+        AxisHelper::getAxisOrGridPossibilities( 
aDialogInput->aPossibilityList, xDiagram );
 
         SolarMutexGuard aGuard;
-        SchAxisDlg aDlg(GetChartFrame(), aDialogInput);
-        if (aDlg.run() == RET_OK)
-        {
-            // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getChartModel() );
+        auto aDlg = std::make_shared<SchAxisDlg>(GetChartFrame(), 
*aDialogInput);
+        weld::DialogController::runAsync(aDlg, [this, aDlg, aDialogInput, 
aUndoGuard](int nResult) {
+            if ( nResult == RET_OK )
+            {
+                // lock controllers till end of block
+                ControllerLockGuardUNO aCLGuard( getChartModel() );
 
-            InsertAxisOrGridDialogData aDialogOutput;
-            aDlg.getResult(aDialogOutput);
-            ReferenceSizeProvider 
aRefSizeProvider(impl_createReferenceSizeProvider());
-            bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
-                , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, 
m_xCC
-                , &aRefSizeProvider );
-            if( bChanged )
-                aUndoGuard.commit();
-        }
+                InsertAxisOrGridDialogData aDialogOutput;
+                aDlg->getResult(aDialogOutput);
+                ReferenceSizeProvider 
aRefSizeProvider(impl_createReferenceSizeProvider());
+                bool bChanged = AxisHelper::changeVisibilityOfAxes( 
getFirstDiagram()
+                    , aDialogInput->aExistenceList, 
aDialogOutput.aExistenceList, m_xCC
+                    , &aRefSizeProvider );
+                if( bChanged )
+                    aUndoGuard->commit();
+            }
+        });
     }
     catch(const uno::RuntimeException&)
     {
@@ -274,28 +276,30 @@ void ChartController::executeDispatch_DeleteDataTable()
 
 void ChartController::executeDispatch_InsertTitles()
 {
-    UndoGuard aUndoGuard(
+    auto aUndoGuard = std::make_shared<UndoGuard>(
         ActionDescriptionProvider::createDescription(
             ActionDescriptionProvider::ActionType::Insert, SchResId( 
STR_OBJECT_TITLES )),
         m_xUndoManager );
 
     try
     {
-        TitleDialogData aDialogInput;
-        aDialogInput.readFromModel( getChartModel() );
+        auto aDialogInput = std::make_shared<TitleDialogData>();
+        aDialogInput->readFromModel( getChartModel() );
 
         SolarMutexGuard aGuard;
-        SchTitleDlg aDlg(GetChartFrame(), aDialogInput);
-        if (aDlg.run() == RET_OK)
-        {
-            // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getChartModel() );
-            TitleDialogData aDialogOutput(impl_createReferenceSizeProvider());
-            aDlg.getResult(aDialogOutput);
-            bool bChanged = aDialogOutput.writeDifferenceToModel( 
getChartModel(), m_xCC, &aDialogInput );
-            if( bChanged )
-                aUndoGuard.commit();
-        }
+        auto aDlg = std::make_shared<SchTitleDlg>(GetChartFrame(), 
*aDialogInput);
+        weld::DialogController::runAsync(aDlg, [this, aDlg, aDialogInput, 
aUndoGuard](int nResult){
+            if ( nResult == RET_OK )
+            {
+                // lock controllers till end of block
+                ControllerLockGuardUNO aCLGuard( getChartModel() );
+                TitleDialogData aDialogOutput( 
impl_createReferenceSizeProvider() );
+                aDlg->getResult( aDialogOutput );
+                bool bChanged = aDialogOutput.writeDifferenceToModel( 
getChartModel(), m_xCC, aDialogInput.get() );
+                if( bChanged )
+                    aUndoGuard->commit();
+            }
+        });
     }
     catch(const uno::RuntimeException&)
     {
@@ -470,7 +474,7 @@ void ChartController::executeDispatch_InsertTrendline()
     if( !xRegressionCurveContainer.is() )
         return;
 
-    UndoLiveUpdateGuard aUndoGuard(
+    auto aUndoGuard = std::make_shared<UndoLiveUpdateGuard>(
         ActionDescriptionProvider::createDescription(
             ActionDescriptionProvider::ActionType::Insert, SchResId( 
STR_OBJECT_CURVE )),
         m_xUndoManager );
@@ -483,14 +487,14 @@ void ChartController::executeDispatch_InsertTrendline()
     if( !xCurve.is())
         return;
 
-    wrapper::RegressionCurveItemConverter aItemConverter(
+    auto aItemConverter = 
std::make_shared<wrapper::RegressionCurveItemConverter>(
         xCurve, xRegressionCurveContainer, 
m_pDrawModelWrapper->getSdrModel().GetItemPool(),
         m_pDrawModelWrapper->getSdrModel(),
         getChartModel() );
 
     // open dialog
-    SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
-    aItemConverter.FillItemSet( aItemSet );
+    SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet();
+    aItemConverter->FillItemSet( aItemSet );
     ObjectPropertiesDialogParameter aDialogParameter(
         ObjectIdentifier::createDataCurveCID(
             ObjectIdentifier::getSeriesParticleFromCID( 
m_aSelection.getSelectedCID()),
@@ -498,23 +502,23 @@ void ChartController::executeDispatch_InsertTrendline()
     aDialogParameter.init( getChartModel() );
     ViewElementListProvider aViewElementListProvider( 
m_pDrawModelWrapper.get());
     SolarMutexGuard aGuard;
-    SchAttribTabDlg aDialog(
-        GetChartFrame(), &aItemSet, &aDialogParameter,
-        &aViewElementListProvider,
-        getChartModel() );
+    auto aDialog = std::make_shared<SchAttribTabDlg>(GetChartFrame(), 
&aItemSet, &aDialogParameter,
+                                                     
&aViewElementListProvider, getChartModel());
 
     // note: when a user pressed "OK" but didn't change any settings in the
     // dialog, the SfxTabDialog returns "Cancel"
-    if( aDialog.run() == RET_OK || aDialog.DialogWasClosedWithOK())
-    {
-        const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet();
-        if( pOutItemSet )
+    SfxTabDialogController::runAsync(aDialog, [this, aDialog, aItemConverter, 
aUndoGuard](int nResult) {
+        if ( nResult == RET_OK || aDialog->DialogWasClosedWithOK() )
         {
-            ControllerLockGuardUNO aCLGuard( getChartModel() );
-            aItemConverter.ApplyItemSet( *pOutItemSet );
+            const SfxItemSet* pOutItemSet = aDialog->GetOutputItemSet();
+            if( pOutItemSet )
+            {
+                ControllerLockGuardUNO aCLGuard( getChartModel() );
+                aItemConverter->ApplyItemSet( *pOutItemSet );
+            }
+            aUndoGuard->commit();
         }
-        aUndoGuard.commit();
-    }
+    });
 }
 
 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
@@ -527,7 +531,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
 
     if( xSeries.is())
     {
-        UndoLiveUpdateGuard aUndoGuard(
+        auto aUndoGuard = std::make_shared<UndoLiveUpdateGuard>(
             ActionDescriptionProvider::createDescription(
                 ActionDescriptionProvider::ActionType::Insert,
                 SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : 
STR_OBJECT_ERROR_BARS_X )),
@@ -540,46 +544,48 @@ void ChartController::executeDispatch_InsertErrorBars( 
bool bYError )
                                             bYError));
 
         // get an appropriate item converter
-        wrapper::ErrorBarItemConverter aItemConverter(
+        auto aItemConverter = std::make_shared<wrapper::ErrorBarItemConverter> 
(
             getChartModel(), xErrorBarProp, 
m_pDrawModelWrapper->getSdrModel().GetItemPool(),
             m_pDrawModelWrapper->getSdrModel(),
             getChartModel() );
 
         // open dialog
-        SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
+        SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet();
         aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
-        aItemConverter.FillItemSet( aItemSet );
+        aItemConverter->FillItemSet( aItemSet );
         ObjectPropertiesDialogParameter aDialogParameter(
             ObjectIdentifier::createClassifiedIdentifierWithParent(
                 objType, u"", m_aSelection.getSelectedCID()));
         aDialogParameter.init( getChartModel() );
         ViewElementListProvider aViewElementListProvider( 
m_pDrawModelWrapper.get());
         SolarMutexGuard aGuard;
-        SchAttribTabDlg aDlg(
+        auto aDlg = std::make_shared<SchAttribTabDlg>(
                 GetChartFrame(), &aItemSet, &aDialogParameter,
                 &aViewElementListProvider,
                 getChartModel() );
-        aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
+        aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
             InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getChartModel(),
                                                                              
m_xChartView, m_aSelection.getSelectedCID()));
 
         // note: when a user pressed "OK" but didn't change any settings in the
         // dialog, the SfxTabDialog returns "Cancel"
-        if (aDlg.run() == RET_OK || aDlg.DialogWasClosedWithOK())
-        {
-            const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
-            if( pOutItemSet )
+        SfxTabDialogController::runAsync(aDlg, [this, aDlg, aItemConverter, 
aUndoGuard](int nResult) {
+            if ( nResult == RET_OK || aDlg->DialogWasClosedWithOK() )
             {
-                ControllerLockGuardUNO aCLGuard( getChartModel() );
-                aItemConverter.ApplyItemSet( *pOutItemSet );
+                const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet();
+                if( pOutItemSet )
+                {
+                    ControllerLockGuardUNO aCLGuard( getChartModel() );
+                    aItemConverter->ApplyItemSet( *pOutItemSet );
+                }
+                aUndoGuard->commit();
             }
-            aUndoGuard.commit();
-        }
+        });
     }
     else
     {
         //if no series is selected insert error bars for all series
-        UndoGuard aUndoGuard(
+        auto aUndoGuard = std::make_shared<UndoGuard>(
             ActionDescriptionProvider::createDescription(
                 ActionDescriptionProvider::ActionType::Insert,
                 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
@@ -587,32 +593,34 @@ void ChartController::executeDispatch_InsertErrorBars( 
bool bYError )
 
         try
         {
-            wrapper::AllSeriesStatisticsConverter aItemConverter(
+            auto aItemConverter = 
std::make_shared<wrapper::AllSeriesStatisticsConverter>(
                 getChartModel(), m_pDrawModelWrapper->GetItemPool() );
-            SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
-            aItemConverter.FillItemSet( aItemSet );
+            SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet();
+            aItemConverter->FillItemSet( aItemSet );
 
             //prepare and open dialog
             SolarMutexGuard aGuard;
-            InsertErrorBarsDialog aDlg(
+            auto aDlg = std::make_shared<InsertErrorBarsDialog>(
                 GetChartFrame(), aItemSet,
                 getChartModel(),
                 bYError ? ErrorBarResources::ERROR_BAR_Y : 
ErrorBarResources::ERROR_BAR_X);
 
-            aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
+            aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
                 
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getChartModel(), m_xChartView, u"" ) );
 
-            if (aDlg.run() == RET_OK)
-            {
-                SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
-                aDlg.FillItemSet( aOutItemSet );
-
-                // lock controllers till end of block
-                ControllerLockGuardUNO aCLGuard( getChartModel() );
-                bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet 
);//model should be changed now
-                if( bChanged )
-                    aUndoGuard.commit();
-            }
+            weld::DialogController::runAsync(aDlg, [this, aDlg, 
aItemConverter, aUndoGuard](int nResult) {
+                if ( nResult == RET_OK )
+                {
+                    SfxItemSet aOutItemSet = 
aItemConverter->CreateEmptyItemSet();
+                    aDlg->FillItemSet( aOutItemSet );
+
+                    // lock controllers till end of block
+                    ControllerLockGuardUNO aCLGuard( getChartModel() );
+                    bool bChanged = aItemConverter->ApplyItemSet( aOutItemSet 
);//model should be changed now
+                    if( bChanged )
+                        aUndoGuard->commit();
+                }
+            });
         }
         catch(const uno::RuntimeException&)
         {

Reply via email to