summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2017-06-27 14:35:58 -0400
committerJan Holesovsky <kendy@collabora.com>2017-07-26 18:24:17 +0200
commitea31fa38bfef778428203d1473cafc31659be1b9 (patch)
treebc746ba1434c63e7fed065f2e0f6f01048488028
parent3274eae5ba8bc02ab6f39ee0b3b95880547aa5b5 (diff)
sd lok: fix Undo/Redo Document Repair
REPAIRPACKAGE is sent to enable Undo/Redo actions when two views have conflicts. Change-Id: I58133f5b9006c41a297711c52ed0acfce3c19f92 Reviewed-on: https://gerrit.libreoffice.org/39325 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Henry Castro <hcastro@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/39398 Reviewed-by: Jan Holesovsky <kendy@collabora.com> Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r--sd/inc/undo/undomanager.hxx5
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx38
-rw-r--r--sd/source/core/undo/undomanager.cxx49
-rw-r--r--sd/source/ui/view/viewshe3.cxx10
-rw-r--r--sd/source/ui/view/viewshel.cxx35
5 files changed, 57 insertions, 80 deletions
diff --git a/sd/inc/undo/undomanager.hxx b/sd/inc/undo/undomanager.hxx
index 2b1ed48a4abc..7d1e04cab58b 100644
--- a/sd/inc/undo/undomanager.hxx
+++ b/sd/inc/undo/undomanager.hxx
@@ -37,9 +37,6 @@ public:
virtual void EnterListAction(const OUString &rComment, const OUString& rRepeatComment, sal_uInt16 nId, sal_Int32 nViewShellId) override;
virtual void AddUndoAction( SfxUndoAction *pAction, bool bTryMerg=false ) override;
- size_t GetUndoActionCount(const bool bCurrentLevel = true) const override;
- size_t GetRedoActionCount(const bool bCurrentLevel = true) const override;
- void SetViewShell(SfxViewShell* pViewShell);
/** Set or reset the undo manager linked with the called undo manager.
*/
@@ -53,8 +50,6 @@ private:
synchronize the undo managers.
*/
::svl::IUndoManager* mpLinkedUndoManager;
- /// Return undo/redo info for this view.
- SfxViewShell* mpViewShell;
/** Call ClearRedo() at the linked undo manager, when present.
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index a6f13cbcead9..6a75280b7f4f 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1170,31 +1170,37 @@ void SdTiledRenderingTest::testUndoLimiting()
// Create the first view.
SdXImpressDocument* pXImpressDocument = createDoc("title-shape.odp");
- SfxViewShell& rViewShell1 = pXImpressDocument->GetDocShell()->GetViewShell()->GetViewShellBase();
+ sd::ViewShell* pViewShell1 = pXImpressDocument->GetDocShell()->GetViewShell();
+ int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
- pXImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
- SfxViewShell& rViewShell2 = pXImpressDocument->GetDocShell()->GetViewShell()->GetViewShellBase();
+ sd::ViewShell* pViewShell2 = pXImpressDocument->GetDocShell()->GetViewShell();
+ CPPUNIT_ASSERT(pViewShell1 != pViewShell2);
// Begin text edit on the only object on the slide.
- sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
- SdrView* pView = pViewShell->GetView();
+ SfxLokHelper::setView(nView1);
pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB);
pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
Scheduler::ProcessEventsToIdle();
- CPPUNIT_ASSERT(pView->IsTextEdit());
+ CPPUNIT_ASSERT(pViewShell1->GetView()->IsTextEdit());
- // Now check what views see the undo action.
- SdDrawDocument* pDocument = pXImpressDocument->GetDoc();
- sd::UndoManager* pUndoManager = pDocument->GetUndoManager();
- pUndoManager->SetViewShell(&rViewShell1);
- // This was 1, undo action was visible to the first view, even if the
- // action belongs to the second view.
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetUndoActionCount());
- pUndoManager->SetViewShell(&rViewShell2);
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount());
- pUndoManager->SetViewShell(nullptr);
+ // Now check view2 cannot undo actions.
+ {
+ SfxRequest aReq2(SID_UNDO, SfxCallMode::SLOT, pXImpressDocument->GetDocShell()->GetDoc()->GetPool());
+ aReq2.AppendItem(SfxUInt16Item(SID_UNDO, 1));
+ pViewShell2->ExecuteSlot(aReq2);
+ CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(aReq2.GetReturnValue()));
+ CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), dynamic_cast< const SfxUInt32Item * >(aReq2.GetReturnValue())->GetValue());
+ }
+
+ // Now check view1 can undo action
+ {
+ SfxRequest aReq1(SID_UNDO, SfxCallMode::SLOT, pXImpressDocument->GetDocShell()->GetDoc()->GetPool());
+ aReq1.AppendItem(SfxUInt16Item(SID_UNDO, 1));
+ pViewShell1->ExecuteSlot(aReq1);
+ CPPUNIT_ASSERT(aReq1.IsDone());
+ }
mxComponent->dispose();
mxComponent.clear();
diff --git a/sd/source/core/undo/undomanager.cxx b/sd/source/core/undo/undomanager.cxx
index a18c858a680e..d89868aa91db 100644
--- a/sd/source/core/undo/undomanager.cxx
+++ b/sd/source/core/undo/undomanager.cxx
@@ -17,7 +17,6 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <comphelper/lok.hxx>
#include <sfx2/viewsh.hxx>
#include <undo/undomanager.hxx>
@@ -26,7 +25,6 @@ using namespace sd;
UndoManager::UndoManager()
: SdrUndoManager( 20/*nMaxUndoActionCount*/ )
, mpLinkedUndoManager(nullptr)
- , mpViewShell(nullptr)
{
}
@@ -52,53 +50,6 @@ void UndoManager::AddUndoAction( SfxUndoAction *pAction, bool bTryMerg /* = sal_
}
}
-size_t UndoManager::GetUndoActionCount(const bool bCurrentLevel) const
-{
- size_t nRet = SdrUndoManager::GetUndoActionCount(bCurrentLevel);
- if (!comphelper::LibreOfficeKit::isActive() || !mpViewShell)
- return nRet;
-
- if (!nRet || !SdrUndoManager::GetUndoActionCount())
- return nRet;
-
- const SfxUndoAction* pAction = SdrUndoManager::GetUndoAction();
- if (!pAction)
- return nRet;
-
- // If an other view created the last undo action, prevent undoing it from this view.
- sal_Int32 nViewShellId = mpViewShell->GetViewShellId();
- if (pAction->GetViewShellId() != nViewShellId)
- nRet = 0;
-
- return nRet;
-}
-
-size_t UndoManager::GetRedoActionCount(const bool bCurrentLevel) const
-{
- size_t nRet = SdrUndoManager::GetRedoActionCount(bCurrentLevel);
- if (!comphelper::LibreOfficeKit::isActive() || !mpViewShell)
- return nRet;
-
- if (!nRet || !SdrUndoManager::GetRedoActionCount())
- return nRet;
-
- const SfxUndoAction* pAction = SdrUndoManager::GetRedoAction();
- if (!pAction)
- return nRet;
-
- // If an other view created the first redo action, prevent redoing it from this view.
- sal_Int32 nViewShellId = mpViewShell->GetViewShellId();
- if (pAction->GetViewShellId() != nViewShellId)
- nRet = 0;
-
- return nRet;
-}
-
-void UndoManager::SetViewShell(SfxViewShell* pViewShell)
-{
- mpViewShell = pViewShell;
-}
-
void UndoManager::SetLinkedUndoManager (::svl::IUndoManager* pLinkedUndoManager)
{
mpLinkedUndoManager = pLinkedUndoManager;
diff --git a/sd/source/ui/view/viewshe3.cxx b/sd/source/ui/view/viewshe3.cxx
index f769a3bf7da8..6600248086f3 100644
--- a/sd/source/ui/view/viewshe3.cxx
+++ b/sd/source/ui/view/viewshe3.cxx
@@ -129,15 +129,10 @@ void ViewShell::GetMenuState( SfxItemSet &rSet )
if(pUndoManager)
{
- auto pSdUndoManager = dynamic_cast<sd::UndoManager*>(pUndoManager);
- if (pSdUndoManager)
- pSdUndoManager->SetViewShell(&GetViewShellBase());
if(pUndoManager->GetUndoActionCount() != 0)
{
bActivate = true;
}
- if (pSdUndoManager)
- pSdUndoManager->SetViewShell(nullptr);
}
if(bActivate)
@@ -161,15 +156,10 @@ void ViewShell::GetMenuState( SfxItemSet &rSet )
if(pUndoManager)
{
- auto pSdUndoManager = dynamic_cast<sd::UndoManager*>(pUndoManager);
- if (pSdUndoManager)
- pSdUndoManager->SetViewShell(&GetViewShellBase());
if(pUndoManager->GetRedoActionCount() != 0)
{
bActivate = true;
}
- if (pSdUndoManager)
- pSdUndoManager->SetViewShell(nullptr);
}
if(bActivate)
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 91be0281b146..443515373618 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -1259,11 +1259,18 @@ void ViewShell::ImpSidUndo(bool, SfxRequest& rReq)
::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
sal_uInt16 nNumber(1);
const SfxItemSet* pReqArgs = rReq.GetArgs();
+ bool bRepair = false;
if(pReqArgs)
{
const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_UNDO));
nNumber = pUIntItem->GetValue();
+
+ // Repair mode: allow undo/redo of all undo actions, even if access would
+ // be limited based on the view shell ID.
+ const SfxPoolItem* pRepairItem;
+ if (pReqArgs->GetItemState(SID_REPAIRPACKAGE, false, &pRepairItem) == SfxItemState::SET)
+ bRepair = static_cast<const SfxBoolItem*>(pRepairItem)->GetValue();
}
if(nNumber && pUndoManager)
@@ -1271,6 +1278,17 @@ void ViewShell::ImpSidUndo(bool, SfxRequest& rReq)
sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
if(nCount >= nNumber)
{
+ if (comphelper::LibreOfficeKit::isActive() && !bRepair)
+ {
+ // If an other view created the first undo action, prevent redoing it from this view.
+ const SfxUndoAction* pAction = pUndoManager->GetUndoAction();
+ if (pAction->GetViewShellId() != static_cast<sal_Int32>(GetViewShellBase().GetViewShellId()))
+ {
+ rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+ return;
+ }
+ }
+
try
{
// when UndoStack is cleared by ModifyPageUndoAction
@@ -1310,11 +1328,17 @@ void ViewShell::ImpSidRedo(bool, SfxRequest& rReq)
::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
sal_uInt16 nNumber(1);
const SfxItemSet* pReqArgs = rReq.GetArgs();
+ bool bRepair = false;
if(pReqArgs)
{
const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_REDO));
nNumber = pUIntItem->GetValue();
+ // Repair mode: allow undo/redo of all undo actions, even if access would
+ // be limited based on the view shell ID.
+ const SfxPoolItem* pRepairItem;
+ if (pReqArgs->GetItemState(SID_REPAIRPACKAGE, false, &pRepairItem) == SfxItemState::SET)
+ bRepair = static_cast<const SfxBoolItem*>(pRepairItem)->GetValue();
}
if(nNumber && pUndoManager)
@@ -1322,6 +1346,17 @@ void ViewShell::ImpSidRedo(bool, SfxRequest& rReq)
sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
if(nCount >= nNumber)
{
+ if (comphelper::LibreOfficeKit::isActive() && !bRepair)
+ {
+ // If an other view created the first undo action, prevent redoing it from this view.
+ const SfxUndoAction* pAction = pUndoManager->GetRedoAction();
+ if (pAction->GetViewShellId() != static_cast<sal_Int32>(GetViewShellBase().GetViewShellId()))
+ {
+ rReq.SetReturnValue(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+ return;
+ }
+ }
+
try
{
// when UndoStack is cleared by ModifyPageRedoAction