1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016-2018 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 3
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 
24 #ifndef HOTKEY_STORE__H
25 #define HOTKEY_STORE__H
26 
27 #include <hotkeys_basic.h>
28 #include <tool/tool_action.h>
29 #include <vector>
30 
31 class TOOL_MANAGER;
32 
33 
34 struct HOTKEY
35 {
36     std::vector<TOOL_ACTION*> m_Actions;
37     int                       m_EditKeycode;
38 
HOTKEYHOTKEY39     HOTKEY() :
40             m_EditKeycode( 0 )
41     { }
42 
HOTKEYHOTKEY43     HOTKEY( TOOL_ACTION* aAction ) :
44             m_EditKeycode( aAction->GetHotKey() )
45     {
46         m_Actions.push_back( aAction );
47     }
48 };
49 
50 
51 struct HOTKEY_SECTION
52 {
53     wxString            m_SectionName;   // The displayed, translated, name of the section
54     std::vector<HOTKEY> m_HotKeys;
55 };
56 
57 
58 /**
59  * A class that contains a set of hotkeys, arranged into "sections"
60  * and provides some book-keeping functions for them.
61  */
62 class HOTKEY_STORE
63 {
64 public:
65 
66     /**
67      * Construct a HOTKEY_STORE from a list of hotkey sections
68      *
69      * @param aHotkeys the hotkey configs that will be managed by this store.
70      */
71     HOTKEY_STORE();
72 
73     void Init( std::vector<TOOL_MANAGER*> aToolManagerList, bool aIncludeReadOnlyCmds );
74 
75     static wxString GetAppName( TOOL_ACTION* aAction );
76     static wxString GetSectionName( TOOL_ACTION* aAction );
77 
78     /**
79      * Get the list of sections managed by this store
80      */
81     std::vector<HOTKEY_SECTION>& GetSections();
82 
83     /**
84      * Persist all changes to hotkeys in the store to the underlying
85      * data structures.
86      */
87     void SaveAllHotkeys();
88 
89     /**
90      * Reset every hotkey in the store to the default values
91      */
92     void ResetAllHotkeysToDefault();
93 
94     /**
95      * Resets every hotkey to the original values.
96      */
97     void ResetAllHotkeysToOriginal();
98 
99     /**
100      * Check whether the given key conflicts with anything in this store.
101      *
102      * @param aAction - the action the key is proposed to be assigned to.  Only conflicts
103      *                  within the same section will be flagged.
104      * @param aKey - key to check
105      * @param aConflict - outparam getting the section this one conflicts with
106      */
107     bool CheckKeyConflicts( TOOL_ACTION* aAction, long aKey, HOTKEY** aConflict );
108 
109 private:
110     std::vector<TOOL_MANAGER*>  m_toolManagers;
111     std::vector<HOTKEY_SECTION> m_hk_sections;
112 };
113 
114 #endif // HOTKEY_STORE__H