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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PROJECT_TEMPLATE_SELECTOR_H
26#define PROJECT_TEMPLATE_SELECTOR_H
27
30#include "project_template.h"
31
32#include <memory>
33#include <vector>
34#include <utility>
35#include <wx/filename.h>
36#include <wx/fswatcher.h>
37#include <wx/notebook.h>
38#include <wx/timer.h>
39#include <wx/webview.h>
40
42class TEMPLATE_WIDGET;
43
44
48class TEMPLATE_MRU_WIDGET : public wxPanel
49{
50public:
51 TEMPLATE_MRU_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog,
52 const wxString& aPath, const wxString& aTitle, const wxBitmap& aIcon );
53
54 wxString GetTemplatePath() const { return m_templatePath; }
55
56protected:
57 void OnClick( wxMouseEvent& event );
58 void OnDoubleClick( wxMouseEvent& event );
59 void OnEnter( wxMouseEvent& event );
60 void OnLeave( wxMouseEvent& event );
61
62private:
65};
66
67
69{
70public:
71 TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog );
72
77 void SetTemplate( PROJECT_TEMPLATE* aTemplate );
78
80
81 void Select();
83 void Unselect();
84
85 void SetDescription( const wxString& aDescription );
86 wxString GetDescription() const { return m_description; }
87
92 void SetIsUserTemplate( bool aIsUser ) { m_isUserTemplate = aIsUser; }
93 bool IsUserTemplate() const { return m_isUserTemplate; }
94
95protected:
96 void OnKillFocus( wxFocusEvent& event );
97 void OnMouse( wxMouseEvent& event );
98 void OnDoubleClick( wxMouseEvent& event );
99 void OnSize( wxSizeEvent& event );
100 void onRightClick( wxMouseEvent& event );
101 void onEditTemplate( wxCommandEvent& event );
102 void onDuplicateTemplate( wxCommandEvent& event );
103
104public:
105 bool IsSelected() const { return m_selected; }
106
107protected:
109 wxWindow* m_parent;
110 wxPanel* m_panel;
114
116};
117
118
120{
121public:
122 DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize,
123 const wxString& aUserTemplatesPath,
124 const wxString& aSystemTemplatesPath,
125 const std::vector<wxString>& aRecentTemplates );
126
128
130 wxString GetProjectToEdit() const { return m_projectToEdit; }
131
132 void SetWidget( TEMPLATE_WIDGET* aWidget );
133 void SelectTemplateByPath( const wxString& aPath );
134 void SelectTemplateByPath( const wxString& aPath, bool aKeepMRUVisible );
135 wxString GetUserTemplatesPath() const { return m_userTemplatesPath; }
136
137 void SetProjectToEdit( const wxString& aPath ) { m_projectToEdit = aPath; }
138 void RefreshTemplateList();
139
140protected:
141 void OnSearchCtrl( wxCommandEvent& event ) override;
142 void OnSearchCtrlCancel( wxCommandEvent& event ) override;
143 void OnFilterChanged( wxCommandEvent& event ) override;
144 void OnBackClicked( wxCommandEvent& event ) override;
145
146 void OnSearchTimer( wxTimerEvent& event );
147 void OnRefreshTimer( wxTimerEvent& event );
148 void OnWebViewLoaded( wxWebViewEvent& event );
149 void OnScrolledTemplatesSize( wxSizeEvent& event );
150
151 void OnFileSystemEvent( wxFileSystemWatcherEvent& event );
152 void OnSysColourChanged( wxSysColourChangedEvent& event );
153
154private:
156
157 void SetState( DialogState aState );
158 void BuildMRUList();
159 void BuildTemplateList();
160 void ApplyFilter();
161 void LoadTemplatePreview( PROJECT_TEMPLATE* aTemplate );
162 void SetupFileWatcher();
163 wxString ExtractDescription( const wxFileName& aHtmlFile );
164 void ShowWelcomeHtml();
166
170
173 std::vector<wxString> m_recentTemplates;
174
175 std::vector<std::unique_ptr<PROJECT_TEMPLATE>> m_templates;
176 std::vector<TEMPLATE_WIDGET*> m_templateWidgets;
177 std::vector<TEMPLATE_MRU_WIDGET*> m_mruWidgets;
178
181
183
185
188};
189
190#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)
DIALOG_TEMPLATE_SELECTOR(wxWindow *aParent, const wxPoint &aPos, const wxSize &aSize, const wxString &aUserTemplatesPath, const wxString &aSystemTemplatesPath, const std::vector< wxString > &aRecentTemplates)
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)
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=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 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 OnKillFocus(wxFocusEvent &event)
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