diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-07-20 11:35:00 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-07-20 13:05:43 +0200 |
commit | 73c1d4f38bda5a51168cabd4bbb4d99a465d872f (patch) | |
tree | 861c1eaa236ff0fa8d527b2d6efcabd9ecf2768f /sw | |
parent | ca49f93839198c7218a7b9f1bf9e0984f6725f45 (diff) |
Make InsertBreak dialog async
Change-Id: I2191ef0ea6b79bd45d682eb1ae6b0d60627f7486
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99033
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/swabstdlg.hxx | 7 | ||||
-rw-r--r-- | sw/source/ui/chrdlg/break.cxx | 34 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 27 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 9 | ||||
-rw-r--r-- | sw/source/uibase/inc/break.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 86 |
6 files changed, 86 insertions, 79 deletions
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx index c7d1114ed6ae..09ffc5a22d8e 100644 --- a/sw/inc/swabstdlg.hxx +++ b/sw/inc/swabstdlg.hxx @@ -229,15 +229,16 @@ public: }; -class AbstractSwBreakDlg : public VclAbstractDialog +class AbstractSwBreakDlg { protected: - virtual ~AbstractSwBreakDlg() override = default; + virtual ~AbstractSwBreakDlg() = default; public: virtual OUString GetTemplateName() = 0; virtual sal_uInt16 GetKind() = 0; virtual ::boost::optional<sal_uInt16> GetPageNumber() = 0; + virtual std::shared_ptr<weld::DialogController> getDialogController() = 0; }; class AbstractSplitTableDialog : public VclAbstractDialog // add for @@ -379,7 +380,7 @@ public: SvStream* pStream) = 0; virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window *pParent, SwWrtShell &rSh, SfxRequest& rReq) = 0; - virtual VclPtr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) = 0; + virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) = 0; virtual VclPtr<VclAbstractDialog> CreateSwChangeDBDlg(SwView& rVw) = 0; virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet, SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) = 0; diff --git a/sw/source/ui/chrdlg/break.cxx b/sw/source/ui/chrdlg/break.cxx index 31cba5287627..b1dea7141fa5 100644 --- a/sw/source/ui/chrdlg/break.cxx +++ b/sw/source/ui/chrdlg/break.cxx @@ -35,32 +35,27 @@ #include <strings.hrc> #include <SwStyleNameMapper.hxx> -short SwBreakDlg::run() +void SwBreakDlg::rememberResult() { - short nRet = GenericDialogController::run(); - if (nRet == RET_OK) + nKind = 0; + if (m_xLineBtn->get_active()) + nKind = 1; + else if(m_xColumnBtn->get_active()) + nKind = 2; + else if(m_xPageBtn->get_active()) { - nKind = 0; - if (m_xLineBtn->get_active()) - nKind = 1; - else if(m_xColumnBtn->get_active()) - nKind = 2; - else if(m_xPageBtn->get_active()) + nKind = 3; + const int nPos = m_xPageCollBox->get_active(); + if (nPos != 0 && nPos != -1) { - nKind = 3; - const int nPos = m_xPageCollBox->get_active(); - if (nPos != 0 && nPos != -1) + m_aTemplate = m_xPageCollBox->get_active_text(); + oPgNum.reset(); + if (m_xPageNumBox->get_active()) { - m_aTemplate = m_xPageCollBox->get_active_text(); - oPgNum.reset(); - if (m_xPageNumBox->get_active()) - { - oPgNum = static_cast<sal_uInt16>(m_xPageNumEdit->get_value()); - } + oPgNum = static_cast<sal_uInt16>(m_xPageNumEdit->get_value()); } } } - return nRet; } IMPL_LINK_NOARG(SwBreakDlg, ToggleHdl, weld::ToggleButton&, void) @@ -126,6 +121,7 @@ IMPL_LINK_NOARG(SwBreakDlg, OkHdl, weld::Button&, void) return; } } + rememberResult(); m_xDialog->response(RET_OK); } diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index e053a69086cf..b6fbf745d86a 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -118,11 +118,6 @@ short AbstractSplitTableDialog_Impl::Execute() return m_xDlg->run(); } -short AbstractSwBreakDlg_Impl::Execute() -{ - return m_xDlg->run(); -} - short AbstractSwTableWidthDlg_Impl::Execute() { return m_xDlg->run(); @@ -366,17 +361,29 @@ SplitTable_HeadlineOption AbstractSplitTableDialog_Impl::GetSplitMode() OUString AbstractSwBreakDlg_Impl::GetTemplateName() { - return m_xDlg->GetTemplateName(); + SwBreakDlg* pDlg = dynamic_cast<SwBreakDlg*>(m_xDlg.get()); + if (pDlg) + return pDlg->GetTemplateName(); + + return ""; } sal_uInt16 AbstractSwBreakDlg_Impl:: GetKind() { - return m_xDlg->GetKind(); + SwBreakDlg* pDlg = dynamic_cast<SwBreakDlg*>(m_xDlg.get()); + if (pDlg) + return pDlg->GetKind(); + + return 0; } ::boost::optional<sal_uInt16> AbstractSwBreakDlg_Impl:: GetPageNumber() { - return m_xDlg->GetPageNumber(); + SwBreakDlg* pDlg = dynamic_cast<SwBreakDlg*>(m_xDlg.get()); + if (pDlg) + return pDlg->GetPageNumber(); + + return 0; } void AbstractSwConvertTableDlg_Impl::GetValues( sal_Unicode& rDelim,SwInsertTableOptions& rInsTableFlags, @@ -819,9 +826,9 @@ VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwInsertBookmarkDl return VclPtr<AbstractGenericDialog_Impl>::Create(std::make_unique<SwInsertBookmarkDlg>(pParent, rSh, rReq)); } -VclPtr<AbstractSwBreakDlg> SwAbstractDialogFactory_Impl::CreateSwBreakDlg(weld::Window* pParent, SwWrtShell &rSh) +std::shared_ptr<AbstractSwBreakDlg> SwAbstractDialogFactory_Impl::CreateSwBreakDlg(weld::Window* pParent, SwWrtShell &rSh) { - return VclPtr<AbstractSwBreakDlg_Impl>::Create(std::make_unique<SwBreakDlg>(pParent, rSh)); + return std::make_shared<AbstractSwBreakDlg_Impl>(std::make_unique<SwBreakDlg>(pParent, rSh)); } VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwChangeDBDlg(SwView& rVw) diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index 15b865ccc5bc..26e04e42ab47 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -174,16 +174,17 @@ public: class AbstractSwBreakDlg_Impl : public AbstractSwBreakDlg { - std::unique_ptr<SwBreakDlg> m_xDlg; + std::shared_ptr<weld::DialogController> m_xDlg; public: - explicit AbstractSwBreakDlg_Impl(std::unique_ptr<SwBreakDlg> p) + explicit AbstractSwBreakDlg_Impl(std::shared_ptr<weld::DialogController> p) : m_xDlg(std::move(p)) { } - virtual short Execute() override; virtual OUString GetTemplateName() override; virtual sal_uInt16 GetKind() override; virtual ::boost::optional<sal_uInt16> GetPageNumber() override; + + virtual std::shared_ptr<weld::DialogController> getDialogController() override { return m_xDlg; } }; class AbstractSwTableWidthDlg_Impl : public VclAbstractDialog @@ -658,7 +659,7 @@ public: virtual VclPtr<AbstractSwAsciiFilterDlg> CreateSwAsciiFilterDlg(weld::Window* pParent, SwDocShell& rDocSh, SvStream* pStream) override; virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window *pParent, SwWrtShell &rSh, SfxRequest& rReq) override; - virtual VclPtr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override; + virtual std::shared_ptr<AbstractSwBreakDlg> CreateSwBreakDlg(weld::Window *pParent, SwWrtShell &rSh) override; virtual VclPtr<VclAbstractDialog> CreateSwChangeDBDlg(SwView& rVw) override; virtual VclPtr<SfxAbstractTabDialog> CreateSwCharDlg(weld::Window* pParent, SwView& pVw, const SfxItemSet& rCoreSet, SwCharDlgMode nDialogMode, const OUString* pFormatStr = nullptr) override; diff --git a/sw/source/uibase/inc/break.hxx b/sw/source/uibase/inc/break.hxx index 65d129fa0eef..9bb9142bca9a 100644 --- a/sw/source/uibase/inc/break.hxx +++ b/sw/source/uibase/inc/break.hxx @@ -50,10 +50,10 @@ class SwBreakDlg : public weld::GenericDialogController DECL_LINK(OkHdl, weld::Button&, void); void CheckEnable(); + void rememberResult(); public: SwBreakDlg(weld::Window *pParent, SwWrtShell &rSh); - virtual short run() override; const OUString& GetTemplateName() const { return m_aTemplate; } sal_uInt16 GetKind() const { return nKind; } const ::boost::optional<sal_uInt16>& GetPageNumber() const { return oPgNum; } diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index c434501cb346..69ef1ef72e17 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -353,6 +353,33 @@ static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRe } } +namespace { + +void InsertBreak(SwWrtShell& rWrtSh, + sal_uInt16 nKind, + ::boost::optional<sal_uInt16> oPageNumber, + const OUString& rTemplateName) +{ + switch ( nKind ) + { + case 1 : + rWrtSh.InsertLineBreak(); break; + case 2 : + rWrtSh.InsertColumnBreak(); break; + case 3 : + { + rWrtSh.StartAllAction(); + if( !rTemplateName.isEmpty() ) + rWrtSh.InsertPageBreak( &rTemplateName, oPageNumber ); + else + rWrtSh.InsertPageBreak(); + rWrtSh.EndAllAction(); + } + } +} + +} + void SwTextShell::Execute(SfxRequest &rReq) { bool bUseDialog = true; @@ -626,12 +653,11 @@ void SwTextShell::Execute(SfxRequest &rReq) } case FN_INSERT_BREAK_DLG: { - sal_uInt16 nKind=0; - ::boost::optional<sal_uInt16> oPageNumber; - OUString aTemplateName; if ( pItem ) { - nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue(); + ::boost::optional<sal_uInt16> oPageNumber; + OUString aTemplateName; + sal_uInt16 nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue(); const SfxStringItem* pTemplate = rReq.GetArg<SfxStringItem>(FN_PARAM_1); const SfxUInt16Item* pNumber = rReq.GetArg<SfxUInt16Item>(FN_PARAM_2); const SfxBoolItem* pIsNumberFilled = rReq.GetArg<SfxBoolItem>(FN_PARAM_3); @@ -639,51 +665,27 @@ void SwTextShell::Execute(SfxRequest &rReq) aTemplateName = pTemplate->GetValue(); if ( pNumber && pIsNumberFilled && pIsNumberFilled->GetValue() ) oPageNumber = pNumber->GetValue(); + + InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName); } else { SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractSwBreakDlg> pDlg(pFact->CreateSwBreakDlg(GetView().GetFrameWeld(), rWrtSh)); - if ( pDlg->Execute() == RET_OK ) - { - nKind = pDlg->GetKind(); - aTemplateName = pDlg->GetTemplateName(); - oPageNumber = pDlg->GetPageNumber(); - bool bIsNumberFilled = false; - sal_uInt16 nPageNumber = 0; + std::shared_ptr<AbstractSwBreakDlg> pAbstractDialog(pFact->CreateSwBreakDlg(GetView().GetFrameWeld(), rWrtSh)); + std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController()); - if (oPageNumber) - { - bIsNumberFilled = true; - nPageNumber = oPageNumber.get(); - } - - rReq.AppendItem( SfxInt16Item ( FN_INSERT_BREAK_DLG, nKind ) ); - rReq.AppendItem( SfxStringItem( FN_PARAM_1, aTemplateName ) ); - rReq.AppendItem( SfxUInt16Item( FN_PARAM_2, nPageNumber ) ); - rReq.AppendItem( SfxBoolItem ( FN_PARAM_3, bIsNumberFilled ) ); - rReq.Done(); - } - else - rReq.Ignore(); - } + weld::DialogController::runAsync(pDialogController, + [pAbstractDialog, &rWrtSh] (sal_Int32 nResult) { + if( RET_OK == nResult ) + { + sal_uInt16 nKind = pAbstractDialog->GetKind(); + OUString aTemplateName = pAbstractDialog->GetTemplateName(); + ::boost::optional<sal_uInt16> oPageNumber = pAbstractDialog->GetPageNumber(); - switch ( nKind ) - { - case 1 : - rWrtSh.InsertLineBreak(); break; - case 2 : - rWrtSh.InsertColumnBreak(); break; - case 3 : - { - rWrtSh.StartAllAction(); - if( !aTemplateName.isEmpty() ) - rWrtSh.InsertPageBreak( &aTemplateName, oPageNumber ); - else - rWrtSh.InsertPageBreak(); - rWrtSh.EndAllAction(); - } + InsertBreak(rWrtSh, nKind, oPageNumber, aTemplateName); + } + }); } break; |