sw/source/uibase/app/docst.cxx | 45 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-)
New commits: commit 32772af4acf40d9c5d6f50fa962e28bb3f838aae Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Fri Aug 9 15:21:52 2019 +0300 Commit: Xisco Faulí <xiscofa...@libreoffice.org> CommitDate: Thu Aug 15 10:08:04 2019 +0200 sw undo/redo derived style storing during creation by example Same as c4d82fc21c5e155472f6a30244b3fce806ada85c done for tdf#118384, but this code is fixing same problem with SwDocShell::MakeByExample ("New Style from Selection"). Change-Id: I488018bbf5ecb02e9e57eb032b6f875f4fe08f98 Reviewed-on: https://gerrit.libreoffice.org/77199 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@cib.de> (cherry picked from commit 2e6b35cdcac629d98e7082fffffdc27e4fb6f70d) Reviewed-on: https://gerrit.libreoffice.org/77422 diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx index dbf79bc31180..9101d131a3f9 100644 --- a/sw/source/uibase/app/docst.cxx +++ b/sw/source/uibase/app/docst.cxx @@ -1221,8 +1221,16 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, else nMask |= SfxStyleSearchBits::UserDefined; - pStyle = static_cast<SwDocStyleSheet*>( &m_xBasePool->Make(rName, - nFamily, nMask ) ); + if (nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char || nFamily == SfxStyleFamily::Frame) + { + // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later + ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); + pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName, nFamily, nMask)); + } + else + { + pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName, nFamily, nMask)); + } } switch(nFamily) @@ -1235,7 +1243,8 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, pCurrWrtShell->StartAllAction(); pCurrWrtShell->FillByEx(pColl); // also apply template to remove hard set attributes - pColl->SetDerivedFrom(pCurrWrtShell->GetCurTextFormatColl()); + SwTextFormatColl * pDerivedFrom = pCurrWrtShell->GetCurTextFormatColl(); + pColl->SetDerivedFrom(pDerivedFrom); // set the mask at the Collection: sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff; @@ -1263,6 +1272,11 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, } pColl->SetPoolFormatId(nId); + if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) + { + GetDoc()->GetIDocumentUndoRedo().AppendUndo( + std::make_unique<SwUndoTextFormatCollCreate>(pColl, pDerivedFrom, GetDoc())); + } pCurrWrtShell->SetTextFormatColl(pColl); pCurrWrtShell->EndAllAction(); } @@ -1281,10 +1295,14 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat(); pFrame->SetDerivedFrom( pFFormat ); - pFrame->SetFormatAttr( aSet ); - // also apply template to remove hard set attributes - pCurrWrtShell->SetFrameFormat( pFrame ); + if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) + { + GetDoc()->GetIDocumentUndoRedo().AppendUndo( + std::make_unique<SwUndoFrameFormatCreate>(pFrame, pFFormat, GetDoc())); + } + // also apply template to remove hard set attributes + pCurrWrtShell->SetFrameFormat(pFrame); pCurrWrtShell->EndAllAction(); } } @@ -1296,9 +1314,20 @@ void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily, { pCurrWrtShell->StartAllAction(); pCurrWrtShell->FillByEx( pChar ); - pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFormat() ); + SwCharFormat * pDerivedFrom = pCurrWrtShell->GetCurCharFormat(); + pChar->SetDerivedFrom( pDerivedFrom ); SwFormatCharFormat aFormat( pChar ); - pCurrWrtShell->SetAttrItem( aFormat ); + + if (GetDoc()->GetIDocumentUndoRedo().DoesUndo()) + { + // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code + // So use default format as a derived from in such situations + GetDoc()->GetIDocumentUndoRedo().AppendUndo( + std::make_unique<SwUndoCharFormatCreate>( + pChar, pDerivedFrom ? pDerivedFrom : GetDoc()->GetDfltCharFormat(), + GetDoc())); + } + pCurrWrtShell->SetAttrItem(aFormat); pCurrWrtShell->EndAllAction(); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits