33#include <wx/settings.h>
42 const wxString& aPath ) :
60 std::vector<TEMPLATE_WIDGET*> sortedList;
67 for(
size_t idx = 0; idx < count; idx++ )
70 if( item && item->IsWindow() )
76 if( default_temp ==
nullptr && title.CmpNoCase(
"default" ) == 0 )
79 sortedList.push_back( temp );
84 sortedList.begin(), sortedList.end(),
87 const wxString* a = aWidgetA->GetTemplate()->GetTitle();
88 const wxString* b = aWidgetB->GetTemplate()->GetTitle();
90 return ( *a ).CmpNoCase( *b ) < 0;
95 if( default_temp !=
nullptr )
132 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNHIGHLIGHT ) );
140 SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
152 wxBitmap* icon = aTemplate->
GetIcon();
154 if( icon && icon->IsOk() )
158 if( icon->GetWidth() > maxSize.x || icon->GetHeight() > maxSize.y )
160 double scale = std::min( (
double) maxSize.x / icon->GetWidth(),
161 (
double) maxSize.y / icon->GetHeight() );
162 wxImage
image = icon->ConvertToImage();
163 int w = wxRound( icon->GetWidth() *
scale );
164 int h = wxRound( icon->GetHeight() *
scale );
165 image.Rescale( w, h, wxIMAGE_QUALITY_HIGH );
188 int newPage =
event.GetSelection();
189 int oldPage =
event.GetOldSelection();
192 if( oldPage != wxNOT_FOUND && (
unsigned)oldPage <
m_panels.size() )
199 if( newPage != wxNOT_FOUND && (
unsigned)newPage <
m_panels.size() )
221 std::vector<std::pair<wxString, wxFileName>> aTitleDirList,
222 const wxFileName& aDefaultTemplate ) :
233 for(
auto& [title, pathFname] : aTitleDirList )
236 wxString
path = pathFname.GetFullPath();
253 wxSizer* parentSizer = m_webviewPanel->GetContainingSizer();
257 parentSizer->Detach( m_webviewPanel );
268 if( m_defaultWidget )
269 m_defaultWidget->Select();
276 m_tcTemplatePath->SelectNone();
279 if( m_selectedWidget )
281 wxFileName htmlFile = m_selectedWidget->GetTemplate()->GetHtmlFile();
283 if( htmlFile.FileExists() && htmlFile.IsFileReadable() && htmlFile.GetSize() > 100 )
284 m_webviewPanel->LoadURL( wxFileName::FileNameToURL( htmlFile ) );
295 finishDialogSettings();
307 if( htmlFile.FileExists() && htmlFile.IsFileReadable() )
322 m_panels[aPage]->AddTemplateWidget( w );
326 base.RemoveLastDir();
331 wxString dirName = base.GetDirs().IsEmpty() ? wxString() : base.GetDirs().back();
333 if( dirName.CmpNoCase(
"default" ) == 0 )
357 if( dir.Open( aPath ) )
359 if( dir.HasSubDirs(
"meta" ) )
366 wxArrayString subdirs;
368 bool cont = dir.GetFirst( &sub_name, wxEmptyString, wxDIR_DIRS );
372 subdirs.Add( wxString( sub_name ) );
373 cont = dir.GetNext( &sub_name );
376 if( !subdirs.IsEmpty() )
379 for(
const wxString& dir_name : subdirs )
382 wxString sub_full = aPath + dir_name;
384 if( sub_dir.Open( sub_full ) )
390 m_panels[aPage]->SortAlphabetically();
400 wxString currPath = fn.GetFullPath();
402 wxDirDialog dirDialog(
this,
_(
"Select Templates Directory" ), currPath,
403 wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
405 if( dirDialog.ShowModal() != wxID_OK )
408 wxFileName dirName = wxFileName::DirName( dirDialog.GetPath() );
429 currPath = fn.GetFullPath();
444 wxString title =
m_notebook->GetPageText( page );
451 if( (
unsigned)page <
m_panels.size() )
462 m_notebook->InsertPage( page, tpanel, title,
true );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
STD_BITMAP_BUTTON * m_browseButton
DIALOG_TEMPLATE_SELECTOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Project Template Selector"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(513, 523), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxTextCtrl * m_tcTemplatePath
STD_BITMAP_BUTTON * m_reloadButton
WEBVIEW_PANEL * m_webviewPanel
void AddTemplate(int aPage, PROJECT_TEMPLATE *aTemplate)
void OnPageChange(wxNotebookEvent &event) override
void onReload(wxCommandEvent &event) override
DIALOG_TEMPLATE_SELECTOR(wxWindow *aParent, const wxPoint &aPos, const wxSize &aSize, std::vector< std::pair< wxString, wxFileName > > aTitleDirList, const wxFileName &aDefaultTemplate)
PROJECT_TEMPLATE * GetDefaultTemplate()
TEMPLATE_WIDGET * m_selectedWidget
void onDirectoryBrowseClicked(wxCommandEvent &event) override
wxFileName m_defaultTemplatePath
void replaceCurrentPage()
PROJECT_TEMPLATE * GetSelectedTemplate()
std::vector< TEMPLATE_WIDGET * > m_allWidgets
void SetWidget(TEMPLATE_WIDGET *aWidget)
void buildPageContent(const wxString &aPath, int aPage)
std::vector< TEMPLATE_SELECTION_PANEL * > m_panels
TEMPLATE_WIDGET * m_defaultWidget
A class which provides project template functionality.
wxBitmap * GetIcon()
Get the 64px^2 icon for the project template.
wxFileName GetHtmlFile()
Get the full Html filename for the project template.
wxString * GetTitle()
Get the title of the project (extracted from the html title tag)
wxBoxSizer * m_SizerChoice
TEMPLATE_SELECTION_PANEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL|wxBORDER_NONE, const wxString &name=wxEmptyString)
TEMPLATE_SELECTION_PANEL(wxNotebookPage *aParent, const wxString &aPath)
wxString m_templatesPath
the path to access to the folder containing the templates (which are also folders)
void AddTemplateWidget(TEMPLATE_WIDGET *aTemplateWidget)
wxNotebookPage * m_parent
void SortAlphabetically()
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString GetWelcomeHtml()
wxString GetTemplateInfoHtml(const wxString &aTemplateName)
Functions to provide common constants and other functions to assist in making a consistent UI.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().