sc/qa/unit/tiledrendering/tiledrendering.cxx | 26 ++++++++++++--- sc/source/ui/view/tabvwshb.cxx | 44 ++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-)
New commits: commit ca2e58aadcf8bc70a6780fd5fe941f643ce81f54 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 10 10:04:09 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Aug 10 12:52:14 2022 +0200 calc: fix undo action disabled in different views when actions are independant. Update existing unit test to test this too. Change-Id: I0af804321c371e72fb1ce096ec4ec3566a3fcffc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138079 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 327c7102eae1..41b885f1a525 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -1588,6 +1588,8 @@ void ScTiledRenderingTest::testDisableUndoRepair() int nView2 = SfxLokHelper::getView(); SfxViewShell* pView2 = SfxViewShell::Current(); CPPUNIT_ASSERT(pView1 != pView2); + + // both views have UNDO disabled { SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); @@ -1604,6 +1606,7 @@ void ScTiledRenderingTest::testDisableUndoRepair() pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); + // view1 has UNDO enabled, view2 is in UNDO-repair { SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); @@ -1625,6 +1628,7 @@ void ScTiledRenderingTest::testDisableUndoRepair() pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); + // both views have UNDO enabled Scheduler::ProcessEventsToIdle(); { SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); @@ -1632,9 +1636,7 @@ void ScTiledRenderingTest::testDisableUndoRepair() pView1->GetSlotState(SID_UNDO, nullptr, &aSet1); pView2->GetSlotState(SID_UNDO, nullptr, &aSet2); CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO)); - const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(aSet1.GetItem(SID_UNDO)); - CPPUNIT_ASSERT(pUInt32Item); - CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), pUInt32Item->GetValue()); + CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet1.GetItem(SID_UNDO))); CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO)); CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet2.GetItem(SID_UNDO))); } @@ -3196,11 +3198,13 @@ void ScTiledRenderingTest::testUndoReorderingRedo() // view #1 int nView1 = SfxLokHelper::getView(); + SfxViewShell* pView1 = SfxViewShell::Current(); ViewCallback aView1; // view #2 SfxLokHelper::createView(); int nView2 = SfxLokHelper::getView(); + SfxViewShell* pView2 = SfxViewShell::Current(); pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); ViewCallback aView2; @@ -3230,8 +3234,8 @@ void ScTiledRenderingTest::testUndoReorderingRedo() // text edit a different cell in view #2 SfxLokHelper::setView(nView2); - ScTabViewShell* pView2 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); - pView2->SetCursor(0, 2); + ScTabViewShell* pViewShell2 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current()); + pViewShell2->SetCursor(0, 2); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'C', 0); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'C', 0); pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'C', 0); @@ -3253,6 +3257,18 @@ void ScTiledRenderingTest::testUndoReorderingRedo() CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(0, 1, 0))); CPPUNIT_ASSERT_EQUAL(OUString("CC"), pDoc->GetString(ScAddress(0, 2, 0))); + // Verify that the UNDO buttons/actions are still enabled + { + SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); + SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>); + pView1->GetSlotState(SID_UNDO, nullptr, &aSet1); + pView2->GetSlotState(SID_UNDO, nullptr, &aSet2); + CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO)); + CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet1.GetItem(SID_UNDO))); + CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO)); + CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet2.GetItem(SID_UNDO))); + } + // View 1 presses undo again, and the first cell is erased dispatchCommand(mxComponent, ".uno:Undo", {}); Scheduler::ProcessEventsToIdle(); diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx index 249ad86abc87..59bff4d7ace4 100644 --- a/sc/source/ui/view/tabvwshb.cxx +++ b/sc/source/ui/view/tabvwshb.cxx @@ -45,6 +45,7 @@ #include <svl/stritem.hxx> #include <svl/slstitm.hxx> #include <svl/whiter.hxx> +#include <svtools/strings.hrc> #include <unotools/moduleoptions.hxx> #include <sot/exchange.hxx> #include <tools/diagnose_ex.h> @@ -62,6 +63,7 @@ #include <undomanager.hxx> #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> #include <svx/svdpagv.hxx> +#include <o3tl/temporary.hxx> #include <comphelper/lok.hxx> @@ -810,7 +812,7 @@ void ScTabViewShell::ExecuteUndo(SfxRequest& rReq) void ScTabViewShell::GetUndoState(SfxItemSet &rSet) { SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0); - SfxUndoManager* pUndoManager = pSh->GetUndoManager(); + ScUndoManager* pUndoManager = static_cast<ScUndoManager*>(pSh->GetUndoManager()); SfxWhichIter aIter(rSet); sal_uInt16 nWhich = aIter.FirstWhich(); @@ -836,6 +838,46 @@ void ScTabViewShell::GetUndoState(SfxItemSet &rSet) rSet.Put( aStrLst ); } break; + + case SID_UNDO: + { + if (pUndoManager->GetUndoActionCount()) + { + const SfxUndoAction* pAction = pUndoManager->GetUndoAction(); + SfxViewShell *pViewSh = GetViewShell(); + if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId() + && !pUndoManager->IsViewUndoActionIndependent(this, o3tl::temporary(sal_uInt16()))) + { + rSet.Put(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE))); + } + else + { + rSet.Put( SfxStringItem( SID_UNDO, SvtResId(STR_UNDO)+pUndoManager->GetUndoActionComment() ) ); + } + } + else + rSet.DisableItem( SID_UNDO ); + break; + } + case SID_REDO: + { + if (pUndoManager->GetRedoActionCount()) + { + const SfxUndoAction* pAction = pUndoManager->GetRedoAction(); + SfxViewShell *pViewSh = GetViewShell(); + if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId()) + { + rSet.Put(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE))); + } + else + { + rSet.Put(SfxStringItem(SID_REDO, SvtResId(STR_REDO) + pUndoManager->GetRedoActionComment())); + } + } + else + rSet.DisableItem( SID_REDO ); + break; + } default: // get state from sfx view frame GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet );