summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-06-15 20:33:47 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-06-30 21:09:30 +0200
commit7a542a41f48c673478606cba307662780e5137e0 (patch)
tree77ffd81e554efcab26ecc8a29a1f851d4c66f8fa
parentdcd3375233714c52c693bbf3a32d380f75d08fac (diff)
tdf#132822 close open undo group before clearing undo stack
when changing paragraph. previous para undo info needs to be discarded, but that cannot be done properly if there is an open undo group. So pass the optional undo group guard down to GetNextSentence_Impl which can close it before it needs to set the new paragraph. Change-Id: I595c3598b15b6b1fdace045c3879617ecfea3faa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96398 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--cui/source/dialogs/SpellDialog.cxx58
-rw-r--r--cui/source/inc/SpellDialog.hxx5
2 files changed, 42 insertions, 21 deletions
diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx
index 85dc7027ceed..26c3b3bc4098 100644
--- a/cui/source/dialogs/SpellDialog.cxx
+++ b/cui/source/dialogs/SpellDialog.cxx
@@ -343,14 +343,14 @@ void SpellDialog::UpdateBoxes_Impl(bool bCallFromSelectHdl)
m_xDialog->resize_to_request();
}
-void SpellDialog::SpellContinue_Impl(bool bUseSavedSentence, bool bIgnoreCurrentError )
+void SpellDialog::SpellContinue_Impl(std::unique_ptr<UndoChangeGroupGuard>* pGuard, bool bUseSavedSentence, bool bIgnoreCurrentError)
{
//initially or after the last error of a sentence MarkNextError will fail
//then GetNextSentence() has to be called followed again by MarkNextError()
//MarkNextError is not initially called if the UndoEdit mode is active
bool bNextSentence = false;
if((!m_xSentenceED->IsUndoEditMode() && m_xSentenceED->MarkNextError( bIgnoreCurrentError, xSpell )) ||
- ( bNextSentence = GetNextSentence_Impl(bUseSavedSentence, m_xSentenceED->IsUndoEditMode()) && m_xSentenceED->MarkNextError( false, xSpell )))
+ ( bNextSentence = GetNextSentence_Impl(pGuard, bUseSavedSentence, m_xSentenceED->IsUndoEditMode()) && m_xSentenceED->MarkNextError( false, xSpell )))
{
SpellErrorDescription aSpellErrorDescription;
bool bSpellErrorDescription = m_xSentenceED->GetAlternatives(aSpellErrorDescription);
@@ -388,7 +388,7 @@ IMPL_LINK_NOARG( SpellDialog, InitHdl, void*, void)
m_xDialog->freeze();
//show or hide AutoCorrect depending on the modules abilities
m_xAutoCorrPB->set_visible(rParent.HasAutoCorrection());
- SpellContinue_Impl();
+ SpellContinue_Impl(nullptr);
m_xSentenceED->ResetUndo();
m_xUndoPB->set_sensitive(false);
@@ -505,6 +505,27 @@ IMPL_LINK_NOARG(SpellDialog, DoubleClickChangeHdl, weld::TreeView&, bool)
return true;
}
+/* tdf#132822 start an undo group in ctor and close it in the dtor. This can
+ then be passed to SpellContinue_Impl which can delete it in advance of its
+ natural scope to force closing the undo group if SpellContinue_Impl needs to
+ fetch a new paragraph and discard all undo information which can only be
+ done properly if there are no open undo groups */
+class UndoChangeGroupGuard
+{
+private:
+ SentenceEditWindow_Impl& m_rSentenceED;
+public:
+ UndoChangeGroupGuard(SentenceEditWindow_Impl& rSentenceED)
+ : m_rSentenceED(rSentenceED)
+ {
+ m_rSentenceED.UndoActionStart(SPELLUNDO_CHANGE_GROUP);
+ }
+ ~UndoChangeGroupGuard()
+ {
+ m_rSentenceED.UndoActionEnd();
+ }
+};
+
IMPL_LINK_NOARG(SpellDialog, ChangeHdl, weld::Button&, void)
{
if (m_xSentenceED->IsUndoEditMode())
@@ -513,11 +534,10 @@ IMPL_LINK_NOARG(SpellDialog, ChangeHdl, weld::Button&, void)
}
else
{
- m_xSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
+ auto xGuard(std::make_unique<UndoChangeGroupGuard>(*m_xSentenceED));
OUString aString = getReplacementString();
m_xSentenceED->ChangeMarkedWord(aString, GetSelectedLang_Impl());
- SpellContinue_Impl();
- m_xSentenceED->UndoActionEnd();
+ SpellContinue_Impl(&xGuard);
}
if(!m_xChangePB->get_sensitive())
m_xIgnorePB->grab_focus();
@@ -525,7 +545,7 @@ IMPL_LINK_NOARG(SpellDialog, ChangeHdl, weld::Button&, void)
IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl, weld::Button&, void)
{
- m_xSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
+ auto xGuard(std::make_unique<UndoChangeGroupGuard>(*m_xSentenceED));
OUString aString = getReplacementString();
LanguageType eLang = GetSelectedLang_Impl();
@@ -547,13 +567,12 @@ IMPL_LINK_NOARG(SpellDialog, ChangeAllHdl, weld::Button&, void)
}
m_xSentenceED->ChangeMarkedWord(aString, eLang);
- SpellContinue_Impl();
- m_xSentenceED->UndoActionEnd();
+ SpellContinue_Impl(&xGuard);
}
IMPL_LINK( SpellDialog, IgnoreAllHdl, weld::Button&, rButton, void )
{
- m_xSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
+ auto xGuard(std::make_unique<UndoChangeGroupGuard>(*m_xSentenceED));
// add word to IgnoreAll list
Reference< XDictionary > aXDictionary = LinguMgr::GetIgnoreAllList();
//in case the error has been changed manually it has to be restored
@@ -593,8 +612,7 @@ IMPL_LINK( SpellDialog, IgnoreAllHdl, weld::Button&, rButton, void )
}
}
- SpellContinue_Impl();
- m_xSentenceED->UndoActionEnd();
+ SpellContinue_Impl(&xGuard);
}
IMPL_LINK_NOARG(SpellDialog, UndoHdl, weld::Button&, void)
@@ -643,7 +661,7 @@ IMPL_LINK( SpellDialog, DialogUndoHdl, SpellUndoAction_Impl&, rAction, void )
case SPELLUNDO_UNDO_EDIT_MODE :
{
//refill the dialog with the currently spelled sentence - throw away all changes
- SpellContinue_Impl(true);
+ SpellContinue_Impl(nullptr, true);
}
break;
case SPELLUNDO_ADD_IGNORE_RULE:
@@ -660,7 +678,7 @@ void SpellDialog::Impl_Restore(bool bUseSavedSentence)
m_xSentenceED->SetText(OUString());
m_xSentenceED->ResetModified();
//Resolves: fdo#39348 refill the dialog with the currently spelled sentence
- SpellContinue_Impl(bUseSavedSentence);
+ SpellContinue_Impl(nullptr, bUseSavedSentence);
m_xIgnorePB->set_label(m_sIgnoreOnceST);
}
@@ -677,7 +695,7 @@ IMPL_LINK_NOARG(SpellDialog, IgnoreHdl, weld::Button&, void)
m_xSentenceED->RestoreCurrentError();
// the word is being ignored
- SpellContinue_Impl( false, true );
+ SpellContinue_Impl(nullptr, false, true);
}
}
@@ -816,7 +834,7 @@ IMPL_LINK(SpellDialog, AddToDictSelectHdl, const OString&, rIdent, void)
void SpellDialog::AddToDictionaryExecute(const OString& rItemId)
{
- m_xSentenceED->UndoActionStart( SPELLUNDO_CHANGE_GROUP );
+ auto xGuard(std::make_unique<UndoChangeGroupGuard>(*m_xSentenceED));
//GetErrorText() returns the current error even if the text is already
//manually changed
@@ -857,8 +875,7 @@ void SpellDialog::AddToDictionaryExecute(const OString& rItemId)
}
// go on
- SpellContinue_Impl();
- m_xSentenceED->UndoActionEnd();
+ SpellContinue_Impl(&xGuard);
}
IMPL_LINK_NOARG(SpellDialog, ModifyHdl, LinkParamNone*, void)
@@ -957,7 +974,7 @@ void SpellDialog::InvalidateDialog()
SfxModelessDialogController::Deactivate();
}
-bool SpellDialog::GetNextSentence_Impl(bool bUseSavedSentence, bool bRecheck)
+bool SpellDialog::GetNextSentence_Impl(std::unique_ptr<UndoChangeGroupGuard>* pGuard, bool bUseSavedSentence, bool bRecheck)
{
bool bRet = false;
if(!bUseSavedSentence)
@@ -994,6 +1011,9 @@ bool SpellDialog::GetNextSentence_Impl(bool bUseSavedSentence, bool bRecheck)
if(!elem.bIsHidden)
sText.append(elem.sText);
}
+ // tdf#132822 fire undo-stack UndoActionEnd to close undo stack because we're about to throw away the paragraph entirely
+ if (pGuard)
+ pGuard->reset();
m_xSentenceED->SetText(sText.makeStringAndClear());
sal_Int32 nStartPosition = 0;
sal_Int32 nEndPosition = 0;
diff --git a/cui/source/inc/SpellDialog.hxx b/cui/source/inc/SpellDialog.hxx
index 61adf31f8afa..0ad462789477 100644
--- a/cui/source/inc/SpellDialog.hxx
+++ b/cui/source/inc/SpellDialog.hxx
@@ -33,6 +33,7 @@
#include <set>
namespace svx{ class SpellUndoAction_Impl;}
+class UndoChangeGroupGuard;
// forward ---------------------------------------------------------------
@@ -192,7 +193,7 @@ private:
int InitUserDicts();
void UpdateBoxes_Impl(bool bCallFromSelectHdl = false);
void Init_Impl();
- void SpellContinue_Impl(bool UseSavedSentence = false, bool bIgnoreCurrentError = false );
+ void SpellContinue_Impl(std::unique_ptr<UndoChangeGroupGuard>* pGuard = nullptr, bool UseSavedSentence = false, bool bIgnoreCurrentError = false );
void LockFocusChanges( bool bLock ) {bFocusLocked = bLock;}
void ToplevelFocusChanged();
void Impl_Restore(bool bUseSavedSentence);
@@ -201,7 +202,7 @@ private:
/** Retrieves the next sentence.
*/
- bool GetNextSentence_Impl(bool bUseSavedSentence, bool bRechek /*for rechecking the current sentence*/);
+ bool GetNextSentence_Impl(std::unique_ptr<UndoChangeGroupGuard>* pGuard, bool bUseSavedSentence, bool bRecheck /*for rechecking the current sentence*/);
/** Corrects all errors that have been selected to be changed always
*/
static bool ApplyChangeAllList_Impl(SpellPortions& rSentence, bool& bHasReplaced);