KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_template_selector.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 Brian Sidebotham <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PROJECT_TEMPLATE_SELECTOR_H
22#define PROJECT_TEMPLATE_SELECTOR_H
23
26#include "project_template.h"
27
28#include <memory>
29#include <vector>
30#include <utility>
31#include <wx/filename.h>
32#include <wx/fswatcher.h>
33#include <wx/notebook.h>
34#include <wx/timer.h>
35#include <wx/webview.h>
36
38class TEMPLATE_WIDGET;
39
40
44class TEMPLATE_MRU_WIDGET : public wxPanel
45{
46public:
47 TEMPLATE_MRU_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog,
48 const wxString& aPath, const wxString& aTitle, const wxBitmap& aIcon );
49
50 wxString GetTemplatePath() const { return m_templatePath; }
51
52protected:
53 void OnClick( wxMouseEvent& event );
54 void OnDoubleClick( wxMouseEvent& event );
55 void OnEnter( wxMouseEvent& event );
56 void OnLeave( wxMouseEvent& event );
57
58private:
61};
62
63
65{
66public:
67 TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog );
68
73 void SetTemplate( PROJECT_TEMPLATE* aTemplate );
74
76
77 void Select();
79 void Unselect();
80
81 void SetDescription( const wxString& aDescription );
82 wxString GetDescription() const { return m_description; }
83
88 void SetIsUserTemplate( bool aIsUser ) { m_isUserTemplate = aIsUser; }
89 bool IsUserTemplate() const { return m_isUserTemplate; }
90
91protected:
92 void OnMouse( wxMouseEvent& event );
93 void OnDoubleClick( wxMouseEvent& event );
94 void OnSize( wxSizeEvent& event );
95 void onRightClick( wxMouseEvent& event );
96 void onEditTemplate( wxCommandEvent& event );
97 void onOpenFolder( wxCommandEvent& event );
98 void onDuplicateTemplate( wxCommandEvent& event );
99
100public:
101 bool IsSelected() const { return m_selected; }
102
103protected:
105 wxWindow* m_parent;
106 wxPanel* m_panel;
110
112};
113
114
116{
117public:
118 DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize,
119 const wxString& aUserTemplatesPath,
120 const wxString& aSystemTemplatesPath,
121 const wxString& aDefaultTemplatesPath,
122 const std::vector<wxString>& aRecentTemplates );
123
125
127 wxString GetProjectToEdit() const { return m_projectToEdit; }
128
129 void SetWidget( TEMPLATE_WIDGET* aWidget );
130 void SelectTemplateByPath( const wxString& aPath );
131 void SelectTemplateByPath( const wxString& aPath, bool aKeepMRUVisible );
132 wxString GetUserTemplatesPath() const { return m_userTemplatesPath; }
133
134 void SetProjectToEdit( const wxString& aPath ) { m_projectToEdit = aPath; }
135 void RefreshTemplateList();
136
137protected:
138 void OnSearchCtrl( wxCommandEvent& event ) override;
139 void OnSearchCtrlCancel( wxCommandEvent& event ) override;
140 void OnFilterChanged( wxCommandEvent& event ) override;
141 void OnBackClicked( wxCommandEvent& event ) override;
142
143 void OnSearchTimer( wxTimerEvent& event );
144 void OnRefreshTimer( wxTimerEvent& event );
145 void OnWebViewLoaded( wxWebViewEvent& event );
146 void OnScrolledTemplatesSize( wxSizeEvent& event );
147
148 void OnFileSystemEvent( wxFileSystemWatcherEvent& event );
149 void OnSysColourChanged( wxSysColourChangedEvent& event );
150
151private:
153
154 void SetState( DialogState aState );
155 void EnsurePreviewSplit();
156 void BuildMRUList();
157 void BuildTemplateList();
158 void ApplyFilter();
159 void LoadTemplatePreview( PROJECT_TEMPLATE* aTemplate );
160 void SetupFileWatcher();
161 wxString ExtractDescription( const wxFileName& aHtmlFile );
162 void ShowWelcomeHtml();
164
168
172 std::vector<wxString> m_recentTemplates;
173
174 std::vector<std::unique_ptr<PROJECT_TEMPLATE>> m_templates;
175 std::vector<TEMPLATE_WIDGET*> m_templateWidgets;
176 std::vector<TEMPLATE_MRU_WIDGET*> m_mruWidgets;
177
180
182
184
187
189};
190
191#endif
DIALOG_TEMPLATE_SELECTOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Project Template Selector"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 600), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxString ExtractDescription(const wxFileName &aHtmlFile)
void SetState(DialogState aState)
void SelectTemplateByPath(const wxString &aPath)
void OnBackClicked(wxCommandEvent &event) override
void LoadTemplatePreview(PROJECT_TEMPLATE *aTemplate)
void OnSearchCtrl(wxCommandEvent &event) override
void OnFileSystemEvent(wxFileSystemWatcherEvent &event)
void OnSearchCtrlCancel(wxCommandEvent &event) override
void OnWebViewLoaded(wxWebViewEvent &event)
void OnFilterChanged(wxCommandEvent &event) override
std::vector< TEMPLATE_WIDGET * > m_templateWidgets
void OnRefreshTimer(wxTimerEvent &event)
void OnScrolledTemplatesSize(wxSizeEvent &event)
void SetProjectToEdit(const wxString &aPath)
void SetWidget(TEMPLATE_WIDGET *aWidget)
std::vector< TEMPLATE_MRU_WIDGET * > m_mruWidgets
void OnSysColourChanged(wxSysColourChangedEvent &event)
DIALOG_TEMPLATE_SELECTOR(wxWindow *aParent, const wxPoint &aPos, const wxSize &aSize, const wxString &aUserTemplatesPath, const wxString &aSystemTemplatesPath, const wxString &aDefaultTemplatesPath, const std::vector< wxString > &aRecentTemplates)
void OnSearchTimer(wxTimerEvent &event)
std::vector< std::unique_ptr< PROJECT_TEMPLATE > > m_templates
std::vector< wxString > m_recentTemplates
A class which provides project template functionality.
DIALOG_TEMPLATE_SELECTOR * m_dialog
void OnEnter(wxMouseEvent &event)
TEMPLATE_MRU_WIDGET(wxWindow *aParent, DIALOG_TEMPLATE_SELECTOR *aDialog, const wxString &aPath, const wxString &aTitle, const wxBitmap &aIcon)
void OnLeave(wxMouseEvent &event)
void OnClick(wxMouseEvent &event)
void OnDoubleClick(wxMouseEvent &event)
TEMPLATE_WIDGET_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxBORDER_THEME|wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void SetIsUserTemplate(bool aIsUser)
Set whether this template widget represents a user template.
PROJECT_TEMPLATE * GetTemplate()
wxString GetDescription() const
void OnMouse(wxMouseEvent &event)
void onOpenFolder(wxCommandEvent &event)
void SetTemplate(PROJECT_TEMPLATE *aTemplate)
Set the project template for this widget, which will determine the icon and title associated with thi...
DIALOG_TEMPLATE_SELECTOR * m_dialog
void SetDescription(const wxString &aDescription)
void OnSize(wxSizeEvent &event)
void onEditTemplate(wxCommandEvent &event)
void OnDoubleClick(wxMouseEvent &event)
void onDuplicateTemplate(wxCommandEvent &event)
void onRightClick(wxMouseEvent &event)
TEMPLATE_WIDGET(wxWindow *aParent, DIALOG_TEMPLATE_SELECTOR *aDialog)
PROJECT_TEMPLATE * m_currTemplate
#define wxFileSystemWatcher