summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2020-07-20 11:35:00 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2020-07-24 09:12:47 +0200
commitc32f31309fc0d8a846418fd373608dd6f84c7972 (patch)
tree6bb5c4de5da9397e54f6114429be56e02393a8c5 /sw
parent8e62e20f1f4da93f84b135d0b221ecd39667b0e4 (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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99280 Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/swabstdlg.hxx7
-rw-r--r--sw/source/ui/chrdlg/break.cxx34
-rw-r--r--sw/source/ui/dialog/swdlgfact.cxx27
-rw-r--r--sw/source/ui/dialog/swdlgfact.hxx9
-rw-r--r--sw/source/uibase/inc/break.hxx2
-rw-r--r--sw/source/uibase/shells/textsh1.cxx86
6 files changed, 86 insertions, 79 deletions
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 1533d816eb8e..0b530d170e77 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 ::std::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 80f0d19fd641..03b316895b09 100644
--- a/sw/source/ui/chrdlg/break.cxx
+++ b/sw/source/ui/chrdlg/break.cxx
@@ -31,32 +31,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)
@@ -122,6 +117,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 163d315bbb9b..639fb25d598c 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -116,11 +116,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();
@@ -364,17 +359,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;
}
::std::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,
@@ -817,9 +824,9 @@ VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwInsertBookmarkDl
return VclPtr<AbstractGenericDialog_Impl>::Create(std::make_shared<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 0f1a7c94f1e0..5c8f0cb0c4e0 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 ::std::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 9c07ce2b502d..9ee79926fb1a 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 ::std::optional<sal_uInt16>& GetPageNumber() const { return oPgNum; }
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 228a8a4b9210..ea797594053c 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -324,6 +324,33 @@ static void sw_ParagraphDialogResult(SfxItemSet* pSet, SwWrtShell &rWrtSh, SfxRe
}
}
+namespace {
+
+void InsertBreak(SwWrtShell& rWrtSh,
+ sal_uInt16 nKind,
+ ::std::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;
@@ -599,12 +626,11 @@ void SwTextShell::Execute(SfxRequest &rReq)
}
case FN_INSERT_BREAK_DLG:
{
- sal_uInt16 nKind=0;
- ::std::optional<sal_uInt16> oPageNumber;
- OUString aTemplateName;
if ( pItem )
{
- nKind = static_cast<const SfxInt16Item*>(pItem)->GetValue();
+ ::std::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);
@@ -612,51 +638,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;
- }
-
- 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();
+ ::std::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;