You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
6.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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. #ifndef __widget_hotkey_list__
  25. #define __widget_hotkey_list__
  26. #include <unordered_map>
  27. #include <utility>
  28. #include <vector>
  29. #include <wx/treelist.h>
  30. #include <wx/dataview.h>
  31. #include <hotkeys_basic.h>
  32. #include <hotkey_store.h>
  33. class WIDGET_HOTKEY_CLIENT_DATA;
  34. class WIDGET_HOTKEY_LIST : public wxTreeListCtrl
  35. {
  36. public:
  37. /**
  38. * Constructor WIDGET_HOTKEY_LIST
  39. * Create a WIDGET_HOTKEY_LIST.
  40. *
  41. * @param aParent - parent widget
  42. * @param aHotkeys - EDA_HOTKEY_CONFIG data - a hotkey store is constructed
  43. * from this.
  44. */
  45. WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly );
  46. /**
  47. * Method ApplyFilterString
  48. * Apply a filter string to the hotkey list, selecting which hotkeys
  49. * to show.
  50. *
  51. * @param aFilterStr the string to filter by
  52. */
  53. void ApplyFilterString( const wxString& aFilterStr );
  54. /**
  55. * Set hotkeys in the control to default or original values.
  56. * @param aResetToDefault if true, reset to the defaults inherent to the hotkeys, else
  57. * reset to the value they had when the dialog was invoked.
  58. */
  59. void ResetAllHotkeys( bool aResetToDefault );
  60. /**
  61. * Method TransferDataToControl
  62. * Load the hotkey data from the store into the control.
  63. * @return true iff the operation was successful
  64. */
  65. bool TransferDataToControl();
  66. /**
  67. * Method TransferDataFromControl
  68. * Save the hotkey data from the control.
  69. * @return true iff the operation was successful
  70. */
  71. bool TransferDataFromControl();
  72. /**
  73. * Static method MapKeypressToKeycode
  74. * Map a keypress event to the correct key code for use as a hotkey.
  75. */
  76. static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
  77. protected:
  78. /**
  79. * Method editItem
  80. * Prompt the user for a new hotkey given a list item.
  81. */
  82. void editItem( wxTreeListItem aItem );
  83. /**
  84. * Method resetItem
  85. * Reset the item to either the default, the value when the dialog was opened, or none.
  86. */
  87. void resetItem( wxTreeListItem aItem, int aResetId );
  88. /**
  89. * Method onActivated
  90. * Handle activation of a row.
  91. */
  92. void onActivated( wxTreeListEvent& aEvent );
  93. /**
  94. * Method onContextMenu
  95. * Handle right-click on a row.
  96. */
  97. void onContextMenu( wxTreeListEvent& aEvent );
  98. /**
  99. * Method onMenu
  100. * Handle activation of a context menu item.
  101. */
  102. void onMenu( wxCommandEvent& aEvent );
  103. /**
  104. * Method resolveKeyConflicts
  105. * Check if we can set a hotkey, and prompt the user if there is a conflict between keys.
  106. * The key code should already have been checked that it's not for the same entry as it's
  107. * current in, or else this method will prompt for the self-change.
  108. *
  109. * The method will do conflict resolution depending on aSectionTag.
  110. * g_CommonSectionTag means the key code must only be checked with the aSectionTag section
  111. * and g_CommonSectionTag section.
  112. *
  113. * @param aKey - key to check
  114. * @param aActionName - name of the action into which the key is proposed to be installed
  115. *
  116. * @return true iff the user accepted the overwrite or no conflict existed
  117. */
  118. bool resolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
  119. private:
  120. /**
  121. * Method getHKClientData
  122. * Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item is invalid.
  123. */
  124. WIDGET_HOTKEY_CLIENT_DATA* getHKClientData( wxTreeListItem aItem );
  125. /**
  126. * Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found. This is for
  127. * use when the data not being present indicates an error.
  128. */
  129. WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
  130. /**
  131. * Method updateFromClientData
  132. * Refresh the visible text on the widget from the rows' client data objects.
  133. */
  134. void updateFromClientData();
  135. /**
  136. * Method updateShownItems
  137. *
  138. * Update the items shown in the widget based on a given filter string.
  139. *
  140. * @param aFilterStr the string to filter with. Empty means no filter.
  141. */
  142. void updateShownItems( const wxString& aFilterStr );
  143. /**
  144. * Attempt to change the given hotkey to the given key code.
  145. *
  146. * If the hotkey conflicts, the user is prompted to change anyway (and in doing so, unset
  147. * the conflicting key), or cancel the attempt.
  148. *
  149. * @param aHotkey the change-able hotkey to try to change
  150. * @param aKey the key code to change it to
  151. */
  152. void changeHotkey( HOTKEY& aHotkey, long aKey );
  153. /**
  154. * Recalculates column widths after model has changed
  155. */
  156. void updateColumnWidths();
  157. private:
  158. HOTKEY_STORE& m_hk_store;
  159. bool m_readOnly;
  160. std::unordered_map<long, wxString> m_reservedHotkeys;
  161. wxTreeListItem m_context_menu_item;
  162. };
  163. #endif // __widget_hotkey_list__