diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-05-19 16:55:39 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-05-21 11:11:32 +0200 |
commit | c0f402da0f3ae8318103fc269e98c25617e83111 (patch) | |
tree | 5e8a277abb84c6f98ab71ad382754ac9ec2a2b7f /sw/source/uibase/shells/basesh.cxx | |
parent | 6010da281c57c007f3dfcbd1c3c12d351d01205c (diff) |
Make Insert Table dialog async
Change-Id: Id2458c16f259a58e2376f42104a9a6c9056cab11
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94536
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94589
Tested-by: Jenkins
Diffstat (limited to 'sw/source/uibase/shells/basesh.cxx')
-rw-r--r-- | sw/source/uibase/shells/basesh.cxx | 172 |
1 files changed, 102 insertions, 70 deletions
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index fd1dfaf5fb0d..99f610eb9c82 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -2680,6 +2680,58 @@ SwWrtShell* SwBaseShell::GetShellPtr() return rView.GetWrtShellPtr(); } +static void EndUndo(SwWrtShell& rSh) +{ + SwRewriter aRewriter; + + if (rSh.GetTableFormat()) + { + aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE)); + aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName()); + aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE)); + + } + rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell +} + +static void InsertTableImpl(SwWrtShell& rSh, + SwView &rTempView, + const OUString& aTableName, + sal_uInt16 nRows, + sal_uInt16 nCols, + SwInsertTableOptions aInsTableOpts, + const OUString& aAutoName, + const std::unique_ptr<SwTableAutoFormat>& pTAFormat) +{ + rSh.StartUndo(SwUndoId::INSTABLE); + + rSh.StartAllAction(); + if( rSh.HasSelection() ) + rSh.DelRight(); + + rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() ); + rSh.MoveTable( GotoPrevTable, fnTableStart ); + + if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) ) + rSh.GetTableFormat()->SetName( aTableName ); + + if( pTAFormat != nullptr && !aAutoName.isEmpty() + && aAutoName != SwViewShell::GetShellRes()->aStrNone ) + { + SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() ); + if ( pTableNode ) + { + pTableNode->GetTable().SetTableStyleName( aAutoName ); + SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat ); + if ( pUndo ) + rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); + } + } + + rSh.EndAllAction(); + rTempView.AutoCaption(TABLE_CAP); +} + void SwBaseShell::InsertTable( SfxRequest& _rRequest ) { const SfxItemSet* pArgs = _rRequest.GetArgs(); @@ -2708,12 +2760,12 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest ) } else { - sal_uInt16 nCols = 0; - sal_uInt16 nRows = 0; - SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 ); - OUString aTableName; - OUString aAutoName; - std::unique_ptr<SwTableAutoFormat> pTAFormat; + sal_uInt16 nColsIn = 0; + sal_uInt16 nRowsIn = 0; + SwInsertTableOptions aInsTableOptsIn( SwInsertTableFlags::All, 1 ); + OUString aTableNameIn; + OUString aAutoNameIn; + std::unique_ptr<SwTableAutoFormat> pTAFormatIn; if( pArgs && pArgs->Count() >= 2 ) { @@ -2724,23 +2776,23 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest ) const SfxStringItem* pAuto = _rRequest.GetArg<SfxStringItem>(FN_PARAM_2); if ( pName ) - aTableName = pName->GetValue(); + aTableNameIn = pName->GetValue(); if ( pCols ) - nCols = pCols->GetValue(); + nColsIn = pCols->GetValue(); if ( pRows ) - nRows = pRows->GetValue(); + nRowsIn = pRows->GetValue(); if ( pAuto ) { - aAutoName = pAuto->GetValue(); - if ( !aAutoName.isEmpty() ) + aAutoNameIn = pAuto->GetValue(); + if ( !aAutoNameIn.isEmpty() ) { SwTableAutoFormatTable aTableTable; aTableTable.Load(); for ( size_t n=0; n<aTableTable.size(); n++ ) { - if ( aTableTable[n].GetName() == aAutoName ) + if ( aTableTable[n].GetName() == aAutoNameIn ) { - pTAFormat.reset(new SwTableAutoFormat( aTableTable[n] )); + pTAFormatIn.reset(new SwTableAutoFormat( aTableTable[n] )); break; } } @@ -2748,81 +2800,61 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest ) } if ( pFlags ) - aInsTableOpts.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue()); + aInsTableOptsIn.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue()); else { const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); - aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode); + aInsTableOptsIn = pModOpt->GetInsTableFlags(bHTMLMode); } } - if( !nCols || !nRows ) + if( !nColsIn || !nRowsIn ) { SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractInsTableDlg> pDlg(pFact->CreateInsTableDlg(rTempView)); - if( RET_OK == pDlg->Execute() ) - { - pDlg->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat ); - } - else - _rRequest.Ignore(); - } + std::shared_ptr<AbstractInsTableDlg> pAbstractDialog(pFact->CreateInsTableDlg(rTempView)); + std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController()); - if( nCols && nRows ) + weld::DialogController::runAsync(pDialogController, + [pAbstractDialog, &rSh, &rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn] (sal_Int32 nResult) { + if( RET_OK == nResult ) + { + sal_uInt16 nCols = nColsIn; + sal_uInt16 nRows = nRowsIn; + SwInsertTableOptions aInsTableOpts = aInsTableOptsIn; + OUString aTableName = aTableNameIn; + OUString aAutoName = aAutoNameIn; + std::unique_ptr<SwTableAutoFormat> pTAFormat; + + pAbstractDialog->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat ); + + if( nCols && nRows ) + { + InsertTableImpl( rSh, rTempView, aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat ); + EndUndo(rSh); + } + } + } + ); + } + else { // record before shell change - _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableName ) ); - if ( !aAutoName.isEmpty() ) - _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoName ) ); - _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nCols ) ); - _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRows ) ); - _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOpts.mnInsMode) ) ); + _rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableNameIn ) ); + if ( !aAutoNameIn.isEmpty() ) + _rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoNameIn ) ); + _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nColsIn ) ); + _rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRowsIn ) ); + _rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOptsIn.mnInsMode) ) ); _rRequest.Done(); - rSh.StartUndo(SwUndoId::INSTABLE); - bCallEndUndo = true; - - rSh.StartAllAction(); - if( rSh.HasSelection() ) - rSh.DelRight(); - - rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() ); - rSh.MoveTable( GotoPrevTable, fnTableStart ); - - if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) ) - rSh.GetTableFormat()->SetName( aTableName ); - - if( pTAFormat != nullptr && !aAutoName.isEmpty() - && aAutoName != SwViewShell::GetShellRes()->aStrNone ) - { - SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() ); - if ( pTableNode ) - { - pTableNode->GetTable().SetTableStyleName( aAutoName ); - SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat ); - if ( pUndo ) - rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); - } - } + InsertTableImpl( rSh, rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn ); - rSh.EndAllAction(); - rTempView.AutoCaption(TABLE_CAP); + bCallEndUndo = true; } } if( bCallEndUndo ) - { - SwRewriter aRewriter; - - if (rSh.GetTableFormat()) - { - aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE)); - aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName()); - aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE)); - - } - rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell - } + EndUndo(rSh); } } |