From 815e403237ab178c8d9d51f02ea10e9f473784d8 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sat, 11 Jul 2015 12:53:08 -0400 Subject: tdf#92612 Right-clicking after applying "paint buckets" leads to multiple Undo In paint bucket mode the user can undo by right-clicking. Undoing, however, is only possible after the first paint op. After undoing is enabled, the user can undo indefinetely by righ-clicking. This is not consistent and can be confusing. This patch tracks the changes done after entering the paint bucket mode, and allows the user to undo them using right-clicking until they reach the first operation before entering this context. Because the user can undo/redo using other means, the patch takes it into account and will reset its tracking to accomodate this. Ultimately, the user is able to make any changes in paint bucket mode and undo them all by right-clicking, but no further than that. Reviewed-on: https://gerrit.libreoffice.org/16951 Tested-by: Jenkins Reviewed-by: Thorsten Behrens (cherry picked from commit d0489d0827fc6cef04d0f3602023d82ceda82480) Change-Id: I93380fb60db83aee37a1d324218ba6ab1700a2e5 Reviewed-on: https://gerrit.libreoffice.org/18256 Reviewed-by: Michael Stahl Tested-by: Michael Stahl --- sw/inc/IDocumentUndoRedo.hxx | 4 ++++ sw/source/core/inc/UndoManager.hxx | 1 + sw/source/core/undo/docundo.cxx | 5 +++++ sw/source/uibase/docvw/edtwin.cxx | 33 +++++++++++++++++++++++---------- sw/source/uibase/inc/view.hxx | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/sw/inc/IDocumentUndoRedo.hxx b/sw/inc/IDocumentUndoRedo.hxx index ee67ba04ec8a..206617f0a034 100644 --- a/sw/inc/IDocumentUndoRedo.hxx +++ b/sw/inc/IDocumentUndoRedo.hxx @@ -193,6 +193,10 @@ public: */ virtual bool IsUndoNodes(SwNodes const& rNodes) const = 0; + /** Get the number of Undo actions. + */ + virtual size_t GetUndoActionCount(const bool bCurrentLevel = true) const = 0; + protected: virtual ~IDocumentUndoRedo() {}; }; diff --git a/sw/source/core/inc/UndoManager.hxx b/sw/source/core/inc/UndoManager.hxx index 43c59950ddeb..df574fdf2879 100644 --- a/sw/source/core/inc/UndoManager.hxx +++ b/sw/source/core/inc/UndoManager.hxx @@ -71,6 +71,7 @@ public: virtual void AppendUndo(SwUndo *const pUndo) SAL_OVERRIDE; virtual void ClearRedo() SAL_OVERRIDE; virtual bool IsUndoNodes(SwNodes const& rNodes) const SAL_OVERRIDE; + virtual size_t GetUndoActionCount(const bool bCurrentLevel = true) const SAL_OVERRIDE; // ::svl::IUndoManager virtual void AddUndoAction(SfxUndoAction *pAction, diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx index 470abe183a30..1b50ec437336 100644 --- a/sw/source/core/undo/docundo.cxx +++ b/sw/source/core/undo/docundo.cxx @@ -79,6 +79,11 @@ bool UndoManager::IsUndoNodes(SwNodes const& rNodes) const return & rNodes == m_xUndoNodes.get(); } +size_t UndoManager::GetUndoActionCount(const bool bCurrentLevel) const +{ + return SdrUndoManager::GetUndoActionCount(bCurrentLevel); +} + void UndoManager::DoUndo(bool const bDoUndo) { if(!isTextEditActive()) diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index d10edecc9d48..7d160526f120 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -4767,15 +4768,15 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) { if( rSh.IsSelection() && !rSh.HasReadonlySel() ) { - if(nId == RES_CHRATR_BACKGROUND) + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); + if (nId == RES_CHRATR_BACKGROUND) rSh.SetAttrItem( SvxBrushItem( SwEditWin::m_aTextBackColor, nId ) ); else rSh.SetAttrItem( SvxColorItem( SwEditWin::m_aTextColor, nId ) ); rSh.UnSetVisCrsr(); rSh.EnterStdMode(); rSh.SetVisCrsr(aDocPt); - - m_pApplyTempl->bUndo = true; bCallBase = false; m_aTemplateTimer.Stop(); } @@ -4796,7 +4797,8 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) & eSelection ) && !rSh.HasReadonlySel() ) { rSh.SetTxtFmtColl( m_pApplyTempl->aColl.pTxtColl ); - m_pApplyTempl->bUndo = true; + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); bCallBase = false; if ( m_pApplyTempl->aColl.pTxtColl ) aStyleName = m_pApplyTempl->aColl.pTxtColl->GetName(); @@ -4810,7 +4812,8 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) rSh.UnSetVisCrsr(); rSh.EnterStdMode(); rSh.SetVisCrsr(aDocPt); - m_pApplyTempl->bUndo = true; + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); bCallBase = false; if ( m_pApplyTempl->aColl.pCharFmt ) aStyleName = m_pApplyTempl->aColl.pCharFmt->GetName(); @@ -4822,7 +4825,8 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) if(PTR_CAST(SwFlyFrmFmt, pFmt)) { rSh.SetFrmFmt( m_pApplyTempl->aColl.pFrmFmt, false, &aDocPt ); - m_pApplyTempl->bUndo = true; + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); bCallBase = false; if( m_pApplyTempl->aColl.pFrmFmt ) aStyleName = m_pApplyTempl->aColl.pFrmFmt->GetName(); @@ -4834,6 +4838,8 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) rSh.ChgCurPageDesc( *m_pApplyTempl->aColl.pPageDesc ); if ( m_pApplyTempl->aColl.pPageDesc ) aStyleName = m_pApplyTempl->aColl.pPageDesc->GetName(); + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); bCallBase = false; break; case SFX_STYLE_FAMILY_PSEUDO: @@ -4843,7 +4849,8 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) false, m_pApplyTempl->aColl.pNumRule->GetDefaultListId() ); bCallBase = false; - m_pApplyTempl->bUndo = true; + m_pApplyTempl->nUndo = + std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()); if( m_pApplyTempl->aColl.pNumRule ) aStyleName = m_pApplyTempl->aColl.pNumRule->GetName(); } @@ -4892,14 +4899,16 @@ void SwEditWin::SetApplyTemplate(const SwApplyTemplate &rTempl) if(rTempl.m_pFormatClipboard) { m_pApplyTempl = new SwApplyTemplate( rTempl ); + m_pApplyTempl->nUndo = rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount(); SetPointer( POINTER_FILL );//@todo #i20119# maybe better a new brush pointer here in future - rSh.NoEdit( false ); - bIdle = rSh.GetViewOptions()->IsIdle(); + rSh.NoEdit( false ); + bIdle = rSh.GetViewOptions()->IsIdle(); ((SwViewOption *)rSh.GetViewOptions())->SetIdle( false ); } else if(rTempl.nColor) { m_pApplyTempl = new SwApplyTemplate( rTempl ); + m_pApplyTempl->nUndo = rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount(); SetPointer( POINTER_FILL ); rSh.NoEdit( false ); bIdle = rSh.GetViewOptions()->IsIdle(); @@ -4908,6 +4917,7 @@ void SwEditWin::SetApplyTemplate(const SwApplyTemplate &rTempl) else if( rTempl.eType ) { m_pApplyTempl = new SwApplyTemplate( rTempl ); + m_pApplyTempl->nUndo = rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount(); SetPointer( POINTER_FILL ); rSh.NoEdit( false ); bIdle = rSh.GetViewOptions()->IsIdle(); @@ -5214,8 +5224,11 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) else if ( !m_rView.ExecSpellPopup( aDocPos ) ) SfxDispatcher::ExecutePopup( 0, this, &aPixPos); } - else if (m_pApplyTempl->bUndo) + else if (m_pApplyTempl->nUndo < rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount()) + { + // Undo until we reach the point when we entered this context. rSh.Do(SwWrtShell::UNDO); + } bCallBase = false; } } diff --git a/sw/source/uibase/inc/view.hxx b/sw/source/uibase/inc/view.hxx index e624560e071f..1399b95dbdfd 100644 --- a/sw/source/uibase/inc/view.hxx +++ b/sw/source/uibase/inc/view.hxx @@ -130,13 +130,13 @@ struct SwApplyTemplate int eType; sal_uInt16 nColor; SwFormatClipboard* m_pFormatClipboard; - bool bUndo; + size_t nUndo; //< The initial undo stack depth. SwApplyTemplate() : eType(0), nColor(0), m_pFormatClipboard(0), - bUndo(false) + nUndo(0) { aColl.pTxtColl = 0; } -- cgit v1.2.3