summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2019-08-09 15:21:52 +0300
committerXisco Faulí <xiscofauli@libreoffice.org>2019-08-15 10:08:04 +0200
commit32772af4acf40d9c5d6f50fa962e28bb3f838aae (patch)
treeb57f7800622cb8afe779cc945d9601f931ccbaec
parent4ceff7f5d65673e57de5878ad5b1ffc470df3483 (diff)
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.Stahl@cib.de> (cherry picked from commit 2e6b35cdcac629d98e7082fffffdc27e4fb6f70d) Reviewed-on: https://gerrit.libreoffice.org/77422
-rw-r--r--sw/source/uibase/app/docst.cxx45
1 files changed, 37 insertions, 8 deletions
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();
}
}