2012-01-23 04:33:36 +00:00
|
|
|
#include <hotkey_grid_table.h>
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads the hotkey table from its stored format into a format suitable
|
|
|
|
* for a wxGrid.
|
|
|
|
*/
|
2013-09-21 17:09:08 +00:00
|
|
|
HOTKEY_EDITOR_GRID_TABLE::HOTKEY_EDITOR_GRID_TABLE( struct EDA_HOTKEY_CONFIG* origin ) :
|
|
|
|
wxGridTableBase(), m_hotkeys()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2011-09-29 16:49:40 +00:00
|
|
|
EDA_HOTKEY_CONFIG* section;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
for( section = origin; section->m_HK_InfoList; section++ )
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
// Add a dummy hotkey_spec which is a header before each hotkey list
|
|
|
|
hotkey_spec spec( *section->m_SectionTag, NULL );
|
2010-08-28 18:02:24 +00:00
|
|
|
m_hotkeys.push_back( spec );
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
EDA_HOTKEY** hotkey_descr_list;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
// Add hotkeys descr
|
|
|
|
for( hotkey_descr_list = section->m_HK_InfoList; *hotkey_descr_list;
|
|
|
|
hotkey_descr_list++ )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
EDA_HOTKEY* hotkey_descr = *hotkey_descr_list;
|
|
|
|
hotkey_spec spec( *section->m_SectionTag, new EDA_HOTKEY( hotkey_descr ) );
|
2010-08-28 18:02:24 +00:00
|
|
|
m_hotkeys.push_back( spec );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
HOTKEY_EDITOR_GRID_TABLE::hotkey_spec_vector& HOTKEY_EDITOR_GRID_TABLE::getHotkeys()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return m_hotkeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
int HOTKEY_EDITOR_GRID_TABLE::GetNumberRows()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return m_hotkeys.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
int HOTKEY_EDITOR_GRID_TABLE::GetNumberCols()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
bool HOTKEY_EDITOR_GRID_TABLE::IsEmptyCell( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
return col == 1 && m_hotkeys[row].second == NULL;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
wxString HOTKEY_EDITOR_GRID_TABLE::GetValue( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
EDA_HOTKEY* hotkey_descr = m_hotkeys[row].second;
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
if( col == 0 )
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
if( hotkey_descr == NULL )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
// section header
|
|
|
|
return m_hotkeys[row].first;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
return hotkey_descr->m_InfoMsg;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
if( hotkey_descr == NULL )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
// section header
|
|
|
|
return wxEmptyString;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
return ReturnKeyNameFromKeyCode( hotkey_descr->m_KeyCode );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetValue( int row, int col, const wxString& value )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
wxString HOTKEY_EDITOR_GRID_TABLE::GetTypeName( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return wxGRID_VALUE_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
bool HOTKEY_EDITOR_GRID_TABLE::CanGetValueAs( int row, int col, const wxString& typeName )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return typeName == wxGRID_VALUE_STRING && col == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
bool HOTKEY_EDITOR_GRID_TABLE::CanSetValueAs( int row, int col, const wxString& typeName )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
long HOTKEY_EDITOR_GRID_TABLE::GetValueAsLong( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return -1L;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
double HOTKEY_EDITOR_GRID_TABLE::GetValueAsDouble( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
bool HOTKEY_EDITOR_GRID_TABLE::GetValueAsBool( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetValueAsLong( int row, int col, long value )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetValueAsDouble( int row, int col, double value )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetValueAsBool( int row, int col, bool value )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void* HOTKEY_EDITOR_GRID_TABLE::GetValueAsCustom( int row, int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetValueAsCustom( int row, int col, void* value )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
wxString HOTKEY_EDITOR_GRID_TABLE::GetColLabelValue( int col )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
return col == 0 ? _( "Command" ) : _( "Hotkey" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
bool HOTKEY_EDITOR_GRID_TABLE::IsHeader( int row )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
return m_hotkeys[row].second == NULL;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::SetKeyCode( int row, long key )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
m_hotkeys[row].second->m_KeyCode = key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
void HOTKEY_EDITOR_GRID_TABLE::RestoreFrom( struct EDA_HOTKEY_CONFIG* origin )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
int row = 0;
|
2011-09-29 16:49:40 +00:00
|
|
|
EDA_HOTKEY_CONFIG* section;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
for( section = origin; section->m_HK_InfoList; section++ )
|
|
|
|
{
|
2013-09-21 17:09:08 +00:00
|
|
|
++row; // Skip header
|
2011-09-29 16:49:40 +00:00
|
|
|
EDA_HOTKEY** info_ptr;
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ )
|
|
|
|
{
|
2011-09-29 16:49:40 +00:00
|
|
|
EDA_HOTKEY* info = *info_ptr;
|
2010-08-28 18:02:24 +00:00
|
|
|
m_hotkeys[row++].second->m_KeyCode = info->m_KeyCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
HOTKEY_EDITOR_GRID_TABLE::~HOTKEY_EDITOR_GRID_TABLE()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
hotkey_spec_vector::iterator i;
|
|
|
|
|
|
|
|
for( i = m_hotkeys.begin(); i != m_hotkeys.end(); ++i )
|
2013-09-21 17:09:08 +00:00
|
|
|
delete i->second;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|