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
This commit is contained in:
parent
8e62e20f1f
commit
c32f31309f
6 changed files with 86 additions and 79 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue