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.

113 lines
3.2 KiB

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