KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_toolbar_customization.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef PANEL_TOOLBAR_CUSTOMIZATION_H_
21 #define PANEL_TOOLBAR_CUSTOMIZATION_H_
22
24
25#include <tool/action_toolbar.h>
27
28#include <wx/bmpbndl.h>
29
30class wxImageList;
31
33class TOOL_ACTION;
34
35
42class TOOLBAR_TREE : public wxTreeCtrl
43{
44public:
45 TOOLBAR_TREE( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize, long style = wxTR_DEFAULT_STYLE ) :
47 wxTreeCtrl( parent, id, pos, size, style )
48 {
49 }
50
51 int OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 ) override;
52
53private:
54 // Need to use wxRTTI macros in order for OnCompareItems to work properly
55 // See: https://docs.wxwidgets.org/3.1/classwx_tree_ctrl.html#ab90a465793c291ca7aa827a576b7d146
57};
58
59
61{
62public:
64 {
65 wxString label;
66 wxString tooltip;
67 wxString search_text;
68 TOOL_ACTION* action = nullptr;
70 int image_index = -1;
71 };
72
73 PANEL_TOOLBAR_CUSTOMIZATION( wxWindow* aParent, APP_SETTINGS_BASE* aCfg, TOOLBAR_SETTINGS* aTbSettings,
74 FRAME_T aActionContext, const std::vector<TOOL_ACTION*>& aTools,
75 const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls );
76
78
79 void ResetPanel() override;
80
81 bool TransferDataFromWindow() override;
82 bool TransferDataToWindow() override;
83
84protected:
85 std::optional<TOOLBAR_CONFIGURATION> parseToolbarTree();
86
88
89 void populateActions();
90 void applyActionFilter();
91 bool isActionSupported( const TOOL_ACTION& aAction ) const;
92 bool actionMatchesFilter( const ACTION_LIST_ENTRY& aEntry, const wxString& aFilter ) const;
93
94 void enableCustomControls( bool enable );
95 void enableToolbarControls( bool enable );
96
97 void onGroupPress( wxCommandEvent& aEvent );
98 void onSpacerPress( wxCommandEvent& aEvent );
99 void onSeparatorPress( wxCommandEvent& aEvent );
100
101 // From the base class
102 void onCustomizeTbCb( wxCommandEvent& event ) override;
103 void onToolDelete( wxCommandEvent& event ) override;
104 void onToolMoveUp( wxCommandEvent& event ) override;
105 void onToolMoveDown( wxCommandEvent& event ) override;
106 void onBtnAddAction( wxCommandEvent& event ) override;
107 void onTreeBeginLabelEdit( wxTreeEvent& event ) override;
108 void onTreeEndLabelEdit( wxTreeEvent& event ) override;
109 void onTbChoiceSelect( wxCommandEvent& event ) override;
110 void onListItemActivated( wxListEvent& event ) override;
111 void onActionFilterText( wxCommandEvent& event );
112 void onActionListMouseMove( wxMouseEvent& event );
113 void onTreeItemActivated( wxTreeEvent& event );
114
115 void removeControlFromOtherToolbars( const std::string& aControlName );
116 void removeControlFromCurrentTree( const std::string& aControlName );
117protected:
118 wxVector<wxBitmapBundle> m_actionImageBundleVector;
119 std::map<std::string, int> m_actionImageListMap;
120 std::vector<ACTION_LIST_ENTRY> m_actionEntries;
122
123 // Actual settings for the frame
126
127 // The toolbar currently being viewed
130 std::vector<TOOLBAR_LOC> m_toolbarChoices;
131
132 // Shadow copy of the toolbar configurations used to store the changes in the dialog
133 std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;
134
135 std::map<std::string, TOOL_ACTION*> m_availableTools;
136 std::map<std::string, ACTION_TOOLBAR_CONTROL*> m_availableControls;
137};
138
139 #endif /* PANEL_TOOLBAR_CUSTOMIZATION_H_ */
Class to hold basic information about controls that can be added to the toolbars.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
PANEL_TOOLBAR_CUSTOMIZATION_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)
bool actionMatchesFilter(const ACTION_LIST_ENTRY &aEntry, const wxString &aFilter) const
void onSpacerPress(wxCommandEvent &aEvent)
wxVector< wxBitmapBundle > m_actionImageBundleVector
void onActionListMouseMove(wxMouseEvent &event)
void onTbChoiceSelect(wxCommandEvent &event) override
bool isActionSupported(const TOOL_ACTION &aAction) const
void onTreeEndLabelEdit(wxTreeEvent &event) override
void onTreeBeginLabelEdit(wxTreeEvent &event) override
void removeControlFromCurrentTree(const std::string &aControlName)
void onToolDelete(wxCommandEvent &event) override
std::map< TOOLBAR_LOC, TOOLBAR_CONFIGURATION > m_toolbars
void onGroupPress(wxCommandEvent &aEvent)
void onSeparatorPress(wxCommandEvent &aEvent)
void ResetPanel() override
Reset the contents of this panel.
std::vector< TOOLBAR_LOC > m_toolbarChoices
std::map< std::string, int > m_actionImageListMap
void onBtnAddAction(wxCommandEvent &event) override
void removeControlFromOtherToolbars(const std::string &aControlName)
std::map< std::string, TOOL_ACTION * > m_availableTools
std::map< std::string, ACTION_TOOLBAR_CONTROL * > m_availableControls
std::optional< TOOLBAR_CONFIGURATION > parseToolbarTree()
PANEL_TOOLBAR_CUSTOMIZATION(wxWindow *aParent, APP_SETTINGS_BASE *aCfg, TOOLBAR_SETTINGS *aTbSettings, FRAME_T aActionContext, const std::vector< TOOL_ACTION * > &aTools, const std::vector< ACTION_TOOLBAR_CONTROL * > &aControls)
void onCustomizeTbCb(wxCommandEvent &event) override
void onActionFilterText(wxCommandEvent &event)
void onToolMoveDown(wxCommandEvent &event) override
void onListItemActivated(wxListEvent &event) override
void onToolMoveUp(wxCommandEvent &event) override
std::vector< ACTION_LIST_ENTRY > m_actionEntries
TOOLBAR_TREE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTR_DEFAULT_STYLE)
wxDECLARE_ABSTRACT_CLASS(TOOLBAR_TREE)
int OnCompareItems(const wxTreeItemId &item1, const wxTreeItemId &item2) override
Represent a single user action.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
TOOL_ACTION * action
wxString label
ACTION_TOOLBAR_CONTROL * control
int image_index
wxString tooltip
wxString search_text