Kaydet (Commit) f0684222 authored tarafından Marco Cecchetti's avatar Marco Cecchetti Kaydeden (comit) Jan Holesovsky

lok: sc: copy / paste confusion -- workaround

Problem:

1. (a) copied April
2. (a) pasted -> April
3. (b) copied March
4. (a) pasted -> March [should have been April]

where (a), (b) are different views

Solution:
A real solution would require to have one clipboard per view.
This patch is only a workaround, which doesn't allow to paste content
which has been copied in a different view; it takes also care to
disable the "Paste" entry in the context menu.

Change-Id: I3254f130af106299b0b519884a4ca03db08fc4c8
Reviewed-on: https://gerrit.libreoffice.org/40459Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst b064a22f
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <vector> #include <vector>
class SfxViewShell;
/** /**
* This struct stores general clipboard parameters associated with a * This struct stores general clipboard parameters associated with a
* ScDocument instance created in clipboard mode. * ScDocument instance created in clipboard mode.
...@@ -38,6 +40,7 @@ struct ScClipParam ...@@ -38,6 +40,7 @@ struct ScClipParam
Direction meDirection; Direction meDirection;
bool mbCutMode; bool mbCutMode;
sal_uInt32 mnSourceDocID; sal_uInt32 mnSourceDocID;
SfxViewShell* mpSourceView;
ScRangeListVector maProtectedChartRangesVector; ScRangeListVector maProtectedChartRangesVector;
ScClipParam(); ScClipParam();
...@@ -67,6 +70,9 @@ struct ScClipParam ...@@ -67,6 +70,9 @@ struct ScClipParam
sal_uInt32 getSourceDocID() const { return mnSourceDocID; } sal_uInt32 getSourceDocID() const { return mnSourceDocID; }
void setSourceDocID( sal_uInt32 nVal ) { mnSourceDocID = nVal; } void setSourceDocID( sal_uInt32 nVal ) { mnSourceDocID = nVal; }
SfxViewShell* getSourceView() const { return mpSourceView; }
void setSourceView( SfxViewShell* pSourceView ) { mpSourceView = pSourceView; }
}; };
#endif #endif
......
...@@ -23,14 +23,16 @@ ...@@ -23,14 +23,16 @@
ScClipParam::ScClipParam() : ScClipParam::ScClipParam() :
meDirection(Unspecified), meDirection(Unspecified),
mbCutMode(false), mbCutMode(false),
mnSourceDocID(0) mnSourceDocID(0),
mpSourceView(nullptr)
{ {
} }
ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) : ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
meDirection(Unspecified), meDirection(Unspecified),
mbCutMode(bCutMode), mbCutMode(bCutMode),
mnSourceDocID(0) mnSourceDocID(0),
mpSourceView(nullptr)
{ {
maRanges.Append(rRange); maRanges.Append(rRange);
} }
......
...@@ -605,6 +605,29 @@ void ScCellShell::GetClipState( SfxItemSet& rSet ) ...@@ -605,6 +605,29 @@ void ScCellShell::GetClipState( SfxItemSet& rSet )
bDisable = true; bDisable = true;
} }
// This is only a workaround, we don't want that text content copied
// in one view is pasted in a different view.
// This part of the patch takes care to disable the "Paste" entry
// in the context menu.
// TODO: implement a solution providing one clipboard per view
if (comphelper::LibreOfficeKit::isActive())
{
ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(nullptr);
if (pOwnClip)
{
ScDocument* pClipDoc = pOwnClip->GetDocument();
if (pClipDoc)
{
ScTabViewShell* pThisView = GetViewData()->GetViewShell();
ScTabViewShell* pSourceView = dynamic_cast<ScTabViewShell*>(pClipDoc->GetClipParam().getSourceView());
if (pThisView && pSourceView && pThisView != pSourceView)
{
bDisable = true;
}
}
}
}
if (bDisable) if (bDisable)
{ {
rSet.DisableItem( SID_PASTE ); rSet.DisableItem( SID_PASTE );
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
#include <sot/exchange.hxx> #include <sot/exchange.hxx>
#include <memory> #include <memory>
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
#include "attrib.hxx" #include "attrib.hxx"
#include "patattr.hxx" #include "patattr.hxx"
#include "dociter.hxx" #include "dociter.hxx"
...@@ -224,6 +227,14 @@ bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, b ...@@ -224,6 +227,14 @@ bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, b
// and lose the 'if' above // and lose the 'if' above
aClipParam.setSourceDocID( pDoc->GetDocumentID() ); aClipParam.setSourceDocID( pDoc->GetDocumentID() );
// This is only a workaround, which doesn't allow to paste content
// in one view which has been copied in a different view.
// TODO: implement a solution providing one clipboard per view
if (comphelper::LibreOfficeKit::isActive())
{
aClipParam.setSourceView(GetViewData().GetViewShell());
}
if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell()) if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell())
{ {
// Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell). // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell).
...@@ -862,6 +873,20 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, ...@@ -862,6 +873,20 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
if (GetViewData().SelectionForbidsCellFill()) if (GetViewData().SelectionForbidsCellFill())
return false; return false;
// This is only a workaround, which doesn't allow to paste content
// in one view which has been copied in a different view.
// TODO: implement a solution providing one clipboard per view
if (comphelper::LibreOfficeKit::isActive())
{
ScTabViewShell* pThisView = GetViewData().GetViewShell();
ScTabViewShell* pSourceView = dynamic_cast<ScTabViewShell*>(pClipDoc->GetClipParam().getSourceView());
if (pThisView && pSourceView && pThisView != pSourceView)
{
return false;
}
}
// undo: save all or no content // undo: save all or no content
InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE; InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE;
if (nFlags & InsertDeleteFlags::CONTENTS) if (nFlags & InsertDeleteFlags::CONTENTS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment