From fad1ec7ce83f0a69668c5418cee1cdc5a12e102d Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 18 Mar 2015 18:44:35 +0100 Subject: [PATCH] Determine whether a new element is added to the list in wxPGArrayEditorDialog when its editing is started. New element can be added to the list not only by clicking "New item" button but also by clicking under the last element of the list and we need to determine its index in both cases because it is used later on in wxPGArrayEditorDialog::OnEndLabelEdit event handler. Closes #16905. --- include/wx/propgrid/props.h | 1 + src/propgrid/props.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index 406f9169a3..0e825af53f 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -968,6 +968,7 @@ public: void OnUpClick(wxCommandEvent& event); void OnDownClick(wxCommandEvent& event); void OnEndLabelEdit(wxListEvent& event); + void OnBeginLabelEdit(wxListEvent& evt); void OnIdle(wxIdleEvent& event); protected: diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 3f707f63d2..a334038736 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -2394,6 +2394,10 @@ bool wxPGArrayEditorDialog::Create( wxWindow *parent, wxCommandEventHandler(wxPGArrayEditorDialog::OnDownClick), NULL, this); + lc->Connect(lc->GetId(), wxEVT_LIST_BEGIN_LABEL_EDIT, + wxListEventHandler(wxPGArrayEditorDialog::OnBeginLabelEdit), + NULL, this); + lc->Connect(lc->GetId(), wxEVT_LIST_END_LABEL_EDIT, wxListEventHandler(wxPGArrayEditorDialog::OnEndLabelEdit), NULL, this); @@ -2462,8 +2466,6 @@ void wxPGArrayEditorDialog::OnAddClick(wxCommandEvent& event) } else { - m_itemPendingAtIndex = newItemIndex; - event.Skip(); } } @@ -2551,6 +2553,18 @@ void wxPGArrayEditorDialog::OnEndLabelEdit(wxListEvent& event) event.Skip(); } +void wxPGArrayEditorDialog::OnBeginLabelEdit(wxListEvent& evt) +{ + wxListCtrl* lc = m_elb->GetListCtrl(); + const int lastStringIndex = lc->GetItemCount() - 1; + const int curItemIndex = evt.GetIndex(); + // If current index is >= then last available index + // then we have a new pending element. + m_itemPendingAtIndex = curItemIndex < lastStringIndex? -1: curItemIndex; + + evt.Skip(); +} + #endif // wxUSE_EDITABLELISTBOX // -----------------------------------------------------------------------