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

New commits:
commit 3649dc202bedf72e37c77993a1f7027bfdfc6d9e
Author:     Attila Szűcs <[email protected]>
AuthorDate: Thu Jun 29 18:32:27 2023 +0200
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Oct 16 11:39:39 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]>
    (cherry picked from commit b95750af717e0693a13c3ef35277779e1394e0ae)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158016
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index c5967bb4e213..523f86cc8468 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -355,6 +355,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 495cdfa91353..9c6db5b5a5eb 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -274,6 +274,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 d047251ea958..02d3a661e4d1 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1135,6 +1135,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));
@@ -1149,6 +1155,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();
@@ -2225,6 +2233,19 @@ bool SwContentTree::RequestingChildren(const 
weld::TreeIter& rParent)
     return false;
 }
 
+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 c868592e904d..3fd5b7f9b682 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -736,12 +736,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 17c56d78e61e..46d5fb675366 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -498,6 +498,16 @@ bool ExecuteAction(const OUString& nWindowId, const 
OUString& rWidget, StringMap
                     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 0c3a179f0adf..81f0f4e8b078 100644
--- a/vcl/source/treelist/svtabbx.cxx
+++ b/vcl/source/treelist/svtabbx.cxx
@@ -104,6 +104,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)
         {
commit 94426f366beff15784bcd2cd852c980e8d5a4467
Author:     Attila Szűcs <[email protected]>
AuthorDate: Fri Jun 9 05:56:31 2023 +0200
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Oct 16 11:39:31 2023 +0200

    LOK: fix for navigator: hide empty contentTypes
    
    fixed that opening heading by default, first check if headings
    are not hidden, because it blindly opened the 1. type, but
    from now, that can be an other type, or nothing
    
    Change-Id: I86cac472d8cba9a46befc5a84ef073c01fa7243d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152779
    Tested-by: Andras Timar <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    (cherry picked from commit 61e2022110d3088bc1653713dc270beaacae4c74)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157966
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/source/uibase/inc/conttree.hxx 
b/sw/source/uibase/inc/conttree.hxx
index 3f3483351daf..495cdfa91353 100644
--- a/sw/source/uibase/inc/conttree.hxx
+++ b/sw/source/uibase/inc/conttree.hxx
@@ -244,6 +244,7 @@ public:
         { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; }
 
     bool            IsInDrag() const;
+    bool            HasHeadings() const;
 
     sal_uInt8       GetOutlineLevel()const {return m_nOutlineLevel;}
     void            SetOutlineLevel(sal_uInt8 nSet);
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index a5079e411331..d047251ea958 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1267,6 +1267,14 @@ bool SwContentTree::IsInDrag() const
     return m_xTreeView->get_drag_source() == m_xTreeView.get();
 }
 
+bool SwContentTree::HasHeadings() const
+{
+    const std::unique_ptr<SwContentType>& rpContentT = 
m_aActiveContentArr[ContentTypeId::OUTLINE];
+    if (rpContentT && rpContentT->GetMemberCount() > 0)
+        return true;
+    return false;
+}
+
 // QueryDrop will be executed in the navigator
 sal_Int8 SwContentTree::AcceptDrop(const AcceptDropEvent& rEvt)
 {
diff --git a/sw/source/uibase/utlui/navipi.cxx 
b/sw/source/uibase/utlui/navipi.cxx
index 67807c69f8bc..c868592e904d 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -736,10 +736,13 @@ SwNavigationPI::SwNavigationPI(weld::Widget* pParent,
         m_xGlobalTree->HideTree();
 
         //Open Headings by default
-        auto& pTreeView = m_xContentTree->get_widget();
-        std::unique_ptr<weld::TreeIter> itEntry(pTreeView.make_iterator());
-        pTreeView.get_iter_first(*itEntry);
-        pTreeView.expand_row(*itEntry);
+        if (m_xContentTree->HasHeadings())
+        {
+            auto& pTreeView = m_xContentTree->get_widget();
+            std::unique_ptr<weld::TreeIter> itEntry(pTreeView.make_iterator());
+            pTreeView.get_iter_first(*itEntry);
+            pTreeView.expand_row(*itEntry);
+        }
     }
 }
 

Reply via email to