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.

197 lines
4.0 KiB

  1. #include <hotkey_grid_table.h>
  2. /*
  3. * Reads the hotkey table from its stored format into a format suitable
  4. * for a wxGrid.
  5. */
  6. HOTKEY_EDITOR_GRID_TABLE::HOTKEY_EDITOR_GRID_TABLE( struct EDA_HOTKEY_CONFIG* origin ) :
  7. wxGridTableBase(), m_hotkeys()
  8. {
  9. EDA_HOTKEY_CONFIG* section;
  10. for( section = origin; section->m_HK_InfoList; section++ )
  11. {
  12. // Add a dummy hotkey_spec which is a header before each hotkey list
  13. hotkey_spec spec( *section->m_SectionTag, NULL );
  14. m_hotkeys.push_back( spec );
  15. EDA_HOTKEY** hotkey_descr_list;
  16. // Add hotkeys descr
  17. for( hotkey_descr_list = section->m_HK_InfoList; *hotkey_descr_list;
  18. hotkey_descr_list++ )
  19. {
  20. EDA_HOTKEY* hotkey_descr = *hotkey_descr_list;
  21. hotkey_spec spec( *section->m_SectionTag, new EDA_HOTKEY( hotkey_descr ) );
  22. m_hotkeys.push_back( spec );
  23. }
  24. }
  25. }
  26. HOTKEY_EDITOR_GRID_TABLE::hotkey_spec_vector& HOTKEY_EDITOR_GRID_TABLE::getHotkeys()
  27. {
  28. return m_hotkeys;
  29. }
  30. int HOTKEY_EDITOR_GRID_TABLE::GetNumberRows()
  31. {
  32. return m_hotkeys.size();
  33. }
  34. int HOTKEY_EDITOR_GRID_TABLE::GetNumberCols()
  35. {
  36. return 2;
  37. }
  38. bool HOTKEY_EDITOR_GRID_TABLE::IsEmptyCell( int row, int col )
  39. {
  40. return col == 1 && m_hotkeys[row].second == NULL;
  41. }
  42. wxString HOTKEY_EDITOR_GRID_TABLE::GetValue( int row, int col )
  43. {
  44. EDA_HOTKEY* hotkey_descr = m_hotkeys[row].second;
  45. if( col == 0 )
  46. {
  47. if( hotkey_descr == NULL )
  48. {
  49. // section header
  50. return m_hotkeys[row].first;
  51. }
  52. else
  53. {
  54. return hotkey_descr->m_InfoMsg;
  55. }
  56. }
  57. else
  58. {
  59. if( hotkey_descr == NULL )
  60. {
  61. // section header
  62. return wxEmptyString;
  63. }
  64. else
  65. {
  66. return ReturnKeyNameFromKeyCode( hotkey_descr->m_KeyCode );
  67. }
  68. }
  69. }
  70. void HOTKEY_EDITOR_GRID_TABLE::SetValue( int row, int col, const wxString& value )
  71. {
  72. }
  73. wxString HOTKEY_EDITOR_GRID_TABLE::GetTypeName( int row, int col )
  74. {
  75. return wxGRID_VALUE_STRING;
  76. }
  77. bool HOTKEY_EDITOR_GRID_TABLE::CanGetValueAs( int row, int col, const wxString& typeName )
  78. {
  79. return typeName == wxGRID_VALUE_STRING && col == 2;
  80. }
  81. bool HOTKEY_EDITOR_GRID_TABLE::CanSetValueAs( int row, int col, const wxString& typeName )
  82. {
  83. return false;
  84. }
  85. long HOTKEY_EDITOR_GRID_TABLE::GetValueAsLong( int row, int col )
  86. {
  87. return -1L;
  88. }
  89. double HOTKEY_EDITOR_GRID_TABLE::GetValueAsDouble( int row, int col )
  90. {
  91. return 0.0;
  92. }
  93. bool HOTKEY_EDITOR_GRID_TABLE::GetValueAsBool( int row, int col )
  94. {
  95. return false;
  96. }
  97. void HOTKEY_EDITOR_GRID_TABLE::SetValueAsLong( int row, int col, long value )
  98. {
  99. }
  100. void HOTKEY_EDITOR_GRID_TABLE::SetValueAsDouble( int row, int col, double value )
  101. {
  102. }
  103. void HOTKEY_EDITOR_GRID_TABLE::SetValueAsBool( int row, int col, bool value )
  104. {
  105. }
  106. void* HOTKEY_EDITOR_GRID_TABLE::GetValueAsCustom( int row, int col )
  107. {
  108. return 0;
  109. }
  110. void HOTKEY_EDITOR_GRID_TABLE::SetValueAsCustom( int row, int col, void* value )
  111. {
  112. }
  113. wxString HOTKEY_EDITOR_GRID_TABLE::GetColLabelValue( int col )
  114. {
  115. return col == 0 ? _( "Command" ) : _( "Hotkey" );
  116. }
  117. bool HOTKEY_EDITOR_GRID_TABLE::IsHeader( int row )
  118. {
  119. return m_hotkeys[row].second == NULL;
  120. }
  121. void HOTKEY_EDITOR_GRID_TABLE::SetKeyCode( int row, long key )
  122. {
  123. m_hotkeys[row].second->m_KeyCode = key;
  124. }
  125. void HOTKEY_EDITOR_GRID_TABLE::RestoreFrom( struct EDA_HOTKEY_CONFIG* origin )
  126. {
  127. int row = 0;
  128. EDA_HOTKEY_CONFIG* section;
  129. for( section = origin; section->m_HK_InfoList; section++ )
  130. {
  131. ++row; // Skip header
  132. EDA_HOTKEY** info_ptr;
  133. for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ )
  134. {
  135. EDA_HOTKEY* info = *info_ptr;
  136. m_hotkeys[row++].second->m_KeyCode = info->m_KeyCode;
  137. }
  138. }
  139. }
  140. HOTKEY_EDITOR_GRID_TABLE::~HOTKEY_EDITOR_GRID_TABLE()
  141. {
  142. hotkey_spec_vector::iterator i;
  143. for( i = m_hotkeys.begin(); i != m_hotkeys.end(); ++i )
  144. delete i->second;
  145. }