KiCad PCB EDA Suite
Loading...
Searching...
No Matches
toolbar_context_menu_registry.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 TOOLBAR_CONTEXT_MENU_REGISTRY_H_
21#define TOOLBAR_CONTEXT_MENU_REGISTRY_H_
22
23#include <functional>
24#include <map>
25#include <memory>
26#include <string>
27
28#include <kicommon.h>
29
30class ACTION_MENU;
31class TOOL_MANAGER;
32
41{
42public:
44 using MENU_FACTORY = std::function<std::unique_ptr<ACTION_MENU>( TOOL_MANAGER* )>;
45
52 static void RegisterMenuFactory( const std::string& aActionName, MENU_FACTORY aFactory );
53
60 static void RegisterGroupMenuFactory( const std::string& aGroupName, MENU_FACTORY aFactory );
61
68 static MENU_FACTORY GetMenuFactory( const std::string& aActionName );
69
76 static MENU_FACTORY GetGroupMenuFactory( const std::string& aGroupName );
77
78private:
79 // Use Meyer's singleton to prevent SIOF
80 static std::map<std::string, MENU_FACTORY>& getActionMenus();
81 static std::map<std::string, MENU_FACTORY>& getGroupMenus();
82};
83
84#endif /* TOOLBAR_CONTEXT_MENU_REGISTRY_H_ */
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
Registry for toolbar context menu factories.
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()
Master controller class:
#define KICOMMON_API
Definition kicommon.h:27