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 enum class CATEGORY
68 {
72 };
73
74 TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog );
75
80 void SetTemplate( PROJECT_TEMPLATE* aTemplate );
81
83
85 wxString GetTemplatePath() const;
86
87 void SetPinned( bool aPinned );
88 bool IsPinned() const { return m_pinned; }
89
90 void Select();
92 void Unselect();
93
94 void SetDescription( const wxString& aDescription );
95 wxString GetDescription() const { return m_description; }
96
97 void SetCategory( CATEGORY aCategory ) { m_category = aCategory; }
98 CATEGORY GetCategory() const { return m_category; }
99
100 // Convenience shim retained for callers that only care whether the template
101 // sits in the user-writable directory (controls edit/duplicate availability).
102 bool IsUserTemplate() const { return m_category == CATEGORY::USER; }
103
104protected:
105 void OnMouse( wxMouseEvent& event );
106 void OnDoubleClick( wxMouseEvent& event );
107 void OnSize( wxSizeEvent& event );
108 void onRightClick( wxMouseEvent& event );
109 void onEditTemplate( wxCommandEvent& event );
110 void onOpenFolder( wxCommandEvent& event );
111 void onDuplicateTemplate( wxCommandEvent& event );
112 void onTogglePinned( wxCommandEvent& event );
113
114public:
115 bool IsSelected() const { return m_selected; }
116
117protected:
119 wxWindow* m_parent;
120 wxPanel* m_panel;
125
127};
128
129
131{
132 friend class TEMPLATE_WIDGET;
133
134public:
135 DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize,
136 const wxString& aUserTemplatesPath,
137 const wxString& aSystemTemplatesPath,
138 const wxString& aDefaultTemplatesPath,
139 const std::vector<wxString>& aRecentTemplates,
140 const wxString& aBrowsedTemplatesPath = wxEmptyString );
141
143
145 wxString GetProjectToEdit() const { return m_projectToEdit; }
146
147 void SetWidget( TEMPLATE_WIDGET* aWidget );
148 void SelectTemplateByPath( const wxString& aPath );
149 void SelectTemplateByPath( const wxString& aPath, bool aKeepMRUVisible );
150 wxString GetUserTemplatesPath() const { return m_userTemplatesPath; }
151
154
155 void SetProjectToEdit( const wxString& aPath ) { m_projectToEdit = aPath; }
156
157 bool IsTemplatePinned( const wxString& aPath ) const;
158 void SetTemplatePinned( const wxString& aPath, bool aPinned );
159
160 void RefreshTemplateList();
161
162protected:
163 void OnSearchCtrl( wxCommandEvent& event ) override;
164 void OnSearchCtrlCancel( wxCommandEvent& event ) override;
165 void OnFilterChanged( wxCommandEvent& event ) override;
166 void OnBackClicked( wxCommandEvent& event ) override;
167
168 void OnSearchTimer( wxTimerEvent& event );
169 void OnRefreshTimer( wxTimerEvent& event );
170 void OnWebViewLoaded( wxWebViewEvent& event );
171 void OnScrolledTemplatesSize( wxSizeEvent& event );
172
173 void OnFileSystemEvent( wxFileSystemWatcherEvent& event );
174 void OnSysColourChanged( wxSysColourChangedEvent& event );
175
176private:
178 {
179 public:
180 explicit REFRESH_GUARD( DIALOG_TEMPLATE_SELECTOR* aDialog );
182
183 private:
185 };
186
188
189 void SetState( DialogState aState );
190 void EnsurePreviewSplit();
191 void BuildMRUList();
192 void BuildTemplateList();
193 void SortTemplateWidgets();
194 void ApplyFilter();
195 void LoadTemplatePreview( PROJECT_TEMPLATE* aTemplate );
196 void SetupFileWatcher();
197 wxString ExtractDescription( const wxFileName& aHtmlFile );
198 void ShowWelcomeHtml();
200 void onBrowseClicked( wxCommandEvent& aEvent ) override;
201 void onClearBrowsedClicked( wxCommandEvent& aEvent ) override;
203
206 bool browsedPathIsDuplicate() const;
207
211
216 std::vector<wxString> m_recentTemplates;
217 std::vector<wxString> m_pinnedTemplates;
218
219 std::vector<std::unique_ptr<PROJECT_TEMPLATE>> m_templates;
220 std::vector<TEMPLATE_WIDGET*> m_templateWidgets;
221 std::vector<TEMPLATE_MRU_WIDGET*> m_mruWidgets;
222
227
229
231
234
236};
237
238#endif
REFRESH_GUARD(DIALOG_TEMPLATE_SELECTOR *aDialog)
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 GetBrowsedTemplatesPath() const
Last directory chosen via the "Browse..." button so the caller can persist it.
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
bool IsTemplatePinned(const wxString &aPath) const
void OnFileSystemEvent(wxFileSystemWatcherEvent &event)
void onClearBrowsedClicked(wxCommandEvent &aEvent) override
bool browsedPathIsDuplicate() const
Returns true if the browsed path is empty or duplicates one of the standard template directories (aft...
void OnSearchCtrlCancel(wxCommandEvent &event) override
void OnWebViewLoaded(wxWebViewEvent &event)
void OnFilterChanged(wxCommandEvent &event) override
void onBrowseClicked(wxCommandEvent &aEvent) override
void SetTemplatePinned(const wxString &aPath, bool aPinned)
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)
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, const wxString &aBrowsedTemplatesPath=wxEmptyString)
std::vector< wxString > m_pinnedTemplates
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)
PROJECT_TEMPLATE * GetTemplate()
wxString GetDescription() const
void OnMouse(wxMouseEvent &event)
void onOpenFolder(wxCommandEvent &event)
void SetCategory(CATEGORY aCategory)
void SetPinned(bool aPinned)
void SetTemplate(PROJECT_TEMPLATE *aTemplate)
Set the project template for this widget, which will determine the icon and title associated with thi...
CATEGORY GetCategory() const
void onTogglePinned(wxCommandEvent &event)
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)
wxString GetTemplatePath() const
The template directory, the identity used for recent and pinned templates.
TEMPLATE_WIDGET(wxWindow *aParent, DIALOG_TEMPLATE_SELECTOR *aDialog)
PROJECT_TEMPLATE * m_currTemplate
#define wxFileSystemWatcher