don't crash if we delete the item being edited (replaces patch 979733)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28472 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -88,11 +88,25 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
|
|||||||
public:
|
public:
|
||||||
wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
|
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:
|
protected:
|
||||||
void OnChar( wxKeyEvent &event );
|
void OnChar( wxKeyEvent &event );
|
||||||
void OnKeyUp( wxKeyEvent &event );
|
void OnKeyUp( wxKeyEvent &event );
|
||||||
void OnKillFocus( wxFocusEvent &event );
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
|
|
||||||
|
void DoStopEditing()
|
||||||
|
{
|
||||||
|
Finish();
|
||||||
|
m_owner->OnRenameCancelled(m_itemEdited);
|
||||||
|
}
|
||||||
|
|
||||||
bool AcceptChanges();
|
bool AcceptChanges();
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
@@ -413,12 +427,10 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
|
|||||||
Finish();
|
Finish();
|
||||||
}
|
}
|
||||||
// else do nothing, do not accept and do not close
|
// else do nothing, do not accept and do not close
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_ESCAPE:
|
case WXK_ESCAPE:
|
||||||
Finish();
|
DoStopEditing();
|
||||||
m_owner->OnRenameCancelled(m_itemEdited);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1295,7 +1307,7 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
|
|||||||
// called by wxTextTreeCtrl when it marks itself for deletion
|
// called by wxTextTreeCtrl when it marks itself for deletion
|
||||||
void wxGenericTreeCtrl::ResetTextControl()
|
void wxGenericTreeCtrl::ResetTextControl()
|
||||||
{
|
{
|
||||||
m_textCtrl = NULL;
|
m_textCtrl = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the first item starting with the given prefix after the given item
|
// 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;
|
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();
|
wxGenericTreeItem *parent = item->GetParent();
|
||||||
|
|
||||||
// don't keep stale pointers around!
|
// don't keep stale pointers around!
|
||||||
@@ -2866,6 +2884,8 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_itemEdited = itemEdit;
|
||||||
|
|
||||||
// We have to call this here because the label in
|
// We have to call this here because the label in
|
||||||
// question might just have been added and no screen
|
// question might just have been added and no screen
|
||||||
// update taken place.
|
// update taken place.
|
||||||
@@ -2913,9 +2933,6 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item)
|
|||||||
GetEventHandler()->ProcessEvent( le );
|
GetEventHandler()->ProcessEvent( le );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void wxGenericTreeCtrl::OnRenameTimer()
|
void wxGenericTreeCtrl::OnRenameTimer()
|
||||||
{
|
{
|
||||||
Edit( m_current );
|
Edit( m_current );
|
||||||
|
Reference in New Issue
Block a user