sw/inc/view.hxx                    |    1 +
 sw/source/uibase/inc/conttree.hxx  |    2 ++
 sw/source/uibase/utlui/content.cxx |   21 +++++++++++++++++++++
 sw/source/uibase/utlui/navipi.cxx  |    9 ++++-----
 vcl/jsdialog/executor.cxx          |   10 ++++++++++
 vcl/source/treelist/svtabbx.cxx    |    4 ++++
 6 files changed, 42 insertions(+), 5 deletions(-)

New commits:
commit b95750af717e0693a13c3ef35277779e1394e0ae
Author:     Attila Szűcs <[email protected]>
AuthorDate: Thu Jun 29 18:32:27 2023 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Sat Jul 1 16:51:44 2023 +0200

    LOK: Navigator: fix expand problems
    
    Save/load content types' expanded status to view, and make sure it
    is synchronized with client.
    Treeviews now receive/send collapse event/status from/to client.
    I've rewritten the way how headings are opened by default
    (because synch of collapsed status broke that, as sub-headings
    were not expanded at core side).
    
    Change-Id: I80f5b4d99fe5224391a92c4609f94ddbcf37b8ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153771
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index b556c2c53f39..9e31e337206b 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -350,6 +350,7 @@ class SW_DLLPUBLIC SwView: public SfxViewShell
 
 public: // #i123922# Needs to be called from a 2nd place now as a helper method
     SAL_DLLPRIVATE bool          InsertGraphicDlg( SfxRequest& );
+    sal_Int32 m_nNaviExpandedStatus = -1;
 
 protected:
 
diff --git a/sw/source/uibase/inc/conttree.hxx 
b/sw/source/uibase/inc/conttree.hxx
index e2cf31028171..c397a15bb20b 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -266,6 +266,8 @@ public:
     // return true if it has any children
     bool RequestingChildren(const weld::TreeIter& rParent);
 
+    void ExpandAllHeadings();
+
     virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override;
 
     sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt);
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 5367627cad03..c837124b723c 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1130,6 +1130,12 @@ 
SwContentTree::SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNaviga
         OUString sDocTitle = pView->GetDocShell()->GetTitle();
         if (lcl_DocOutLineExpandStateMap.find(sDocTitle) != 
lcl_DocOutLineExpandStateMap.end())
             mOutLineNodeMap = lcl_DocOutLineExpandStateMap[sDocTitle];
+        if (comphelper::LibreOfficeKit::isActive()) {
+            if (pView->m_nNaviExpandedStatus < 0)
+                m_nActiveBlock = 1;
+            else
+                m_nActiveBlock = pView->m_nNaviExpandedStatus;
+        }
     }
 
     m_aUpdTimer.SetInvokeHandler(LINK(this, SwContentTree, TimerUpdate));
@@ -1144,6 +1150,8 @@ SwContentTree::~SwContentTree()
     {
         OUString sDocTitle = pView->GetDocShell()->GetTitle();
         lcl_DocOutLineExpandStateMap[sDocTitle] = mOutLineNodeMap;
+        if (comphelper::LibreOfficeKit::isActive())
+            pView->m_nNaviExpandedStatus = m_nActiveBlock;
     }
     clear(); // If applicable erase content types previously.
     m_aUpdTimer.Stop();
@@ -2177,6 +2185,19 @@ bool SwContentTree::RequestingChildren(const 
weld::TreeIter& rParent)
     return bChild;
 }
 
+void SwContentTree::ExpandAllHeadings()
+{
+    if (HasHeadings())
+    {
+        std::unique_ptr<weld::TreeIter> xEntry = GetEntryAtAbsPos(0);
+        if (xEntry)
+        {
+            if (!IsAllExpanded(*m_xTreeView, *xEntry))
+                ExpandOrCollapseAll(*m_xTreeView, *xEntry);
+        }
+    }
+}
+
 SdrObject* SwContentTree::GetDrawingObjectsByContent(const SwContent *pCnt)
 {
     SdrObject *pRetObj = nullptr;
diff --git a/sw/source/uibase/utlui/navipi.cxx 
b/sw/source/uibase/utlui/navipi.cxx
index fb3f461f8f64..0f6d2ac78923 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -694,12 +694,11 @@ SwNavigationPI::SwNavigationPI(weld::Widget* pParent,
         m_xGlobalTree->HideTree();
 
         //Open Headings by default
-        if (m_xContentTree->HasHeadings())
+        SwView *pView = GetCreateView();
+        if (pView->m_nNaviExpandedStatus < 0)
         {
-            auto& pTreeView = m_xContentTree->get_widget();
-            std::unique_ptr<weld::TreeIter> itEntry(pTreeView.make_iterator());
-            pTreeView.get_iter_first(*itEntry);
-            pTreeView.expand_row(*itEntry);
+            pView->m_nNaviExpandedStatus = 1;
+            m_xContentTree->ExpandAllHeadings();
         }
     }
 }
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index 1accb3bc1de0..750b10c0b606 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -474,6 +474,16 @@ bool ExecuteAction(const std::string& nWindowId, const 
OString& rWidget, StringM
                     pTreeView->expand_row(*itEntry);
                     return true;
                 }
+                else if (sAction == "collapse")
+                {
+                    sal_Int32 nAbsPos = o3tl::toInt32(rData["data"]);
+                    std::unique_ptr<weld::TreeIter> 
itEntry(pTreeView->make_iterator());
+                    pTreeView->get_iter_abs_pos(*itEntry, nAbsPos);
+                    pTreeView->set_cursor_without_notify(*itEntry);
+                    pTreeView->grab_focus();
+                    pTreeView->collapse_row(*itEntry);
+                    return true;
+                }
                 else if (sAction == "dragstart")
                 {
                     sal_Int32 nRow = o3tl::toInt32(rData["data"]);
diff --git a/vcl/source/treelist/svtabbx.cxx b/vcl/source/treelist/svtabbx.cxx
index 9ef0e145ed6d..9b39429c20e7 100644
--- a/vcl/source/treelist/svtabbx.cxx
+++ b/vcl/source/treelist/svtabbx.cxx
@@ -102,6 +102,10 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& 
rJsonWriter,
                     rJsonWriter.put("ondemand", true);
             }
         }
+        if (rChildren.size() > 0 && !pTabListBox->IsExpanded(pEntry))
+        {
+            rJsonWriter.put("collapsed", true);
+        }
 
         if (bCheckButtons)
         {

Reply via email to