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.

138 lines
6.0 KiB

11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  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 <fctsys.h>
  26. #include <common.h>
  27. #include <id.h>
  28. #include <pl_editor_frame.h>
  29. #include <hotkeys.h>
  30. #include <pl_editor_id.h>
  31. // Remark: the hotkey message info is used as keyword in hotkey config files and
  32. // as comments in help windows, therefore translated only when displayed
  33. // they are marked _HKI to be extracted by translation tools
  34. // See hotkeys_basic.h for more info
  35. /* How to add a new hotkey:
  36. * add a new id in the enum hotkey_id_command like MY_NEW_ID_FUNCTION.
  37. * add a new EDA_HOTKEY entry like:
  38. * static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION, default key value);
  39. * 'Command Label' is the name used in hotkey list display, and the identifier in the
  40. * hotkey list file
  41. * 'MY_NEW_ID_FUNCTION' is the id event function used in the switch in OnHotKey() function.
  42. * 'Default key value' is the default hotkey for this command.
  43. * Can be overrided by the user hotkey list
  44. * Add the 'HkMyNewEntry' pointer in the s_PlEditor_Hotkey_List list
  45. * Add the new code in the switch in OnHotKey() function.
  46. *
  47. * Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
  48. * is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
  49. * and see this list for some ascii keys (space ...)
  50. */
  51. // Hotkey list:
  52. // mouse click command:
  53. static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 );
  54. static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK,
  55. WXK_END, 0 );
  56. static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ), HK_RESET_LOCAL_COORD, ' ' );
  57. static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME );
  58. static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4 );
  59. static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3 );
  60. static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2 );
  61. static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1 );
  62. static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION,
  63. GR_KB_CTRL + WXK_F5 );
  64. static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
  65. static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE, 'M' );
  66. static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE );
  67. // Common: hotkeys_basic.h
  68. static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
  69. static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
  70. static EDA_HOTKEY HkCut( _HKI( "Cut" ), HK_CUT, GR_KB_CTRL + 'X' );
  71. static EDA_HOTKEY HkCopy( _HKI( "Copy" ), HK_COPY, GR_KB_CTRL + 'C' );
  72. static EDA_HOTKEY HkPaste( _HKI( "Paste" ), HK_PASTE, GR_KB_CTRL + 'V' );
  73. static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N', (int) wxID_NEW );
  74. static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O', (int) wxID_OPEN );
  75. static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S', (int) wxID_SAVE );
  76. static EDA_HOTKEY HkSaveAs( _HKI( "Save As" ), HK_SAVEAS, GR_KB_CTRL + GR_KB_SHIFT + 'S',
  77. (int) wxID_SAVEAS );
  78. static EDA_HOTKEY HkPrint( _HKI( "Print" ), HK_PRINT, GR_KB_CTRL + 'P', (int) wxID_PRINT );
  79. static EDA_HOTKEY HkPreferences( _HKI( "Preferences" ), HK_PREFERENCES, GR_KB_CTRL + ',', (int) wxID_PREFERENCES );
  80. // List of common hotkey descriptors
  81. EDA_HOTKEY* s_Common_Hotkey_List[] =
  82. {
  83. &HkNew, &HkOpen, &HkSave, &HkSaveAs, &HkPrint,
  84. &HkUndo, &HkRedo,
  85. &HkCut, &HkCopy, &HkPaste, &HkDeleteItem,
  86. &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
  87. &HkZoomAuto, &HkZoomSelection, &HkResetLocalCoord,
  88. &HkHelp, &HkPreferences,
  89. &HkMouseLeftClick, &HkMouseLeftDClick,
  90. NULL
  91. };
  92. EDA_HOTKEY* s_PlEditor_Hotkey_List[] =
  93. {
  94. &HkMoveItem,
  95. &HkDeleteItem,
  96. NULL
  97. };
  98. // Titles for hotkey editor and hotkey display
  99. static wxString commonSectionTitle( _HKI( "Common" ) );
  100. // list of sections and corresponding hotkey list for Pl_Editor
  101. // (used to create an hotkey config file)
  102. static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) );
  103. static wxString s_PlEditorSectionTitle( _HKI( "Page Layout Editor" ) );
  104. struct EDA_HOTKEY_CONFIG PlEditorHotkeysDescr[] =
  105. {
  106. { &g_CommonSectionTag, s_Common_Hotkey_List, &commonSectionTitle },
  107. { &s_PlEditorSectionTag, s_PlEditor_Hotkey_List, &s_PlEditorSectionTitle },
  108. { NULL, NULL, NULL }
  109. };
  110. EDA_HOTKEY* PL_EDITOR_FRAME::GetHotKeyDescription( int aCommand ) const
  111. {
  112. EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, s_Common_Hotkey_List );
  113. if( HK_Descr == NULL )
  114. HK_Descr = GetDescriptorFromCommand( aCommand, s_PlEditor_Hotkey_List );
  115. return HK_Descr;
  116. }