2011-09-29 16:49:40 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_hotkeys_editor.cpp
|
|
|
|
*/
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 Kicad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <common.h>
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_hotkeys_editor.h>
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
void InstallHotkeyFrame( EDA_DRAW_FRAME* parent, EDA_HOTKEY_CONFIG* hotkeys )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
HOTKEYS_EDITOR_DIALOG dialog( parent, hotkeys );
|
|
|
|
|
|
|
|
int diag = dialog.ShowModal();
|
|
|
|
if( diag == wxID_OK )
|
|
|
|
{
|
|
|
|
parent->ReCreateMenuBar();
|
|
|
|
parent->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_DRAW_FRAME* parent,
|
|
|
|
EDA_HOTKEY_CONFIG* hotkeys ) :
|
2010-08-28 18:02:24 +00:00
|
|
|
HOTKEYS_EDITOR_DIALOG_BASE( parent )
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
m_hotkeys = hotkeys;
|
2010-08-29 16:36:52 +00:00
|
|
|
m_curEditingRow = -1;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
m_table = new HOTKEY_EDITOR_GRID_TABLE( hotkeys );
|
2010-08-28 18:02:24 +00:00
|
|
|
m_hotkeyGrid->SetTable( m_table, true );
|
|
|
|
|
|
|
|
m_hotkeyGrid->AutoSizeColumn( 0 );
|
|
|
|
m_hotkeyGrid->EnableDragGridSize( false );
|
|
|
|
|
|
|
|
for( int i = 0; i < m_hotkeyGrid->GetNumberRows(); ++i )
|
|
|
|
{
|
|
|
|
m_hotkeyGrid->SetReadOnly( i, 0, true );
|
|
|
|
m_hotkeyGrid->SetReadOnly( i, 1, true );
|
|
|
|
}
|
|
|
|
|
2011-03-14 15:17:18 +00:00
|
|
|
m_OKButton->SetDefault();
|
|
|
|
m_hotkeyGrid->SetFocus();
|
2010-08-28 18:02:24 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HOTKEYS_EDITOR_DIALOG::OnOKClicked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
/* edit the live hotkey table */
|
2013-09-21 17:09:08 +00:00
|
|
|
HOTKEY_EDITOR_GRID_TABLE::hotkey_spec_vector& hotkey_vec = m_table->getHotkeys();
|
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 = m_hotkeys; section->m_HK_InfoList; section++ )
|
|
|
|
{
|
2011-09-29 16:49:40 +00:00
|
|
|
wxString sectionTag = *section->m_SectionTag;
|
|
|
|
|
|
|
|
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
|
|
|
/* find the corresponding hotkey */
|
2013-09-21 17:09:08 +00:00
|
|
|
HOTKEY_EDITOR_GRID_TABLE::hotkey_spec_vector::iterator i;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
for( i = hotkey_vec.begin(); i != hotkey_vec.end(); ++i )
|
|
|
|
{
|
|
|
|
if( i->first == sectionTag
|
|
|
|
&& i->second
|
|
|
|
&& i->second->m_Idcommand == info->m_Idcommand )
|
|
|
|
{
|
|
|
|
info->m_KeyCode = i->second->m_KeyCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the hotkeys */
|
|
|
|
m_parent->WriteHotkeyConfig( m_hotkeys );
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
EndModal( wxID_OK );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HOTKEYS_EDITOR_DIALOG::CancelClicked( wxCommandEvent& event )
|
|
|
|
{
|
2010-08-29 16:36:52 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
/* Reinit the hotkeys to the initial state (remove all pending changes
|
|
|
|
*/
|
2010-08-28 18:02:24 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::UndoClicked( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_table->RestoreFrom( m_hotkeys );
|
2010-08-28 19:08:58 +00:00
|
|
|
m_curEditingRow = -1;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 19:08:58 +00:00
|
|
|
for( int i = 0; i < m_hotkeyGrid->GetNumberRows(); ++i )
|
|
|
|
SetHotkeyCellState( i, false );
|
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
m_hotkeyGrid->Refresh();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HOTKEYS_EDITOR_DIALOG::SetHotkeyCellState( int aRow, bool aHightlight )
|
|
|
|
{
|
|
|
|
if( aHightlight )
|
|
|
|
{
|
|
|
|
m_hotkeyGrid->SetCellTextColour( aRow, 1, *wxRED );
|
|
|
|
wxFont bold_font(m_hotkeyGrid->GetDefaultCellFont() );
|
|
|
|
bold_font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
m_hotkeyGrid->SetCellFont( aRow, 1, bold_font );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hotkeyGrid->SetCellTextColour( aRow, 1, m_hotkeyGrid->GetDefaultCellTextColour() );
|
|
|
|
m_hotkeyGrid->SetCellFont( aRow, 1, m_hotkeyGrid->GetDefaultCellFont() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::OnClickOnCell( wxGridEvent& event )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
if( m_curEditingRow != -1 )
|
|
|
|
SetHotkeyCellState( m_curEditingRow, false );
|
|
|
|
|
|
|
|
int newRow = event.GetRow();
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2013-09-21 17:09:08 +00:00
|
|
|
if( ( event.GetCol() != 1 ) || ( m_table->IsHeader( newRow ) ) )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
m_curEditingRow = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_curEditingRow = newRow;
|
|
|
|
SetHotkeyCellState( m_curEditingRow, true );
|
|
|
|
}
|
|
|
|
m_hotkeyGrid->Refresh();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
/** OnRightClickOnCell
|
|
|
|
* If a cell is selected, display a list of keys for selection
|
|
|
|
* The list is restricted to keys that cannot be entered:
|
|
|
|
* tab, home ... because these keys have special functions in dialogs
|
|
|
|
*/
|
|
|
|
void HOTKEYS_EDITOR_DIALOG::OnRightClickOnCell( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
// Select the new cell if needed
|
|
|
|
OnClickOnCell(event);
|
|
|
|
|
|
|
|
if( m_curEditingRow == -1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Do not translate these key names. They are internally used.
|
|
|
|
//ee hotkeys_basic.cpp
|
|
|
|
#define C_COUNT 8
|
|
|
|
wxString choices[C_COUNT] =
|
|
|
|
{
|
|
|
|
wxT("End")
|
|
|
|
wxT("Tab"),
|
|
|
|
wxT("Ctrl+Tab"),
|
|
|
|
wxT("Alt+Tab"),
|
|
|
|
wxT("Home"),
|
|
|
|
wxT("Space"),
|
|
|
|
wxT("Ctrl+Space"),
|
|
|
|
wxT("Alt+Space"),
|
|
|
|
};
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
wxString keyname = wxGetSingleChoice( _( "Special keys only. For others keys, use keyboard" ),
|
|
|
|
_( "Select a key" ), C_COUNT, choices, this );
|
2010-08-29 16:36:52 +00:00
|
|
|
int key = ReturnKeyCodeFromKeyName( keyname );
|
|
|
|
|
|
|
|
if( key == 0 )
|
|
|
|
return;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
m_table->SetKeyCode( m_curEditingRow, key );
|
|
|
|
m_hotkeyGrid->Refresh();
|
|
|
|
Update();
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::OnKeyPressed( wxKeyEvent& event )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
|
|
|
if( m_curEditingRow != -1 )
|
|
|
|
{
|
|
|
|
long key = event.GetKeyCode();
|
|
|
|
|
|
|
|
switch( key )
|
|
|
|
{
|
|
|
|
case WXK_ESCAPE:
|
|
|
|
SetHotkeyCellState( m_curEditingRow, false );
|
|
|
|
m_curEditingRow = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if( event.ControlDown() )
|
|
|
|
key |= GR_KB_CTRL;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
if( event.AltDown() )
|
|
|
|
key |= GR_KB_ALT;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
if( event.ShiftDown() && (key > 256) )
|
|
|
|
key |= GR_KB_SHIFT;
|
|
|
|
|
|
|
|
// Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
|
|
|
|
// to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
|
|
|
|
if( (key > GR_KB_CTRL) && (key <= GR_KB_CTRL+26) )
|
|
|
|
key += ('A' - 1);
|
|
|
|
|
2010-08-29 16:36:52 +00:00
|
|
|
if( key >= 'a' && key <= 'z' ) // convert to uppercase
|
2010-08-28 18:02:24 +00:00
|
|
|
key = key + ('A' - 'a');
|
|
|
|
|
2010-08-28 19:08:58 +00:00
|
|
|
#if 0 // For debug only
|
2010-08-28 18:02:24 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf(wxT("key %X, keycode %X"),event.GetKeyCode(), key);
|
|
|
|
wxMessageBox(msg);
|
|
|
|
#endif
|
2010-08-29 16:36:52 +00:00
|
|
|
// See if this key code is handled in hotkeys names list
|
2010-08-28 18:02:24 +00:00
|
|
|
bool exists;
|
|
|
|
ReturnKeyNameFromKeyCode( key, &exists );
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 19:08:58 +00:00
|
|
|
if( !exists ) // not handled, see hotkeys_basic.cpp
|
2011-09-29 16:49:40 +00:00
|
|
|
{
|
|
|
|
wxMessageBox( _( "Hotkey code not handled" ) );
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_table->SetKeyCode( m_curEditingRow, key );
|
|
|
|
}
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_hotkeyGrid->Refresh();
|
|
|
|
Update();
|
|
|
|
}
|