sc/qa/unit/tiledrendering/tiledrendering.cxx | 26 ++++++++++++--- sc/source/ui/view/tabvwshb.cxx | 44 ++++++++++++++++++++++++++- sw/source/filter/ww8/ww8par.cxx | 2 - sw/source/filter/ww8/ww8par.hxx | 2 - sw/source/filter/ww8/ww8par5.cxx | 10 +++--- 5 files changed, 71 insertions(+), 13 deletions(-)
New commits: commit c8ef47651a32c9cd00183d51fb31912990b89793 Author: Noel Grandin <[email protected]> AuthorDate: Mon Aug 8 19:02:07 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Aug 11 10:32:36 2022 +0200 unique_ptr->optional in SwWW8ImplReader Change-Id: I9d5961c974cf0ec378dd3560ad24d65e5d3aa197 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138104 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index a22469ba2994..548726482993 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -5478,7 +5478,7 @@ ErrCode SwWW8ImplReader::CoreLoad(WW8Glossary const *pGloss) m_xLstManager.reset(); } - m_pPosAfterTOC.reset(); + m_oPosAfterTOC.reset(); m_xRedlineStack.reset(); mpCursor.reset(); m_pPaM = nullptr; diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index fcd46da1cde4..f6c6e2fd9548 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1399,7 +1399,7 @@ private: // Indicate that current on loading a hyperlink, which is inside a TOC; Managed by Read_F_Hyperlink() and End_Field() bool m_bLoadingTOXHyperlink; // a document position recorded the after-position of TOC section, managed by Read_F_TOX() and End_Field() - std::unique_ptr<SwPaM> m_pPosAfterTOC; + std::optional<SwPaM> m_oPosAfterTOC; // used for some dropcap tweaking std::unique_ptr<TextNodeListener> m_xPreviousNode; diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index d59f41d68174..508cae886c1f 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -569,10 +569,10 @@ sal_uInt16 SwWW8ImplReader::End_Field() m_bCareLastParaEndInToc = true; } - if (m_pPosAfterTOC) + if (m_oPosAfterTOC) { - *m_pPaM = *m_pPosAfterTOC; - m_pPosAfterTOC.reset(); + *m_pPaM = *m_oPosAfterTOC; + m_oPosAfterTOC.reset(); } } } @@ -3479,7 +3479,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, OUString& rStr ) //The TOC field representation contents should be inserted into TOC section, but not after TOC section. //So we need update the document position when loading TOC representation and after loading TOC; - m_pPosAfterTOC.reset(new SwPaM(*m_pPaM, m_pPaM)); + m_oPosAfterTOC.emplace(*m_pPaM, m_pPaM); (*m_pPaM).Move(fnMoveBackward); SwPaM aRegion(*m_pPaM, m_pPaM); @@ -3500,7 +3500,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, OUString& rStr ) // inserting a toc inserts a section before this point, so adjust pos // for future page/section segment insertion - m_aSectionManager.PrependedInlineNode( *m_pPosAfterTOC->GetPoint(), aRegion.GetNode() ); + m_aSectionManager.PrependedInlineNode( *m_oPosAfterTOC->GetPoint(), aRegion.GetNode() ); } // Set end in stack commit 30efbe72f6b3a025ef12695b23821a77e1b1a887 Author: Noel Grandin <[email protected]> AuthorDate: Wed Aug 10 10:04:09 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Aug 11 10:32:22 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 <[email protected]> Reviewed-by: Noel Grandin <[email protected]> (cherry picked from commit db23578b694228c983b615c9be6aed8a6a2af84b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138029 Tested-by: Jenkins 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 );
