sw/source/uibase/inc/conttree.hxx  |    3 +
 sw/source/uibase/utlui/content.cxx |   68 ++++++++++++++++++++-----------------
 2 files changed, 39 insertions(+), 32 deletions(-)

New commits:
commit 5c5f36aa73b11356a3bff0a9cc8b5fe8d1a776b9
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Thu Oct 21 09:09:51 2021 -0800
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Fri Nov 5 00:04:55 2021 +0100

    SwNavigator: Improve detection of when the content tree needs refreshed
    
    Makes the check that determines if the content tree needs refreshed be
    done only when the content tree is visible AND (the document has been
    modified since previous check OR an action has been made within the
    content tree that requires the tree to be refreshed) AND there is no
    writer shell action pending AND the content tree is not in a DnD.
    
    Change-Id: Ie67472d44573df6afafb08b7b3229a4e07fc9db5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124036
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <rayk...@gmail.com>

diff --git a/sw/source/uibase/inc/conttree.hxx 
b/sw/source/uibase/inc/conttree.hxx
index c272e591eba0..0c7eb59dea43 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -139,7 +139,8 @@ class SwContentTree final : public SfxListener
     // outline root mode drag & drop
     std::vector<std::unique_ptr<weld::TreeIter>> m_aDndOutlinesSelected;
 
-    bool m_bIgnoreViewChange = false;
+    bool m_bDocHasChanged = true;
+    bool m_bIgnoreDocChange = false; // used to prevent tracking update
 
     /**
      * Before any data will be deleted, the last active entry has to be found.
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 8d5df012b844..56025c46f5f5 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -2577,7 +2577,7 @@ void SwContentTree::Display( bool bActive )
         }
     }
 
-    if (!m_bIgnoreViewChange && GetEntryCount() == nOldEntryCount)
+    if (!m_bIgnoreDocChange && GetEntryCount() == nOldEntryCount)
     {
         m_xTreeView->vadjustment_set_value(nOldScrollPos);
     }
@@ -3110,9 +3110,9 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint 
const& rHint)
             break;
         }
         case SfxHintId::DocChanged:
-            if (!m_bIgnoreViewChange)
+            if (!m_bIgnoreDocChange)
             {
-                m_bViewHasChanged = true;
+                m_bDocHasChanged = true;
                 TimerUpdate(&m_aUpdTimer);
             }
             break;
@@ -3157,7 +3157,7 @@ void SwContentTree::ExecCommand(std::string_view rCmd, 
bool bOutlineWithChildren
         return;
     }
 
-    m_bIgnoreViewChange = true;
+    m_bIgnoreDocChange = true;
 
     SwWrtShell *const pShell = GetWrtShell();
     sal_Int8 nActOutlineLevel = m_nOutlineLevel;
@@ -3446,7 +3446,7 @@ void SwContentTree::ExecCommand(std::string_view rCmd, 
bool bOutlineWithChildren
             }
         }
     }
-    m_bIgnoreViewChange = false;
+    m_bIgnoreDocChange = false;
 }
 
 void SwContentTree::ShowTree()
@@ -3611,37 +3611,43 @@ static void lcl_SelectDrawObjectByName(weld::TreeView& 
rContentTree, std::u16str
 /** No idle with focus or while dragging */
 IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
 {
+    // No need to update if content tree is not visible
+    if (!m_xTreeView->is_visible())
+        return;
+
     // No update while focus is not in document.
     // No update while drag and drop.
     // Query view because the Navigator is cleared too late.
     SwView* pView = GetParentWindow()->GetCreateView();
     if(pView && pView->GetWrtShellPtr() && pView->GetWrtShellPtr()->GetWin() &&
-        (pView->GetWrtShellPtr()->GetWin()->HasFocus() || m_bViewHasChanged) &&
+        (pView->GetWrtShellPtr()->GetWin()->HasFocus() || m_bDocHasChanged || 
m_bViewHasChanged) &&
         !IsInDrag() && !pView->GetWrtShellPtr()->ActionPend())
     {
-        m_bViewHasChanged = false;
-        m_bIsIdleClear = false;
-        SwWrtShell* pActShell = pView->GetWrtShellPtr();
-        if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell))
-        {
-            SetActiveShell(pActShell);
-            GetParentWindow()->UpdateListBox();
-        }
-
-        if (State::ACTIVE == m_eState && pActShell != GetWrtShell())
+        if (m_bDocHasChanged || m_bViewHasChanged)
         {
-            SetActiveShell(pActShell);
-        }
-        else if ((State::ACTIVE == m_eState || (State::CONSTANT == m_eState && 
pActShell == GetWrtShell())) &&
-                    HasContentChanged())
-        {
-            FindActiveTypeAndRemoveUserData();
-            Display(true);
+            SwWrtShell* pActShell = pView->GetWrtShellPtr();
+            if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell))
+            {
+                SetActiveShell(pActShell);
+                GetParentWindow()->UpdateListBox();
+            }
+            if (State::ACTIVE == m_eState && pActShell != GetWrtShell())
+            {
+                SetActiveShell(pActShell);
+            }
+            else if ((State::ACTIVE == m_eState || (State::CONSTANT == 
m_eState && pActShell == GetWrtShell())) &&
+                        HasContentChanged())
+            {
+                FindActiveTypeAndRemoveUserData();
+                Display(true);
+            }
         }
-
         UpdateTracking();
+        m_bIsIdleClear = false;
+        m_bDocHasChanged = false;
+        m_bViewHasChanged = false;
     }
-    else if (!pView && State::ACTIVE == m_eState && !m_bIsIdleClear)
+    else if (!pView && State::ACTIVE == m_eState && !m_bIsIdleClear) // this 
block seems never to be entered
     {
         if(m_pActiveShell)
         {
@@ -3657,10 +3663,10 @@ void SwContentTree::UpdateTracking()
     if (State::HIDDEN == m_eState || !m_pActiveShell)
         return;
 
-    // m_bIgnoreViewChange is set on delete
-    if (m_bIgnoreViewChange)
+    // m_bIgnoreDocChange is set on delete and outline visibility toggle
+    if (m_bIgnoreDocChange)
     {
-        m_bIgnoreViewChange = false;
+        m_bIgnoreDocChange = false;
         return;
     }
 
@@ -4438,7 +4444,7 @@ void SwContentTree::ExecuteContextMenuAction(const 
OString& rSelectedPopupEntry)
         case SHOW_OUTLINE_CONTENT_VISIBILITY:
         {
             m_pActiveShell->EnterStdMode();
-            m_bIgnoreViewChange = true;
+            m_bIgnoreDocChange = true;
             SwOutlineContent* pCntFirst = 
reinterpret_cast<SwOutlineContent*>(m_xTreeView->get_id(*xFirst).toInt64());
 
             // toggle the outline node outline content visible attribute
@@ -4475,7 +4481,7 @@ void SwContentTree::ExecuteContextMenuAction(const 
OString& rSelectedPopupEntry)
             else
                 m_pActiveShell->GotoOutline(pCntFirst->GetOutlinePos());
             grab_focus();
-            m_bIgnoreViewChange = false;
+            m_bIgnoreDocChange = false;
         }
         break;
         case 11:
@@ -4851,7 +4857,7 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
     sal_uInt16 nSlot = 0;
 
     if(EditEntryMode::DELETE == nMode)
-        m_bIgnoreViewChange = true;
+        m_bIgnoreDocChange = true;
 
     uno::Reference< container::XNameAccess >  xNameAccess, xSecond, xThird;
     switch(nType)

Reply via email to