Wildcards: unify handling of all files wildcards
Use the AddFileExtListToFilter() to also generate the wildcard for "all files". This is because: * Users can use AddFileExtListToFilter for the all files WC with the same interface as for any other extensions. * Users do not need to worry about wxGetTranslation, as the _() is applied in the same way as the other *Wildcard() helpers, and it is a function just like the others, so it is consistent * There is a testable interface to document the expected result. The test is added.
This commit is contained in:
parent
dd313d4d47
commit
658cc8fd96
|
@ -68,9 +68,17 @@ static wxString formatWildcardExt( const wxString& aWildcard )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
|
wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
|
||||||
{
|
{
|
||||||
|
if( aExts.size() == 0 )
|
||||||
|
{
|
||||||
|
// The "all files" wildcard is different on different systems
|
||||||
|
wxString filter;
|
||||||
|
filter << " (" << wxFileSelectorDefaultWildcardStr << ")|"
|
||||||
|
<< wxFileSelectorDefaultWildcardStr;
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
wxString files_filter = " (";
|
wxString files_filter = " (";
|
||||||
|
|
||||||
// Add extensions to the info message:
|
// Add extensions to the info message:
|
||||||
|
@ -136,7 +144,10 @@ const std::string PngFileExtension( "png" );
|
||||||
const std::string JpegFileExtension( "jpg" );
|
const std::string JpegFileExtension( "jpg" );
|
||||||
|
|
||||||
|
|
||||||
const wxString AllFilesWildcard( _( "All files (*)|*" ) );
|
wxString AllFilesWildcard()
|
||||||
|
{
|
||||||
|
return _( "All files" ) + AddFileExtListToFilter( {} );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString SchematicSymbolFileWildcard()
|
wxString SchematicSymbolFileWildcard()
|
||||||
|
|
|
@ -632,7 +632,7 @@ bool NETLIST_DIALOG::FilenamePrms( NETLIST_TYPE_ID aNetTypeId,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // custom, NET_TYPE_CUSTOM1 and greater
|
default: // custom, NET_TYPE_CUSTOM1 and greater
|
||||||
fileWildcard = AllFilesWildcard;
|
fileWildcard = AllFilesWildcard();
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -764,7 +764,7 @@ void DIALOG_SPICE_MODEL::onSelectLibrary( wxCommandEvent& event )
|
||||||
if( searchPath.IsEmpty() )
|
if( searchPath.IsEmpty() )
|
||||||
searchPath = Prj().GetProjectPath();
|
searchPath = Prj().GetProjectPath();
|
||||||
|
|
||||||
wxString wildcards = SpiceLibraryFileWildcard() + "|" + AllFilesWildcard;
|
wxString wildcards = SpiceLibraryFileWildcard() + "|" + AllFilesWildcard();
|
||||||
wxFileDialog openDlg( this, _( "Select library" ), searchPath, "", wildcards,
|
wxFileDialog openDlg( this, _( "Select library" ), searchPath, "", wildcards,
|
||||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
filetypes += _( "Bottom Pad Master (*.GPB)|*.GPB;*.gpb|" );
|
filetypes += _( "Bottom Pad Master (*.GPB)|*.GPB;*.gpb|" );
|
||||||
|
|
||||||
// All filetypes
|
// All filetypes
|
||||||
filetypes += AllFilesWildcard;
|
filetypes += AllFilesWildcard();
|
||||||
|
|
||||||
// Use the current working directory if the file name path does not exist.
|
// Use the current working directory if the file name path does not exist.
|
||||||
if( filename.DirExists() )
|
if( filename.DirExists() )
|
||||||
|
@ -391,7 +391,7 @@ bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
|
||||||
filetypes << wxT( "|" );
|
filetypes << wxT( "|" );
|
||||||
|
|
||||||
/* All filetypes */
|
/* All filetypes */
|
||||||
filetypes += wxGetTranslation( AllFilesWildcard );
|
filetypes += AllFilesWildcard();
|
||||||
|
|
||||||
/* Use the current working directory if the file name path does not exist. */
|
/* Use the current working directory if the file name path does not exist. */
|
||||||
if( filename.DirExists() )
|
if( filename.DirExists() )
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
* are all match if you pass "txt" into the function).
|
* are all match if you pass "txt" into the function).
|
||||||
*
|
*
|
||||||
* @param aExts is the list of exts to add to the filter. Do not include the
|
* @param aExts is the list of exts to add to the filter. Do not include the
|
||||||
* leading dot.
|
* leading dot. Empty means "allow all files".
|
||||||
*
|
*
|
||||||
* @return the appropriate file dialog wildcard filter list.
|
* @return the appropriate file dialog wildcard filter list.
|
||||||
*/
|
*/
|
||||||
|
@ -127,7 +127,7 @@ extern const std::string JpegFileExtension;
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern const wxString AllFilesWildcard;
|
extern wxString AllFilesWildcard();
|
||||||
|
|
||||||
extern wxString ComponentFileWildcard();
|
extern wxString ComponentFileWildcard();
|
||||||
extern wxString PageLayoutDescrFileWildcard();
|
extern wxString PageLayoutDescrFileWildcard();
|
||||||
|
|
|
@ -471,7 +471,7 @@ void KICAD_MANAGER_FRAME::OnOpenTextEditor( wxCommandEvent& event )
|
||||||
void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
|
void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
// show all files in file dialog (in Kicad all files are editable texts):
|
// show all files in file dialog (in Kicad all files are editable texts):
|
||||||
wxString wildcard = AllFilesWildcard;
|
wxString wildcard = AllFilesWildcard();
|
||||||
|
|
||||||
wxString default_dir = Prj().GetProjectPath();
|
wxString default_dir = Prj().GetProjectPath();
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxStrin
|
||||||
wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
|
wildCard << KiCadFootprintLibFileWildcard() << wxChar( '|' )
|
||||||
<< ModLegacyExportFileWildcard() << wxChar( '|' )
|
<< ModLegacyExportFileWildcard() << wxChar( '|' )
|
||||||
<< GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
|
<< GedaPcbFootprintLibFileWildcard() << wxChar( '|' )
|
||||||
<< AllFilesWildcard;
|
<< AllFilesWildcard();
|
||||||
|
|
||||||
wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
|
wxFileDialog dlg( aParent, FMT_IMPORT_MODULE, aLastPath, wxEmptyString, wildCard,
|
||||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
||||||
|
|
|
@ -86,4 +86,22 @@ BOOST_AUTO_TEST_CASE( BasicFilter )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr bool should_use_windows_filters()
|
||||||
|
{
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( AllFilesFilter )
|
||||||
|
{
|
||||||
|
const auto resp = AddFileExtListToFilter( {} );
|
||||||
|
|
||||||
|
const std::string exp_filter = should_use_windows_filters() ? " (*.*)|*.*" : " (*)|*";
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( resp, exp_filter );
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Reference in New Issue