diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-10 10:04:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-11 10:32:22 +0200 |
commit | 30efbe72f6b3a025ef12695b23821a77e1b1a887 (patch) | |
tree | 63044ae23d8ccd3abb7f566fef23ff427915252d /sc | |
parent | 335eb038e8964f6be99528341bfa76e4d7f55e27 (diff) |
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit db23578b694228c983b615c9be6aed8a6a2af84b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138029
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/tiledrendering/tiledrendering.cxx | 26 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwshb.cxx | 44 |
2 files changed, 64 insertions, 6 deletions
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 559769c0c251..cfd80d53fa89 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -1544,6 +1544,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>); @@ -1560,6 +1562,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>); @@ -1581,6 +1584,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>); @@ -1588,9 +1592,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))); } @@ -3063,11 +3065,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; @@ -3097,8 +3101,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); @@ -3120,6 +3124,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 7052820099c9..2b1a96f919d1 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 ); |