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, 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 TOOLBAR_CONFIGURATION_H_
26#define TOOLBAR_CONFIGURATION_H_
27
28#include <string>
29#include <vector>
30
32#include <settings/parameters.h>
33#include <tool/action_toolbar.h>
34#include <tool/tool_action.h>
36
45
47{
48public:
51 m_Size( 0 )
52 { }
53
55 m_Type( aType ),
56 m_Size( 0 )
57 { }
58
59 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, int aSize ) :
60 m_Type( aType ),
61 m_Size( aSize )
62 {
63 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
64 }
65
66 TOOLBAR_ITEM( TOOLBAR_ITEM_TYPE aType, std::string aName ) :
67 m_Type( aType ),
68 m_Size( 0 )
69 {
70 if( aType == TOOLBAR_ITEM_TYPE::CONTROL )
71 m_ControlName = aName;
72 else if( aType == TOOLBAR_ITEM_TYPE::TOOL )
73 m_ActionName = aName;
74 }
75
76public:
78
79 // Control properties
80 std::string m_ControlName;
81
82 // Tool properties
83 std::string m_ActionName;
84
85 // Spacer properties
86 int m_Size;
87
88 // Group properties
89 wxString m_GroupName;
90 std::vector<TOOLBAR_ITEM> m_GroupItems;
91};
92
93// Forward declaration for use in TOOLBAR_ITEM_REF
95
101{
102public:
104 m_parent( aParent ),
105 m_item( aItem )
106 {
107 }
108
118 TOOLBAR_CONFIGURATION& WithContextMenu(
120
122 operator TOOLBAR_CONFIGURATION&() { return m_parent; }
123
124 // Forwarding methods to allow continued chaining after WithContextMenu or directly
125 TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName );
126 TOOLBAR_ITEM_REF AppendAction( const TOOL_ACTION& aAction );
127 TOOLBAR_CONFIGURATION& AppendSeparator();
128 TOOLBAR_CONFIGURATION& AppendSpacer( int aSize );
129 TOOLBAR_CONFIGURATION& AppendGroup( const TOOLBAR_GROUP_CONFIG& aGroup );
130 TOOLBAR_CONFIGURATION& AppendControl( const std::string& aControlName );
131 TOOLBAR_CONFIGURATION& AppendControl( const ACTION_TOOLBAR_CONTROL& aControl );
132
133private:
136};
137
139{
140public:
141 TOOLBAR_GROUP_CONFIG( const wxString& aName ) :
142 m_groupName( aName )
143 {
144 }
145
146 const wxString& GetName() const
147 {
148 return m_groupName;
149 }
150
151 TOOLBAR_GROUP_CONFIG& AddAction( std::string aActionName )
152 {
153
154 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
155 return *this;
156 }
157
159 {
160 m_groupItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
161 return *this;
162 }
163
176 {
177 // Register the factory globally using the group name
179 m_groupName.ToStdString(), std::move( aFactory ) );
180 return *this;
181 }
182
183 std::vector<TOOLBAR_ITEM> GetGroupItems() const
184 {
185 return m_groupItems;
186 }
187
188public:
189 // These are public to write the JSON, but are lower-cased to encourage people not to directly
190 // access them and treat them as private.
191 wxString m_groupName;
192 std::vector<TOOLBAR_ITEM> m_groupItems;
193};
194
196{
197public:
198
201
202 TOOLBAR_ITEM_REF AppendAction( const std::string& aActionName )
203 {
204 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aActionName );
205 return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() );
206 }
207
209 {
210 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::TOOL, aAction.GetName() );
211 return TOOLBAR_ITEM_REF( *this, m_toolbarItems.back() );
212 }
213
215 {
217 return *this;
218 }
219
221 {
222 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::SPACER, aSize );
223 return *this;
224 }
225
227 {
229 item.m_GroupName = aGroup.GetName();
230 item.m_GroupItems = aGroup.GetGroupItems();
231
232 m_toolbarItems.push_back( item );
233 return *this;
234 }
235
236 TOOLBAR_CONFIGURATION& AppendControl( const std::string& aControlName )
237 {
238 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControlName );
239 return *this;
240 }
241
243 {
244 m_toolbarItems.emplace_back( TOOLBAR_ITEM_TYPE::CONTROL, aControl.GetName() );
245 return *this;
246 }
247
248 std::vector<TOOLBAR_ITEM> GetToolbarItems() const
249 {
250 return m_toolbarItems;
251 }
252
253 void Clear()
254 {
255 m_toolbarItems.clear();
256 }
257
258public:
259 // These are public to write the JSON, but are lower-cased to encourage people not to directly
260 // access them and treat them as private.
261 std::vector<TOOLBAR_ITEM> m_toolbarItems;
262};
263
264
272
274{
275public:
276 TOOLBAR_SETTINGS( const wxString& aFilename );
277
278 virtual ~TOOLBAR_SETTINGS() {}
279
283 virtual std::optional<TOOLBAR_CONFIGURATION> DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
284 {
285 return std::nullopt;
286 }
287
293 std::optional<TOOLBAR_CONFIGURATION> GetToolbarConfig( TOOLBAR_LOC aToolbar, bool aAllowCustom = true );
294
298 std::optional<TOOLBAR_CONFIGURATION> GetStoredToolbarConfig( TOOLBAR_LOC aToolbar );
299
304 {
305 m_toolbars[aToolbar] = aConfig;
306 }
307
308protected:
309 // The toolbars
310 std::map<TOOLBAR_LOC, TOOLBAR_CONFIGURATION> m_toolbars;
311};
312
313#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:28
@ TOP_AUX
Toolbar on the top of the canvas.
@ TOP_MAIN
Toolbar on the top of the canvas.
#define SEPARATOR