X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9146872cb5243c629dfb0afc51fd5d8d8ca22826..6dd18972d509fce16afa05eba194ca21db2c48f3:/src/generic/treectlg.cpp diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 69094f0757..61cfce6b52 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -88,11 +88,25 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl public: wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item); + // wxGenericTreeCtrl can use this one to abandon editing the given item, + // it's not an error to call it if this item is not being edited + void StopEditing(wxGenericTreeItem *item) + { + if ( item == m_itemEdited ) + DoStopEditing(); + } + protected: void OnChar( wxKeyEvent &event ); void OnKeyUp( wxKeyEvent &event ); void OnKillFocus( wxFocusEvent &event ); + void DoStopEditing() + { + Finish(); + m_owner->OnRenameCancelled(m_itemEdited); + } + bool AcceptChanges(); void Finish(); @@ -413,12 +427,10 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) Finish(); } // else do nothing, do not accept and do not close - break; case WXK_ESCAPE: - Finish(); - m_owner->OnRenameCancelled(m_itemEdited); + DoStopEditing(); break; default: @@ -1295,7 +1307,7 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const // called by wxTextTreeCtrl when it marks itself for deletion void wxGenericTreeCtrl::ResetTextControl() { - m_textCtrl = NULL; + m_textCtrl = NULL; } // find the first item starting with the given prefix after the given item @@ -1495,6 +1507,12 @@ void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId) wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; + if ( m_textCtrl ) + { + // can't delete the item being edited, cancel editing it first + m_textCtrl->StopEditing(item); + } + wxGenericTreeItem *parent = item->GetParent(); // don't keep stale pointers around! @@ -2913,9 +2931,6 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item) GetEventHandler()->ProcessEvent( le ); } - - - void wxGenericTreeCtrl::OnRenameTimer() { Edit( m_current );