summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-05-19 16:55:39 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2020-05-20 13:17:29 +0200
commitba8595407be6eb094448534e3ea93b6c22eac892 (patch)
tree71ffaed371ba74f8e9f081af2e50f9aaa9c22aac /sw/source/uibase/shells
parent26a2c330c5a170d947fd3e33b07d396874a28925 (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>
Diffstat (limited to 'sw/source/uibase/shells')
-rw-r--r--sw/source/uibase/shells/basesh.cxx156
1 files changed, 95 insertions, 61 deletions
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index c386f9ea710f..aca0bb0d0302 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -2648,6 +2648,48 @@ 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,
+ SwTableAutoFormat* pTAFormat)
+{
+ rSh.StartUndo(SwUndoId::INSTABLE);
+
+ rSh.StartAllAction();
+ if( rSh.HasSelection() )
+ rSh.DelRight();
+
+ rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat );
+ rSh.MoveTable( GotoPrevTable, fnTableStart );
+
+ if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
+ rSh.GetTableFormat()->SetName( aTableName );
+
+ if( pTAFormat != nullptr && aAutoName != SwStyleNameMapper::GetUIName( RES_POOLTABSTYLE_DEFAULT, OUString() ) )
+ rSh.SetTableStyle( aAutoName );
+
+ rSh.EndAllAction();
+ rTempView.AutoCaption(TABLE_CAP);
+}
+
void SwBaseShell::InsertTable( SfxRequest& _rRequest )
{
const SfxItemSet* pArgs = _rRequest.GetArgs();
@@ -2676,12 +2718,12 @@ void SwBaseShell::InsertTable( SfxRequest& _rRequest )
}
else
{
- sal_uInt16 nCols = 0;
- sal_uInt16 nRows = 0;
- SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
- OUString aTableName;
- OUString aAutoName;
- SwTableAutoFormat* pTAFormat = nullptr;
+ sal_uInt16 nColsIn = 0;
+ sal_uInt16 nRowsIn = 0;
+ SwInsertTableOptions aInsTableOptsIn( SwInsertTableFlags::All, 1 );
+ OUString aTableNameIn;
+ OUString aAutoNameIn;
+ SwTableAutoFormat* pTAFormatIn = nullptr;
if( pArgs && pArgs->Count() >= 2 )
{
@@ -2692,23 +2734,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 = new SwTableAutoFormat( aTableTable[n] );
+ pTAFormatIn = new SwTableAutoFormat( aTableTable[n] );
break;
}
}
@@ -2716,72 +2758,64 @@ 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();
- }
-
- if( nCols && nRows )
- {
- // 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.Done();
+ std::shared_ptr<AbstractInsTableDlg> pAbstractDialog(pFact->CreateInsTableDlg(rTempView));
+ std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
- rSh.StartUndo(SwUndoId::INSTABLE);
- bCallEndUndo = true;
+ weld::DialogController::runAsync(pDialogController,
+ [pAbstractDialog, &rSh, &rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn] (sal_Int32 nResult) {
+ if( RET_OK == nResult )
+ {
+ sal_uInt16 nCols = nColsIn;
+ sal_uInt16 nRows = nRowsIn;
+ SwInsertTableOptions aInsTableOpts = aInsTableOptsIn;
+ OUString aTableName = aTableNameIn;
+ OUString aAutoName = aAutoNameIn;
+ SwTableAutoFormat* pTAFormat = pTAFormatIn;
- rSh.StartAllAction();
- if( rSh.HasSelection() )
- rSh.DelRight();
+ pAbstractDialog->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
- rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat );
- rSh.MoveTable( GotoPrevTable, fnTableStart );
+ if( nCols && nRows )
+ {
+ InsertTableImpl( rSh, rTempView, aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
+ EndUndo(rSh);
+ }
- if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
- rSh.GetTableFormat()->SetName( aTableName );
+ delete pTAFormat;
+ }
+ }
+ );
+ }
+ else
+ {
+ // record before shell change
+ _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();
- if( pTAFormat != nullptr && aAutoName != SwStyleNameMapper::GetUIName( RES_POOLTABSTYLE_DEFAULT, OUString() ) )
- rSh.SetTableStyle( aAutoName );
+ InsertTableImpl( rSh, rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn );
- rSh.EndAllAction();
- rTempView.AutoCaption(TABLE_CAP);
+ bCallEndUndo = true;
+ delete pTAFormatIn;
}
- delete pTAFormat;
}
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);
}
}