diff options
author | Henry Castro <hcastro@collabora.com> | 2017-06-27 14:35:58 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2017-06-28 02:50:00 +0200 |
commit | 9f3814af7264ce90685a82cbf4eb015a38f22bf7 (patch) | |
tree | 9aeba4af7e08129fd69ab73b8e71d7069c7bec25 | |
parent | e0f67add2ec56706ce06a03572535266f21c0303 (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>
-rw-r--r-- | sd/inc/undo/undomanager.hxx | 5 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 38 | ||||
-rw-r--r-- | sd/source/core/undo/undomanager.cxx | 49 | ||||
-rw-r--r-- | sd/source/ui/view/viewshe3.cxx | 10 | ||||
-rw-r--r-- | sd/source/ui/view/viewshel.cxx | 35 |
5 files changed, 57 insertions, 80 deletions
diff --git a/sd/inc/undo/undomanager.hxx b/sd/inc/undo/undomanager.hxx index c053e9b8cabb..b22ea929ad82 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, ViewShellId 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 499b7f0a5641..628c72afef30 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -1174,31 +1174,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 e4caf4df4cb7..57bc43880e63 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> @@ -25,7 +24,6 @@ using namespace sd; UndoManager::UndoManager() : mpLinkedUndoManager(nullptr) - , mpViewShell(nullptr) { } @@ -51,53 +49,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. - ViewShellId 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. - ViewShellId 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 2a59f0ecdfab..7e744d07f598 100644 --- a/sd/source/ui/view/viewshe3.cxx +++ b/sd/source/ui/view/viewshe3.cxx @@ -130,15 +130,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) @@ -162,15 +157,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 c72d90886dc6..a0e86368021f 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -1258,11 +1258,18 @@ void ViewShell::ImpSidUndo(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) @@ -1270,6 +1277,17 @@ void ViewShell::ImpSidUndo(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() != GetViewShellBase().GetViewShellId()) + { + rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE))); + return; + } + } + try { // when UndoStack is cleared by ModifyPageUndoAction @@ -1309,11 +1327,17 @@ void ViewShell::ImpSidRedo(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) @@ -1321,6 +1345,17 @@ void ViewShell::ImpSidRedo(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() != GetViewShellBase().GetViewShellId()) + { + rReq.SetReturnValue(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE))); + return; + } + } + try { // when UndoStack is cleared by ModifyPageRedoAction |