KiCad PCB EDA Suite
Loading...
Searching...
No Matches
toolbar_context_menu_registry.cpp
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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26
27std::map<std::string, TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY>&
29{
30 static std::map<std::string, MENU_FACTORY> s_actionMenus;
31 return s_actionMenus;
32}
33
34
35std::map<std::string, TOOLBAR_CONTEXT_MENU_REGISTRY::MENU_FACTORY>&
37{
38 static std::map<std::string, MENU_FACTORY> s_groupMenus;
39 return s_groupMenus;
40}
41
42
44 MENU_FACTORY aFactory )
45{
46 getActionMenus()[aActionName] = std::move( aFactory );
47}
48
49
51 MENU_FACTORY aFactory )
52{
53 getGroupMenus()[aGroupName] = std::move( aFactory );
54}
55
56
58TOOLBAR_CONTEXT_MENU_REGISTRY::GetMenuFactory( const std::string& aActionName )
59{
60 auto& menus = getActionMenus();
61 auto it = menus.find( aActionName );
62
63 if( it != menus.end() )
64 return it->second;
65
66 return nullptr;
67}
68
69
72{
73 auto& menus = getGroupMenus();
74 auto it = menus.find( aGroupName );
75
76 if( it != menus.end() )
77 return it->second;
78
79 return nullptr;
80}
static MENU_FACTORY GetMenuFactory(const std::string &aActionName)
Get the menu factory for an action, if one is registered.
static void RegisterGroupMenuFactory(const std::string &aGroupName, MENU_FACTORY aFactory)
Register a context menu factory for a toolbar group.
static void RegisterMenuFactory(const std::string &aActionName, MENU_FACTORY aFactory)
Register a context menu factory for an action.
std::function< std::unique_ptr< ACTION_MENU >(TOOL_MANAGER *)> MENU_FACTORY
Factory function type: takes TOOL_MANAGER, returns owned ACTION_MENU.
static MENU_FACTORY GetGroupMenuFactory(const std::string &aGroupName)
Get the menu factory for a group, if one is registered.
static std::map< std::string, MENU_FACTORY > & getActionMenus()
static std::map< std::string, MENU_FACTORY > & getGroupMenus()
#define KICOMMON_API
Definition kicommon.h:28