Make more use of shared dialogs.

This commit is contained in:
Jeff Young 2025-08-10 21:29:35 +01:00
parent 892f9031d7
commit cf5c00bcf2
11 changed files with 44 additions and 106 deletions

View File

@ -68,6 +68,8 @@ void PANEL_IMAGE_EDITOR::OnGreyScaleConvert( wxCommandEvent& event )
*/
bool PANEL_IMAGE_EDITOR::CheckValues()
{
wxWindow* host = wxGetTopLevelParent( this );
#define MIN_SIZE 15 // Min size in pixels after scaling (50 mils)
#define MAX_SIZE 6000 // Max size in pixels after scaling (20 inches)
double tmp;
@ -76,7 +78,7 @@ bool PANEL_IMAGE_EDITOR::CheckValues()
// Test number correctness
if( !msg.ToDouble( &tmp ) || tmp < 0.0 )
{
wxMessageBox( _( "Incorrect scale number" ) );
DisplayErrorMessage( host, _( "Scale must be a positive number." ) );
return false;
}
@ -86,10 +88,10 @@ bool PANEL_IMAGE_EDITOR::CheckValues()
if( size_min < MIN_SIZE ) // if the size is too small, the image will be hard to locate
{
wxMessageDialog( wxGetTopLevelParent( this ),
wxString::Format( _( "This scale results in an image which is too "
"small (%.2f mm or %.1f mil)." ),
25.4 / 300 * size_min, 1000.0 / 300.0 * size_min ) );
DisplayErrorMessage( host, wxString::Format( _( "This scale results in an image which is too small "
"(%.2f mm or %.1f mil)." ),
25.4 / 300 * size_min,
1000.0 / 300.0 * size_min ) );
return false;
}
@ -98,10 +100,10 @@ bool PANEL_IMAGE_EDITOR::CheckValues()
if( size_max > MAX_SIZE )
{
// the actual size is 25.4/300 * size_max in mm
if( !IsOK( wxGetTopLevelParent( this ),
wxString::Format( _( "This scale results in an image which is very large "
"(%.1f mm or %.2f in). Are you sure?" ),
25.4 / 300 * size_max, size_max / 300.0 ) ) )
if( !IsOK( host, wxString::Format( _( "This scale results in an image which is very large "
"(%.1f mm or %.2f in). Are you sure?" ),
25.4 / 300 * size_max,
size_max / 300.0 ) ) )
{
return false;
}

View File

@ -1314,19 +1314,13 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnOutputFileBrowseClicked( wxCommandEvent& even
wxFileName file = wxFileName( saveDlg.GetPath() );
wxString defaultPath = fn.GetPathWithSep();
wxString msg;
msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
wxMessageDialog dialog( this, msg, _( "BOM Output File" ),
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
if( dialog.ShowModal() == wxID_YES )
if( IsOK( this, wxString::Format( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath ) ) )
{
if( !file.MakeRelativeTo( defaultPath ) )
{
wxMessageBox( _( "Cannot make path relative (target volume different from schematic "
"file volume)!" ),
_( "BOM Output File" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, _( "Cannot make path relative (target volume different from schematic "
"file volume)!" ) );
}
}

View File

@ -77,19 +77,6 @@ void IMPORT_PROJ_HELPER::FindEmptyTargetDir()
}
void IMPORT_PROJ_HELPER::OutputCopyError( const wxFileName& aSrc, const wxFileName& aFileCopy )
{
wxString msg;
msg.Printf( _( "Cannot copy file '%s'\n"
"to '%s'\n"
"The project cannot be imported." ),
aSrc.GetFullPath(), aFileCopy.GetFullPath() );
wxMessageDialog fileCopyErrorDlg( m_frame, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR );
fileCopyErrorDlg.ShowModal();
}
class SCOPED_FILE_REMOVER
{
wxString m_file;

View File

@ -68,7 +68,6 @@ private:
std::vector<wxString> m_schExtenstions;
std::vector<wxString> m_pcbExtenstions;
void OutputCopyError( const wxFileName& aSrc, const wxFileName& aFileCopy );
void ImportIndividualFile( KICAD_T aKicad_T, int aImportedFileType );
void doImport( const wxString& aFile, FRAME_T aFrameType, int aImportedFileType );

View File

@ -324,15 +324,11 @@ bool PGM_KICAD::OnPgmInit()
{
wxFileName tmp = parser.GetParam( 0 );
if( tmp.GetExt() != FILEEXT::ProjectFileExtension
&& tmp.GetExt() != FILEEXT::LegacyProjectFileExtension )
if( tmp.GetExt() != FILEEXT::ProjectFileExtension && tmp.GetExt() != FILEEXT::LegacyProjectFileExtension )
{
wxString msg;
msg.Printf( _( "File '%s'\ndoes not appear to be a valid KiCad project file." ),
tmp.GetFullPath() );
wxMessageDialog dlg( nullptr, msg, _( "Error" ), wxOK | wxICON_EXCLAMATION );
dlg.ShowModal();
DisplayErrorMessage( nullptr, wxString::Format( _( "File '%s'\n"
"does not appear to be a KiCad project file." ),
tmp.GetFullPath() ) );
}
else
{

View File

@ -314,27 +314,18 @@ int KICAD_MANAGER_CONTROL::NewFromTemplate( const TOOL_EVENT& aEvent )
fn.AppendDir( fn.GetName() );
// Check if the project directory is empty if it already exists.
if( !fn.DirExists() )
if( !fn.DirExists() && !fn.Mkdir() )
{
if( !fn.Mkdir() )
{
wxString msg;
msg.Printf( _( "Folder '%s' could not be created.\n\n"
"Make sure you have write permissions and try again." ),
fn.GetPath() );
DisplayErrorMessage( m_frame, msg );
return -1;
}
DisplayErrorMessage( m_frame, wxString::Format( _( "Folder '%s' could not be created.\n\n"
"Make sure you have write permissions and try again." ),
fn.GetPath() ) );
return -1;
}
if( !fn.IsDirWritable() )
{
wxString msg;
msg.Printf( _( "Insufficient permissions to write to folder '%s'." ), fn.GetPath() );
wxMessageDialog msgDlg( m_frame, msg, _( "Error" ), wxICON_ERROR | wxOK | wxCENTER );
msgDlg.ShowModal();
DisplayErrorMessage( m_frame, wxString::Format( _( "Insufficient permissions to write to folder '%s'." ),
fn.GetPath() ) );
return -1;
}
@ -375,13 +366,7 @@ int KICAD_MANAGER_CONTROL::NewFromTemplate( const TOOL_EVENT& aEvent )
// create a project
if( !ps.GetSelectedTemplate()->CreateProject( fn, &errorMsg ) )
{
wxMessageDialog createDlg( m_frame, _( "A problem occurred creating new project from template." ),
_( "Error" ), wxOK | wxICON_ERROR );
if( !errorMsg.empty() )
createDlg.SetExtendedMessage( errorMsg );
createDlg.ShowModal();
DisplayErrorMessage( m_frame, _( "A problem occurred creating new project from template." ), errorMsg );
return -1;
}
@ -757,19 +742,16 @@ int KICAD_MANAGER_CONTROL::SaveProjectAs( const TOOL_EVENT& aEvent )
if( !wxMkdir( newProjectDir.GetFullPath() ) )
{
msg.Printf( _( "Folder '%s' could not be created.\n\n"
"Please make sure you have write permissions and try again." ),
newProjectDir.GetPath() );
DisplayErrorMessage( m_frame, msg );
DisplayErrorMessage( m_frame, wxString::Format( _( "Folder '%s' could not be created.\n\n"
"Please make sure you have sufficient permissions." ),
newProjectDir.GetPath() ) );
return -1;
}
if( !newProjectDir.IsDirWritable() )
{
msg.Printf( _( "Insufficient permissions to write to folder '%s'." ),
newProjectDir.GetFullPath() );
wxMessageDialog msgDlg( m_frame, msg, _( "Error!" ), wxICON_ERROR | wxOK | wxCENTER );
msgDlg.ShowModal();
DisplayErrorMessage( m_frame, wxString::Format( _( "Insufficient permissions to write to folder '%s'." ),
newProjectDir.GetFullPath() ) );
return -1;
}

View File

@ -187,17 +187,14 @@ void DIALOG_GEN_FOOTPRINT_POSITION::onOutputDirectoryBrowseClicked( wxCommandEve
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
wxMessageDialog dialog( this, _( "Use a relative path?"), _( "Plot Output Directory" ),
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
if( dialog.ShowModal() == wxID_YES )
if( IsOK( this, _( "Use a relative path?" ) ) )
{
wxString boardFilePath = ( (wxFileName) m_editFrame->GetBoard()->GetFileName() ).GetPath();
if( !dirName.MakeRelativeTo( boardFilePath ) )
{
wxMessageBox( _( "Cannot make path relative (target volume different from board file volume)!" ),
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, _( "Cannot make path relative (target volume different from board "
"file volume)!" ) );
}
}

View File

@ -273,17 +273,13 @@ void DIALOG_GENDRILL::onOutputDirectoryBrowseClicked( wxCommandEvent& event )
wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
wxFileName fn( Prj().AbsolutePath( m_board->GetFileName() ) );
wxString defaultPath = fn.GetPathWithSep();
wxString msg;
msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ), wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
if( dialog.ShowModal() == wxID_YES )
if( IsOK( this, wxString::Format( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath ) ) )
{
if( !dirName.MakeRelativeTo( defaultPath ) )
{
wxMessageBox( _( "Cannot make path relative (target volume different from board file volume)!" ),
_( "Plot Output Directory" ), wxOK | wxICON_ERROR );
DisplayErrorMessage( this, _( "Cannot make path relative (target volume different from board "
"file volume)!" ) );
}
}

View File

@ -28,6 +28,7 @@
#include <board_design_settings.h>
#include <pcb_layer_box_selector.h>
#include <wx/msgdlg.h>
#include <confirm.h>
/**
* Some handy preset values for common outset distances.
@ -171,19 +172,13 @@ bool DIALOG_OUTSET_ITEMS::TransferDataFromWindow()
{
if( m_outset.GetIntValue() <= 0 )
{
wxString msg = _( "Outset must be a positive value." );
wxMessageDialog errdlg( this, msg, _( "Error" ) );
errdlg.ShowModal();
DisplayErrorMessage( this, _( "Outset must be a positive value." ) );
return false;
}
if( m_lineWidth.GetIntValue() <= 0 )
{
wxString msg = _( "Line width must be a positive value." );
wxMessageDialog errdlg( this, msg, _( "Error" ) );
errdlg.ShowModal();
DisplayErrorMessage( this, _( "Line width must be a positive value." ) );
return false;
}

View File

@ -785,12 +785,7 @@ void DIALOG_PLOT::onOutputDirectoryBrowseClicked( wxCommandEvent& event )
// Test if making the path relative is possible before asking the user if they want to do it
if( relPathTest.MakeRelativeTo( defaultPath ) )
{
msg.Printf( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath );
wxMessageDialog dialog( this, msg, _( "Plot Output Directory" ),
wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
if( dialog.ShowModal() == wxID_YES )
if( IsOK( this, wxString::Format( _( "Do you want to use a path relative to\n'%s'?" ), defaultPath ) ) )
dirName.MakeRelativeTo( defaultPath );
}

View File

@ -441,10 +441,8 @@ int BOARD_EDITOR_CONTROL::ExportNetlist( const TOOL_EVENT& aEvent )
if( !fn.IsDirWritable() )
{
wxString msg;
msg.Printf( _( "Path `%s` is read only." ), fn.GetPath() );
wxMessageDialog( m_frame, msg, _( "I/O Error" ), wxOK | wxCENTER | wxICON_EXCLAMATION );
DisplayErrorMessage( m_frame, wxString::Format( _( "Insufficient permissions to folder '%s'." ),
fn.GetPath() ) );
return 0;
}
@ -465,10 +463,7 @@ int BOARD_EDITOR_CONTROL::ExportNetlist( const TOOL_EVENT& aEvent )
const wxString& netname = pad->GetShortNetname();
if( !netname.IsEmpty() )
{
component->AddNet( pad->GetNumber(), netname, pad->GetPinFunction(),
pad->GetPinType() );
}
component->AddNet( pad->GetNumber(), netname, pad->GetPinFunction(), pad->GetPinType() );
}
nlohmann::ordered_map<wxString, wxString> fields;