Make KiCad default template the default

Should clear up new project questions

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21651

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21675
This commit is contained in:
Seth Hillbrand 2025-09-08 12:16:16 -07:00
parent fdbf740ee2
commit 09c40a0e0f
4 changed files with 202 additions and 125 deletions

View File

@ -30,96 +30,10 @@
#include <wx/dir.h>
#include <wx/dirdlg.h>
#include <wx/settings.h>
#include <wx/bitmap.h>
#include "template_default_html.h"
static const wxString GetWelcomeHtml()
{
return wxString(
"<!DOCTYPE html>"
"<html lang=\"en\">"
"<head>"
"<meta charset=\"UTF-8\">"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
"<title>KiCad Project Template Selector</title>"
"<style>"
"body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; margin: 0; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #333; min-height: 100vh; box-sizing: border-box; }"
".container { max-width: 800px; margin: 0 auto; background: rgba(255, 255, 255, 0.95); border-radius: 12px; padding: 30px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); backdrop-filter: blur(10px); }"
".header { text-align: center; margin-bottom: 30px; }"
".logo { font-size: 2.5rem; font-weight: bold; color: #4a5568; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); }"
".subtitle { font-size: 1.2rem; color: #666; margin-bottom: 20px; }"
".welcome-card { "
#if defined( __MINGW32__ )
"background: #4299e1;" // linear-gradient does not work with webview used on MSYS2
#else
"background: linear-gradient(135deg, #4299e1, #3182ce);"
#endif
"color: white; padding: 25px; border-radius: 10px; margin-bottom: 25px; box-shadow: 0 4px 15px rgba(66, 153, 225, 0.3); }"
".welcome-card h2 { margin-top: 0; font-size: 1.8rem; margin-bottom: 15px; }"
".instructions { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 25px; }"
".instruction-card { background: #f7fafc; border: 2px solid #e2e8f0; border-radius: 8px; padding: 20px; transition: all 0.3s ease; position: relative; overflow: hidden; }"
".instruction-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); border-color: #4299e1; }"
".instruction-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: linear-gradient(135deg, #4299e1, #3182ce); }"
".instruction-card h3 { color: #2d3748; margin-top: 0; margin-bottom: 10px; font-size: 1.3rem; }"
".instruction-card p { color: #4a5568; line-height: 1.6; margin: 0; }"
".features { background: #f0fff4; border: 2px solid #9ae6b4; border-radius: 8px; padding: 20px; margin-bottom: 25px; }"
".features h3 { color: #22543d; margin-top: 0; margin-bottom: 15px; font-size: 1.4rem; }"
".features ul { color: #2f855a; line-height: 1.8; margin: 0; padding-left: 20px; }"
".features li { margin-bottom: 8px; }"
".tips { background: #fffaf0; border: 2px solid #fbd38d; border-radius: 8px; padding: 20px; }"
".tips h3 { color: #c05621; margin-top: 0; margin-bottom: 15px; font-size: 1.4rem; }"
".tips p { color: #c05621; line-height: 1.6; margin: 0 0 10px 0; }"
".highlight { background: linear-gradient(120deg, #a8edea 0%, #fed6e3 100%); padding: 2px 6px; border-radius: 4px; font-weight: 600; }"
"</style>"
"</head>"
"<body>"
"<div class=\"container\">"
"<div class=\"header\">"
"<div class=\"logo\">KiCad 📑</div>"
"<div class=\"subtitle\">" + _( "Project Template Selector" ) + "</div>"
"</div>"
"<div class=\"welcome-card\">"
"<h2>" + _( "Welcome to Template Selection!" ) + "</h2>"
"<p>" + _( "Choose from a variety of pre-configured project templates to jumpstart your PCB design. Templates provide ready-to-use project structures with common components, libraries, and design rules." ) + "</p>"
"</div>"
"<div class=\"instructions\">"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Browse Templates" ) + "</h3>"
"<p>" + _( "Navigate through the template tabs above to explore different categories of project templates. Each tab contains templates organized by type or complexity." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Select a Template" ) + "</h3>"
"<p>" + _( "Click on any template in the list to " ) + "<span class=\"highlight\">" + _( "preview its details" ) + "</span>. " + _( "The template information will appear in this panel, showing descriptions, included components, and project structure." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Customize Path" ) + "</h3>"
"<p>" + _( "Use the " ) + "<span class=\"highlight\">" + _( "folder path field" ) + "</span> " + _( "above to browse custom template directories. Click the folder icon to browse, or the refresh icon to reload templates." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Create Project" ) + "</h3>"
"<p>" + _( "Once you've found the right template, click " ) + "<span class=\"highlight\">" + _( "OK" ) + "</span> " + _( "to create a new project based on the selected template. Your project will inherit all template settings and files." ) + "</p>"
"</div>"
"</div>"
"<div class=\"features\">"
"<h3>" + _( "What You Get with Templates" ) + "</h3>"
"<ul>"
"<li><strong>" + _( "Pre-configured libraries" ) + "</strong> " + _( "- Common components and footprints already linked" ) + "</li>"
"<li><strong>" + _( "Design rules" ) + "</strong> " + _( "- Appropriate electrical and mechanical constraints" ) + "</li>"
"<li><strong>" + _( "Layer stackups" ) + "</strong> " + _( "- Optimized for the intended application" ) + "</li>"
"<li><strong>" + _( "Component placement" ) + "</strong> " + _( "- Basic layout and routing guidelines" ) + "</li>"
"<li><strong>" + _( "Documentation" ) + "</strong> " + _( "- README files and design notes" ) + "</li>"
"<li><strong>" + _( "Manufacturing files" ) + "</strong> " + _( "- Gerber and drill file configurations" ) + "</li>"
"</ul>"
"</div>"
"<div class=\"tips\">"
"<h3>" + _( "Pro Tips" ) + "</h3>"
"<p><strong>" + _( "Start Simple:" ) + "</strong> " + _( "Begin with basic templates and add more elements as you go." ) + "</p>"
"<p><strong>" + _( "Customize Later:" ) + "</strong> " + _( "Templates are starting points - you can modify libraries, rules, and layouts after project creation." ) + "</p>"
"<p><strong>" + _( "Save Your Own:" ) + "</strong> " + _( "Once you develop preferred settings, create a custom template for future projects." ) + "</p>"
"</div>"
"</div>"
"</body>"
"</html>"
);
}
// Welcome / fallback HTML now provided by template_default_html.h
TEMPLATE_SELECTION_PANEL::TEMPLATE_SELECTION_PANEL( wxNotebookPage* aParent,
const wxString& aPath ) :
@ -182,7 +96,12 @@ void TEMPLATE_WIDGET::SetTemplate( PROJECT_TEMPLATE* aTemplate )
m_staticTitle->SetFont( KIUI::GetInfoFont( this ) );
m_staticTitle->SetLabel( *aTemplate->GetTitle() );
m_staticTitle->Wrap( 100 );
m_bitmapIcon->SetBitmap( *aTemplate->GetIcon() );
wxBitmap* icon = aTemplate->GetIcon();
if( icon && icon->IsOk() )
m_bitmapIcon->SetBitmap( *icon );
else
m_bitmapIcon->SetBitmap( KiBitmap( BITMAPS::icon_kicad ) );
}
@ -229,7 +148,7 @@ void DIALOG_TEMPLATE_SELECTOR::OnPageChange( wxNotebookEvent& event )
DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos,
const wxSize& aSize,
std::map<wxString, wxFileName> aTitleDirMap,
std::vector<std::pair<wxString, wxFileName>> aTitleDirList,
const wxFileName& aDefaultTemplate ) :
DIALOG_TEMPLATE_SELECTOR_BASE( aParent, wxID_ANY, _( "Project Template Selector" ), aPos,
aSize )
@ -241,7 +160,7 @@ DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxP
m_defaultTemplatePath = aDefaultTemplate;
m_defaultWidget = nullptr;
for( auto& [title, pathFname] : aTitleDirMap )
for( auto& [title, pathFname] : aTitleDirList )
{
pathFname.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
wxString path = pathFname.GetFullPath(); // caller ensures this ends with file separator.
@ -291,7 +210,7 @@ DIALOG_TEMPLATE_SELECTOR::DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxP
{
wxFileName htmlFile = m_selectedWidget->GetTemplate()->GetHtmlFile();
if( htmlFile.FileExists() && htmlFile.IsFileReadable() )
if( htmlFile.FileExists() && htmlFile.IsFileReadable() && htmlFile.GetSize() > 100 /* Basic HTML */ )
m_webviewPanel->LoadURL( wxFileName::FileNameToURL( htmlFile ) );
else
m_webviewPanel->SetPage( GetWelcomeHtml() );
@ -321,21 +240,7 @@ void DIALOG_TEMPLATE_SELECTOR::SetWidget( TEMPLATE_WIDGET* aWidget )
}
else
{
// Fallback to a simple template info page if no HTML file exists
wxString templateHtml = wxString::Format(
"<!DOCTYPE html>"
"<html><head><meta charset='UTF-8'><style>"
"body { font-family: Arial, sans-serif; margin: 20px; }"
".template-info { background: #f0f8ff; padding: 20px; border-radius: 8px; }"
"h1 { color: #333; margin-top: 0; }"
"</style></head><body>"
"<div class='template-info'>"
"<h1>%s</h1>"
"<p>Template selected. Click OK to create a new project based on this template.</p>"
"</div></body></html>",
*aWidget->GetTemplate()->GetTitle()
);
m_webviewPanel->SetPage( templateHtml );
m_webviewPanel->SetPage( GetTemplateInfoHtml( *aWidget->GetTemplate()->GetTitle() ) );
}
}
@ -345,12 +250,21 @@ void DIALOG_TEMPLATE_SELECTOR::AddTemplate( int aPage, PROJECT_TEMPLATE* aTempla
TEMPLATE_WIDGET* w = new TEMPLATE_WIDGET( m_panels[aPage]->m_scrolledWindow, this );
w->SetTemplate( aTemplate );
m_panels[aPage]->AddTemplateWidget( w );
m_allWidgets.push_back( w );
wxFileName base = aTemplate->GetHtmlFile();
base.RemoveLastDir();
if( m_defaultTemplatePath.IsOk() && base == m_defaultTemplatePath )
if( !m_defaultWidget || (m_defaultTemplatePath.IsOk() && base == m_defaultTemplatePath) )
m_defaultWidget = w;
wxString dirName = base.GetDirs().IsEmpty() ? wxString() : base.GetDirs().back();
if( dirName.CmpNoCase( "default" ) == 0 )
{
// Prefer a directory literally named 'default'
m_defaultWidget = w;
}
}
@ -359,6 +273,11 @@ PROJECT_TEMPLATE* DIALOG_TEMPLATE_SELECTOR::GetSelectedTemplate()
return m_selectedWidget? m_selectedWidget->GetTemplate() : nullptr;
}
PROJECT_TEMPLATE* DIALOG_TEMPLATE_SELECTOR::GetDefaultTemplate()
{
return m_defaultWidget? m_defaultWidget->GetTemplate() : nullptr;
}
void DIALOG_TEMPLATE_SELECTOR::buildPageContent( const wxString& aPath, int aPage )
{

View File

@ -29,7 +29,8 @@
#include <widgets/webview_panel.h>
#include "project_template.h"
#include <map>
#include <vector>
#include <utility>
#include <wx/filename.h>
class DIALOG_TEMPLATE_SELECTOR;
@ -91,13 +92,14 @@ class DIALOG_TEMPLATE_SELECTOR : public DIALOG_TEMPLATE_SELECTOR_BASE
{
public:
DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize,
std::map<wxString, wxFileName> aTitleDirMap,
std::vector<std::pair<wxString, wxFileName>> aTitleDirList,
const wxFileName& aDefaultTemplate );
/**
* @return the selected template, or NULL
*/
PROJECT_TEMPLATE* GetSelectedTemplate();
PROJECT_TEMPLATE* GetDefaultTemplate();
void SetWidget( TEMPLATE_WIDGET* aWidget );
@ -123,6 +125,8 @@ protected:
TEMPLATE_WIDGET* m_selectedWidget;
wxFileName m_defaultTemplatePath;
TEMPLATE_WIDGET* m_defaultWidget;
// Keep track of all template widgets so we can pick a sensible default
std::vector<TEMPLATE_WIDGET*> m_allWidgets;
};
#endif

View File

@ -0,0 +1,149 @@
/*
* KiCad Project Template HTML defaults
* Extracted from dialog_template_selector.cpp to allow reuse and to provide
* a styled fallback page when a template does not supply an info.html.
*/
#ifndef KICAD_TEMPLATE_DEFAULT_HTML_H
#define KICAD_TEMPLATE_DEFAULT_HTML_H
#include <wx/string.h>
// Uses _() translation macro which is defined globally in KiCad builds.
// Welcome (no template selected) page.
inline wxString GetWelcomeHtml()
{
return wxString(
"<!DOCTYPE html>"
"<html lang=\"en\">"
"<head>"
"<meta charset=\"UTF-8\">"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
"<title>KiCad Project Template Selector</title>"
"<style>"
"body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; margin: 0; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #333; min-height: 100vh; box-sizing: border-box; }"
".container { max-width: 800px; margin: 0 auto; background: rgba(255, 255, 255, 0.95); border-radius: 12px; padding: 30px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); backdrop-filter: blur(10px); }"
".header { text-align: center; margin-bottom: 30px; }"
".logo { font-size: 2.5rem; font-weight: bold; color: #4a5568; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); }"
".subtitle { font-size: 1.2rem; color: #666; margin-bottom: 20px; }"
".welcome-card { "
#if defined( __MINGW32__ )
"background: #4299e1;" // linear-gradient does not work with webview used on MSYS2
#else
"background: linear-gradient(135deg, #4299e1, #3182ce);"
#endif
"color: white; padding: 25px; border-radius: 10px; margin-bottom: 25px; box-shadow: 0 4px 15px rgba(66, 153, 225, 0.3); }"
".welcome-card h2 { margin-top: 0; font-size: 1.8rem; margin-bottom: 15px; }"
".instructions { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 25px; }"
".instruction-card { background: #f7fafc; border: 2px solid #e2e8f0; border-radius: 8px; padding: 20px; transition: all 0.3s ease; position: relative; overflow: hidden; }"
".instruction-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); border-color: #4299e1; }"
".instruction-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: linear-gradient(135deg, #4299e1, #3182ce); }"
".instruction-card h3 { color: #2d3748; margin-top: 0; margin-bottom: 10px; font-size: 1.3rem; }"
".instruction-card p { color: #4a5568; line-height: 1.6; margin: 0; }"
".features { background: #f0fff4; border: 2px solid #9ae6b4; border-radius: 8px; padding: 20px; margin-bottom: 25px; }"
".features h3 { color: #22543d; margin-top: 0; margin-bottom: 15px; font-size: 1.4rem; }"
".features ul { color: #2f855a; line-height: 1.8; margin: 0; padding-left: 20px; }"
".features li { margin-bottom: 8px; }"
".tips { background: #fffaf0; border: 2px solid #fbd38d; border-radius: 8px; padding: 20px; }"
".tips h3 { color: #c05621; margin-top: 0; margin-bottom: 15px; font-size: 1.4rem; }"
".tips p { color: #c05621; line-height: 1.6; margin: 0 0 10px 0; }"
".highlight { background: linear-gradient(120deg, #a8edea 0%, #fed6e3 100%); padding: 2px 6px; border-radius: 4px; font-weight: 600; }"
"</style>"
"</head>"
"<body>"
"<div class=\"container\">"
"<div class=\"header\">"
"<div class=\"logo\">KiCad 📑</div>"
"<div class=\"subtitle\">" + _( "Project Template Selector" ) + "</div>"
"</div>"
"<div class=\"welcome-card\">"
"<h2>" + _( "Welcome to Template Selection!" ) + "</h2>"
"<p>" + _( "Choose from a variety of pre-configured project templates to jumpstart your PCB design. Templates provide ready-to-use project structures with common components, libraries, and design rules." ) + "</p>"
"</div>"
"<div class=\"instructions\">"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Browse Templates" ) + "</h3>"
"<p>" + _( "Navigate through the template tabs above to explore different categories of project templates. Each tab contains templates organized by type or complexity." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Select a Template" ) + "</h3>"
"<p>" + _( "Click on any template in the list to " ) + "<span class=\"highlight\">" + _( "preview its details" ) + "</span>. " + _( "The template information will appear in this panel, showing descriptions, included components, and project structure." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Customize Path" ) + "</h3>"
"<p>" + _( "Use the " ) + "<span class=\"highlight\">" + _( "folder path field" ) + "</span> " + _( "above to browse custom template directories. Click the folder icon to browse, or the refresh icon to reload templates." ) + "</p>"
"</div>"
"<div class=\"instruction-card\">"
"<h3>→ " + _( "Create Project" ) + "</h3>"
"<p>" + _( "Once you've found the right template, click " ) + "<span class=\"highlight\">" + _( "OK" ) + "</span> " + _( "to create a new project based on the selected template. Your project will inherit all template settings and files." ) + "</p>"
"</div>"
"</div>"
"<div class=\"features\">"
"<h3>" + _( "What You Get with Templates" ) + "</h3>"
"<ul>"
"<li><strong>" + _( "Pre-configured libraries" ) + "</strong> " + _( "- Common components and footprints already linked" ) + "</li>"
"<li><strong>" + _( "Design rules" ) + "</strong> " + _( "- Appropriate electrical and mechanical constraints" ) + "</li>"
"<li><strong>" + _( "Layer stackups" ) + "</strong> " + _( "- Optimized for the intended application" ) + "</li>"
"<li><strong>" + _( "Component placement" ) + "</strong> " + _( "- Basic layout and routing guidelines" ) + "</li>"
"<li><strong>" + _( "Documentation" ) + "</strong> " + _( "- README files and design notes" ) + "</li>"
"<li><strong>" + _( "Manufacturing files" ) + "</strong> " + _( "- Gerber and drill file configurations" ) + "</li>"
"</ul>"
"</div>"
"<div class=\"tips\">"
"<h3>" + _( "Pro Tips" ) + "</h3>"
"<p><strong>" + _( "Start Simple:" ) + "</strong> " + _( "Begin with basic templates and add more elements as you go." ) + "</p>"
"<p><strong>" + _( "Customize Later:" ) + "</strong> " + _( "Templates are starting points - you can modify libraries, rules, and layouts after project creation." ) + "</p>"
"<p><strong>" + _( "Save Your Own:" ) + "</strong> " + _( "Once you develop preferred settings, create a custom template for future projects." ) + "</p>"
"</div>"
"</div>"
"</body>"
"</html>"
);
}
// Fallback when a specific template has no meta/info.html.
inline wxString GetTemplateInfoHtml( const wxString& aTemplateName )
{
return wxString(
"<!DOCTYPE html>"
"<html lang=\"en\">"
"<head>"
"<meta charset=\"UTF-8\">"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
"<title>" + aTemplateName + " - KiCad Template</title>"
"<style>"
"body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; margin:0; padding:20px; background:#edf2f7; color:#2d3748; }"
".container { max-width: 780px; margin:0 auto; background:#ffffff; border-radius:12px; padding:32px; box-shadow:0 6px 24px rgba(0,0,0,0.08); }"
".header { display:flex; align-items:center; gap:12px; margin-bottom:24px; }"
".badge { background:#3182ce; color:white; padding:4px 10px; border-radius:6px; font-size:0.75rem; letter-spacing:0.05em; text-transform:uppercase; }"
"h1 { font-size:1.9rem; margin:0; }"
"p { line-height:1.55; }"
".cta { background:#ebf8ff; border:1px solid #bee3f8; padding:16px 20px; border-radius:10px; margin:28px 0 18px; }"
".steps { display:grid; gap:16px; margin-top:10px; }"
".step { background:#f7fafc; border:1px solid #e2e8f0; padding:14px 16px; border-radius:8px; }"
".step h3 { margin:0 0 6px 0; font-size:1.05rem; }"
".edit-hint { background:#fffaf0; border:1px solid #fbd38d; padding:14px 16px; border-radius:8px; margin-top:24px; }"
"code { background:#f1f5f9; padding:2px 5px; border-radius:4px; font-size:0.85rem; }"
"</style>"
"</head><body><div class=\"container\">"
"<div class=\"header\"><div class=\"badge\">" + _( "Template" ) + "</div><h1>" + aTemplateName + "</h1></div>"
"<p>" + _( "This project template doesn't include an info page yet. You can still use it to create a new project." ) + "</p>"
"<div class=\"cta\">"
"<strong>" + _( "To use this template:" ) + "</strong>"
"<div class=\"steps\">"
"<div class=\"step\"><h3>1. " + _( "Create the project" ) + "</h3><p>" + _( "Click OK below. KiCad will create a new project folder populated with the contents of this template." ) + "</p></div>"
"<div class=\"step\"><h3>2. " + _( "Open schematic and PCB" ) + "</h3><p>" + _( "Use the Project Manager tree or launch Schematic and PCB editors to begin designing." ) + "</p></div>"
"<div class=\"step\"><h3>3. " + _( "Review libraries & settings" ) + "</h3><p>" + _( "Confirm symbol/footprint libraries, design rules, and board stackup match your needs." ) + "</p></div>"
"</div>" // steps
"</div>" // cta
"<div class=\"edit-hint\">"
"<strong>" + _( "Add an info page later:" ) + "</strong>"
"<p>" + _( "Create a file at" ) + " <code>meta/info.html</code> " + _( "inside this template's directory to provide rich documentation, images, or guidance." ) + "</p>"
"<p>" + _( "You can copy styling from the default pages for consistency." ) + "</p>"
"</div>"
"</div></body></html>"
);
}
#endif // KICAD_TEMPLATE_DEFAULT_HTML_H

View File

@ -203,28 +203,28 @@ int KICAD_MANAGER_CONTROL::NewProject( const TOOL_EVENT& aEvent )
}
KICAD_SETTINGS* settings = GetAppSettings<KICAD_SETTINGS>( "kicad" );
std::map<wxString, wxFileName> titleDirMap;
std::vector<std::pair<wxString, wxFileName>> titleDirList;
wxFileName templatePath;
ENV_VAR_MAP_CITER itUser = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
if( itUser != Pgm().GetLocalEnvVariables().end() && itUser->second.GetValue() != wxEmptyString )
{
templatePath.AssignDir( itUser->second.GetValue() );
titleDirList.emplace_back( _( "User Templates" ), templatePath );
}
std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( Pgm().GetLocalEnvVariables(),
wxT( "TEMPLATE_DIR" ) );
if( v && !v->IsEmpty() )
{
templatePath.AssignDir( *v );
titleDirMap.emplace( _( "System Templates" ), templatePath );
}
ENV_VAR_MAP_CITER itUser = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
if( itUser != Pgm().GetLocalEnvVariables().end() && itUser->second.GetValue() != wxEmptyString )
{
templatePath.AssignDir( itUser->second.GetValue() );
titleDirMap.emplace( _( "User Templates" ), templatePath );
titleDirList.emplace_back( _( "System Templates" ), templatePath );
}
DIALOG_TEMPLATE_SELECTOR ps( m_frame, settings->m_TemplateWindowPos, settings->m_TemplateWindowSize,
titleDirMap, defaultTemplate );
titleDirList, defaultTemplate );
int result = ps.ShowModal();
@ -234,7 +234,12 @@ int KICAD_MANAGER_CONTROL::NewProject( const TOOL_EVENT& aEvent )
if( result != wxID_OK )
return -1;
if( !ps.GetSelectedTemplate() )
PROJECT_TEMPLATE* selectedTemplate = ps.GetSelectedTemplate();
if( !selectedTemplate )
selectedTemplate = ps.GetDefaultTemplate();
if( !selectedTemplate )
{
wxMessageBox( _( "No project template was selected. Cannot generate new project." ), _( "Error" ),
wxOK | wxICON_ERROR, m_frame );
@ -288,7 +293,7 @@ int KICAD_MANAGER_CONTROL::NewProject( const TOOL_EVENT& aEvent )
std::vector< wxFileName > destFiles;
if( ps.GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) )
if( selectedTemplate->GetDestinationFiles( fn, destFiles ) )
{
std::vector<wxFileName> overwrittenFiles;
@ -318,7 +323,7 @@ int KICAD_MANAGER_CONTROL::NewProject( const TOOL_EVENT& aEvent )
wxString errorMsg;
if( !ps.GetSelectedTemplate()->CreateProject( fn, &errorMsg ) )
if( !selectedTemplate->CreateProject( fn, &errorMsg ) )
{
DisplayErrorMessage( m_frame, _( "A problem occurred creating new project from template." ), errorMsg );
return -1;