KiCad PCB EDA Suite
Loading...
Searching...
No Matches
toolbar_configuration.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 * @author Ian McInerney
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 TOOLBAR_CONFIGURATION_H_
22#define TOOLBAR_CONFIGURATION_H_
23
24#include <string>
25#include <vector>
26
28#include <settings/parameters.h>
29#include <tool/action_toolbar.h>
30#include <tool/tool_action.h>
32
41
43{
44public:
47 m_Size( 0 )
48 { }
49
51 m_Type( aType ),
52 m_Size( 0 )
53 { }
54
55 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, int aSize ) :
56 m_Type( aType ),
57 m_Size( aSize )
58 {
59 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
60 }
61
62 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, std::string aName ) :
63 m_Type( aType ),
64 m_Size( 0 )
65 {
66 if( aType == TOOLBAR_ITEM_TYPE::CONTROL )
67 m_ControlName = aName;
68 else if( aType == TOOLBAR_ITEM_TYPE::TOOL )
69 m_ActionName = aName;
70 }
71
72public:
74
75 // Control properties
76 std::string m_ControlName;
77
78 // Tool properties
79 std::string m_ActionName;
80
81 // Spacer properties
82 int m_Size;
83
84 // Group properties
85 wxString m_GroupName;
86 std::vector<TOOLBAR_ITEM> m_GroupItems;
87};
88
89// Forward declaration for use in TOOLBAR_ITEM_REF
91
97{
98public:
100 m_parent( aParent ),
101 m_item( aItem )
102 {
103 }
104
114 TOOLBAR_CONFIGURATION& WithContextMenu(
116
118 operator TOOLBAR_CONFIGURATION&() { return m_parent; }
119
120 // Forwarding methods to allow continued chaining after WithContextMenu or directly
121 TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName );
122 TOOLBAR_ITEM_REF AppendAction( const TOOL_ACTION& aAction );
123 TOOLBAR_CONFIGURATION& AppendSeparator();
124 TOOLBAR_CONFIGURATION& AppendSpacer( int aSize );
125 TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup );
126 TOOLBAR_CONFIGURATION& AppendControl( const std::string& aControlName );
127 TOOLBAR_CONFIGURATION& AppendControl( const ACTION_TOOLBAR_CONTROL& aControl );
128
129private:
132};
133
135{
136public:
137 TOOLBAR_GROUP_CONFIG( const wxString& aName ) :
138 m_groupName( aName )
139 {
140 }
141
142 const wxString& GetName() const
143 {
144 return m_groupName;
145 }
146
147 TOOLBAR_GROUP_CONFIG& AddAction( std::string aActionName )
148 {
149
150 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
151 return *this;
152 }
153
155 {
156 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
157 return *this;
158 }
159
172 {
173 // Register the factory globally using the group name
175 m_groupName.ToStdString(), std::move( aFactory ) );
176 return *this;
177 }
178
179 std::vector<TOOLBAR_ITEM> GetGroupItems() const
180 {
181 return m_groupItems;
182 }
183
184public:
185 // These are public to write the JSON, but are lower-cased to encourage people not to directly
186 // access them and treat them as private.
187 wxString m_groupName;
188 std::vector<TOOLBAR_ITEM> m_groupItems;
189};
190
192{
193public:
194
197
198 TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName )
199 {
200 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
201 return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() );
202 }
203
205 {
206 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
207 return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() );
208 }
209
211 {
213 return *this;
214 }
215
217 {
218 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SPACER, aSize );
219 return *this;
220 }
221
223 {
225 item.m_GroupName = aGroup.GetName();
226 item.m_GroupItems = aGroup.GetGroupItems();
227
228 m_toolbarItems.push_back( item );
229 return *this;
230 }
231
232 TOOLBAR_CONFIGURATION& AppendControl( const std::string& aControlName )
233 {
234 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName );
235 return *this;
236 }
237
239 {
240 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControl.GetName() );
241 return *this;
242 }
243
244 std::vector<TOOLBAR_ITEM> GetToolbarItems() const
245 {
246 return m_toolbarItems;
247 }
248
249 void Clear()
250 {
251 m_toolbarItems.clear();
252 }
253
254public:
255 // These are public to write the JSON, but are lower-cased to encourage people not to directly
256 // access them and treat them as private.
257 std::vector<TOOLBAR_ITEM> m_toolbarItems;
258};
259
260
268
270{
271public:
272 TOOLBAR_SETTINGS( const wxString& aFilename );
273
274 virtual ~TOOLBAR_SETTINGS() {}
275
279 virtual std::optional<TOOLBAR_CONFIGURATION> DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
280 {
281 return std::nullopt;
282 }
283
289 std::optional<TOOLBAR_CONFIGURATION> GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aAllowCustom = true );
290
294 std::optional<TOOLBAR_CONFIGURATION> GetStoredToolbarConfig( TOOLBAR_LOC aToolbar );
295
300 {
301 m_toolbars[aToolbar] = aConfig;
302 }
303
304protected:
305 // The toolbars
306 std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;
307};
308
309#endif /* TOOLBAR_CONFIGURATION_H_ */
Class to hold basic information about controls that can be added to the toolbars.
const std::string & GetName() const
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
TOOLBAR_CONFIGURATION & AppendControl(const ACTION_TOOLBAR_CONTROL &aControl)
TOOLBAR_CONFIGURATION & AppendGroup(const TOOLBAR_GROUP_CONFIG &aGroup)
TOOLBAR_ITEM_REF AppendAction(const TOOL_ACTION &aAction)
TOOLBAR_ITEM_REF AppendAction(const std::string &aActionName)
TOOLBAR_CONFIGURATION & AppendControl(const std::string &aControlName)
TOOLBAR_CONFIGURATION & AppendSpacer(int aSize)
std::vector< TOOLBAR_ITEM > m_toolbarItems
std::vector< TOOLBAR_ITEM > GetToolbarItems() const
TOOLBAR_CONFIGURATION & AppendSeparator()
static void RegisterGroupMenuFactory(const std::string &aGroupName, MENU_FACTORY aFactory)
Register a context menu factory for a toolbar group.
std::function< std::unique_ptr< ACTION_MENU >(TOOL_MANAGER *)> MENU_FACTORY
Factory function type: takes TOOL_MANAGER, returns owned ACTION_MENU.
TOOLBAR_GROUP_CONFIG(const wxString &aName)
TOOLBAR_GROUP_CONFIG & AddAction(std::string aActionName)
std::vector< TOOLBAR_ITEM > GetGroupItems() const
TOOLBAR_GROUP_CONFIG & AddContextMenu(TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY aFactory)
Associate a context menu factory with this group.
TOOLBAR_GROUP_CONFIG & AddAction(const TOOL_ACTION &aAction)
const wxString & GetName() const
std::vector< TOOLBAR_ITEM > m_groupItems
Helper class returned by TOOLBAR_CONFIGURATION::AppendAction() to allow chaining of context menu regi...
TOOLBAR_ITEM_REF(class TOOLBAR_CONFIGURATION &aParent, TOOLBAR_ITEM &aItem)
TOOLBAR_CONFIGURATION & m_parent
std::vector< TOOLBAR_ITEM > m_GroupItems
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType, int aSize)
std::string m_ActionName
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType, std::string aName)
TOOLBAR_ITEM_TYPE m_Type
std::string m_ControlName
TOOLBAR_ITEM(TOOLBAR_ITEM_TYPE aType)
void SetStoredToolbarConfig(TOOLBAR_LOC aToolbar, const TOOLBAR_CONFIGURATION &aConfig)
Set the stored configuration for the given toolbar.
TOOLBAR_SETTINGS(const wxString &aFilename)
virtual std::optional< TOOLBAR_CONFIGURATION > DefaultToolbarConfig(TOOLBAR_LOC aToolbar)
Get the default tools to show on the specified canvas toolbar.
std::map< TOOLBAR_LOC, TOOLBAR_CONFIGURATION > m_toolbars
Represent a single user action.
const std::string & GetName() const
Return name of the action.
#define KICOMMON_API
Definition kicommon.h:27
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.
#define SEPARATOR