KiCad PCB EDA Suite
widget_hotkey_list.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 (C) 2016 Chris Pavlina <pavlina.chris@gmail.com>
5  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
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 3
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 
29 #ifndef __widget_hotkey_list__
30 #define __widget_hotkey_list__
31 
32 #include <utility>
33 #include <vector>
34 
35 #include <wx/treelist.h>
37 
38 #include <hotkeys_basic.h>
39 
45 {
46  wxString m_name;
48 };
49 
50 typedef std::vector<HOTKEY_SECTION> HOTKEY_SECTIONS;
51 typedef std::vector<EDA_HOTKEY> HOTKEY_LIST;
52 
54 
56 {
58  std::vector<HOTKEY_LIST> m_hotkeys;
59  wxTreeListItem m_context_menu_item;
60 
66  WIDGET_HOTKEY_CLIENT_DATA* GetHKClientData( wxTreeListItem aItem );
67 
74 
79  void UpdateFromClientData();
80 
81 protected:
87  void LoadSection( EDA_HOTKEY_CONFIG* aSection );
88 
93  void EditItem( wxTreeListItem aItem );
94 
99  void ResetItem( wxTreeListItem aItem );
100 
105  void ResetItemToDefault( wxTreeListItem aItem );
106 
111  void OnActivated( wxTreeListEvent& aEvent );
112 
117  void OnContextMenu( wxTreeListEvent& aEvent );
118 
123  void OnMenu( wxCommandEvent& aEvent );
124 
129  void OnSize( wxSizeEvent& aEvent );
130 
140  bool CheckKeyConflicts( long aKey, const wxString& aSectionTag,
141  EDA_HOTKEY** aConfKey, EDA_HOTKEY_CONFIG** aConfSect );
142 
158  bool ResolveKeyConflicts( long aKey, const wxString& aSectionTag );
159 
160 public:
170  WIDGET_HOTKEY_LIST( wxWindow* aParent, const HOTKEY_SECTIONS& aSections );
171 
177  static HOTKEY_SECTIONS GenSections( EDA_HOTKEY_CONFIG* aHotkeys );
178 
185  void InstallOnPanel( wxPanel* aPanel );
186 
193 
200  bool TransferDataToControl();
201 
208 
213  static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
214 };
215 
216 #endif // __widget_hotkey_list__
void ResetItemToDefault(wxTreeListItem aItem)
Method ResetItemToDefault Reset the item to the default value.
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey...
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
HOTKEY_SECTIONS m_sections
Modified wxTreeListCtrl designed for use with two columns, with better column resizing.
void OnMenu(wxCommandEvent &aEvent)
Method OnMenu Handle activation of a context menu item.
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data into the control.
void OnSize(wxSizeEvent &aEvent)
Function OnSize Handle resizing of the control.
bool CheckKeyConflicts(long aKey, const wxString &aSectionTag, EDA_HOTKEY **aConfKey, EDA_HOTKEY_CONFIG **aConfSect)
Method CheckKeyConflicts Check whether the given key conflicts with anything in this WIDGET_HOTKEY_LI...
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
static HOTKEY_SECTIONS GenSections(EDA_HOTKEY_CONFIG *aHotkeys)
Static method GenSections Generate a list of sections and names from an EDA_HOTKEY_CONFIG*.
WIDGET_HOTKEY_CLIENT_DATA * GetSelHKClientData()
Method GetSelHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the item being edited...
std::vector< HOTKEY_LIST > m_hotkeys
void InstallOnPanel(wxPanel *aPanel)
Method InstallOnPanel Install this WIDGET_HOTKEY_LIST onto an empty panel.
wxTreeListItem m_context_menu_item
Class WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey and section tag associated with each row...
void LoadSection(EDA_HOTKEY_CONFIG *aSection)
Method LoadSection Generates a HOTKEY_LIST from the given hotkey configuration array and pushes it to...
std::vector< HOTKEY_SECTION > HOTKEY_SECTIONS
WIDGET_HOTKEY_LIST(wxWindow *aParent, const HOTKEY_SECTIONS &aSections)
Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
std::vector< EDA_HOTKEY > HOTKEY_LIST
WIDGET_HOTKEY_CLIENT_DATA * GetHKClientData(wxTreeListItem aItem)
Method GetHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...
bool ResolveKeyConflicts(long aKey, const wxString &aSectionTag)
Method ResolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
void ResetItem(wxTreeListItem aItem)
Method ResetItem Reset the item to the original from the dialog was created.
Some functions to handle hotkeys in KiCad.
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.
EDA_HOTKEY_CONFIG * m_section
struct HOTKEY_SECTION Associates a hotkey configuration with a name.
bool TransferDefaultsToControl()
Method TransferDefaultsToControl Set hotkeys in the control to default values.
void OnContextMenu(wxTreeListEvent &aEvent)
Method OnContextMenu Handle right-click on a row.
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.