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 | |
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')
-rw-r--r-- | sw/inc/swabstdlg.hxx | 8 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 13 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 11 | ||||
-rw-r--r-- | sw/source/uibase/shells/basesh.cxx | 172 |
4 files changed, 118 insertions, 86 deletions
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx index f70fd068090a..3d0d3233d9de 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, std::unique_ptr<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 b3a40e9ecebc..de22333e4127 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -231,11 +231,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(); @@ -599,7 +594,9 @@ void AbstractInsTableDlg_Impl::GetValues( OUString& rName, sal_uInt16& rRow, sal SwInsertTableOptions& rInsTableFlags, OUString& rTableAutoFormatName, std::unique_ptr<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 @@ -1039,9 +1036,9 @@ VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateVclSwViewDialog(Sw return VclPtr<AbstractGenericDialog_Impl>::Create(std::make_shared<SwLineNumberingDlg>(rView)); } -VclPtr<AbstractInsTableDlg> SwAbstractDialogFactory_Impl::CreateInsTableDlg(SwView& rView) +std::shared_ptr<AbstractInsTableDlg> SwAbstractDialogFactory_Impl::CreateInsTableDlg(SwView& rView) { - return VclPtr<AbstractInsTableDlg_Impl>::Create(std::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 315cfba7b143..9f84f34a44a8 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -471,16 +471,17 @@ public: class SwInsTableDlg; class AbstractInsTableDlg_Impl : public AbstractInsTableDlg { - std::unique_ptr<SwInsTableDlg> m_xDlg; +protected: + 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, std::unique_ptr<SwTableAutoFormat>& prTAFormat ) override; + virtual std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; } }; class SwJavaEditDialog; @@ -728,7 +729,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 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); } } |