diff options
author | Jim Raykowski <raykowj@gmail..com> | 2019-10-11 17:14:22 -0800 |
---|---|---|
committer | Jim Raykowski <raykowj@gmail.com> | 2019-10-19 01:22:06 +0200 |
commit | 888ac516aacbc30a8e9331f6aba7684228568871 (patch) | |
tree | 481afe50a03dd792efc98d9d58f73b0638046876 /vcl/source | |
parent | 7d72b9d34c1183b7471a7a97c007aba10de2d27e (diff) |
tdf#128058 Make ctrl * expand/collapse tree list entries
Provides same expand all behavior as ctrl + and provides for ctrl - like
behavior but instead of collapsing all to root only collapses to focused
entry aka cursor entry.
Change-Id: Ib65dd98857dd083f77d4bec873c2fa7a4212550a
Reviewed-on: https://gerrit.libreoffice.org/80702
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Tested-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/treelist/svimpbox.cxx | 95 |
1 files changed, 60 insertions, 35 deletions
diff --git a/vcl/source/treelist/svimpbox.cxx b/vcl/source/treelist/svimpbox.cxx index 5595d9bcb19d..a936c4a3f9e4 100644 --- a/vcl/source/treelist/svimpbox.cxx +++ b/vcl/source/treelist/svimpbox.cxx @@ -2095,6 +2095,51 @@ void SvImpLBox::MouseMove( const MouseEvent& rMEvt) m_aSelEng.SelMouseMove( rMEvt ); } +void SvImpLBox::ExpandAll() +{ + sal_uInt16 nRefDepth = m_pTree->GetDepth(m_pCursor); + SvTreeListEntry* pCur = m_pTree->Next(m_pCursor); + while (pCur && m_pTree->GetDepth(pCur) > nRefDepth) + { + if (pCur->HasChildren() && !m_pView->IsExpanded(pCur)) + m_pView->Expand(pCur); + pCur = m_pTree->Next(pCur); + } +} + +void SvImpLBox::CollapseTo(SvTreeListEntry* pParentToCollapse) +{ + // collapse all parents until we get to the given parent to collapse + if (pParentToCollapse) + { + sal_uInt16 nRefDepth; + // special case explorer: if the root only has a single + // entry, don't collapse the root entry + if (m_pTree->GetChildList(nullptr).size() < 2) + { + nRefDepth = 1; + pParentToCollapse = m_pCursor; + while (m_pTree->GetParent(pParentToCollapse) + && m_pTree->GetDepth(m_pTree->GetParent(pParentToCollapse)) > 0) + { + pParentToCollapse = m_pTree->GetParent(pParentToCollapse); + } + } + else + nRefDepth = m_pTree->GetDepth(pParentToCollapse); + + if (m_pView->IsExpanded(pParentToCollapse)) + m_pView->Collapse(pParentToCollapse); + SvTreeListEntry* pCur = m_pTree->Next(pParentToCollapse); + while (pCur && m_pTree->GetDepth(pCur) > nRefDepth) + { + if (pCur->HasChildren() && m_pView->IsExpanded(pCur)) + m_pView->Collapse(pCur); + pCur = m_pTree->Next(pCur); + } + } +} + bool SvImpLBox::KeyInput( const KeyEvent& rKEvt) { m_aEditIdle.Stop(); @@ -2404,16 +2449,7 @@ bool SvImpLBox::KeyInput( const KeyEvent& rKEvt) if (!m_pView->IsExpanded(m_pCursor)) m_pView->Expand(m_pCursor); if (bMod1) - { - sal_uInt16 nRefDepth = m_pTree->GetDepth(m_pCursor); - SvTreeListEntry* pCur = m_pTree->Next(m_pCursor); - while (pCur && m_pTree->GetDepth(pCur) > nRefDepth) - { - if (pCur->HasChildren() && !m_pView->IsExpanded(pCur)) - m_pView->Expand(pCur); - pCur = m_pTree->Next(pCur); - } - } + ExpandAll(); break; case KEY_A: @@ -2427,38 +2463,27 @@ bool SvImpLBox::KeyInput( const KeyEvent& rKEvt) if (m_pView->IsExpanded(m_pCursor)) m_pView->Collapse(m_pCursor); if (bMod1) + CollapseTo(m_pTree->GetRootLevelParent(m_pCursor)); + break; + + case KEY_MULTIPLY: + if( bMod1 ) { - // collapse all parents until we get to the root - SvTreeListEntry* pParentToCollapse = m_pTree->GetRootLevelParent(m_pCursor); - if (pParentToCollapse) + // only try to expand/collapse if sublist is expandable, + // otherwise ignore the key press + if( IsExpandable() ) { - sal_uInt16 nRefDepth; - // special case explorer: if the root only has a single - // entry, don't collapse the root entry - if (m_pTree->GetChildList(nullptr).size() < 2) + if (!m_pView->IsExpanded(m_pCursor)) { - nRefDepth = 1; - pParentToCollapse = m_pCursor; - while (m_pTree->GetParent(pParentToCollapse) - && m_pTree->GetDepth(m_pTree->GetParent(pParentToCollapse)) > 0) - { - pParentToCollapse = m_pTree->GetParent(pParentToCollapse); - } + m_pView->Expand(m_pCursor); + ExpandAll(); } else - nRefDepth = 0; - - if (m_pView->IsExpanded(pParentToCollapse)) - m_pView->Collapse(pParentToCollapse); - SvTreeListEntry* pCur = m_pTree->Next(pParentToCollapse); - while (pCur && m_pTree->GetDepth(pCur) > nRefDepth) - { - if (pCur->HasChildren() && m_pView->IsExpanded(pCur)) - m_pView->Collapse(pCur); - pCur = m_pTree->Next(pCur); - } + CollapseTo(m_pCursor); } } + else + bKeyUsed = false; break; case KEY_DIVIDE : |