Fix issues created by Adds Save As... to the Kicad manger.

Mainly replacing std::string by wxString to manage filenames.
On Windows, a sdt::string cannot manage a filename, unless using
in many places TO_UTF8 and FROM_UTF8.
So the best way is to use a wxString for filenames and error messages.
This commit is contained in:
jean-pierre charras 2019-11-10 09:37:39 +01:00
parent b5904b0401
commit 4de6ed6206
8 changed files with 52 additions and 52 deletions

View File

@ -359,13 +359,13 @@ bool CanPrintFile( const wxString& file )
}
void CopyFile( const wxString& aSrcPath, const wxString& aDestPath, std::string& aErrors )
void CopyFile( const wxString& aSrcPath, const wxString& aDestPath, wxString& aErrors )
{
if( !wxCopyFile( aSrcPath, aDestPath ) )
{
wxString msg;
if( !aErrors.empty() )
if( !aErrors.IsEmpty() )
aErrors += "\n";
msg.Printf( _( "Cannot copy file \"%s\"." ), aDestPath );

View File

@ -42,8 +42,8 @@
#include <kiway.h>
#include <sim/sim_plot_frame.h>
#include <kiface_ids.h>
#include <libs/sexpr/include/sexpr/sexpr.h>
#include <libs/sexpr/include/sexpr/sexpr_parser.h>
#include <../libs/sexpr/include/sexpr/sexpr.h>
#include <../libs/sexpr/include/sexpr/sexpr_parser.h>
// The main sheet of the project
SCH_SHEET* g_RootSheet = NULL;
@ -135,9 +135,9 @@ static struct IFACE : public KIFACE_I
* the project doesn't know the internal format of the various files (which may have
* paths in them that need updating).
*/
void SaveFileAs( const std::string& aProjectBasePath, const std::string& aProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors ) override;
void SaveFileAs( const wxString& aProjectBasePath, const wxString& aProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors ) override;
} kiface( "eeschema", KIWAY::FACE_SCH );
@ -311,15 +311,15 @@ static void traverseSEXPR( SEXPR::SEXPR* aNode,
if( aNode->IsList() )
{
for( int i = 0; i < aNode->GetNumberOfChildren(); i++ )
for( unsigned i = 0; i < aNode->GetNumberOfChildren(); i++ )
traverseSEXPR( aNode->GetChild( i ), aVisitor );
}
}
void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string& aProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors )
void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
@ -366,7 +366,7 @@ void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string&
try
{
SEXPR::PARSER parser;
std::unique_ptr<SEXPR::SEXPR> sexpr( parser.ParseFromFile( aSrcFilePath ) );
std::unique_ptr<SEXPR::SEXPR> sexpr( parser.ParseFromFile( TO_UTF8( aSrcFilePath ) ) );
traverseSEXPR( sexpr.get(), [&]( SEXPR::SEXPR* node )
{
@ -416,7 +416,7 @@ void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string&
SYMBOL_LIB_TABLE symbolLibTable;
symbolLibTable.Load( aSrcFilePath );
for( int i = 0; i < symbolLibTable.GetCount(); i++ )
for( unsigned i = 0; i < symbolLibTable.GetCount(); i++ )
{
LIB_TABLE_ROW& row = symbolLibTable.At( i );
wxString uri = row.GetFullURI();

View File

@ -100,9 +100,9 @@ static struct IFACE : public KIFACE_I
* the project doesn't know the internal format of the various files (which may have
* paths in them that need updating).
*/
void SaveFileAs( const std::string& aProjectBasePath, const std::string& aProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors ) override;
void SaveFileAs( const wxString& aProjectBasePath, const wxString& aProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors ) override;
} kiface( "gerbview", KIWAY::FACE_GERBVIEW );
@ -144,9 +144,9 @@ void IFACE::OnKifaceEnd()
}
void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string& aProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors )
void GERBV::IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();

View File

@ -63,9 +63,9 @@ bool CanPrintFile( const wxString& file );
* Function CopyFile
* @param aSrcPath
* @param aDestPath
* @param aErrors a string to *append* any errors to
* @param aErrors a wxString to *append* any errors to
*/
void CopyFile( const wxString& aSrcPath, const wxString& aDestPath, std::string& aErrors );
void CopyFile( const wxString& aSrcPath, const wxString& aDestPath, wxString& aErrors );
/**
* Function EDA_FILE_SELECTOR

View File

@ -217,12 +217,12 @@ struct KIFACE
* the project doesn't know the internal format of the various files (which may have
* paths in them that need updating).
*/
VTBL_ENTRY void SaveFileAs( const std::string& srcProjectBasePath,
const std::string& srcProjectName,
const std::string& newProjectBasePath,
const std::string& newProjectName,
const std::string& srcFilePath,
std::string& aErrors )
VTBL_ENTRY void SaveFileAs( const wxString& srcProjectBasePath,
const wxString& srcProjectName,
const wxString& newProjectBasePath,
const wxString& newProjectName,
const wxString& srcFilePath,
wxString& aErrors )
{
// If a KIFACE owns files then it needs to implement this....
}

View File

@ -18,7 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gestfich.h>
#include <wildcards_and_files_ext.h>
#include <executable_names.h>
#include <pgm_base.h>
@ -32,6 +31,7 @@
#include <tools/kicad_manager_actions.h>
#include <tools/kicad_manager_control.h>
#include <dialogs/dialog_template_selector.h>
#include <gestfich.h>
///> Helper widget to select whether a new directory should be created for a project
class DIR_CHECKBOX : public wxPanel
@ -134,7 +134,7 @@ int KICAD_MANAGER_CONTROL::NewProject( const TOOL_EVENT& aEvent )
m_frame->CreateNewProject( pro );
m_frame->LoadProject( pro );
return 0;
}
@ -179,7 +179,7 @@ int KICAD_MANAGER_CONTROL::NewFromTemplate( const TOOL_EVENT& aEvent )
// Get project destination folder and project file name.
wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep();
wxString title = _( "New Project Folder" );
wxFileDialog dlg( m_frame, title, default_dir, wxEmptyString, ProjectFileWildcard(),
wxFileDialog dlg( m_frame, title, default_dir, wxEmptyString, ProjectFileWildcard(),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
// Add a "Create a new directory" checkbox
@ -324,14 +324,14 @@ private:
wxString m_newProjectName;
wxFileName m_newProjectFile;
std::string m_errors;
wxString m_errors;
public:
SAVE_AS_TRAVERSER( KICAD_MANAGER_FRAME* aFrame,
const std::string& aSrcProjectDirPath,
const std::string& aSrcProjectName,
const std::string& aNewProjectDirPath,
const std::string& aNewProjectName ) :
const wxString& aSrcProjectDirPath,
const wxString& aSrcProjectName,
const wxString& aNewProjectDirPath,
const wxString& aNewProjectName ) :
m_frame( aFrame ),
m_projectDirPath( aSrcProjectDirPath ),
m_projectName( aSrcProjectName ),
@ -340,7 +340,7 @@ public:
{
}
virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath )
virtual wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override
{
wxFileName destFile( aSrcFilePath );
wxString ext = destFile.GetExt();
@ -436,7 +436,7 @@ public:
return wxDIR_CONTINUE;
}
virtual wxDirTraverseResult OnDir( const wxString& dirPath )
virtual wxDirTraverseResult OnDir( const wxString& dirPath ) override
{
wxFileName destDir( dirPath );
wxString destDirPath = destDir.GetPath(); // strips off last directory
@ -591,7 +591,7 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
if( !player->IsVisible() ) // A hidden frame might not have the document loaded.
{
wxString filepath;
if( playerType == FRAME_SCH )
{
filepath = m_frame->SchFileName();
@ -600,7 +600,7 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
{
wxFileName kicad_board( m_frame->PcbFileName() );
wxFileName legacy_board( m_frame->PcbLegacyFileName() );
if( !legacy_board.FileExists() || kicad_board.FileExists() )
filepath = kicad_board.GetFullPath();
else

View File

@ -92,9 +92,9 @@ static struct IFACE : public KIFACE_I
* the project doesn't know the internal format of the various files (which may have
* paths in them that need updating).
*/
void SaveFileAs( const std::string& aProjectBasePath, const std::string& aSrcProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors ) override;
void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors ) override;
} kiface( "pl_editor", KIWAY::FACE_PL_EDITOR );
@ -136,9 +136,9 @@ void IFACE::OnKifaceEnd()
}
void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string& aSrcProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors )
void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();

View File

@ -167,9 +167,9 @@ static struct IFACE : public KIFACE_I
* the project doesn't know the internal format of the various files (which may have
* paths in them that need updating).
*/
void SaveFileAs( const std::string& aProjectBasePath, const std::string& aSrcProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors ) override;
void SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors ) override;
} kiface( "pcbnew", KIWAY::FACE_PCB );
@ -386,9 +386,9 @@ void IFACE::OnKifaceEnd()
}
void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string& aSrcProjectName,
const std::string& aNewProjectBasePath, const std::string& aNewProjectName,
const std::string& aSrcFilePath, std::string& aErrors )
void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcProjectName,
const wxString& aNewProjectBasePath, const wxString& aNewProjectName,
const wxString& aSrcFilePath, wxString& aErrors )
{
wxFileName destFile( aSrcFilePath );
wxString destPath = destFile.GetPath();
@ -442,7 +442,7 @@ void IFACE::SaveFileAs( const std::string& aProjectBasePath, const std::string&
FP_LIB_TABLE fpLibTable;
fpLibTable.Load( aSrcFilePath );
for( int i = 0; i < fpLibTable.GetCount(); i++ )
for( unsigned i = 0; i < fpLibTable.GetCount(); i++ )
{
LIB_TABLE_ROW& row = fpLibTable.At( i );
wxString uri = row.GetFullURI();