summaryrefslogtreecommitdiff
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
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>
-rw-r--r--sw/inc/swabstdlg.hxx8
-rw-r--r--sw/source/ui/dialog/swdlgfact.cxx13
-rw-r--r--sw/source/ui/dialog/swdlgfact.hxx10
-rw-r--r--sw/source/uibase/shells/basesh.cxx156
4 files changed, 110 insertions, 77 deletions
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 2347116e172c..8e7020d37e87 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -57,6 +57,7 @@ struct SfxChildWinInfo;
class SwTOXMark;
struct SwDocStat;
struct SwInsertTableOptions;
+class SwInsTableDlg;
enum class SwBorderModes;
enum class SwCharDlgMode;
enum class SfxStyleFamily;
@@ -117,14 +118,15 @@ public:
virtual void SetText( const OUString& rStr ) = 0;
};
-class AbstractInsTableDlg : public VclAbstractDialog
+class AbstractInsTableDlg
{
protected:
- virtual ~AbstractInsTableDlg() override = default;
+ virtual ~AbstractInsTableDlg() = default;
public:
virtual void GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rCol,
SwInsertTableOptions& rInsTableFlags, OUString& rTableAutoFormatName,
SwTableAutoFormat *& prTAFormat ) = 0;
+ virtual std::shared_ptr<weld::DialogController> getDialogController() = 0;
};
class AbstractJavaEditDialog : public VclAbstractDialog
@@ -457,7 +459,7 @@ public:
SwWrtShell &rSh, bool bEd = false) = 0;
virtual VclPtr<VclAbstractDialog> CreateTitlePageDlg(weld::Window* pParent) = 0;
virtual VclPtr<VclAbstractDialog> CreateVclSwViewDialog(SwView& rView) = 0;
- virtual VclPtr<AbstractInsTableDlg> CreateInsTableDlg(SwView& rView) = 0;
+ virtual std::shared_ptr<AbstractInsTableDlg> CreateInsTableDlg(SwView& rView) = 0;
virtual VclPtr<AbstractJavaEditDialog> CreateJavaEditDialog(weld::Window* pParent,
SwWrtShell* pWrtSh) = 0;
virtual VclPtr<AbstractMailMergeDlg> CreateMailMergeDlg(
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx
index 970d83e40d38..20097ec6c385 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -218,11 +218,6 @@ short AbstractInsFootNoteDlg_Impl::Execute()
return m_xDlg->run();
}
-short AbstractInsTableDlg_Impl::Execute()
-{
- return m_xDlg->run();
-}
-
short AbstractJavaEditDialog_Impl::Execute()
{
return m_xDlg->run();
@@ -590,7 +585,9 @@ void AbstractInsTableDlg_Impl::GetValues( OUString& rName, sal_uInt16& rRow, sal
SwInsertTableOptions& rInsTableFlags, OUString& rTableAutoFormatName,
SwTableAutoFormat *& prTAFormat )
{
- m_xDlg->GetValues(rName, rRow, rCol, rInsTableFlags, rTableAutoFormatName, prTAFormat);
+ SwInsTableDlg* pDlg = dynamic_cast<SwInsTableDlg*>(m_xDlg.get());
+ if (pDlg)
+ pDlg->GetValues(rName, rRow, rCol, rInsTableFlags, rTableAutoFormatName, prTAFormat);
}
OUString AbstractJavaEditDialog_Impl::GetScriptText() const
@@ -1048,9 +1045,9 @@ VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateVclSwViewDialog(Sw
return VclPtr<AbstractGenericDialog_Impl>::Create(o3tl::make_unique<SwLineNumberingDlg>(rView));
}
-VclPtr<AbstractInsTableDlg> SwAbstractDialogFactory_Impl::CreateInsTableDlg(SwView& rView)
+std::shared_ptr<AbstractInsTableDlg> SwAbstractDialogFactory_Impl::CreateInsTableDlg(SwView& rView)
{
- return VclPtr<AbstractInsTableDlg_Impl>::Create(o3tl::make_unique<SwInsTableDlg>(rView));
+ return std::make_shared<AbstractInsTableDlg_Impl>(std::make_shared<SwInsTableDlg>(rView));
}
VclPtr<AbstractJavaEditDialog> SwAbstractDialogFactory_Impl::CreateJavaEditDialog(
diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx
index 3a31db3546da..295b56f92348 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -467,16 +467,16 @@ class SwInsTableDlg;
class AbstractInsTableDlg_Impl : public AbstractInsTableDlg
{
protected:
- std::unique_ptr<SwInsTableDlg> m_xDlg;
+ std::shared_ptr<weld::DialogController> m_xDlg;
public:
- explicit AbstractInsTableDlg_Impl(std::unique_ptr<SwInsTableDlg> p)
- : m_xDlg(std::move(p))
+ explicit AbstractInsTableDlg_Impl(std::shared_ptr<weld::DialogController> p)
+ : m_xDlg(p)
{
}
- virtual short Execute() override;
virtual void GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rCol,
SwInsertTableOptions& rInsTableFlags, OUString& rTableAutoFormatName,
SwTableAutoFormat *& prTAFormat ) override;
+ virtual std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; }
};
class SwJavaEditDialog;
@@ -702,7 +702,7 @@ public:
weld::Window * pParent, SwWrtShell &rSh, bool bEd = false) override;
virtual VclPtr<VclAbstractDialog> CreateTitlePageDlg(weld::Window* pParent) override;
virtual VclPtr<VclAbstractDialog> CreateVclSwViewDialog(SwView& rView) override;
- virtual VclPtr<AbstractInsTableDlg> CreateInsTableDlg(SwView& rView) override;
+ virtual std::shared_ptr<AbstractInsTableDlg> CreateInsTableDlg(SwView& rView) override;
virtual VclPtr<AbstractJavaEditDialog> CreateJavaEditDialog(weld::Window* pParent,
SwWrtShell* pWrtSh) override;
virtual VclPtr<AbstractMailMergeDlg> CreateMailMergeDlg(
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);
}
}