[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sc/inc sc/qa sc/source
Marco Cecchetti
marco.cecchetti at collabora.com
Wed May 23 14:15:27 UTC 2018
sc/inc/scabstdlg.hxx | 3 -
sc/qa/unit/screenshots/screenshots.cxx | 2
sc/source/ui/attrdlg/scdlgfact.cxx | 5 +
sc/source/ui/attrdlg/scdlgfact.hxx | 3 -
sc/source/ui/unoobj/filtuno.cxx | 2
sc/source/ui/view/cellsh2.cxx | 2
sc/source/ui/view/viewfun5.cxx | 86 ++++++++++++++++++++-------------
7 files changed, 63 insertions(+), 40 deletions(-)
New commits:
commit ca8f4e2961fd1a49af92e348da618827189ac7c0
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date: Fri Apr 27 21:51:41 2018 +0200
lok: sc: tunneling the ascii import dialog on paste action
I needed to modify CreateScImportAsciiDlg signature so that we are able
to pass a pointer to a dialog parent window to ScImportAsciiDlg.
Moreover, I needed to perform the execution of the ScImportAsciiDlg
dialog in ScViewFunc::PasteDataFormat asynchronously, both for lok and
desktop case. In order to achieve this result it has been needed
to modify the lifespan of some objects previously local
to PasteDataFormat.
Since PasteDataFormat returns a boolean, I took care to check how this
return value is used. I found out 2 cases:
1) in ScViewFunc::PasteFromSystem where it is used for popping up an
error dialog box, informing the user in the case that the paste
operation is failed;
2) in ScGridWindow::ExecuteDrop where it is used for informing the
system window manager of the success or fail of the drag and drop
action.
The first case is now handled by a lamba invoked soon after the dialog
execution ended. The second case is more tricky: I handle it as
the paste operation is always successful, hoping it doesn't do any real
difference since the return value is used not by LO but by the system
window manager (e.g. gtk).
The asynchronous call and the behaviors described above occur only
when the paste operation involves some kind of simple text, in all other
cases nothing is changed.
Change-Id: Id4f96180a9336f665a22a2441ea490af993431b0
Reviewed-on: https://gerrit.libreoffice.org/53575
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index edb52e238a67..620b19297517 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -397,7 +397,8 @@ class ScAbstractDialogFactory
public:
SC_DLLPUBLIC static ScAbstractDialogFactory* Create();
- virtual VclPtr<AbstractScImportAsciiDlg> CreateScImportAsciiDlg( const OUString& aDatName,
+ virtual VclPtr<AbstractScImportAsciiDlg> CreateScImportAsciiDlg(vcl::Window* pParent,
+ const OUString& aDatName,
SvStream* pInStream,
ScImportAsciiCall eCall) = 0;
diff --git a/sc/qa/unit/screenshots/screenshots.cxx b/sc/qa/unit/screenshots/screenshots.cxx
index 2c32d2c75874..a9c70b2f9e2d 100644
--- a/sc/qa/unit/screenshots/screenshots.cxx
+++ b/sc/qa/unit/screenshots/screenshots.cxx
@@ -243,7 +243,7 @@ VclPtr<VclAbstractDialog> ScScreenshotTest::createDialogByID(sal_uInt32 nID)
case 13: // "modules/scalc/ui/textimportcsv.ui"
{
- pReturnDialog = mpFact->CreateScImportAsciiDlg(OUString(), mpStream.get(), SC_PASTETEXT);
+ pReturnDialog = mpFact->CreateScImportAsciiDlg(nullptr, OUString(), mpStream.get(), SC_PASTETEXT);
break;
}
case 14: // "modules/scalc/ui/formatcellsdialog.ui"
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 513ecd8974ac..637986fbcea1 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -611,10 +611,11 @@ bool AbstractScTextImportOptionsDlg_Impl::IsDateConversionSet() const
}
// =========================Factories for createdialog ===================
-VclPtr<AbstractScImportAsciiDlg> ScAbstractDialogFactory_Impl::CreateScImportAsciiDlg ( const OUString& aDatName,
+VclPtr<AbstractScImportAsciiDlg> ScAbstractDialogFactory_Impl::CreateScImportAsciiDlg ( vcl::Window* pParent,
+ const OUString& aDatName,
SvStream* pInStream, ScImportAsciiCall eCall )
{
- VclPtr<ScImportAsciiDlg> pDlg = VclPtr<ScImportAsciiDlg>::Create( nullptr, aDatName,pInStream, eCall );
+ VclPtr<ScImportAsciiDlg> pDlg = VclPtr<ScImportAsciiDlg>::Create( pParent, aDatName,pInStream, eCall );
return VclPtr<AbstractScImportAsciiDlg_Impl>::Create( pDlg );
}
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index 842505f2b4b7..79f3e11ffb96 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -396,7 +396,8 @@ class ScAbstractDialogFactory_Impl : public ScAbstractDialogFactory
public:
virtual ~ScAbstractDialogFactory_Impl() {}
- virtual VclPtr<AbstractScImportAsciiDlg> CreateScImportAsciiDlg( const OUString& aDatName,
+ virtual VclPtr<AbstractScImportAsciiDlg> CreateScImportAsciiDlg(vcl::Window* pParent,
+ const OUString& aDatName,
SvStream* pInStream,
ScImportAsciiCall eCall) override;
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index ee6e6ed3c265..cef30678fde5 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -191,7 +191,7 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
if ( xInputStream.is() )
pInStream.reset(utl::UcbStreamHelper::CreateStream( xInputStream ));
- ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg( aPrivDatName, pInStream.get(), SC_IMPORTFILE));
+ ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(nullptr, aPrivDatName, pInStream.get(), SC_IMPORTFILE));
OSL_ENSURE(pDlg, "Dialog create fail!");
if ( pDlg->Execute() == RET_OK )
{
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index bd654de87e95..99b16039501c 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -1002,7 +1002,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(
- OUString(), &aStream, SC_TEXTTOCOLUMNS));
+ nullptr, OUString(), &aStream, SC_TEXTTOCOLUMNS));
OSL_ENSURE( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
if ( pDlg->Execute() == RET_OK )
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 7e3194ab64d4..1590baee2f97 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -44,6 +44,7 @@
#include <svtools/transfer.hxx>
#include <vcl/graph.hxx>
+#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/storagehelper.hxx>
#include <comphelper/string.hxx>
@@ -56,6 +57,8 @@
#include <dbdata.hxx>
#include <sc.hrc>
#include <filter.hxx>
+#include <globstr.hrc>
+#include <global.hxx>
#include <scextopt.hxx>
#include <tabvwsh.hxx>
#include <compiler.hxx>
@@ -294,10 +297,11 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
else
{
ScAddress aCellPos( nPosX, nPosY, GetViewData().GetTabNo() );
- ScImportExport aObj( GetViewData().GetDocument(), aCellPos );
- aObj.SetOverwriting( true );
+ std::shared_ptr<ScImportExport> pObj(new ScImportExport(GetViewData().GetDocument(), aCellPos));
+ pObj->SetOverwriting( true );
- OUString aStr;
+
+ std::shared_ptr<OUString> pStrBuffer(new OUString());
tools::SvRef<SotStorageStream> xStream;
if ( aDataHelper.GetSotStorageStream( nFormatId, xStream ) && xStream.is() )
{
@@ -315,7 +319,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
ScAsciiOptions aOptions;
aOptions.SetLanguage(pDlg->GetLanguageType());
aOptions.SetDetectSpecialNumber(pDlg->IsDateConversionSet());
- aObj.SetExtOptions(aOptions);
+ pObj->SetExtOptions(aOptions);
}
else
{
@@ -324,48 +328,64 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId nFormatId,
}
}
if(!bRet)
- bRet = aObj.ImportStream( *xStream, OUString(), nFormatId );
+ bRet = pObj->ImportStream( *xStream, OUString(), nFormatId );
// mba: clipboard always must contain absolute URLs (could be from alien source)
}
else if ((nFormatId == SotClipboardFormatId::STRING || nFormatId == SotClipboardFormatId::STRING_TSVC)
- && aDataHelper.GetString( nFormatId, aStr ))
+ && aDataHelper.GetString( nFormatId, *pStrBuffer ))
{
// Do CSV dialog if more than one line.
- sal_Int32 nDelim = aStr.indexOf('\n');
- if (nDelim >= 0 && nDelim != aStr.getLength () - 1)
+ sal_Int32 nDelim = pStrBuffer->indexOf('\n');
+ if (nDelim >= 0 && nDelim != pStrBuffer->getLength () - 1)
{
- ScImportStringStream aStrm( aStr);
- ScAbstractDialogFactory* pFact =
- ScAbstractDialogFactory::Create();
- ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(
- pFact->CreateScImportAsciiDlg( OUString(), &aStrm, SC_PASTETEXT));
+ vcl::Window* pParent = comphelper::LibreOfficeKit::isActive() ? GetActiveWin() : nullptr;
- if (pDlg->Execute() == RET_OK)
- {
- ScAsciiOptions aOptions;
- pDlg->GetOptions( aOptions );
- pDlg->SaveParameters();
- aObj.SetExtOptions( aOptions );
+ std::shared_ptr<ScImportStringStream> pStrm(new ScImportStringStream(*pStrBuffer));
- bRet = aObj.ImportString( aStr, nFormatId );
+ ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
+ VclPtr<AbstractScImportAsciiDlg> pDlg(
+ pFact->CreateScImportAsciiDlg(pParent, OUString(), pStrm.get(), SC_PASTETEXT));
+
+ bAllowDialogs = bAllowDialogs && !SC_MOD()->IsInExecuteDrop();
+
+ pDlg->StartExecuteAsync([this, pDlg, pDoc, pStrm, nFormatId, pStrBuffer, pObj, bAllowDialogs](sal_Int32 nResult){
+ bool bShowErrorDialog = bAllowDialogs;
+ if (RET_OK == nResult)
+ {
+ ScAsciiOptions aOptions;
+ pDlg->GetOptions( aOptions );
+ pDlg->SaveParameters();
+ pObj->SetExtOptions( aOptions );
+ pObj->ImportString( *pStrBuffer, nFormatId );
+
+ // TODO: what if (aObj.IsOverflow())
+ // Content was partially pasted, which can be undone by
+ // the user though.
+ bShowErrorDialog = bShowErrorDialog && pObj->IsOverflow();
+ }
+ else
+ {
+ bShowErrorDialog = false;
+ // Yes, no failure, don't raise a "couldn't paste"
+ // dialog if user cancelled.
+ }
- // TODO: what if (aObj.IsOverflow())
- // Content was partially pasted, which can be undone by
- // the user though.
- if (aObj.IsOverflow())
- bRet = false;
- }
- else
- bRet = true;
- // Yes, no failure, don't raise a "couldn't paste"
- // dialog if user cancelled.
+ InvalidateAttribs();
+ GetViewData().UpdateInputHandler();
+
+ pDoc->SetPastingDrawFromOtherDoc( false );
+
+ if (bShowErrorDialog)
+ ErrorMessage(STR_PASTE_ERROR);
+ });
+ return true;
}
else
- bRet = aObj.ImportString( aStr, nFormatId );
+ bRet = pObj->ImportString( *pStrBuffer, nFormatId );
}
else if ((nFormatId != SotClipboardFormatId::STRING && nFormatId != SotClipboardFormatId::STRING_TSVC)
- && aDataHelper.GetString( nFormatId, aStr ))
- bRet = aObj.ImportString( aStr, nFormatId );
+ && aDataHelper.GetString( nFormatId, *pStrBuffer ))
+ bRet = pObj->ImportString( *pStrBuffer, nFormatId );
InvalidateAttribs();
GetViewData().UpdateInputHandler();
More information about the Libreoffice-commits
mailing list