sw/source/uibase/inc/wrtsh.hxx    |    2 
 sw/source/uibase/wrtsh/wrtsh1.cxx |   95 ++++++++++++++++++--------------------
 2 files changed, 47 insertions(+), 50 deletions(-)

New commits:
commit be2cd4bcc4e55b9fe6e5fcd6276511d37f3f8e4c
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Thu Nov 3 02:53:34 2022 -0800
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Thu Nov 3 20:09:37 2022 +0100

    tdf#142446 Improve show outline content to level
    
    by reworking the MakeOutlineLevelsVisible function
    
    Change-Id: I0a102420475ed97e35b8f92315eaa4cca2958599
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142226
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <rayk...@gmail.com>

diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index ebc255d3b05e..61f4570a71ab 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -501,7 +501,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
     void InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq);
 
     bool IsOutlineContentVisible(const size_t nPos);
-    void MakeOutlineContentVisible(const size_t nPos, bool bMakeVisible = 
true);
+    void MakeOutlineContentVisible(const size_t nPos, bool bMakeVisible = 
true, bool bSetAttrOutlineVisibility = true);
     void MakeAllFoldedOutlineContentVisible(bool bMakeVisible = true);
     void InvalidateOutlineContentVisibility();
     bool GetAttrOutlineContentVisible(const size_t nPos);
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 9bf10af5ce2a..9ca81b72b4cd 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -2360,59 +2360,53 @@ bool SwWrtShell::IsOutlineContentVisible(const size_t 
nPos)
 
 void SwWrtShell::MakeOutlineLevelsVisible(const int nLevel)
 {
+    MakeAllOutlineContentTemporarilyVisible a(GetDoc());
+
     m_rView.SetMaxOutlineLevelShown(nLevel);
 
     bool bDocChanged = false;
 
-    const SwNodes& rNodes = GetNodes();
-    const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
+    const SwOutlineNodes& rOutlineNodes = GetNodes().GetOutLineNds();
 
-    StartAction();
+    // Make all missing frames.
     for (SwOutlineNodes::size_type nPos = 0; nPos < rOutlineNodes.size(); 
++nPos)
     {
         SwNode* pNode = rOutlineNodes[nPos];
-        auto nOutlineLevel = pNode->GetTextNode()->GetAttrOutlineLevel();
-        if ( nOutlineLevel > nLevel)
+        if (!pNode->GetTextNode()->getLayoutFrame(GetLayout()))
         {
-            // MakeOutlineContentVisible(nPos, false) sets the outline node 
outline content
-            // visible attribute false so it needs restored to true if it was 
true.
-            bool bOutlineContentVisible = false;
-            
pNode->GetTextNode()->GetAttrOutlineContentVisible(bOutlineContentVisible);
-            MakeOutlineContentVisible(nPos, false);
-            pNode->GetTextNode()->DelFrames(GetLayout());
-            if (bOutlineContentVisible)
-                pNode->GetTextNode()->SetAttrOutlineContentVisible(true);
+            SwNodeIndex aIdx(*pNode, +1);
+            // Make the outline paragraph frame
+            MakeFrames(GetDoc(), *pNode, aIdx.GetNode());
+            // Make the outline content visible but don't set the outline 
visible attribute and
+            // don't make outline content made visible not visible that have 
outline visible
+            // attribute false. Visibility will be taken care of when
+            // MakeAllOutlineContentTemporarilyVisible goes out of scope.
+            MakeOutlineContentVisible(nPos, true, false);
             bDocChanged = true;
         }
-        else
+    }
+    // Remove outline paragraph frame and outline content frames above given 
level.
+    for (SwOutlineNodes::size_type nPos = 0; nPos < rOutlineNodes.size(); 
++nPos)
+    {
+        SwNode* pNode = rOutlineNodes[nPos];
+        auto nOutlineLevel = pNode->GetTextNode()->GetAttrOutlineLevel();
+        if (nOutlineLevel > nLevel)
         {
-            if (!pNode->GetTextNode()->getLayoutFrame(GetLayout()))
-            {
-                SwNodeIndex aIdx(*pNode, +1);
-                {
-                    // MakeAllOutlineContentTemporarilyVisible in this scope! 
Don't place at the
-                    // start of the function. Placed there will restore 
content to what it was
-                    // was at that point when the function exits.
-                    MakeAllOutlineContentTemporarilyVisible a(GetDoc());
-                    MakeFrames(GetDoc(), *pNode, aIdx.GetNode());
-                }
-                bool bVisible = true;
-                if (GetViewOptions()->IsShowOutlineContentVisibilityButton())
-                    
pNode->GetTextNode()->GetAttrOutlineContentVisible(bVisible);
-                if (bVisible)
-                    MakeOutlineContentVisible(nPos, true);
-                bDocChanged = true;
-            }
+            // Remove the outline content but don't set the outline visible 
attribute. Visibility
+            // will be taken care of when 
MakeAllOutlineContentTemporarilyVisible goes out of scope.
+            MakeOutlineContentVisible(nPos, false, false);
+            // Remove the outline paragraph frame.
+            pNode->GetTextNode()->DelFrames(GetLayout());
+            bDocChanged = true;
         }
     }
-    EndAction();
 
     // Broadcast DocChanged if document layout has changed so the Navigator 
will be updated.
     if (bDocChanged)
         GetDoc()->GetDocShell()->Broadcast(SfxHint(SfxHintId::DocChanged));
 }
 
-void SwWrtShell::MakeOutlineContentVisible(const size_t nPos, bool 
bMakeVisible)
+void SwWrtShell::MakeOutlineContentVisible(const size_t nPos, bool 
bMakeVisible, bool bSetAttrOutlineVisibility)
 {
     const SwNodes& rNodes = GetNodes();
     const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
@@ -2499,31 +2493,34 @@ void SwWrtShell::MakeOutlineContentVisible(const size_t 
nPos, bool bMakeVisible)
         aIdx.Assign(*pSttNd, +1);
         MakeFrames(GetDoc(), aIdx.GetNode(), *pEndNd);
 
-        pSttNd->GetTextNode()->SetAttrOutlineContentVisible(true);
-
-        // make outline content made visible that have outline visible 
attribute false not visible
-        while (aIdx != *pEndNd)
+        if (bSetAttrOutlineVisibility)
         {
-            SwNode* pNd = &aIdx.GetNode();
-            if (pNd->IsTextNode() && pNd->GetTextNode()->IsOutline())
+            pSttNd->GetTextNode()->SetAttrOutlineContentVisible(true);
+
+            // make outline content made visible that have outline visible 
attribute false not visible
+            while (aIdx != *pEndNd)
             {
-                SwTextNode* pTextNd = pNd->GetTextNode();
-                bool bOutlineContentVisibleAttr = true;
-                
pTextNd->GetAttrOutlineContentVisible(bOutlineContentVisibleAttr);
-                if (!bOutlineContentVisibleAttr)
+                SwNode* pNd = &aIdx.GetNode();
+                if (pNd->IsTextNode() && pNd->GetTextNode()->IsOutline())
                 {
-                    SwOutlineNodes::size_type iPos;
-                    if (rOutlineNodes.Seek_Entry(pTextNd, &iPos))
+                    SwTextNode* pTextNd = pNd->GetTextNode();
+                    bool bOutlineContentVisibleAttr = true;
+                    
pTextNd->GetAttrOutlineContentVisible(bOutlineContentVisibleAttr);
+                    if (!bOutlineContentVisibleAttr)
                     {
-                        if (pTextNd->getLayoutFrame(nullptr))
-                            MakeOutlineContentVisible(iPos, false);
+                        SwOutlineNodes::size_type iPos;
+                        if (rOutlineNodes.Seek_Entry(pTextNd, &iPos))
+                        {
+                            if (pTextNd->getLayoutFrame(nullptr))
+                                MakeOutlineContentVisible(iPos, false);
+                        }
                     }
                 }
+                aIdx++;
             }
-            aIdx++;
         }
     }
-    else
+    else if (bSetAttrOutlineVisibility)
         pSttNd->GetTextNode()->SetAttrOutlineContentVisible(false);
 }
 

Reply via email to