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.

139 lines
4.8 KiB

  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, 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. #ifndef HOTKEYS_BASIC_H
  24. #define HOTKEYS_BASIC_H
  25. #include <wx/string.h>
  26. #include <map>
  27. #include <vector>
  28. #define EESCHEMA_HOTKEY_NAME wxT( "Eeschema" )
  29. #define PCBNEW_HOTKEY_NAME wxT( "PcbNew" )
  30. // A define to allow translation of Hot Key message Info in hotkey help menu
  31. // We do not want to use the _( x ) usual macro from wxWidgets, which calls wxGetTranslation(),
  32. // because the English string is used in key file configuration
  33. // The translated string is used only when displaying the help window.
  34. // Therefore translation tools have to use the "_" and the "_HKI" prefix to extract
  35. // strings to translate
  36. #include <i18n_utility.h> // _HKI definition
  37. class TOOL_ACTION;
  38. class TOOL_MANAGER;
  39. class EDA_BASE_FRAME;
  40. /*
  41. * Keep these out of the ASCII range, and out of the WXK range
  42. */
  43. #define PSEUDO_WXK_CLICK 400
  44. #define PSEUDO_WXK_DBLCLICK 401
  45. #define PSEUDO_WXK_WHEEL 402
  46. /**
  47. * Return the key code from its user-friendly key name (ie: "Ctrl+M").
  48. */
  49. int KeyCodeFromKeyName( const wxString& keyname );
  50. /**
  51. * Return the key name from the key code.
  52. *
  53. * Only some wxWidgets key values are handled for function key ( see hotkeyNameList[] )
  54. *
  55. * @param aKeycode key code (ASCII value, or wxWidgets value for function keys).
  56. * @param aIsFound a pointer to a bool to return true if found, or false. an be nullptr default).
  57. * @return the key name in a wxString.
  58. */
  59. wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound = nullptr );
  60. /**
  61. * In menus we can add a hot key, or an accelerator, or sometimes just a comment.
  62. *
  63. * Hot keys can perform actions using the current mouse cursor position and accelerators perform
  64. * the same action as the associated menu.
  65. *
  66. * A comment is used in tool tips for some tools (zoom ..) to show the hot key that performs
  67. * this action
  68. */
  69. enum HOTKEY_ACTION_TYPE
  70. {
  71. IS_HOTKEY,
  72. IS_COMMENT
  73. };
  74. /**
  75. * @param aText the base text on which to append the hotkey.
  76. * @param aHotKey the hotkey keycode.
  77. * @param aStyle #IS_HOTKEY to add <tab><keyname> (shortcuts in menus, same as hotkeys).
  78. * #IS_COMMENT to add <spaces><(keyname)> mainly in tool tips.
  79. */
  80. wxString AddHotkeyName( const wxString& aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle = IS_HOTKEY );
  81. /**
  82. * Display the current hotkey list.
  83. *
  84. * @param aFrame current active frame.
  85. * @param aToolMgr the tool manager holding the registered actions from which the hotkeys
  86. * will be harvested.
  87. */
  88. void DisplayHotkeyList( EDA_BASE_FRAME* aFrame );
  89. /**
  90. * Read a hotkey config file into a map.
  91. *
  92. * If \a aFileName is empty it will read in the default hotkeys file.
  93. */
  94. void ReadHotKeyConfig( const wxString& aFileName,
  95. std::map<std::string, std::pair<int, int>>& aHotKeys );
  96. /**
  97. * Read a hotkey config file into a list of actions.
  98. *
  99. * If \a aFileName is empty it will read in the default hotkeys file.
  100. */
  101. void ReadHotKeyConfigIntoActions( const wxString& aFileName, std::vector<TOOL_ACTION*>& aActions );
  102. /**
  103. * Update the hotkeys config file with the hotkeys from the given actions map.
  104. */
  105. int WriteHotKeyConfig( const std::vector<TOOL_ACTION*>& aActions );
  106. /**
  107. * Read hotkey configuration for a given app.
  108. *
  109. * @param aFilename the filename to save the hotkeys as.
  110. * @param aMap The list of keycodes mapped by legacy property names.
  111. * @return 1 on success, 0 on failure.
  112. */
  113. int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string, int>& aMap );
  114. /**
  115. * Read configuration data and fill the current hotkey list with hotkeys.
  116. *
  117. * @param aAppname the value of the app's m_FrameName.
  118. * @param aMap The list of keycodes mapped by legacy property names.
  119. */
  120. int ReadLegacyHotkeyConfig( const wxString& aAppname, std::map<std::string, int>& aMap );
  121. #endif // HOTKEYS_BASIC_H