summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-07-02 23:25:00 +0300
committerMuhammet Kara <muhammet.kara@collabora.com>2019-07-10 16:48:09 +0200
commit1fedfa62784a4f61b0cf6cede29634dc863a7b60 (patch)
treea2c0fb351c07c5ceb050b0e588431d1c604337e9
parent74d56d44804efa3424cff3434d2baf00c60b3cd5 (diff)
Prepare PasteSpecial for Async-ness (sw, basesh.cxx)
This change is needed to make the paste special dialog async exec because the current design relies on return values of inner functions/methods while moving on. After this patch, the dialog creation and execution will not be so deep, so that it will be able to be converted to async exec in the usual way. The duplication in SvPasteObjectDialog::PreGetFormat() coming from SvPasteObjectDialog::GetFormat() will go away when the conversion is complete for all modules. It is only temporarily needed. Change-Id: I55e8aee39c41be6035c89f217f90f79720f32196 Reviewed-on: https://gerrit.libreoffice.org/75016 Tested-by: Jenkins Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
-rw-r--r--cui/source/dialogs/pastedlg.cxx119
-rw-r--r--cui/source/factory/dlgfact.cxx10
-rw-r--r--cui/source/factory/dlgfact.hxx2
-rw-r--r--cui/source/inc/pastedlg.hxx15
-rw-r--r--include/sfx2/sfxdlg.hxx2
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx25
-rw-r--r--sw/source/uibase/inc/swdtflvr.hxx8
-rw-r--r--sw/source/uibase/shells/basesh.cxx44
8 files changed, 194 insertions, 31 deletions
diff --git a/cui/source/dialogs/pastedlg.cxx b/cui/source/dialogs/pastedlg.cxx
index 9b47043138a6..eb8b37c3ec62 100644
--- a/cui/source/dialogs/pastedlg.cxx
+++ b/cui/source/dialogs/pastedlg.cxx
@@ -72,6 +72,125 @@ void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString&
aSupplementMap.insert( std::make_pair( nFormat, rFormatName ) );
}
+void SvPasteObjectDialog::PreGetFormat( const TransferableDataHelper &rHelper )
+{
+ //TODO/LATER: why is the Descriptor never used?!
+ TransferableObjectDescriptor aDesc;
+ if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
+ {
+ (void)const_cast<TransferableDataHelper&>(rHelper).GetTransferableObjectDescriptor(
+ SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
+ }
+ const DataFlavorExVector* pFormats = &rHelper.GetDataFlavorExVector();
+
+ // create and fill dialog box
+ OUString aSourceName, aTypeName;
+ SvGlobalName aEmptyNm;
+
+ //ObjectLB().SetUpdateMode( false );
+ ObjectLB().freeze();
+
+ DataFlavorExVector::iterator aIter( const_cast<DataFlavorExVector&>(*pFormats).begin() ),
+ aEnd( const_cast<DataFlavorExVector&>(*pFormats).end() );
+ while( aIter != aEnd )
+ {
+ SotClipboardFormatId nFormat = (*aIter++).mnSotId;
+
+ std::map< SotClipboardFormatId, OUString >::iterator itName =
+ aSupplementMap.find( nFormat );
+
+ // if there is an "Embed Source" or and "Embedded Object" on the
+ // Clipboard we read the Description and the Source of this object
+ // from an accompanied "Object Descriptor" format on the clipboard
+ // Remember: these formats mostly appear together on the clipboard
+ OUString aName;
+ const OUString* pName = nullptr;
+ if ( itName == aSupplementMap.end() )
+ {
+ SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
+ if ( !aName.isEmpty() )
+ pName = &aName;
+ }
+ else
+ {
+ pName = &(itName->second);
+ }
+
+ if( pName )
+ {
+ aName = *pName;
+
+ if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
+ {
+ if( aDesc.maClassName != aEmptyNm )
+ {
+ aSourceName = aDesc.maDisplayName;
+
+ if( aDesc.maClassName == aObjClassName )
+ aName = aObjName;
+ else
+ aName = aTypeName = aDesc.maTypeName;
+ }
+ }
+ else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
+ {
+ continue;
+ }
+ else if( aName.isEmpty() )
+ aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
+
+ // Show RICHTEXT only in case RTF is not present.
+ if (nFormat == SotClipboardFormatId::RICHTEXT &&
+ std::any_of(pFormats->begin(), pFormats->end(),
+ [](const DataFlavorEx& rFlavor) {
+ return rFlavor.mnSotId == SotClipboardFormatId::RTF;
+ }))
+ {
+ continue;
+ }
+
+ if (ObjectLB().find_text(aName) == -1)
+ {
+ ObjectLB().append(OUString::number(static_cast<sal_uInt32>(nFormat)), aName);
+ }
+ }
+ }
+
+ if( aTypeName.isEmpty() && aSourceName.isEmpty() )
+ {
+ if( aDesc.maClassName != aEmptyNm )
+ {
+ aSourceName = aDesc.maDisplayName;
+ aTypeName = aDesc.maTypeName;
+ }
+
+ if( aTypeName.isEmpty() && aSourceName.isEmpty() )
+ {
+ // global resource from svtools (former so3 resource)
+ aSourceName = SvtResId(STR_UNKNOWN_SOURCE);
+ }
+ }
+
+ ObjectLB().thaw();
+ SelectObject();
+
+ if( !aSourceName.isEmpty() )
+ {
+ if( !aTypeName.isEmpty() )
+ aTypeName += "\n";
+
+ aTypeName += aSourceName;
+ aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
+ }
+
+ m_xFtObjectSource->set_label(aTypeName);
+}
+
+SotClipboardFormatId SvPasteObjectDialog::GetFormatOnly()
+{
+ return static_cast<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
+}
+
SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper)
{
//TODO/LATER: why is the Descriptor never used?!
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index e27ce6891b0d..19bd83ed5ad0 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -510,6 +510,16 @@ void AbstractPasteDialog_Impl::SetObjName(const SvGlobalName & rClass, const OUS
m_xDlg->SetObjName(rClass, rObjName);
}
+void AbstractPasteDialog_Impl::PreGetFormat( const TransferableDataHelper& aHelper )
+{
+ m_xDlg->PreGetFormat(aHelper);
+}
+
+SotClipboardFormatId AbstractPasteDialog_Impl::GetFormatOnly()
+{
+ return m_xDlg->GetFormatOnly();
+}
+
SotClipboardFormatId AbstractPasteDialog_Impl::GetFormat( const TransferableDataHelper& aHelper )
{
return m_xDlg->GetFormat(aHelper);
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index 94bb772fecbe..f0e343947aaf 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -571,6 +571,8 @@ public:
public:
virtual void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ) override;
virtual void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ) override;
+ virtual void PreGetFormat( const TransferableDataHelper& aHelper ) override;
+ virtual SotClipboardFormatId GetFormatOnly() override;
virtual SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper ) override;
};
diff --git a/cui/source/inc/pastedlg.hxx b/cui/source/inc/pastedlg.hxx
index 45495dba119a..ff66beca7c5a 100644
--- a/cui/source/inc/pastedlg.hxx
+++ b/cui/source/inc/pastedlg.hxx
@@ -50,6 +50,21 @@ public:
void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName );
void SetObjName( const SvGlobalName & rClass, const OUString & rObjName );
+ /**
+ * @brief PreGetFormat Prepares the dialog for running to get format of paste as a SotClipboardFormatId value by calling GetFormatOnly()
+ * @param aHelper
+ */
+ void PreGetFormat( const TransferableDataHelper& aHelper);
+ /**
+ * @brief GetFormatOnly Returns a SotClipboardFormatId value. Should be called after actually running the dialog.
+ * @return
+ */
+ SotClipboardFormatId GetFormatOnly();
+ /**
+ * @brief GetFormat Prepares and runs the dialog, and returns a SotClipboardFormatId depending on the RET_OK result
+ * @param aHelper TransferableDataHelper containing the data to be pasted
+ * @return a SotClipboardFormatId value depending on the result of running the dialog
+ */
SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper);
};
diff --git a/include/sfx2/sfxdlg.hxx b/include/sfx2/sfxdlg.hxx
index d4296c413524..d47b4f219bc6 100644
--- a/include/sfx2/sfxdlg.hxx
+++ b/include/sfx2/sfxdlg.hxx
@@ -92,6 +92,8 @@ protected:
public:
virtual void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ) = 0;
virtual void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ) = 0;
+ virtual void PreGetFormat( const TransferableDataHelper& aHelper ) = 0;
+ virtual SotClipboardFormatId GetFormatOnly() = 0;
virtual SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper ) = 0;
};
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 9e4852af8551..75a5fd240168 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -143,6 +143,7 @@
#include <vcl/GraphicNativeMetadata.hxx>
#include <comphelper/lok.hxx>
#include <sfx2/classificationhelper.hxx>
+#include <sfx2/sfxdlg.hxx>
#include <memory>
@@ -3125,12 +3126,8 @@ bool SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper&
return SwTransferable::PasteFormat( rSh, rData, SotClipboardFormatId::STRING );
}
-bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, SotClipboardFormatId& rFormatUsed )
+void SwTransferable::PrePasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, VclPtr<SfxAbstractPasteDialog>& pDlg )
{
- bool bRet = false;
- SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
- ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(rSh.GetView().GetEditWin().GetFrameWeld()));
-
DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
TransferableObjectDescriptor aDesc;
@@ -3162,7 +3159,7 @@ bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rDat
}
pDlg->SetObjName( pClipboard->m_aObjDesc.maClassName,
SwResId(pResId) );
- pDlg->Insert(SotClipboardFormatId::EMBED_SOURCE, OUString());
+ pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, OUString() );
}
}
else
@@ -3174,9 +3171,9 @@ bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rDat
}
if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
- pDlg->Insert(SotClipboardFormatId::EMBED_SOURCE, OUString());
+ pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, OUString() );
if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
- pDlg->Insert(SotClipboardFormatId::LINK_SOURCE, OUString());
+ pDlg->Insert( SotClipboardFormatId::LINK_SOURCE, OUString() );
}
if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
@@ -3184,17 +3181,7 @@ bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rDat
for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
if( SwTransferable::TestAllowedFormat( rData, *pIds, nDest ))
- pDlg->Insert(*pIds, OUString());
-
- SotClipboardFormatId nFormat = pDlg->GetFormat( rData.GetTransferable() );
-
- if( nFormat != SotClipboardFormatId::NONE )
- bRet = SwTransferable::PasteFormat( rSh, rData, nFormat );
-
- if ( bRet )
- rFormatUsed = nFormat;
-
- return bRet;
+ pDlg->Insert( *pIds, OUString() );
}
void SwTransferable::FillClipFormatItem( const SwWrtShell& rSh,
diff --git a/sw/source/uibase/inc/swdtflvr.hxx b/sw/source/uibase/inc/swdtflvr.hxx
index cf58d7e5bbed..1b3cf2536964 100644
--- a/sw/source/uibase/inc/swdtflvr.hxx
+++ b/sw/source/uibase/inc/swdtflvr.hxx
@@ -34,6 +34,7 @@ class Graphic;
class ImageMap;
class INetBookmark;
class INetImage;
+class SfxAbstractPasteDialog;
class SwDoc;
class SwDocFac;
class SwTextBlocks;
@@ -189,7 +190,12 @@ public:
static bool IsPasteSpecial( const SwWrtShell& rWrtShell,
const TransferableDataHelper& );
static bool PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& );
- static bool PasteSpecial( SwWrtShell& rSh, TransferableDataHelper&, SotClipboardFormatId& rFormatUsed );
+ /**
+ * @brief PrePasteSpecial Prepares the given dialog without actually running it
+ * @param rSh
+ * @param rFormatUsed
+ */
+ static void PrePasteSpecial( SwWrtShell& rSh, TransferableDataHelper&, VclPtr<SfxAbstractPasteDialog>& pDlg );
static bool PasteFormat( SwWrtShell& rSh, TransferableDataHelper& rData,
SotClipboardFormatId nFormat );
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index f5a59dbb9e0a..dc5e0c5be334 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -113,6 +113,8 @@
#include <comphelper/scopeguard.hxx>
#include <comphelper/lok.hxx>
+#include <svx/svxdlg.hxx>
+
#include <SwStyleNameMapper.hxx>
#include <poolfmt.hxx>
#include <shellres.hxx>
@@ -384,21 +386,41 @@ void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
SotClipboardFormatId nFormatId = SotClipboardFormatId::NONE;
rReq.Ignore();
bIgnore = true;
- if(SwTransferable::PasteSpecial( rSh, aDataHelper, nFormatId ))
+ bool bRet = false;
+
+ SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
+ VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( rReq.GetFrameWeld() ));
+
+ // Prepare the dialog
+ SwTransferable::PrePasteSpecial(rSh, aDataHelper, pDlg);
+ pDlg->PreGetFormat(aDataHelper);
+
+
+ if (pDlg->Execute() == RET_OK)
{
- SfxViewFrame* pViewFrame = pView->GetViewFrame();
- uno::Reference< frame::XDispatchRecorder > xRecorder =
- pViewFrame->GetBindings().GetRecorder();
- if(xRecorder.is()) {
- SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
- aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
- aReq.Done();
+ nFormatId = pDlg->GetFormatOnly();
+
+ if( nFormatId != SotClipboardFormatId::NONE )
+ bRet = SwTransferable::PasteFormat( rSh, aDataHelper, nFormatId );
+
+ if (bRet)
+ {
+ SfxViewFrame* pViewFrame = pView->GetViewFrame();
+ uno::Reference< frame::XDispatchRecorder > xRecorder =
+ pViewFrame->GetBindings().GetRecorder();
+ if(xRecorder.is()) {
+ SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
+ aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
+ aReq.Done();
+ }
}
+
+ if (rSh.IsFrameSelected() || rSh.IsObjSelected())
+ rSh.EnterSelFrameMode();
+ pView->AttrChangedNotify( &rSh );
}
- if (rSh.IsFrameSelected() || rSh.IsObjSelected())
- rSh.EnterSelFrameMode();
- pView->AttrChangedNotify( &rSh );
+ pDlg->disposeOnce();
}
else
return;