diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2017-05-24 20:46:31 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-07-28 15:05:47 +0200 |
commit | 7fc62b59ddad40f725709f14331c38c0a78ff6ee (patch) | |
tree | c71707e3f27ed37d2901fc0e9d07166e4e898496 /sc | |
parent | 0f75c004cc20e14c7d33c8f2a4451d71681af146 (diff) |
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/40460
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/clipparam.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/clipparam.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 23 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun3.cxx | 25 |
4 files changed, 58 insertions, 2 deletions
diff --git a/sc/inc/clipparam.hxx b/sc/inc/clipparam.hxx index 2e5dece711e8..16555225d074 100644 --- a/sc/inc/clipparam.hxx +++ b/sc/inc/clipparam.hxx @@ -26,6 +26,8 @@ #include <vector> +class SfxViewShell; + /** * This struct stores general clipboard parameters associated with a * ScDocument instance created in clipboard mode. @@ -38,6 +40,7 @@ struct ScClipParam Direction meDirection; bool mbCutMode; sal_uInt32 mnSourceDocID; + SfxViewShell* mpSourceView; ScRangeListVector maProtectedChartRangesVector; ScClipParam(); @@ -67,6 +70,9 @@ struct ScClipParam sal_uInt32 getSourceDocID() const { return mnSourceDocID; } void setSourceDocID( sal_uInt32 nVal ) { mnSourceDocID = nVal; } + + SfxViewShell* getSourceView() const { return mpSourceView; } + void setSourceView( SfxViewShell* pSourceView ) { mpSourceView = pSourceView; } }; #endif diff --git a/sc/source/core/data/clipparam.cxx b/sc/source/core/data/clipparam.cxx index 9c08d6093dfc..bc856672fbba 100644 --- a/sc/source/core/data/clipparam.cxx +++ b/sc/source/core/data/clipparam.cxx @@ -23,14 +23,16 @@ ScClipParam::ScClipParam() : meDirection(Unspecified), mbCutMode(false), - mnSourceDocID(0) + mnSourceDocID(0), + mpSourceView(nullptr) { } ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) : meDirection(Unspecified), mbCutMode(bCutMode), - mnSourceDocID(0) + mnSourceDocID(0), + mpSourceView(nullptr) { maRanges.Append(rRange); } diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 58fd0ee27ace..7642274eead4 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -613,6 +613,29 @@ void ScCellShell::GetClipState( SfxItemSet& rSet ) 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) { rSet.DisableItem( SID_PASTE ); diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 2c481f5ce0fe..ba37ef4077e1 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -37,6 +37,9 @@ #include <sot/exchange.hxx> #include <memory> +#include <comphelper/lok.hxx> +#include <sfx2/lokhelper.hxx> + #include "attrib.hxx" #include "patattr.hxx" #include "dociter.hxx" @@ -225,6 +228,14 @@ bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, b // and lose the 'if' above 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()) { // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell). @@ -870,6 +881,20 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, if (GetViewData().SelectionForbidsCellFill()) 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 InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE; if (nFlags & InsertDeleteFlags::CONTENTS) |