sw/source/uibase/inc/conttree.hxx  |    2 +
 sw/source/uibase/utlui/content.cxx |   52 ++++++++++++++++++++++---------------
 2 files changed, 34 insertions(+), 20 deletions(-)

New commits:
commit 37b4784ca722aa0496cda95191869c2086223e24
Author:     Jim Raykowski <rayk...@gmail..com>
AuthorDate: Wed Feb 26 20:30:01 2020 -0900
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Mar 3 08:35:47 2020 +0100

    Keep selections selected after outline moves
    
    and don't update content view until after move is complete.
    
    In this patch a flag is used to not allow document changed notifications
    to rebuild the content tree while doing outline moves. This flag also
    prevents the content view from being update until after outline move is
    complete. A condition is added in SwContentTree::Paint which prevents a
    focus rectangle flash at the top of the list from SvTreeListBox::Paint
    when the tree is empty.
    
    Change-Id: I5691a532a6bb916c3152900eda3bc9333c24871e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89608
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/uibase/inc/conttree.hxx 
b/sw/source/uibase/inc/conttree.hxx
index c134e10551b3..c42b081e7aa0 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -122,6 +122,8 @@ class SwContentTree final
     // outline root mode drag & drop
     std::vector< SvTreeListEntry* > m_aDndOutlinesSelected;
 
+    bool m_bIsInPromoteDemote = false;
+
     /**
      * Before any data will be deleted, the last active entry has to be found.
      * After this the UserData will be deleted
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index dcfa88e668d7..e220797c38fe 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1773,8 +1773,8 @@ void SwContentTree::Display( bool bActive )
             nEntryRelPos = GetModel()->GetAbsPos(pOldSelEntry) - 
GetModel()->GetAbsPos(pParentEntry);
         }
     }
-    Clear();
     SetUpdateMode( false );
+    SvTreeListBox::Clear();
     if (!bActive)
         m_eState = State::HIDDEN;
     else if (State::HIDDEN == m_eState)
@@ -1912,7 +1912,6 @@ void SwContentTree::Display( bool bActive )
                 SetCurEntry(pParent);
         }
     }
-    SetUpdateMode( true );
     ScrollBar* pVScroll = GetVScroll();
     if(GetEntryCount() == nOldEntryCount &&
         nOldScrollPos && pVScroll && pVScroll->IsVisible()
@@ -1921,6 +1920,8 @@ void SwContentTree::Display( bool bActive )
         sal_Int32 nDelta = pVScroll->GetThumbPos() - nOldScrollPos;
         ScrollOutputArea( static_cast<short>(nDelta) );
     }
+    if (!m_bIsInPromoteDemote)
+        SetUpdateMode( true );
 }
 
 void SwContentTree::Clear()
@@ -2398,7 +2399,6 @@ void SwContentTree::SetConstantShell(SwWrtShell* pSh)
     Display(true);
 }
 
-
 void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint const& rHint)
 {
     SfxViewEventHint const*const pVEHint(dynamic_cast<SfxViewEventHint 
const*>(&rHint));
@@ -2416,7 +2416,11 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint 
const& rHint)
     switch (rHint.GetId())
     {
         case SfxHintId::DocChanged:
-            m_bViewHasChanged = true;
+            if (!m_bIsInPromoteDemote)
+            {
+                m_bViewHasChanged = true;
+                TimerUpdate(&m_aUpdTimer);
+            }
             break;
         case SfxHintId::ModeChanged:
             if (SwWrtShell* pShell = GetWrtShell())
@@ -2434,8 +2438,6 @@ void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint 
const& rHint)
     }
 }
 
-
-
 void SwContentTree::ExecCommand(const OUString& rCmd, bool 
bOutlineWithChildren)
 {
     const bool bUp = rCmd == "up";
@@ -2451,6 +2453,8 @@ void SwContentTree::ExecCommand(const OUString& rCmd, 
bool bOutlineWithChildren)
         return;
     }
 
+    m_bIsInPromoteDemote = true;
+
     SwWrtShell *const pShell = GetWrtShell();
     sal_Int8 nActOutlineLevel = m_nOutlineLevel;
     SwOutlineNodes::size_type nActPos = 
pShell->GetOutlinePos(nActOutlineLevel);
@@ -2684,25 +2688,27 @@ void SwContentTree::ExecCommand(const OUString& rCmd, 
bool bOutlineWithChildren)
         pShell->EndAllAction();
         if (m_aActiveContentArr[ContentTypeId::OUTLINE])
             m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
+
+        // clear all selections to prevent the Display function from trying to 
reselect selected entries
+        SelectAll(false);
         Display(true);
-        if (!m_bIsRoot)
-        {
-            const SwOutlineNodes::size_type nCurrPos = 
pShell->GetOutlinePos(MAXLEVEL);
-            SvTreeListEntry* pFirst = First();
 
-            while (nullptr != (pFirst = Next(pFirst)) && lcl_IsContent(pFirst))
+        // reselect entries
+        const SwOutlineNodes::size_type nCurrPos = 
pShell->GetOutlinePos(MAXLEVEL);
+        SvTreeListEntry* pListEntry = First();
+        while (nullptr != (pListEntry = Next(pListEntry)) && 
lcl_IsContent(pListEntry))
+        {
+            
assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pListEntry->GetUserData())));
+            if 
(static_cast<SwOutlineContent*>(pListEntry->GetUserData())->GetOutlinePos() == 
nCurrPos)
             {
-                
assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pFirst->GetUserData())));
-                if 
(static_cast<SwOutlineContent*>(pFirst->GetUserData())->GetOutlinePos() == 
nCurrPos)
-                {
-                    Select(pFirst);
-                    MakeVisible(pFirst);
-                }
+                if (!IsExpanded(pListEntry->GetParent()))
+                    Expand(pListEntry->GetParent());
+                SetCurEntry(pListEntry); // unselect all entries, make entry 
visible, set focus, and select
+                break;
             }
         }
-        else
+        if (m_bIsRoot)
         {
-            // Reselect entries
             const SwOutlineNodes& rOutLineNds = 
pShell->GetNodes().GetOutLineNds();
             for (SwTextNode* pNode : selectedOutlineNodes)
             {
@@ -2718,9 +2724,11 @@ void SwContentTree::ExecCommand(const OUString& rCmd, 
bool bOutlineWithChildren)
                         Expand(pEntry->GetParent());
                 }
             }
-            SvTreeListBox::Invalidate();
         }
+        // SetUpdateMode is set false in the Display function
+        SetUpdateMode(true);
     }
+    m_bIsInPromoteDemote = false;
 }
 
 void SwContentTree::ShowTree()
@@ -2731,6 +2739,10 @@ void SwContentTree::ShowTree()
 void SwContentTree::Paint( vcl::RenderContext& rRenderContext,
                            const tools::Rectangle& rRect )
 {
+    // prevent focus rect from flashing when tree is cleared
+    // SvTreeListBox::Paint shows focus rectangle when tree is empty
+    if (!GetEntryCount())
+        return;
     // Start the update timer on the first paint; avoids
     // flicker on the first reveal.
     m_aUpdTimer.Start();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to