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)
This commit is contained in:
parent
6da5e2cdd0
commit
fc6d73813e
|
@ -155,6 +155,13 @@ public:
|
|||
*/
|
||||
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
|
||||
* 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 )
|
|||
|
||||
// Toolbar events
|
||||
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_SAVE_PROJECT, KICAD_MANAGER_FRAME::OnSaveProject )
|
||||
EVT_TOOL( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles )
|
||||
|
|
|
@ -289,6 +289,32 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
|
|||
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 )
|
||||
{
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include <wx/txtstrm.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
#include <macros.h>
|
||||
|
||||
|
||||
#define SEP() wxFileName::GetPathSeparator()
|
||||
|
||||
|
||||
|
@ -92,7 +95,7 @@ std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList()
|
|||
}
|
||||
|
||||
|
||||
wxString PROJECT_TEMPLATE::GetName()
|
||||
wxString PROJECT_TEMPLATE::GetPrjDirName()
|
||||
{
|
||||
return templateBasePath.GetDirs()[ templateBasePath.GetDirCount()-1 ];
|
||||
}
|
||||
|
@ -121,21 +124,17 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
|
|||
bool result = true;
|
||||
|
||||
std::vector<wxFileName> srcFiles = GetFileList();
|
||||
std::vector<wxFileName> dstFiles;
|
||||
|
||||
for( size_t i=0; i < srcFiles.size(); i++ )
|
||||
{
|
||||
// Replace the template path
|
||||
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!)
|
||||
if( destination.GetExt() != wxEmptyString )
|
||||
destname += wxT(".") + destination.GetExt();
|
||||
// Replace the template filename with the project filename for the new project creation
|
||||
destination.SetName( aNewProjectPath.GetName() );
|
||||
|
||||
// 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();
|
||||
destpath.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
|
||||
|
||||
|
@ -145,11 +144,10 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath )
|
|||
if( !wxFileName::DirExists( destpath ) )
|
||||
wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL );
|
||||
|
||||
destination = destpath + destname;
|
||||
dstFiles.push_back( destination );
|
||||
destination.SetPath( destpath );
|
||||
|
||||
wxString srcFile = srcFiles[i].GetFullPath();
|
||||
wxString dstFile = dstFiles[i].GetFullPath();
|
||||
wxString dstFile = destination.GetFullPath();
|
||||
|
||||
if( !wxCopyFile( srcFile, dstFile ) )
|
||||
{
|
||||
|
|
|
@ -165,10 +165,11 @@ public:
|
|||
~PROJECT_TEMPLATE();
|
||||
|
||||
/**
|
||||
* @brief Get the system name of the project template
|
||||
* @return the system name of the template
|
||||
* @brief Get the dir name of the project 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
|
||||
|
|
|
@ -46,4 +46,6 @@ DIALOG_SELECT_PRETTY_LIB::DIALOG_SELECT_PRETTY_LIB( wxWindow* parent ) :
|
|||
void DIALOG_SELECT_PRETTY_LIB::OnSelectFolder( wxTreeEvent& event )
|
||||
{
|
||||
m_libName->SetValue( m_dirCtrl->GetPath() );
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue