Move multiple wxMessageBox to DisplayErrorMessage

Also provide protection for headless running in multiple callsites

Fixes https://gitlab.com/kicad/code/kicad/issues/13575
This commit is contained in:
Seth Hillbrand 2023-01-18 16:53:16 -08:00
parent ae55b1581e
commit 7e5a2450b8
13 changed files with 31 additions and 18 deletions

View File

@ -39,6 +39,9 @@ static std::unordered_map<unsigned long, int> doNotShowAgainDlgs;
bool IsGUI()
{
if( !wxTheApp )
return false;
#if wxCHECK_VERSION( 3, 1, 6 )
return wxTheApp->IsGUI();
#else

View File

@ -1219,7 +1219,7 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
if( !msg.IsEmpty() )
{
if( aVerbose )
wxMessageBox( msg );
DisplayErrorMessage( this, msg );
return false;
}
@ -1230,6 +1230,9 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
{
if( !IsGUI() )
return;
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxFileName autoSaveFileName = aFileName;

View File

@ -428,7 +428,7 @@ void EDA_DRAW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent )
void EDA_DRAW_FRAME::PrintPage( const RENDER_SETTINGS* aSettings )
{
wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
DisplayErrorMessage( this, wxT("EDA_DRAW_FRAME::PrintPage() error") );
}

View File

@ -488,8 +488,7 @@ bool FILENAME_RESOLVER::addPath( const SEARCH_PATH& aPath )
msg.append( wxT( "\n" ) );
msg.append( _( "Existing path:" ) + wxS( " " ) );
msg.append( sPL->m_Pathvar );
DisplayErrorMessage( nullptr, msg );
DisplayErrorMessage( nullptr, _( "Bad alias (duplicate name)" ), msg );
return false;
}

View File

@ -1395,6 +1395,9 @@ bool SCH_EDIT_FRAME::updateAutoSaveFile()
void SCH_EDIT_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
{
if( !IsGUI() )
return;
wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
wxLogTrace( traceAutoSave,

View File

@ -227,7 +227,7 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject )
{
success = false;
msg.Printf( _( "Error saving global symbol library table:\n%s" ), ioe.What() );
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, msg );
}
}
@ -244,7 +244,7 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject )
success = false;
msg.Printf( _( "Error saving project-specific symbol library table:\n%s" ),
ioe.What() );
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, msg );
}
}

View File

@ -194,4 +194,11 @@ int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxStrin
int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage,
const wxArrayString& aOptions );
/**
* Determine if the application is running with a GUI
*
* @return true if there is a GUI and false otherwise
*/
bool IsGUI();
#endif /* __INCLUDE__CONFIRM_H__ */

View File

@ -576,12 +576,11 @@ int PCB_EDIT_FRAME::inferLegacyEdgeClearance( BOARD* aBoard )
if( mixed )
{
// If they had different widths then we can't ensure that fills will be the same.
wxMessageBox( _( "If the zones on this board are refilled the Copper Edge Clearance "
DisplayInfoMessage( this, _( "If the zones on this board are refilled the Copper Edge Clearance "
"setting will be used (see Board Setup > Design Rules > Constraints).\n"
"This may result in different fills from previous KiCad versions which "
"used the line thicknesses of the board boundary on the Edge Cuts "
"layer." ),
_( "Edge Clearance Warning" ), wxOK | wxICON_WARNING, this );
"layer." ) );
}
return std::max( 0, edgeWidth / 2 );

View File

@ -1267,7 +1267,7 @@ void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
if( id.empty() )
{
wxMessageBox( _( "No footprint selected." ) );
DisplayErrorMessage( this, _( "No footprint selected." ) );
return;
}

View File

@ -364,7 +364,7 @@ void FOOTPRINT_EDIT_FRAME::ExportFootprint( FOOTPRINT* aFootprint )
if( fp == nullptr )
{
wxMessageBox( wxString::Format( _( "Insufficient permissions to write file '%s'." ),
DisplayErrorMessage( this, wxString::Format( _( "Insufficient permissions to write file '%s'." ),
dlg.GetPath() ) );
return;
}

View File

@ -27,6 +27,7 @@
#include <functional>
using namespace std::placeholders;
#include <confirm.h>
#include <kiway.h>
#include <pcb_edit_frame.h>
#include <netlist_reader/pcb_netlist.h>
@ -44,7 +45,6 @@ using namespace std::placeholders;
#include <tools/pcb_actions.h>
#include <tools/pcb_selection_tool.h>
#include <project/project_file.h> // LAST_PATH_TYPE
#include <wx/msgdlg.h>
bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aNetlist,
@ -60,7 +60,7 @@ bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aN
if( !netlistReader.get() )
{
msg.Printf( _( "Cannot open netlist file '%s'." ), aFilename );
wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
DisplayErrorMessage( this, msg );
return false;
}
@ -71,7 +71,7 @@ bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aN
catch( const IO_ERROR& ioe )
{
msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, msg );
return false;
}

View File

@ -1824,7 +1824,7 @@ void PCB_EDIT_FRAME::RunEeschema()
else
{
msg.Printf( _( "Schematic file '%s' not found." ), schematic.GetFullPath() );
wxMessageBox( msg, _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
DisplayErrorMessage( this, msg );
return;
}
}
@ -1853,8 +1853,7 @@ void PCB_EDIT_FRAME::RunEeschema()
}
catch( const IO_ERROR& err )
{
wxMessageBox( _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What(),
_( "KiCad Error" ), wxOK | wxICON_ERROR, this );
DisplayErrorMessage( this, _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What() );
return;
}
}

View File

@ -2569,7 +2569,7 @@ void PCB_PLUGIN::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* a
"Would you like to create it?"),
aLibraryPath );
if( wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
if( !IsGUI() || wxMessageBox( msg, _( "Library Not Found"), wxYES_NO | wxICON_QUESTION ) != wxYES )
return;
// Save throws its own IO_ERROR on failure, so no need to recreate here