pl_editor: fix a crash when cancelling the "add bitmap dialog" by escape key.

This commit is contained in:
jean-pierre charras 2019-06-20 13:05:23 +02:00
parent 77cefe0c16
commit b8d2fef079
1 changed files with 10 additions and 10 deletions

View File

@ -115,23 +115,24 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
if( evt->IsActivate() ) if( evt->IsActivate() )
break; break;
} }
else if( evt->IsClick( BUT_LEFT ) ) else if( evt->IsClick( BUT_LEFT ) )
{ {
// First click creates... // First click creates...
if( !item ) if( !item )
{ {
m_frame->SaveCopyInUndoList(); WS_DATA_ITEM* dataItem = m_frame->AddPageLayoutItem( type );
m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); if( dataItem ) // dataItem = nullptr can happens if the command was cancelled
{
m_frame->SaveCopyInUndoList();
WS_DATA_ITEM* dataItem; m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true );
dataItem = m_frame->AddPageLayoutItem( type );
item = dataItem->GetDrawItems()[0]; item = dataItem->GetDrawItems()[0];
item->SetFlags( IS_NEW | IS_MOVED ); item->SetFlags( IS_NEW | IS_MOVED );
m_selectionTool->AddItemToSel( item ); m_selectionTool->AddItemToSel( item );
}
} }
// ... and second click places: // ... and second click places:
else else
{ {
@ -153,7 +154,6 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else if( item && ( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) ) else if( item && ( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) )
{ {
item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos ); item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos );