The user can cancel the opening of many editors.

Don't play dice with the devil.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17989

(cherry picked from commit a99377c1ec)
This commit is contained in:
Jeff Young 2024-05-08 18:19:24 +01:00
parent 1a932cb13b
commit cde18d7ae7
11 changed files with 172 additions and 148 deletions

View File

@ -214,13 +214,15 @@ protected:
rawValue = m_preselect; rawValue = m_preselect;
wxString symbolId = escapeLibId( rawValue ); wxString symbolId = escapeLibId( rawValue );
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SYMBOL_CHOOSER, true, m_dlg );
if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SYMBOL_CHOOSER, true, m_dlg ) )
{
if( frame->ShowModal( &symbolId, m_dlg ) ) if( frame->ShowModal( &symbolId, m_dlg ) )
SetValue( UnescapeString( symbolId ) ); SetValue( UnescapeString( symbolId ) );
frame->Destroy(); frame->Destroy();
} }
}
DIALOG_SHIM* m_dlg; DIALOG_SHIM* m_dlg;
wxString m_preselect; wxString m_preselect;
@ -267,8 +269,13 @@ protected:
if( fpid.IsEmpty() ) if( fpid.IsEmpty() )
fpid = m_preselect; fpid = m_preselect;
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ); // Disable the button until we have finished processing it. Normally this is not an issue
// but if the footprint chooser is loading for the first time, it can be slow enough that
// multiple clicks will cause multiple instances of the footprint loader process to start
Disable();
if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) )
{
if( !m_symbolNetlist.empty() ) if( !m_symbolNetlist.empty() )
{ {
KIWAY_EXPRESS event( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, m_symbolNetlist ); KIWAY_EXPRESS event( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, m_symbolNetlist );
@ -281,6 +288,9 @@ protected:
frame->Destroy(); frame->Destroy();
} }
Enable();
}
protected: protected:
DIALOG_SHIM* m_dlg; DIALOG_SHIM* m_dlg;
wxString m_preselect; wxString m_preselect;

View File

@ -176,11 +176,11 @@ int CVPCB_CONTROL::ShowFootprintViewer( const TOOL_EVENT& aEvent )
fpframe = (DISPLAY_FOOTPRINTS_FRAME*) m_frame->Kiway().Player( FRAME_CVPCB_DISPLAY, true, fpframe = (DISPLAY_FOOTPRINTS_FRAME*) m_frame->Kiway().Player( FRAME_CVPCB_DISPLAY, true,
m_frame ); m_frame );
// If Kiway() cannot create the eeschema frame, it shows a error message, and
// frame is null
if( !fpframe ) if( !fpframe )
{
wxMessageBox( _( "Unable to create the footprint viewer frame" ) );
return 0; return 0;
}
fpframe->Show( true ); fpframe->Show( true );
} }

View File

@ -248,8 +248,8 @@ void DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser( wxCommandEvent& aEvent )
{ {
wxString newName = getLibIdValue( m_specifiedId ); wxString newName = getLibIdValue( m_specifiedId );
KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ); if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ) )
{
if( frame->ShowModal( &newName, this ) ) if( frame->ShowModal( &newName, this ) )
{ {
m_specifiedId->SetValue( UnescapeString( newName ) ); m_specifiedId->SetValue( UnescapeString( newName ) );
@ -258,14 +258,15 @@ void DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser( wxCommandEvent& aEvent )
frame->Destroy(); frame->Destroy();
} }
}
void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent ) void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent )
{ {
wxString newName = getLibIdValue( m_newId ); wxString newName = getLibIdValue( m_newId );
KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ); if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ) )
{
if( frame->ShowModal( &newName, this ) ) if( frame->ShowModal( &newName, this ) )
{ {
m_newId->SetValue( UnescapeString( newName ) ); m_newId->SetValue( UnescapeString( newName ) );
@ -274,6 +275,7 @@ void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent )
frame->Destroy(); frame->Destroy();
} }
}
void DIALOG_CHANGE_SYMBOLS::updateFieldsList() void DIALOG_CHANGE_SYMBOLS::updateFieldsList()

View File

@ -109,15 +109,16 @@ protected:
if( event.GetId() == MYID_SELECT_FOOTPRINT ) if( event.GetId() == MYID_SELECT_FOOTPRINT )
{ {
// pick a footprint using the footprint picker. // pick a footprint using the footprint picker.
wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD );
FOOTPRINT_FIELD );
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg );
if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) )
{
if( frame->ShowModal( &fpid, m_dlg ) ) if( frame->ShowModal( &fpid, m_dlg ) )
m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid ); m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid );
frame->Destroy(); frame->Destroy();
} }
}
else if (event.GetId() == MYID_SHOW_DATASHEET ) else if (event.GetId() == MYID_SHOW_DATASHEET )
{ {
wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(),

View File

@ -947,13 +947,15 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
{ {
// pick a footprint using the footprint picker. // pick a footprint using the footprint picker.
wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE ); wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE );
KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg );
if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) )
{
if( frame->ShowModal( &fpid, m_dlg ) ) if( frame->ShowModal( &fpid, m_dlg ) )
m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid ); m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid );
frame->Destroy(); frame->Destroy();
} }
}
else if (event.GetId() == MYID_SHOW_DATASHEET ) else if (event.GetId() == MYID_SHOW_DATASHEET )
{ {
wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE ); wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE );

View File

@ -1791,10 +1791,9 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
} }
else if( retval == SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL ) else if( retval == SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL )
{ {
auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) )
true ); {
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( frame );
wxCHECK( editor, 0 );
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
blocking_win->Close( true ); blocking_win->Close( true );
@ -1804,25 +1803,24 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
return 0; return 0;
editor->LoadSymbolFromSchematic( symbol ); editor->LoadSymbolFromSchematic( symbol );
editor->Show( true ); editor->Show( true );
editor->Raise(); editor->Raise();
} }
}
else if( retval == SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL ) else if( retval == SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL )
{ {
auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) )
true ); {
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( frame );
wxCHECK( editor, 0 );
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
blocking_win->Close( true ); blocking_win->Close( true );
editor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() ); editor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() );
editor->Show( true ); editor->Show( true );
editor->Raise(); editor->Raise();
} }
}
else if( retval == SYMBOL_PROPS_WANT_UPDATE_SYMBOL ) else if( retval == SYMBOL_PROPS_WANT_UPDATE_SYMBOL )
{ {
DIALOG_CHANGE_SYMBOLS dlg( m_frame, symbol, DIALOG_CHANGE_SYMBOLS::MODE::UPDATE ); DIALOG_CHANGE_SYMBOLS dlg( m_frame, symbol, DIALOG_CHANGE_SYMBOLS::MODE::UPDATE );

View File

@ -536,8 +536,8 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
{ {
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>(); PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
SIMULATOR_FRAME* simFrame = (SIMULATOR_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, KIWAY_PLAYER* player = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
false ); SIMULATOR_FRAME* simFrame = static_cast<SIMULATOR_FRAME*>( player );
if( !simFrame ) // Defensive coding; shouldn't happen. if( !simFrame ) // Defensive coding; shouldn't happen.
return 0; return 0;

View File

@ -405,8 +405,8 @@ void DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint( wxCommandEvent& event )
{ {
wxString newname = m_newID->GetValue(); wxString newname = m_newID->GetValue();
KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, this ); if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, this ) )
{
if( m_currentFootprint ) if( m_currentFootprint )
{ {
/* /*
@ -443,5 +443,6 @@ void DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint( wxCommandEvent& event )
frame->Destroy(); frame->Destroy();
} }
}

View File

@ -2053,21 +2053,25 @@ void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( FOOTPRINT* aFootprint )
} }
else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_BOARD_FP ) else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_BOARD_FP )
{ {
auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) )
{
FOOTPRINT_EDIT_FRAME* fp_editor = static_cast<FOOTPRINT_EDIT_FRAME*>( frame );
editor->LoadFootprintFromBoard( aFootprint ); fp_editor->LoadFootprintFromBoard( aFootprint );
fp_editor->Show( true );
editor->Show( true ); fp_editor->Raise(); // Iconize( false );
editor->Raise(); // Iconize( false ); }
} }
else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_LIBRARY_FP ) else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_LIBRARY_FP )
{ {
auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) )
{
FOOTPRINT_EDIT_FRAME* fp_editor = static_cast<FOOTPRINT_EDIT_FRAME*>( frame );
editor->LoadFootprintFromLibrary( aFootprint->GetFPID() ); fp_editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
fp_editor->Show( true );
editor->Show( true ); fp_editor->Raise(); // Iconize( false );
editor->Raise(); // Iconize( false ); }
} }
else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_UPDATE_FP ) else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_UPDATE_FP )
{ {

View File

@ -1575,15 +1575,18 @@ int BOARD_EDITOR_CONTROL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); if( KIWAY_PLAYER* frame = editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) )
{
FOOTPRINT_EDIT_FRAME* fp_editor = static_cast<FOOTPRINT_EDIT_FRAME*>( frame );
if( aEvent.IsAction( &PCB_ACTIONS::editFpInFpEditor ) ) if( aEvent.IsAction( &PCB_ACTIONS::editFpInFpEditor ) )
editor->LoadFootprintFromBoard( fp ); fp_editor->LoadFootprintFromBoard( fp );
else if( aEvent.IsAction( &PCB_ACTIONS::editLibFpInFpEditor ) ) else if( aEvent.IsAction( &PCB_ACTIONS::editLibFpInFpEditor ) )
editor->LoadFootprintFromLibrary( fp->GetFPID() ); fp_editor->LoadFootprintFromLibrary( fp->GetFPID() );
editor->Show( true ); fp_editor->Show( true );
editor->Raise(); // Iconize( false ); fp_editor->Raise(); // Iconize( false );
}
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );

View File

@ -208,8 +208,9 @@ int FOOTPRINT_EDITOR_CONTROL::CreateFootprint( const TOOL_EVENT& aEvent )
} }
} }
auto* wizard = (FOOTPRINT_WIZARD_FRAME*) m_frame->Kiway().Player( FRAME_FOOTPRINT_WIZARD, if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, m_frame ) )
true, m_frame ); {
FOOTPRINT_WIZARD_FRAME* wizard = static_cast<FOOTPRINT_WIZARD_FRAME*>( frame );
if( wizard->ShowModal( nullptr, m_frame ) ) if( wizard->ShowModal( nullptr, m_frame ) )
{ {
@ -224,8 +225,8 @@ int FOOTPRINT_EDITOR_CONTROL::CreateFootprint( const TOOL_EVENT& aEvent )
// Add the new object to board // Add the new object to board
m_frame->AddFootprintToBoard( newFootprint ); m_frame->AddFootprintToBoard( newFootprint );
// Initialize data relative to nets and netclasses (for a new footprint the defaults // Initialize data relative to nets and netclasses (for a new footprint the
// are used). This is mandatory to handle and draw pads. // defaults are used). This is mandatory to handle and draw pads.
board()->BuildListOfNets(); board()->BuildListOfNets();
newFootprint->SetPosition( VECTOR2I( 0, 0 ) ); newFootprint->SetPosition( VECTOR2I( 0, 0 ) );
newFootprint->ClearFlags(); newFootprint->ClearFlags();
@ -253,6 +254,8 @@ int FOOTPRINT_EDITOR_CONTROL::CreateFootprint( const TOOL_EVENT& aEvent )
} }
wizard->Destroy(); wizard->Destroy();
}
return 0; return 0;
} }