lokdialog: Convert the Format -> ... -> Position and Size... to async exec.

Change-Id: Idcdbfb1366db61e247c31eab5cb27a39978b0fd9
Reviewed-on: https://gerrit.libreoffice.org/48055
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
This commit is contained in:
Jan Holesovsky
2018-01-17 15:20:31 +01:00
parent e6e1259463
commit d3dbbdce4e
3 changed files with 111 additions and 70 deletions

View File

@@ -67,12 +67,17 @@ public: \
explicit Class( DialogClass* p) \ explicit Class( DialogClass* p) \
: pDlg(p) \ : pDlg(p) \
{} \ {} \
virtual short Execute() override ; virtual short Execute() override; \
virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) override;
#define IMPL_ABSTDLG_BASE(Class) \ #define IMPL_ABSTDLG_BASE(Class) \
short Class::Execute() \ short Class::Execute() \
{ \ { \
return pDlg->Execute(); \ return pDlg->Execute(); \
} \
bool Class::StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) \
{ \
return pDlg->StartExecuteAsync(rCtx); \
} }
class VclAbstractDialog2_Impl : public VclAbstractDialog2 class VclAbstractDialog2_Impl : public VclAbstractDialog2

View File

@@ -32,8 +32,7 @@
#include <memory> #include <memory>
namespace sd { using namespace sd;
FuTransform::FuTransform(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, FuTransform::FuTransform(ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
SdDrawDocument* pDoc, SfxRequest& rReq) SdDrawDocument* pDoc, SfxRequest& rReq)
@@ -48,16 +47,63 @@ rtl::Reference<FuPoor> FuTransform::Create( ViewShell* pViewSh, ::sd::Window* pW
return xFunc; return xFunc;
} }
namespace {
void setUndo(::sd::View* pView, const SfxItemSet* pArgs)
{
// Undo
OUString aString(pView->GetDescriptionOfMarkedObjects());
aString += " " + SdResId(STR_TRANSFORM);
pView->BegUndo(aString);
pView->SetGeoAttrToMarked(*pArgs);
pView->SetAttributes(*pArgs);
pView->EndUndo();
}
class ScopeCleanup
{
ViewShell* mpViewShell;
public:
ScopeCleanup(ViewShell* pViewShell) : mpViewShell(pViewShell)
{
}
~ScopeCleanup()
{
if (mpViewShell)
{
mpViewShell->Invalidate(SID_RULER_OBJECT);
mpViewShell->Cancel();
}
}
void ignore()
{
mpViewShell = nullptr;
}
};
}
void FuTransform::DoExecute( SfxRequest& rReq ) void FuTransform::DoExecute( SfxRequest& rReq )
{ {
if( mpView->AreObjectsMarked() ) ScopeCleanup aCleanup(mpViewShell);
{
if (!mpView->AreObjectsMarked())
return;
const SfxItemSet* pArgs = rReq.GetArgs(); const SfxItemSet* pArgs = rReq.GetArgs();
if( !pArgs ) if (pArgs)
{ {
setUndo(mpView, pArgs);
return;
}
// --------- itemset for size and position -------- // --------- itemset for size and position --------
SfxItemSet aSet( mpView->GetGeoAttrFromMarked() ); SfxItemSet aSet( mpView->GetGeoAttrFromMarked() );
VclPtr<SfxAbstractTabDialog> pDlg;
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
@@ -70,52 +116,43 @@ void FuTransform::DoExecute( SfxRequest& rReq )
mpView->GetAttributes( aNewAttr ); mpView->GetAttributes( aNewAttr );
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if ( pFact ) if (!pFact)
{ return;
ScopedVclPtr< SfxAbstractTabDialog > pDlg( pFact->CreateCaptionDialog( nullptr, mpView ) );
pDlg.reset(pFact->CreateCaptionDialog(nullptr, mpView));
const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() ); const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange ); SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
aCombSet.Put( aNewAttr ); aCombSet.Put( aNewAttr );
aCombSet.Put( aSet ); aCombSet.Put( aSet );
pDlg->SetInputSet( &aCombSet ); pDlg->SetInputSet( &aCombSet );
if( pDlg.get() && (pDlg->Execute() == RET_OK) )
{
rReq.Done( *( pDlg->GetOutputItemSet() ) );
pArgs = rReq.GetArgs();
}
}
} }
else else
{ {
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if (!pFact)
{ return;
ScopedVclPtr< SfxAbstractTabDialog > pDlg( pFact->CreateSvxTransformTabDialog( nullptr, &aSet, mpView ) );
if( pDlg.get() && (pDlg->Execute() == RET_OK) ) pDlg.reset(pFact->CreateSvxTransformTabDialog(nullptr, &aSet, mpView));
{
rReq.Done( *( pDlg->GetOutputItemSet() ) );
pArgs = rReq.GetArgs();
}
}
}
} }
if( pArgs ) if (!pDlg)
{ return;
// Undo
OUString aString( mpView->GetDescriptionOfMarkedObjects() );
aString += " " + SdResId( STR_TRANSFORM );
mpView->BegUndo( aString );
mpView->SetGeoAttrToMarked( *pArgs ); std::shared_ptr<SfxRequest> pRequest(new SfxRequest(rReq));
mpView->SetAttributes( *pArgs ); rReq.Ignore(); // the 'old' request is not relevant any more
mpView->EndUndo(); aCleanup.ignore(); // the lambda does it
}
pDlg->StartExecuteAsync([=](sal_Int32 nResult){
if (nResult == RET_OK)
{
pRequest->Done(*(pDlg->GetOutputItemSet()));
setUndo(mpView, pRequest->GetArgs());
} }
mpViewShell->Invalidate(SID_RULER_OBJECT);
mpViewShell->Cancel();
}, pDlg);
} }
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -1381,8 +1381,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
case SID_ATTR_TRANSFORM: case SID_ATTR_TRANSFORM:
{ {
SetCurrentFunction( FuTransform::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) ); SetCurrentFunction( FuTransform::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
Invalidate(SID_RULER_OBJECT); // Cancel() and Invalidate() called directly in FuTransform::Create()
Cancel();
} }
break; break;