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.

117 lines
3.3 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 3
  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 HOTKEY_STORE__H
  24. #define HOTKEY_STORE__H
  25. #include <hotkeys_basic.h>
  26. #include <tool/tool_action.h>
  27. #include <vector>
  28. class TOOL_MANAGER;
  29. struct HOTKEY
  30. {
  31. std::vector<TOOL_ACTION*> m_Actions;
  32. int m_EditKeycode;
  33. int m_EditKeycodeAlt;
  34. HOTKEY() :
  35. m_EditKeycode( 0 ),
  36. m_EditKeycodeAlt( 0 )
  37. { }
  38. HOTKEY( TOOL_ACTION* aAction ) :
  39. m_EditKeycode( aAction->GetHotKey() ),
  40. m_EditKeycodeAlt( aAction->GetHotKeyAlt() )
  41. {
  42. m_Actions.push_back( aAction );
  43. }
  44. };
  45. struct HOTKEY_SECTION
  46. {
  47. wxString m_SectionName; // The displayed, translated, name of the section
  48. std::vector<HOTKEY> m_HotKeys;
  49. };
  50. /**
  51. * A class that contains a set of hotkeys, arranged into "sections"
  52. * and provides some book-keeping functions for them.
  53. */
  54. class HOTKEY_STORE
  55. {
  56. public:
  57. /**
  58. * Construct a HOTKEY_STORE from a list of hotkey sections
  59. *
  60. * @param aHotkeys the hotkey configs that will be managed by this store.
  61. */
  62. HOTKEY_STORE();
  63. void Init( std::vector<TOOL_ACTION*> aActionsList, bool aIncludeReadOnlyCmds );
  64. static wxString GetAppName( TOOL_ACTION* aAction );
  65. static wxString GetSectionName( TOOL_ACTION* aAction );
  66. /**
  67. * Get the list of sections managed by this store
  68. */
  69. std::vector<HOTKEY_SECTION>& GetSections();
  70. /**
  71. * Persist all changes to hotkeys in the store to the underlying
  72. * data structures.
  73. */
  74. void SaveAllHotkeys();
  75. /**
  76. * Reset every hotkey in the store to the default values
  77. */
  78. void ResetAllHotkeysToDefault();
  79. /**
  80. * Resets every hotkey to the original values.
  81. */
  82. void ResetAllHotkeysToOriginal();
  83. /**
  84. * Check whether the given key conflicts with anything in this store.
  85. *
  86. * @param aAction - the action the key is proposed to be assigned to. Only conflicts
  87. * within the same section will be flagged.
  88. * @param aKey - key to check
  89. * @param aConflict - outparam getting the section this one conflicts with
  90. */
  91. bool CheckKeyConflicts( TOOL_ACTION* aAction, long aKey, HOTKEY** aConflict );
  92. private:
  93. std::vector<TOOL_MANAGER*> m_toolManagers;
  94. std::vector<HOTKEY_SECTION> m_hk_sections;
  95. };
  96. #endif // HOTKEY_STORE__H