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.
|
|
|
|
*
|
2014-10-16 01:17:51 +00:00
|
|
|
* Copyright (C) 1992-2014 Kicad Developers, see CHANGELOG.TXT for contributors.
|
2010-08-29 16:36:52 +00:00
|
|
|
*
|
|
|
|
* 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>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
2014-10-16 01:17:46 +00:00
|
|
|
#include <confirm.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
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
HOTKEY_LIST_CTRL::HOTKEY_LIST_CTRL( wxWindow *aParent, struct EDA_HOTKEY_CONFIG* aSection ) :
|
|
|
|
wxListCtrl( aParent, wxID_ANY, wxDefaultPosition,
|
2014-10-17 14:36:47 +00:00
|
|
|
wxDefaultSize, wxLC_HRULES|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VIRTUAL )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
m_sectionTag = aSection->m_SectionTag;
|
|
|
|
m_curEditingRow = -1;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
InsertColumn( 0, _( "Command" ) );
|
|
|
|
InsertColumn( 1, _( "Hotkey" ) );
|
|
|
|
|
|
|
|
// Add a dummy hotkey_spec which is a header before each hotkey list
|
|
|
|
EDA_HOTKEY** hotkey_descr_list;
|
|
|
|
|
|
|
|
// Add a copy of hotkeys to our list
|
2014-10-17 14:36:47 +00:00
|
|
|
for( hotkey_descr_list = aSection->m_HK_InfoList; *hotkey_descr_list; hotkey_descr_list++ )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
EDA_HOTKEY* hotkey_descr = *hotkey_descr_list;
|
|
|
|
m_hotkeys.push_back( new EDA_HOTKEY( hotkey_descr ) );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
// Set item count to hotkey size, this gets it to autoload the entries
|
|
|
|
SetItemCount( m_hotkeys.size() );
|
|
|
|
|
|
|
|
SetColumnWidth( 0, wxLIST_AUTOSIZE );
|
|
|
|
SetColumnWidth( 1, wxLIST_AUTOSIZE );
|
|
|
|
|
|
|
|
Bind( wxEVT_CHAR, &HOTKEY_LIST_CTRL::OnChar, this );
|
|
|
|
Bind( wxEVT_LIST_ITEM_SELECTED, &HOTKEY_LIST_CTRL::OnListItemSelected, this );
|
|
|
|
Bind( wxEVT_SIZE, &HOTKEY_LIST_CTRL::OnSize, this );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_LIST_CTRL::OnSize( wxSizeEvent& aEvent )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:51 +00:00
|
|
|
recalculateColumns();
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
|
2014-10-16 01:17:51 +00:00
|
|
|
void HOTKEY_LIST_CTRL::recalculateColumns()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
float totalLength = 0;
|
|
|
|
float scale = 0;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
// Find max character length of first column
|
|
|
|
int maxInfoMsgLength = 0;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( int i = 0; i < GetItemCount(); i++ )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
int length = GetItemText( i, 0 ).Length();
|
2014-10-17 14:36:47 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
if( length > maxInfoMsgLength )
|
|
|
|
maxInfoMsgLength = length;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
// Find max character length of second column
|
|
|
|
int maxKeyCodeLength = 0;
|
2014-10-17 14:36:47 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( int i = 0; i < GetItemCount(); i++ )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
int length = GetItemText( i, 1 ).Length();
|
|
|
|
if( length > maxKeyCodeLength )
|
|
|
|
maxKeyCodeLength = length;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
// Use the lengths of column texts to create a scale of the max list width
|
|
|
|
// to set the column widths
|
|
|
|
totalLength = maxInfoMsgLength + maxKeyCodeLength;
|
|
|
|
|
|
|
|
scale = (float) GetClientSize().x / totalLength;
|
|
|
|
|
|
|
|
SetColumnWidth( 0, int( maxInfoMsgLength*scale ) - 2 );
|
|
|
|
SetColumnWidth( 1, int( maxKeyCodeLength*scale ) );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_LIST_CTRL::OnListItemSelected( wxListEvent& aEvent )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
m_curEditingRow = aEvent.GetIndex();
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_LIST_CTRL::DeselectRow( int aRow )
|
|
|
|
{
|
|
|
|
SetItemState( aRow, 0, wxLIST_STATE_SELECTED );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString HOTKEY_LIST_CTRL::OnGetItemText( long aRow, long aColumn ) const
|
|
|
|
{
|
|
|
|
EDA_HOTKEY* hotkey_descr = m_hotkeys[aRow];
|
|
|
|
|
|
|
|
if( aColumn == 0 )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
return hotkey_descr->m_InfoMsg;
|
|
|
|
}
|
|
|
|
else
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
return KeyNameFromKeyCode( hotkey_descr->m_KeyCode );
|
|
|
|
}
|
|
|
|
}
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_LIST_CTRL::OnChar( wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_curEditingRow != -1 )
|
|
|
|
{
|
|
|
|
long key = aEvent.GetKeyCode();
|
|
|
|
|
|
|
|
switch( key )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
case WXK_ESCAPE:
|
|
|
|
// Remove selection
|
|
|
|
DeselectRow( m_curEditingRow );
|
|
|
|
m_curEditingRow = -1;
|
|
|
|
break;
|
2014-12-18 18:53:19 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
default:
|
2014-12-18 18:53:19 +00:00
|
|
|
if( key >= 'a' && key <= 'z' ) // convert to uppercase
|
|
|
|
key = key + ('A' - 'a');
|
|
|
|
|
|
|
|
// Remap Ctrl A (=1+GR_KB_CTRL) to Ctrl Z(=26+GR_KB_CTRL)
|
|
|
|
// to GR_KB_CTRL+'A' .. GR_KB_CTRL+'Z'
|
|
|
|
if( aEvent.ControlDown() && key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
|
|
|
|
key += 'A' - 1;
|
|
|
|
|
|
|
|
/* Disallow shift for keys that have two keycodes on them (e.g. number and
|
|
|
|
* punctuation keys) leaving only the "letter keys" of A-Z.
|
|
|
|
* Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout)
|
|
|
|
* and Ctrl-( and Ctrl-5 (FR layout).
|
|
|
|
* Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout
|
|
|
|
*/
|
|
|
|
bool keyIsLetter = key >= 'A' && key <= 'Z';
|
|
|
|
|
|
|
|
if( aEvent.ShiftDown() && ( keyIsLetter || key > 256 ) )
|
|
|
|
key |= GR_KB_SHIFT;
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
if( aEvent.ControlDown() )
|
|
|
|
key |= GR_KB_CTRL;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
if( aEvent.AltDown() )
|
|
|
|
key |= GR_KB_ALT;
|
|
|
|
|
|
|
|
// See if this key code is handled in hotkeys names list
|
|
|
|
bool exists;
|
|
|
|
KeyNameFromKeyCode( key, &exists );
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
if( exists && m_hotkeys[m_curEditingRow]->m_KeyCode != key )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
bool canUpdate = ((HOTKEY_SECTION_PAGE *)m_parent)->GetDialog()->CanSetKey( key, m_sectionTag );
|
|
|
|
|
|
|
|
if( canUpdate )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
m_hotkeys[m_curEditingRow]->m_KeyCode = key;
|
2014-10-16 01:17:51 +00:00
|
|
|
recalculateColumns();
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
// Remove selection
|
|
|
|
DeselectRow( m_curEditingRow );
|
|
|
|
m_curEditingRow = -1;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-16 01:17:46 +00:00
|
|
|
RefreshItems(0,m_hotkeys.size()-1);
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_LIST_CTRL::RestoreFrom( struct EDA_HOTKEY_CONFIG* aSection )
|
|
|
|
{
|
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
EDA_HOTKEY** info_ptr;
|
|
|
|
|
|
|
|
for( info_ptr = aSection->m_HK_InfoList; *info_ptr; info_ptr++ )
|
|
|
|
{
|
|
|
|
EDA_HOTKEY* info = *info_ptr;
|
|
|
|
m_hotkeys[row++]->m_KeyCode = info->m_KeyCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove selection
|
|
|
|
DeselectRow( m_curEditingRow );
|
|
|
|
m_curEditingRow = -1;
|
|
|
|
|
|
|
|
RefreshItems( 0, m_hotkeys.size()-1 );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
HOTKEY_SECTION_PAGE::HOTKEY_SECTION_PAGE( HOTKEYS_EDITOR_DIALOG* aDialog,
|
|
|
|
wxNotebook* aParent,
|
|
|
|
const wxString& aTitle,
|
|
|
|
EDA_HOTKEY_CONFIG* aSection ) :
|
2014-10-17 14:36:47 +00:00
|
|
|
wxPanel( aParent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER ),
|
2014-10-16 01:17:46 +00:00
|
|
|
m_hotkeySection( aSection ),
|
|
|
|
m_dialog( aDialog )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
aParent->AddPage( this, aTitle );
|
|
|
|
|
|
|
|
wxBoxSizer* bMainSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2014-10-17 03:16:46 +00:00
|
|
|
SetSizer( bMainSizer );
|
|
|
|
Layout();
|
|
|
|
bMainSizer->Fit( this );
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
m_hotkeyList = new HOTKEY_LIST_CTRL( this, aSection );
|
|
|
|
bMainSizer->Add( m_hotkeyList, 1, wxALL|wxEXPAND, 5 );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEY_SECTION_PAGE::Restore()
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
m_hotkeyList->RestoreFrom( m_hotkeySection );
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 17:29:18 +00:00
|
|
|
void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
HOTKEYS_EDITOR_DIALOG dialog( aParent, aHotkeys );
|
|
|
|
|
|
|
|
int diag = dialog.ShowModal();
|
|
|
|
if( diag == wxID_OK )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
aParent->ReCreateMenuBar();
|
|
|
|
aParent->Refresh();
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 17:29:18 +00:00
|
|
|
HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent,
|
2014-10-16 01:17:46 +00:00
|
|
|
EDA_HOTKEY_CONFIG* aHotkeys ) :
|
|
|
|
HOTKEYS_EDITOR_DIALOG_BASE( aParent ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_hotkeys( aHotkeys )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
EDA_HOTKEY_CONFIG* section;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( section = m_hotkeys; section->m_HK_InfoList; section++ )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-17 14:36:47 +00:00
|
|
|
m_hotkeySectionPages.push_back( new HOTKEY_SECTION_PAGE( this, m_hotkeySections,
|
|
|
|
_( *section->m_Title ),
|
|
|
|
section ) );
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
m_OKButton->SetDefault();
|
|
|
|
Center();
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::OnOKClicked( wxCommandEvent& event )
|
2010-08-29 16:36:52 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
std::vector<HOTKEY_SECTION_PAGE*>::iterator i;
|
2010-08-29 16:36:52 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i )
|
2010-08-29 16:36:52 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
std::vector<EDA_HOTKEY*>& hotkey_vec = (*i)->GetHotkeys();
|
|
|
|
EDA_HOTKEY_CONFIG* section = (*i)->GetHotkeySection();
|
|
|
|
|
|
|
|
EDA_HOTKEY** info_ptr;
|
|
|
|
|
|
|
|
for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ )
|
|
|
|
{
|
|
|
|
EDA_HOTKEY* info = *info_ptr;
|
|
|
|
|
|
|
|
/* find the corresponding hotkey */
|
|
|
|
std::vector<EDA_HOTKEY*>::iterator j;
|
|
|
|
|
|
|
|
for( j = hotkey_vec.begin(); j != hotkey_vec.end(); ++j )
|
|
|
|
{
|
|
|
|
if( (*j) && (*j)->m_Idcommand == info->m_Idcommand )
|
|
|
|
{
|
|
|
|
info->m_KeyCode = (*j)->m_KeyCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the hotkeys */
|
|
|
|
m_parent->WriteHotkeyConfig( m_hotkeys );
|
|
|
|
|
|
|
|
EndModal( wxID_OK );
|
2010-08-29 16:36:52 +00:00
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::CancelClicked( wxCommandEvent& event )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
EndModal( wxID_CANCEL );
|
|
|
|
}
|
2010-08-28 18:02:24 +00:00
|
|
|
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
void HOTKEYS_EDITOR_DIALOG::UndoClicked( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
std::vector<HOTKEY_SECTION_PAGE*>::iterator i;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i )
|
|
|
|
{
|
|
|
|
(*i)->Restore();
|
|
|
|
}
|
|
|
|
}
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
bool HOTKEYS_EDITOR_DIALOG::CanSetKey( long aKey, const wxString* sectionTag )
|
|
|
|
{
|
|
|
|
std::vector<HOTKEY_SECTION_PAGE*>::iterator i;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
EDA_HOTKEY* conflictingKey = NULL;
|
|
|
|
HOTKEY_SECTION_PAGE* conflictingSection = NULL;
|
2010-08-28 18:02:24 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i )
|
|
|
|
{
|
|
|
|
// Any non Common section can only conflict with itself and Common
|
|
|
|
if( *sectionTag != g_CommonSectionTag
|
|
|
|
&& *((*i)->GetHotkeySection()->m_SectionTag) != g_CommonSectionTag
|
|
|
|
&& *((*i)->GetHotkeySection()->m_SectionTag) != *sectionTag )
|
|
|
|
continue;
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
std::vector<EDA_HOTKEY*>& hotkey_vec = (*i)->GetHotkeys();
|
|
|
|
/* find the corresponding hotkey */
|
|
|
|
std::vector<EDA_HOTKEY*>::iterator j;
|
|
|
|
|
|
|
|
for( j = hotkey_vec.begin(); j != hotkey_vec.end(); ++j )
|
|
|
|
{
|
|
|
|
if( aKey == (*j)->m_KeyCode )
|
2010-08-28 18:02:24 +00:00
|
|
|
{
|
2014-10-16 01:17:46 +00:00
|
|
|
conflictingKey = (*j);
|
|
|
|
conflictingSection = (*i);
|
|
|
|
|
|
|
|
break;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
2014-10-16 01:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 16:49:40 +00:00
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
if( conflictingKey != NULL )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
2014-10-17 14:36:47 +00:00
|
|
|
_( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want "
|
|
|
|
"to change its assignment?" ),
|
|
|
|
KeyNameFromKeyCode( aKey ), conflictingKey->m_InfoMsg,
|
|
|
|
*(conflictingSection->GetHotkeySection()->m_Title) );
|
2014-10-16 01:17:46 +00:00
|
|
|
|
|
|
|
wxMessageDialog dlg( this, msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_YES )
|
|
|
|
{
|
|
|
|
conflictingKey->m_KeyCode = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 01:17:46 +00:00
|
|
|
return true;
|
2010-08-28 18:02:24 +00:00
|
|
|
}
|