Commit fc6d7381 authored by jean-pierre charras's avatar jean-pierre charras

Kicad: more understandable dialog when creating a project from template. Fix...

Kicad:  more understandable dialog when creating a project from template. Fix also a bug when copying and renaming template files.
Pcbnew: dialog to create new .pretty lib: fix an issue which prevent to open a full disk directory (at least on Windows)
parent 6da5e2cd
...@@ -155,6 +155,13 @@ public: ...@@ -155,6 +155,13 @@ public:
*/ */
void OnLoadProject( wxCommandEvent& event ); void OnLoadProject( wxCommandEvent& event );
/**
* Function OnCreateProjectFromTemplate
* Creates a new project folder, copy a template into this new folder.
* and open this new projrct as working project
*/
void OnCreateProjectFromTemplate( wxCommandEvent& event );
/** /**
* Function OnSaveProject * Function OnSaveProject
* is the command event hendler to Save the project (.pro) file containing the top level * is the command event hendler to Save the project (.pro) file containing the top level
......
...@@ -41,7 +41,7 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME ) ...@@ -41,7 +41,7 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
// Toolbar events // Toolbar events
EVT_TOOL( ID_NEW_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject ) EVT_TOOL( ID_NEW_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject )
EVT_TOOL( ID_NEW_PROJECT_FROM_TEMPLATE, KICAD_MANAGER_FRAME::OnLoadProject ) EVT_TOOL( ID_NEW_PROJECT_FROM_TEMPLATE, KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate )
EVT_TOOL( ID_LOAD_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject ) EVT_TOOL( ID_LOAD_PROJECT, KICAD_MANAGER_FRAME::OnLoadProject )
EVT_TOOL( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject ) EVT_TOOL( ID_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject )
EVT_TOOL( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles ) EVT_TOOL( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles )
......
...@@ -289,6 +289,32 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) ...@@ -289,6 +289,32 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
PrintPrjInfo(); PrintPrjInfo();
} }
/* Creates a new project folder, copy a template into this new folder.
* and open this new projrct as working project
*/
void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event )
{
wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep();
wxString title = _("New Project Folder");
wxDirDialog dlg( this, title, default_dir );
if( dlg.ShowModal() == wxID_CANCEL )
return;
// Buils the project .pro filename, from the new project folder name
wxFileName fn;
fn.AssignDir( dlg.GetPath() );
fn.SetName( dlg.GetPath().AfterLast( SEP() ) );
fn.SetExt( wxT( "pro" ) );
// Launch the template selector dialog, and copy files
CreateNewProject( fn.GetFullPath(), true );
// Initialize the project
event.SetId( wxID_ANY );
OnLoadProject( event );
}
void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
{ {
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include <wx/txtstrm.h> #include <wx/txtstrm.h>
#include <wx/wfstream.h> #include <wx/wfstream.h>
#include <macros.h>
#define SEP() wxFileName::GetPathSeparator() #define SEP() wxFileName::GetPathSeparator()
...@@ -92,7 +95,7 @@ std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList() ...@@ -92,7 +95,7 @@ std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList()
} }
wxString PROJECT_TEMPLATE::GetName() wxString PROJECT_TEMPLATE::GetPrjDirName()
{ {
return templateBasePath.GetDirs()[ templateBasePath.GetDirCount()-1 ]; return templateBasePath.GetDirs()[ templateBasePath.GetDirCount()-1 ];
} }
...@@ -121,21 +124,17 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath ) ...@@ -121,21 +124,17 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
bool result = true; bool result = true;
std::vector<wxFileName> srcFiles = GetFileList(); std::vector<wxFileName> srcFiles = GetFileList();
std::vector<wxFileName> dstFiles;
for( size_t i=0; i < srcFiles.size(); i++ ) for( size_t i=0; i < srcFiles.size(); i++ )
{ {
// Replace the template path // Replace the template path
wxFileName destination = srcFiles[i]; wxFileName destination = srcFiles[i];
wxString destname = destination.GetName();
// Replace the template name with the project name for the new project creation
destname.Replace( GetName(), aNewProjectPath.GetName() );
// Add the file extension (if there was one!) // Replace the template filename with the project filename for the new project creation
if( destination.GetExt() != wxEmptyString ) destination.SetName( aNewProjectPath.GetName() );
destname += wxT(".") + destination.GetExt();
// Replace the template path with the project path for the new project creation
// but keep the sub directory name, if exists
wxString destpath = destination.GetPathWithSep(); wxString destpath = destination.GetPathWithSep();
destpath.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() ); destpath.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
...@@ -145,11 +144,10 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath ) ...@@ -145,11 +144,10 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
if( !wxFileName::DirExists( destpath ) ) if( !wxFileName::DirExists( destpath ) )
wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL ); wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL );
destination = destpath + destname; destination.SetPath( destpath );
dstFiles.push_back( destination );
wxString srcFile = srcFiles[i].GetFullPath(); wxString srcFile = srcFiles[i].GetFullPath();
wxString dstFile = dstFiles[i].GetFullPath(); wxString dstFile = destination.GetFullPath();
if( !wxCopyFile( srcFile, dstFile ) ) if( !wxCopyFile( srcFile, dstFile ) )
{ {
......
...@@ -165,10 +165,11 @@ public: ...@@ -165,10 +165,11 @@ public:
~PROJECT_TEMPLATE(); ~PROJECT_TEMPLATE();
/** /**
* @brief Get the system name of the project template * @brief Get the dir name of the project template
* @return the system name of the template * (i.e. the name of the last folder containing the template files)
* @return the dir name of the template
*/ */
wxString GetName(); wxString GetPrjDirName();
/** /**
* @brief Get the full Html filename for the project template * @brief Get the full Html filename for the project template
......
...@@ -46,4 +46,6 @@ DIALOG_SELECT_PRETTY_LIB::DIALOG_SELECT_PRETTY_LIB( wxWindow* parent ) : ...@@ -46,4 +46,6 @@ DIALOG_SELECT_PRETTY_LIB::DIALOG_SELECT_PRETTY_LIB( wxWindow* parent ) :
void DIALOG_SELECT_PRETTY_LIB::OnSelectFolder( wxTreeEvent& event ) void DIALOG_SELECT_PRETTY_LIB::OnSelectFolder( wxTreeEvent& event )
{ {
m_libName->SetValue( m_dirCtrl->GetPath() ); m_libName->SetValue( m_dirCtrl->GetPath() );
event.Skip();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment