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.
This commit is contained in:
Artur Wieczorek
2015-03-18 18:44:35 +01:00
parent e46d9da243
commit fad1ec7ce8
2 changed files with 17 additions and 2 deletions

View File

@@ -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
// -----------------------------------------------------------------------