sw_redlinehide: try harder to prevent SetRedlineFlags from messing things up

Rearrange the code added in 15f1555da8adfa81ea1d4b0d8b694164fddbb2ae
to set all layouts to non-hidden before moving redlines in the model.

tdf52550-1.doc contains lots of consecutive delete redlines that
when exported to ODF trigger asserts about wrong start nodes in
CheckParaRedlineMerge().

Change-Id: I89c3d4fefd26691a9632807b9899138eee895fff
Reviewed-on: https://gerrit.libreoffice.org/65965
Tested-by: Jenkins
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 326b151..5eddd00 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -839,6 +839,25 @@ void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode )
            CheckAnchoredFlyConsistency(m_rDoc);
            CHECK_REDLINE( *this )

            std::set<SwRootFrame *> hiddenLayouts;
            if (eShowMode == (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete))
            {
                // sw_redlinehide: the problem here is that MoveFromSection
                // creates the frames wrongly (non-merged), because its own
                // SwRangeRedline has wrong positions until after the nodes
                // are all moved, so fix things up by force by re-creating
                // all merged frames from scratch.
                std::set<SwRootFrame *> const layouts(m_rDoc.GetAllLayouts());
                for (SwRootFrame *const pLayout : layouts)
                {
                    if (pLayout->IsHideRedlines())
                    {
                        pLayout->SetHideRedlines(false);
                        hiddenLayouts.insert(pLayout);
                    }
                }
            }

            for (sal_uInt16 nLoop = 1; nLoop <= 2; ++nLoop)
                for (size_t i = 0; i < mpRedlineTable->size(); ++i)
                {
@@ -857,24 +876,13 @@ void DocumentRedlineManager::SetRedlineFlags( RedlineFlags eMode )

            CheckAnchoredFlyConsistency(m_rDoc);
            CHECK_REDLINE( *this )
            m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
            if (eShowMode == (RedlineFlags::ShowInsert | RedlineFlags::ShowDelete))

            for (SwRootFrame *const pLayout : hiddenLayouts)
            {
                // sw_redlinehide: the problem here is that MoveFromSection
                // creates the frames wrongly (non-merged), because its own
                // SwRangeRedline has wrong positions until after the nodes
                // are all moved, so fix things up by force by re-creating
                // all merged frames from scratch.
                std::set<SwRootFrame *> const layouts(m_rDoc.GetAllLayouts());
                for (SwRootFrame *const pLayout : layouts)
                {
                    if (pLayout->IsHideRedlines())
                    {
                        pLayout->SetHideRedlines(false);
                        pLayout->SetHideRedlines(true);
                    }
                }
                pLayout->SetHideRedlines(true);
            }

            m_rDoc.SetInXMLImport( bSaveInXMLImportFlag );
        }
        meRedlineFlags = eMode;
        m_rDoc.getIDocumentState().SetModified();