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 
25 #ifndef __widget_hotkey_list__
26 #define __widget_hotkey_list__
27 
28 #include <unordered_map>
29 #include <utility>
30 #include <vector>
31 
32 #include <wx/treelist.h>
33 #include <wx/dataview.h>
34 
35 #include <hotkeys_basic.h>
36 #include <hotkey_store.h>
37 
38 
40 
41 class WIDGET_HOTKEY_LIST : public wxTreeListCtrl
42 {
43 public:
52  WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly );
53 
61  void ApplyFilterString( const wxString& aFilterStr );
62 
68  void ResetAllHotkeys( bool aResetToDefault );
69 
75  bool TransferDataToControl();
76 
83 
88  static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
89 
90 protected:
95  void editItem( wxTreeListItem aItem );
96 
101  void resetItem( wxTreeListItem aItem, int aResetId );
102 
107  void onActivated( wxTreeListEvent& aEvent );
108 
113  void onContextMenu( wxTreeListEvent& aEvent );
114 
119  void onMenu( wxCommandEvent& aEvent );
120 
136  bool resolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
137 
138 private:
143  WIDGET_HOTKEY_CLIENT_DATA* getHKClientData( wxTreeListItem aItem );
144 
149  WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
150 
155  void updateFromClientData();
156 
164  void updateShownItems( const wxString& aFilterStr );
165 
175  void changeHotkey( HOTKEY& aHotkey, long aKey );
176 
180  void updateColumnWidths();
181 
182 private:
185 
186  std::unordered_map<long, wxString> m_reservedHotkeys;
187 
188  wxTreeListItem m_context_menu_item;
189 };
190 
191 #endif // __widget_hotkey_list__
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
std::unordered_map< long, wxString > m_reservedHotkeys
void editItem(wxTreeListItem aItem)
Method editItem Prompt the user for a new hotkey given a list item.
A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping funct...
Definition: hotkey_store.h:62
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
void onActivated(wxTreeListEvent &aEvent)
Method onActivated Handle activation of a row.
void onContextMenu(wxTreeListEvent &aEvent)
Method onContextMenu Handle right-click on a row.
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
HOTKEY_STORE & m_hk_store
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.
void updateFromClientData()
Method updateFromClientData Refresh the visible text on the widget from the rows' client data objects...
wxTreeListItem m_context_menu_item
Store the hotkey change data associated with each row.
void ApplyFilterString(const wxString &aFilterStr)
Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.
WIDGET_HOTKEY_LIST(wxWindow *aParent, HOTKEY_STORE &aHotkeyStore, bool aReadOnly)
Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.
void onMenu(wxCommandEvent &aEvent)
Method onMenu Handle activation of a context menu item.
void updateColumnWidths()
Recalculates column widths after model has changed.
Represent a single user action.
Definition: tool_action.h:67
void resetItem(wxTreeListItem aItem, int aResetId)
Method resetItem Reset the item to either the default, the value when the dialog was opened,...
bool resolveKeyConflicts(TOOL_ACTION *aAction, long aKey)
Method resolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
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...
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.