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.

507 lines
16 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
3 years ago
3 years ago
3 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2010 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <kiface_base.h>
  26. #include <hotkeys_basic.h>
  27. #include <id.h>
  28. #include <string_utils.h>
  29. #include <eda_base_frame.h>
  30. #include <eda_draw_frame.h>
  31. #include <wildcards_and_files_ext.h>
  32. #include <paths.h>
  33. #include <tool/tool_manager.h>
  34. #include "dialogs/dialog_hotkey_list.h"
  35. #include <wx/apptrait.h>
  36. #include <wx/stdpaths.h>
  37. #include <wx/tokenzr.h>
  38. #include <wx/txtstrm.h>
  39. #include <wx/wfstream.h>
  40. #include <tool/tool_action.h>
  41. /*
  42. * class to handle the printable name and the keycode
  43. */
  44. struct hotkey_name_descr
  45. {
  46. const wxChar* m_Name;
  47. int m_KeyCode;
  48. };
  49. /* table giving the hotkey name from the hotkey code, for special keys
  50. * Note : when modifiers (ATL, SHIFT, CTRL) do not modify
  51. * the code of the key, do need to enter the modified key code
  52. * For instance wxT( "F1" ), WXK_F1 handle F1, AltF1, CtrlF1 ...
  53. * Key names are:
  54. * "Space","Ctrl+Space","Alt+Space" or
  55. * "Alt+A","Ctrl+F1", ...
  56. */
  57. #define KEY_NON_FOUND -1
  58. static struct hotkey_name_descr hotkeyNameList[] =
  59. {
  60. { wxT( "F1" ), WXK_F1 },
  61. { wxT( "F2" ), WXK_F2 },
  62. { wxT( "F3" ), WXK_F3 },
  63. { wxT( "F4" ), WXK_F4 },
  64. { wxT( "F5" ), WXK_F5 },
  65. { wxT( "F6" ), WXK_F6 },
  66. { wxT( "F7" ), WXK_F7 },
  67. { wxT( "F8" ), WXK_F8 },
  68. { wxT( "F9" ), WXK_F9 },
  69. { wxT( "F10" ), WXK_F10 },
  70. { wxT( "F11" ), WXK_F11 },
  71. { wxT( "F12" ), WXK_F12 },
  72. { wxT( "F13" ), WXK_F13 },
  73. { wxT( "F14" ), WXK_F14 },
  74. { wxT( "F15" ), WXK_F15 },
  75. { wxT( "F16" ), WXK_F16 },
  76. { wxT( "F17" ), WXK_F17 },
  77. { wxT( "F18" ), WXK_F18 },
  78. { wxT( "F19" ), WXK_F19 },
  79. { wxT( "F20" ), WXK_F20 },
  80. { wxT( "F21" ), WXK_F21 },
  81. { wxT( "F22" ), WXK_F22 },
  82. { wxT( "F23" ), WXK_F23 },
  83. { wxT( "F24" ), WXK_F24 },
  84. { wxT( "Esc" ), WXK_ESCAPE },
  85. { wxT( "Del" ), WXK_DELETE },
  86. { wxT( "Tab" ), WXK_TAB },
  87. { wxT( "Back" ), WXK_BACK },
  88. { wxT( "Ins" ), WXK_INSERT },
  89. { wxT( "Home" ), WXK_HOME },
  90. { wxT( "End" ), WXK_END },
  91. { wxT( "PgUp" ), WXK_PAGEUP },
  92. { wxT( "PgDn" ), WXK_PAGEDOWN },
  93. { wxT( "Up" ), WXK_UP },
  94. { wxT( "Down" ), WXK_DOWN },
  95. { wxT( "Left" ), WXK_LEFT },
  96. { wxT( "Right" ), WXK_RIGHT },
  97. { wxT( "Return" ), WXK_RETURN },
  98. { wxT( "Space" ), WXK_SPACE },
  99. { wxT( "Num Pad 0" ), WXK_NUMPAD0 },
  100. { wxT( "Num Pad 1" ), WXK_NUMPAD1 },
  101. { wxT( "Num Pad 2" ), WXK_NUMPAD2 },
  102. { wxT( "Num Pad 3" ), WXK_NUMPAD3 },
  103. { wxT( "Num Pad 4" ), WXK_NUMPAD4 },
  104. { wxT( "Num Pad 5" ), WXK_NUMPAD5 },
  105. { wxT( "Num Pad 6" ), WXK_NUMPAD6 },
  106. { wxT( "Num Pad 7" ), WXK_NUMPAD7 },
  107. { wxT( "Num Pad 8" ), WXK_NUMPAD8 },
  108. { wxT( "Num Pad 9" ), WXK_NUMPAD9 },
  109. { wxT( "Num Pad +" ), WXK_NUMPAD_ADD },
  110. { wxT( "Num Pad -" ), WXK_NUMPAD_SUBTRACT },
  111. { wxT( "Num Pad *" ), WXK_NUMPAD_MULTIPLY },
  112. { wxT( "Num Pad /" ), WXK_NUMPAD_DIVIDE },
  113. { wxT( "Num Pad ." ), WXK_NUMPAD_SEPARATOR },
  114. { wxT( "Num Pad Enter" ), WXK_NUMPAD_ENTER },
  115. { wxT( "Num Pad F1"), WXK_NUMPAD_F1 },
  116. { wxT( "Num Pad F2"), WXK_NUMPAD_F2 },
  117. { wxT( "Num Pad F3"), WXK_NUMPAD_F3 },
  118. { wxT( "Num Pad F4"), WXK_NUMPAD_F4 },
  119. { wxT( "" ), 0 },
  120. { wxT( "Click" ), PSEUDO_WXK_CLICK },
  121. { wxT( "DblClick" ), PSEUDO_WXK_DBLCLICK },
  122. { wxT( "Wheel" ), PSEUDO_WXK_WHEEL },
  123. // Do not change this line: end of list
  124. { wxT( "" ), KEY_NON_FOUND }
  125. };
  126. // name of modifier keys.
  127. // Note: the Ctrl key is Cmd key on Mac OS X.
  128. // However, in wxWidgets defs, the key WXK_CONTROL is the Cmd key,
  129. // so the code using WXK_CONTROL should be ok on any system.
  130. // (on Mac OS X the actual Ctrl key code is WXK_RAW_CONTROL)
  131. #ifdef __WXMAC__
  132. #define USING_MAC_CMD
  133. #endif
  134. #ifdef USING_MAC_CMD
  135. #define MODIFIER_CTRL wxT( "Cmd+" )
  136. #define MODIFIER_ALT wxT( "Option+" )
  137. #else
  138. #define MODIFIER_CTRL wxT( "Ctrl+" )
  139. #define MODIFIER_ALT wxT( "Alt+" )
  140. #endif
  141. #define MODIFIER_CMD_MAC wxT( "Cmd+" )
  142. #define MODIFIER_CTRL_BASE wxT( "Ctrl+" )
  143. #define MODIFIER_SHIFT wxT( "Shift+" )
  144. wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound )
  145. {
  146. wxString keyname, modifier, fullkeyname;
  147. int ii;
  148. bool found = false;
  149. if( aKeycode == WXK_CONTROL )
  150. return wxString( MODIFIER_CTRL ).BeforeFirst( '+' );
  151. else if( aKeycode == WXK_RAW_CONTROL )
  152. return wxString( MODIFIER_CTRL_BASE ).BeforeFirst( '+' );
  153. else if( aKeycode == WXK_SHIFT )
  154. return wxString( MODIFIER_SHIFT ).BeforeFirst( '+' );
  155. else if( aKeycode == WXK_ALT )
  156. return wxString( MODIFIER_ALT ).BeforeFirst( '+' );
  157. // Assume keycode of 0 is "unassigned"
  158. if( (aKeycode & MD_CTRL) != 0 )
  159. modifier << MODIFIER_CTRL;
  160. if( (aKeycode & MD_ALT) != 0 )
  161. modifier << MODIFIER_ALT;
  162. if( (aKeycode & MD_SHIFT) != 0 )
  163. modifier << MODIFIER_SHIFT;
  164. aKeycode &= ~( MD_CTRL | MD_ALT | MD_SHIFT );
  165. if( (aKeycode > ' ') && (aKeycode < 0x7F ) )
  166. {
  167. found = true;
  168. keyname.Append( (wxChar)aKeycode );
  169. }
  170. else
  171. {
  172. for( ii = 0; ; ii++ )
  173. {
  174. if( hotkeyNameList[ii].m_KeyCode == KEY_NON_FOUND ) // End of list
  175. {
  176. keyname = wxT( "<unknown>" );
  177. break;
  178. }
  179. if( hotkeyNameList[ii].m_KeyCode == aKeycode )
  180. {
  181. keyname = hotkeyNameList[ii].m_Name;
  182. found = true;
  183. break;
  184. }
  185. }
  186. }
  187. if( aIsFound )
  188. *aIsFound = found;
  189. fullkeyname = modifier + keyname;
  190. return fullkeyname;
  191. }
  192. wxString AddHotkeyName( const wxString& aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle )
  193. {
  194. wxString msg = aText;
  195. wxString keyname = KeyNameFromKeyCode( aHotKey );
  196. if( !keyname.IsEmpty() )
  197. {
  198. switch( aStyle )
  199. {
  200. case IS_HOTKEY:
  201. {
  202. // Don't add a suffix for unassigned hotkeys:
  203. // WX spews debug from wxAcceleratorEntry::ParseAccel if it doesn't
  204. // recognize the keyname, which is the case for <unassigned>.
  205. if( aHotKey != 0 )
  206. {
  207. msg << wxT( "\t" ) << keyname;
  208. }
  209. break;
  210. }
  211. case IS_COMMENT:
  212. {
  213. msg << wxT( " (" ) << keyname << wxT( ")" );
  214. break;
  215. }
  216. }
  217. }
  218. #ifdef USING_MAC_CMD
  219. // On OSX, the modifier equivalent to the Ctrl key of PCs
  220. // is the Cmd key, but in code we should use Ctrl as prefix in menus
  221. msg.Replace( MODIFIER_CMD_MAC, MODIFIER_CTRL_BASE );
  222. #endif
  223. return msg;
  224. }
  225. int KeyCodeFromKeyName( const wxString& keyname )
  226. {
  227. int ii, keycode = KEY_NON_FOUND;
  228. // Search for modifiers: Ctrl+ Alt+ and Shift+
  229. // Note: on Mac OSX, the Cmd key is equiv here to Ctrl
  230. wxString key = keyname;
  231. wxString prefix;
  232. int modifier = 0;
  233. while( true )
  234. {
  235. prefix.Empty();
  236. if( key.StartsWith( MODIFIER_CTRL_BASE ) )
  237. {
  238. modifier |= MD_CTRL;
  239. prefix = MODIFIER_CTRL_BASE;
  240. }
  241. else if( key.StartsWith( MODIFIER_CMD_MAC ) )
  242. {
  243. modifier |= MD_CTRL;
  244. prefix = MODIFIER_CMD_MAC;
  245. }
  246. else if( key.StartsWith( MODIFIER_ALT ) )
  247. {
  248. modifier |= MD_ALT;
  249. prefix = MODIFIER_ALT;
  250. }
  251. else if( key.StartsWith( MODIFIER_SHIFT ) )
  252. {
  253. modifier |= MD_SHIFT;
  254. prefix = MODIFIER_SHIFT;
  255. }
  256. else
  257. {
  258. break;
  259. }
  260. if( !prefix.IsEmpty() )
  261. key.Remove( 0, prefix.Len() );
  262. }
  263. if( (key.length() == 1) && (key[0] > ' ') && (key[0] < 0x7F) )
  264. {
  265. keycode = key[0];
  266. keycode += modifier;
  267. return keycode;
  268. }
  269. for( ii = 0; hotkeyNameList[ii].m_KeyCode != KEY_NON_FOUND; ii++ )
  270. {
  271. if( key.CmpNoCase( hotkeyNameList[ii].m_Name ) == 0 )
  272. {
  273. keycode = hotkeyNameList[ii].m_KeyCode + modifier;
  274. break;
  275. }
  276. }
  277. return keycode;
  278. }
  279. void DisplayHotkeyList( EDA_BASE_FRAME* aParent )
  280. {
  281. DIALOG_LIST_HOTKEYS dlg( aParent );
  282. dlg.ShowModal();
  283. }
  284. void ReadHotKeyConfig( const wxString& aFileName,
  285. std::map<std::string, std::pair<int, int>>& aHotKeys )
  286. {
  287. wxString fileName = aFileName;
  288. if( fileName.IsEmpty() )
  289. {
  290. wxFileName fn( wxS( "user" ) );
  291. fn.SetExt( FILEEXT::HotkeyFileExtension );
  292. fn.SetPath( PATHS::GetUserSettingsPath() );
  293. fileName = fn.GetFullPath();
  294. }
  295. if( !wxFile::Exists( fileName ) )
  296. return;
  297. wxFFile file( fileName, "rb" );
  298. if( !file.IsOpened() ) // There is a problem to open file
  299. return;
  300. wxString input;
  301. file.ReadAll( &input );
  302. input.Replace( "\r\n", "\n" ); // Convert Windows files to Unix line-ends
  303. wxStringTokenizer fileTokenizer( input, wxS( "\n" ), wxTOKEN_STRTOK );
  304. while( fileTokenizer.HasMoreTokens() )
  305. {
  306. wxStringTokenizer lineTokenizer( fileTokenizer.GetNextToken(), wxS( "\t" ) );
  307. wxString cmdName = lineTokenizer.GetNextToken();
  308. wxString primary = lineTokenizer.GetNextToken();
  309. wxString secondary = lineTokenizer.GetNextToken();
  310. if( !cmdName.IsEmpty() )
  311. aHotKeys[cmdName.ToStdString()] = std::pair<int, int>(
  312. KeyCodeFromKeyName( primary ), KeyCodeFromKeyName( secondary ) );
  313. }
  314. }
  315. void ReadHotKeyConfigIntoActions( const wxString& aFileName, std::vector<TOOL_ACTION*>& aActions )
  316. {
  317. std::map<std::string, std::pair<int, int>> hotkeys;
  318. // Read the existing config (all hotkeys)
  319. ReadHotKeyConfig( aFileName, hotkeys );
  320. // Set each tool action hotkey to the config file hotkey if present
  321. for( TOOL_ACTION* action : aActions )
  322. {
  323. if( hotkeys.find( action->GetName() ) != hotkeys.end() )
  324. {
  325. std::pair<int, int> keys = hotkeys[action->GetName()];
  326. action->SetHotKey( keys.first, keys.second );
  327. }
  328. }
  329. }
  330. int WriteHotKeyConfig( const std::vector<TOOL_ACTION*>& aActions )
  331. {
  332. std::map<std::string, std::pair<int, int>> hotkeys;
  333. wxFileName fn( "user" );
  334. fn.SetExt( FILEEXT::HotkeyFileExtension );
  335. fn.SetPath( PATHS::GetUserSettingsPath() );
  336. // Read the existing config (all hotkeys)
  337. ReadHotKeyConfig( fn.GetFullPath(), hotkeys );
  338. // Overlay the current app's hotkey definitions onto the map
  339. for( const TOOL_ACTION* action : aActions )
  340. hotkeys[ action->GetName() ] = std::pair<int, int>( action->GetHotKey(),
  341. action->GetHotKeyAlt() );
  342. // Write entire hotkey set
  343. wxFFileOutputStream outStream( fn.GetFullPath() );
  344. wxTextOutputStream txtStream( outStream, wxEOL_UNIX );
  345. for( const std::pair<const std::string, std::pair<int, int>>& entry : hotkeys )
  346. txtStream << entry.first
  347. << "\t" << KeyNameFromKeyCode( entry.second.first )
  348. << "\t" << KeyNameFromKeyCode( entry.second.second ) << endl;
  349. txtStream.Flush();
  350. outStream.Close();
  351. return 1;
  352. }
  353. int ReadLegacyHotkeyConfig( const wxString& aAppname, std::map<std::string, int>& aMap )
  354. {
  355. // For Eeschema and Pcbnew frames, we read the new combined file.
  356. // For other kifaces, we read the frame-based file
  357. if( aAppname == LIB_EDIT_FRAME_NAME || aAppname == SCH_EDIT_FRAME_NAME )
  358. {
  359. return ReadLegacyHotkeyConfigFile( EESCHEMA_HOTKEY_NAME, aMap );
  360. }
  361. else if( aAppname == PCB_EDIT_FRAME_NAME || aAppname == FOOTPRINT_EDIT_FRAME_NAME )
  362. {
  363. return ReadLegacyHotkeyConfigFile( PCBNEW_HOTKEY_NAME, aMap );
  364. }
  365. return ReadLegacyHotkeyConfigFile( aAppname, aMap );
  366. }
  367. int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string, int>& aMap )
  368. {
  369. wxFileName fn( aFilename );
  370. fn.SetExt( FILEEXT::HotkeyFileExtension );
  371. fn.SetPath( PATHS::GetUserSettingsPath() );
  372. if( !wxFile::Exists( fn.GetFullPath() ) )
  373. return 0;
  374. wxFFile cfgfile( fn.GetFullPath(), "rb" );
  375. if( !cfgfile.IsOpened() ) // There is a problem to open file
  376. return 0;
  377. // get length
  378. wxFileOffset size = cfgfile.Length();
  379. // read data
  380. std::vector<char> buffer( size );
  381. cfgfile.Read( buffer.data(), size );
  382. wxString data( buffer.data(), wxConvUTF8, size );
  383. // Is this the wxConfig format? If so, remove "Keys=" and parse the newlines.
  384. if( data.StartsWith( wxT("Keys="), &data ) )
  385. data.Replace( "\\n", "\n", true );
  386. // parse
  387. wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK );
  388. while( tokenizer.HasMoreTokens() )
  389. {
  390. wxString line = tokenizer.GetNextToken();
  391. wxStringTokenizer lineTokenizer( line );
  392. wxString line_type = lineTokenizer.GetNextToken();
  393. if( line_type[0] == '#' ) // comment
  394. continue;
  395. if( line_type[0] == '[' ) // tags ignored reading legacy hotkeys
  396. continue;
  397. if( line_type == wxT( "$Endlist" ) )
  398. break;
  399. if( line_type != wxT( "shortcut" ) )
  400. continue;
  401. // Get the key name
  402. lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK );
  403. wxString keyname = lineTokenizer.GetNextToken();
  404. wxString remainder = lineTokenizer.GetString();
  405. // Get the command name
  406. wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' );
  407. // Add the pair to the map
  408. aMap[ fctname.ToStdString() ] = KeyCodeFromKeyName( keyname );
  409. }
  410. // cleanup
  411. cfgfile.Close();
  412. return 1;
  413. }