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 <vector>
33#include <utility>
34#include <wx/filename.h>
35
37
39{
40public:
41 TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog );
42
47 void SetTemplate(PROJECT_TEMPLATE* aTemplate);
48
50
51 void Select();
52 void Unselect();
53
58 void SetIsUserTemplate( bool aIsUser ) { m_isUserTemplate = aIsUser; }
59 bool IsUserTemplate() const { return m_isUserTemplate; }
60
61protected:
62 void OnKillFocus( wxFocusEvent& event );
63 void OnMouse( wxMouseEvent& event );
64 void OnDoubleClick( wxMouseEvent& event );
65 void onRightClick( wxMouseEvent& event );
66 void onEditTemplate( wxCommandEvent& event );
67 void onDuplicateTemplate( wxCommandEvent& event );
68
69private:
70 bool IsSelected() { return m_selected; }
71
72protected:
74 wxWindow* m_parent;
75 wxPanel* m_panel;
78
80};
81
82
84{
85public:
90 TEMPLATE_SELECTION_PANEL( wxNotebookPage* aParent, const wxString& aPath );
91
92 const wxString& GetPath() const { return m_templatesPath; }
93
94 void AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidget );
95
96 void SortAlphabetically();
97
101 void SetIsUserTemplates( bool aIsUser ) { m_isUserTemplates = aIsUser; }
102 bool IsUserTemplates() const { return m_isUserTemplates; }
103
104protected:
105 wxNotebookPage* m_parent;
109};
110
111
113{
114public:
115 DIALOG_TEMPLATE_SELECTOR( wxWindow* aParent, const wxPoint& aPos, const wxSize& aSize,
116 std::vector<std::pair<wxString, wxFileName>> aTitleDirList,
117 const wxFileName& aDefaultTemplate );
118
124
125 void SetWidget( TEMPLATE_WIDGET* aWidget );
126
130 wxString GetProjectToEdit() const { return m_projectToEdit; }
131
135 void SetProjectToEdit( const wxString& aPath ) { m_projectToEdit = aPath; }
136
140 void replaceCurrentPage();
141
145 wxString GetUserTemplatesPath() const;
146
147protected:
148 void AddTemplate( int aPage, PROJECT_TEMPLATE* aTemplate );
149
150private:
151 void SetHtml( const wxFileName& aFilename )
152 {
153 m_webviewPanel->LoadURL( aFilename.GetFullPath() );
154 }
155
156private:
157 void buildPageContent( const wxString& aPath, int aPage );
158
159 void OnPageChange( wxNotebookEvent& event ) override;
160 void onDirectoryBrowseClicked( wxCommandEvent& event ) override;
161 void onReload( wxCommandEvent& event ) override;
162
163protected:
164 std::vector<TEMPLATE_SELECTION_PANEL*> m_panels;
168 // Keep track of all template widgets so we can pick a sensible default
169 std::vector<TEMPLATE_WIDGET*> m_allWidgets;
171};
172
173#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(513, 523), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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)
void SetHtml(const wxFileName &aFilename)
void onDirectoryBrowseClicked(wxCommandEvent &event) override
void replaceCurrentPage()
Refresh the current page to show updated template list.
wxString m_projectToEdit
Project path to edit instead of creating new.
std::vector< TEMPLATE_WIDGET * > m_allWidgets
void SetProjectToEdit(const wxString &aPath)
Set the project path to edit (used by template widgets)
void SetWidget(TEMPLATE_WIDGET *aWidget)
void buildPageContent(const wxString &aPath, int aPage)
wxString GetUserTemplatesPath() const
Get the path to the user templates directory (first panel marked as user templates)
std::vector< TEMPLATE_SELECTION_PANEL * > m_panels
A class which provides project template functionality.
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)
bool m_isUserTemplates
true if this panel contains user templates
void SetIsUserTemplates(bool aIsUser)
Set whether templates in this panel are user templates (can be edited/duplicated)
const wxString & GetPath() const
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()
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 OnKillFocus(wxFocusEvent &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