From 2f05f5e2eb36e1f189c932f74ff784324f836dad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 16 Mar 2020 00:24:03 +0100 Subject: [PATCH 1/5] Remove unnecessary commented out test This test remained since 902725eefee5a402d21d13b2630583ab28ae3931 but should have been simply removed back then, as we return if the item is null due to a test above. No real changes. --- src/generic/treectlg.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 112894060e..948b8118b3 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -3790,8 +3790,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) } // this facilitates multiple-item drag-and-drop - - if ( /* item && */ HasFlag(wxTR_MULTIPLE)) + if ( HasFlag(wxTR_MULTIPLE)) { wxArrayTreeItemIds selections; size_t count = GetSelections(selections); From 8bc830337c04176ef857f6010b9448e74b58c9d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 16 Mar 2020 00:27:12 +0100 Subject: [PATCH 2/5] Slightly optimize Shift/Control-clicking in wxTR_MULTIPLE case Don't call GetSelections() unnecessarily if we're not going to use its result in any case because either Shift or Command/Control key was pressed when the mouse button was released. See #18680. --- src/generic/treectlg.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 948b8118b3..2473fb8c97 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -3790,14 +3790,10 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) } // this facilitates multiple-item drag-and-drop - if ( HasFlag(wxTR_MULTIPLE)) + if ( HasFlag(wxTR_MULTIPLE) && !(event.CmdDown() || event.ShiftDown()) ) { wxArrayTreeItemIds selections; - size_t count = GetSelections(selections); - - if (count > 1 && - !event.CmdDown() && - !event.ShiftDown()) + if ( GetSelections(selections) > 1 ) { DoSelectItem(item, true, false); } From 0c6d6e6472fa7663acb301b227b733faabcb6aaf Mon Sep 17 00:00:00 2001 From: Anton Triest Date: Mon, 16 Mar 2020 00:30:41 +0100 Subject: [PATCH 3/5] Fix deselecting items on branch toggle in wxTR_MULTIPLE control Don't deselect all the other items when an item is collapsed or expanded in wxGenericTreeCtrl with wxTR_MULTIPLE style, this was completely unexpected and seems to have been accidentally introduced back in 35cf1ec63c447856f09fc59bcf60f040f51f3aca Closes #18680. --- src/generic/treectlg.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 2473fb8c97..63acf179cc 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -3789,13 +3789,19 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) GetEventHandler()->ProcessEvent(nevent); } - // this facilitates multiple-item drag-and-drop - if ( HasFlag(wxTR_MULTIPLE) && !(event.CmdDown() || event.ShiftDown()) ) + // Don't deselect anything if we're just collapsing or expanding + // the item. + if ( !(flags & wxTREE_HITTEST_ONITEMBUTTON) ) { - wxArrayTreeItemIds selections; - if ( GetSelections(selections) > 1 ) + // this facilitates multiple-item drag-and-drop + if ( HasFlag(wxTR_MULTIPLE) && + !(event.CmdDown() || event.ShiftDown()) ) { - DoSelectItem(item, true, false); + wxArrayTreeItemIds selections; + if ( GetSelections(selections) > 1 ) + { + DoSelectItem(item, true, false); + } } } From 730b3d1a44d4a919aa5f7b1384eca5b0543d2465 Mon Sep 17 00:00:00 2001 From: Anton Triest Date: Mon, 16 Mar 2020 00:34:31 +0100 Subject: [PATCH 4/5] Allow accepting edit with Numpad Enter key in wxTreeCtrl too This key should work in the same way as normal Enter key and accept the changes. Closes #18682. --- src/common/treebase.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/treebase.cpp b/src/common/treebase.cpp index d1493de28d..f3b11d3b11 100644 --- a/src/common/treebase.cpp +++ b/src/common/treebase.cpp @@ -357,6 +357,7 @@ void wxTreeCtrlBase::OnCharHook(wxKeyEvent& event) wxFALLTHROUGH; case WXK_RETURN: + case WXK_NUMPAD_ENTER: EndEditLabel(GetFocusedItem(), discardChanges); // Do not call Skip() below. From 6b04c9938d3d719d613d5cd1580229dbb0e8f7f8 Mon Sep 17 00:00:00 2001 From: Anton Triest Date: Mon, 16 Mar 2020 00:55:04 +0100 Subject: [PATCH 5/5] Improve behaviour of Left/Right arrow keys in wxGenericTreeCtrl Make the left arrow collapse the item if it's currently expanded before falling back to its previous behaviour of going to the item parent and the right arrow to go to the first child if the item is already expanded. This is compatible with the native MSW control behaviour, but mostly just more useful and convenient. Closes #18684. --- src/generic/treectlg.cpp | 57 ++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 63acf179cc..383140a210 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -3081,8 +3081,8 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) // ' ' | return : activate // up : go up (not last children!) // down : go down - // left : go to parent - // right : open if parent and go next + // left : collapse or go to parent + // right : expand or go to first child // home : go to root // end : go to last item without opening parents // alnum : start or continue searching for the item with this prefix @@ -3210,28 +3210,57 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) } break; - // left arrow goes to the parent + // left arrow collapses or goes to the parent if it's not expanded case WXK_LEFT: { - wxTreeItemId prev = GetItemParent( m_current ); - if ((prev == GetRootItem()) && HasFlag(wxTR_HIDE_ROOT)) + if (m_current == GetRootItem().m_pItem && HasFlag(wxTR_HIDE_ROOT)) { - // don't go to root if it is hidden - prev = GetPrevSibling( m_current ); + // don't try to collapse hidden root item + // (which can be the current one when the tree is empty) + break; } - if (prev) + if (IsExpanded(m_current)) { - DoSelectItem( prev, unselect_others, extended_select ); + Collapse(m_current); + } + else + { + // select parent unless it's the hidden root + wxTreeItemId parent = GetItemParent(m_current); + if (parent && (parent != GetRootItem() || !HasFlag(wxTR_HIDE_ROOT))) + { + DoSelectItem(parent, unselect_others, extended_select); + } } } break; + // right arrow expands or goes to first child if it's already expanded case WXK_RIGHT: - // right arrow just expand the item will be fine - if (m_current != GetRootItem().m_pItem || !HasFlag(wxTR_HIDE_ROOT)) - Expand(m_current); - //else: don't try to expand hidden root item (which can be the - // current one when the tree is empty) + { + if (m_current == GetRootItem().m_pItem && HasFlag(wxTR_HIDE_ROOT)) + { + // don't try to expand hidden root item + // (which can be the current one when the tree is empty) + break; + } + if (HasChildren(m_current)) + { + if (IsExpanded(m_current)) + { + wxTreeItemIdValue cookie; + wxTreeItemId child = GetFirstChild(m_current, cookie); + if (child) + { + DoSelectItem(child, unselect_others, extended_select); + } + } + else + { + Expand(m_current); + } + } + } break; case WXK_DOWN: