diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 8d8844dc2b..80103c05aa 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -26,6 +26,8 @@ set(COMMON_SRCS confirm.cpp copy_to_clipboard.cpp dialog_display_info_HTML_base.cpp + dialog_hotkeys_editor.cpp + dialog_hotkeys_editor_base.cpp dialog_load_error.cpp dcsvg.cpp dialog_page_settings_base.cpp @@ -42,6 +44,7 @@ set(COMMON_SRCS get_component_dialog.cpp gr_basic.cpp hotkeys_basic.cpp + hotkey_grid_table.cpp msgpanel.cpp netlist_keywords.cpp newstroke_font.cpp diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 59888ccdcf..a40b12e7d4 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -355,13 +355,21 @@ void WinEDA_BasicFrame::CopyVersionInfoToClipboard( wxCommandEvent& WXUNUSED( ev #define __BO_COMPILER ",unknown" #endif +#if wxCHECK_VERSION( 2, 9, 0 ) +#define KICAD_BUILD_OPTIONS_SIGNATURE \ + " (" __WX_BO_UNICODE \ + __ABI_VERSION __BO_COMPILER \ + __WX_BO_STL \ + __WX_BO_WXWIN_COMPAT_2_6 __WX_BO_WXWIN_COMPAT_2_8 \ + ")" +#else #define KICAD_BUILD_OPTIONS_SIGNATURE \ " (" __WX_BO_DEBUG "," __WX_BO_UNICODE \ __ABI_VERSION __BO_COMPILER \ __WX_BO_STL \ __WX_BO_WXWIN_COMPAT_2_4 __WX_BO_WXWIN_COMPAT_2_6 \ ")" - +#endif tmp = wxT( "Application: " ) + wxGetApp().GetTitle() + wxT( "\n" ); tmp += wxT( "Version: " ) + GetBuildVersion() + wxT( "\n" ); tmp << wxT( "Build: " ) << wxVERSION_STRING diff --git a/common/dialog_hotkeys_editor.cpp b/common/dialog_hotkeys_editor.cpp new file mode 100644 index 0000000000..6ef2905799 --- /dev/null +++ b/common/dialog_hotkeys_editor.cpp @@ -0,0 +1,191 @@ +#include +#include + +#include "fctsys.h" +#include "appl_wxstruct.h" +#include "gr_basic.h" +#include "common.h" +#include "class_drawpanel.h" +#include "confirm.h" + +#include "dialog_hotkeys_editor.h" + +void InstallHotkeyFrame( WinEDA_DrawFrame* parent, + Ki_HotkeyInfoSectionDescriptor* hotkeys ) +{ + HOTKEYS_EDITOR_DIALOG dialog( parent, hotkeys ); + + int diag = dialog.ShowModal(); + if( diag == wxID_OK ) + { + parent->ReCreateMenuBar(); + parent->Refresh(); + } +} + + +HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( WinEDA_DrawFrame* parent, + Ki_HotkeyInfoSectionDescriptor* hotkeys ) : + HOTKEYS_EDITOR_DIALOG_BASE( parent ) +{ + m_parent = parent; + m_hotkeys = hotkeys; + + m_table = new HotkeyGridTable( hotkeys ); + 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 ); + } + + SetFocus(); + GetSizer()->SetSizeHints( this ); + Center(); +} + + +void HOTKEYS_EDITOR_DIALOG::OnOKClicked( wxCommandEvent& event ) +{ + /* edit the live hotkey table */ + HotkeyGridTable::hotkey_spec_vector& hotkey_vec = m_table->getHotkeys(); + + Ki_HotkeyInfoSectionDescriptor* section; + + for( section = m_hotkeys; section->m_HK_InfoList; section++ ) + { + wxString sectionTag = *section->m_SectionTag; + + Ki_HotkeyInfo** info_ptr; + for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ ) + { + Ki_HotkeyInfo* info = *info_ptr; + /* find the corresponding hotkey */ + HotkeyGridTable::hotkey_spec_vector::iterator i; + 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 ); + + Close( TRUE ); +} + + +void HOTKEYS_EDITOR_DIALOG::CancelClicked( wxCommandEvent& event ) +{ + Close( TRUE ); +} + + +void HOTKEYS_EDITOR_DIALOG::UndoClicked( wxCommandEvent& event ) +{ + m_table->RestoreFrom( m_hotkeys ); + 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() ); + } +} + + +void HOTKEYS_EDITOR_DIALOG::StartEditing( wxGridEvent& event ) +{ + if( m_curEditingRow != -1 ) + SetHotkeyCellState( m_curEditingRow, false ); + + int newRow = event.GetRow(); + if( m_curEditingRow == newRow || m_table->isHeader( newRow ) ) + { + m_curEditingRow = -1; + } + else + { + m_curEditingRow = newRow; + SetHotkeyCellState( m_curEditingRow, true ); + } + m_hotkeyGrid->Refresh(); + Update(); +} + + +void HOTKEYS_EDITOR_DIALOG::KeyPressed( wxKeyEvent& event ) +{ + 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; + if( event.AltDown() ) + key |= GR_KB_ALT; + 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); + + if( key >= 'a' && key <= 'z' ) //upcase key + key = key + ('A' - 'a'); + +#if 0 // For debug + wxString msg; + msg.Printf(wxT("key %X, keycode %X"),event.GetKeyCode(), key); + wxMessageBox(msg); +#endif + // See if this key code is handled in hotkeys list + bool exists; + ReturnKeyNameFromKeyCode( key, &exists ); + if( !exists ) // not handled, see s_Hotkey_Name_List[] in hotkeys_basic.cpp + wxMessageBox( _("Hotkey value not handled" ) ); + else + { + m_table->SetKeyCode( m_curEditingRow, key ); + SetHotkeyCellState( m_curEditingRow, false ); + } + break; + } + } + + m_hotkeyGrid->Refresh(); + Update(); +} diff --git a/common/dialog_hotkeys_editor_base.cpp b/common/dialog_hotkeys_editor_base.cpp new file mode 100644 index 0000000000..09e18c1aca --- /dev/null +++ b/common/dialog_hotkeys_editor_base.cpp @@ -0,0 +1,79 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Apr 16 2008) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_hotkeys_editor_base.h" + +/////////////////////////////////////////////////////////////////////////// + +HOTKEYS_EDITOR_DIALOG_BASE::HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* bMainSizer; + bMainSizer = new wxBoxSizer( wxHORIZONTAL ); + + m_hotkeyGrid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_hotkeyGrid->CreateGrid( 5, 2 ); + m_hotkeyGrid->EnableEditing( true ); + m_hotkeyGrid->EnableGridLines( true ); + m_hotkeyGrid->EnableDragGridSize( false ); + m_hotkeyGrid->SetMargins( 0, 0 ); + + // Columns + m_hotkeyGrid->AutoSizeColumns(); + m_hotkeyGrid->EnableDragColMove( false ); + m_hotkeyGrid->EnableDragColSize( true ); + m_hotkeyGrid->SetColLabelSize( 30 ); + m_hotkeyGrid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Rows + m_hotkeyGrid->EnableDragRowSize( true ); + m_hotkeyGrid->SetRowLabelSize( 0 ); + m_hotkeyGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Label Appearance + + // Cell Defaults + m_hotkeyGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + bMainSizer->Add( m_hotkeyGrid, 1, wxALL|wxEXPAND, 5 ); + + wxBoxSizer* bSizer2; + bSizer2 = new wxBoxSizer( wxVERTICAL ); + + m_OKButton = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer2->Add( m_OKButton, 0, wxALL|wxEXPAND, 5 ); + + m_cancelButton = new wxButton( this, wxID_ANY, _("Close"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer2->Add( m_cancelButton, 0, wxALL|wxEXPAND, 5 ); + + m_undoButton = new wxButton( this, wxID_CANCEL, _("Undo"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer2->Add( m_undoButton, 0, wxALL|wxEXPAND, 5 ); + + bMainSizer->Add( bSizer2, 0, wxALIGN_CENTER_VERTICAL, 5 ); + + this->SetSizer( bMainSizer ); + this->Layout(); + + // Connect Events + m_hotkeyGrid->Connect( wxEVT_CHAR, wxKeyEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::KeyPressed ), NULL, this ); + m_hotkeyGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::StartEditing ), NULL, this ); + m_OKButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::OnOKClicked ), NULL, this ); + m_cancelButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::CancelClicked ), NULL, this ); + m_undoButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::UndoClicked ), NULL, this ); +} + +HOTKEYS_EDITOR_DIALOG_BASE::~HOTKEYS_EDITOR_DIALOG_BASE() +{ + // Disconnect Events + m_hotkeyGrid->Disconnect( wxEVT_CHAR, wxKeyEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::KeyPressed ), NULL, this ); + m_hotkeyGrid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::StartEditing ), NULL, this ); + m_OKButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::OnOKClicked ), NULL, this ); + m_cancelButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::CancelClicked ), NULL, this ); + m_undoButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( HOTKEYS_EDITOR_DIALOG_BASE::UndoClicked ), NULL, this ); +} diff --git a/common/dialog_hotkeys_editor_base.fbp b/common/dialog_hotkeys_editor_base.fbp new file mode 100644 index 0000000000..774211ca6b --- /dev/null +++ b/common/dialog_hotkeys_editor_base.fbp @@ -0,0 +1,359 @@ + + + + + + C++ + 1 + UTF-8 + connect + dialog_hotkeys_editor_base + 1000 + none + 1 + dialog_hotkeys_editor_base + + . + + 1 + 0 + 0 + + + + + 1 + + + + 0 + wxID_ANY + + + HOTKEYS_EDITOR_DIALOG_BASE + + 304,235 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + + Hotkeys Editor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bMainSizer + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 0 + + + + wxALIGN_LEFT + + wxALIGN_TOP + wxALIGN_CENTRE + 30 + + wxALIGN_CENTRE + 2 + + + 0 + 1 + 0 + 1 + 1 + 1 + + + + 1 + 0 + wxID_ANY + + + + 0 + 0 + + + m_hotkeyGrid + protected + + wxALIGN_CENTRE + 0 + + wxALIGN_CENTRE + + 5 + + + + + + + KeyPressed + + + + StartEditing + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL + 0 + + + bSizer2 + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + + + 0 + 1 + + + 0 + wxID_OK + OK + + + m_OKButton + protected + + + + + + + + + OnOKClicked + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + + + 0 + 1 + + + 0 + wxID_ANY + Close + + + m_cancelButton + protected + + + + + + + + + CancelClicked + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 0 + + + + 0 + 1 + + + 0 + wxID_CANCEL + Undo + + + m_undoButton + protected + + + + + + + + + UndoClicked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/common/dialog_hotkeys_editor_base.h b/common/dialog_hotkeys_editor_base.h new file mode 100644 index 0000000000..18962111c7 --- /dev/null +++ b/common/dialog_hotkeys_editor_base.h @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Apr 16 2008) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __dialog_hotkeys_editor_base__ +#define __dialog_hotkeys_editor_base__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class HOTKEYS_EDITOR_DIALOG_BASE +/////////////////////////////////////////////////////////////////////////////// +class HOTKEYS_EDITOR_DIALOG_BASE : public wxDialog +{ + private: + + protected: + wxGrid* m_hotkeyGrid; + wxButton* m_OKButton; + wxButton* m_cancelButton; + wxButton* m_undoButton; + + // Virtual event handlers, overide them in your derived class + virtual void KeyPressed( wxKeyEvent& event ){ event.Skip(); } + virtual void StartEditing( wxGridEvent& event ){ event.Skip(); } + virtual void OnOKClicked( wxCommandEvent& event ){ event.Skip(); } + virtual void CancelClicked( wxCommandEvent& event ){ event.Skip(); } + virtual void UndoClicked( wxCommandEvent& event ){ event.Skip(); } + + + public: + HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Hotkeys Editor"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 304,235 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~HOTKEYS_EDITOR_DIALOG_BASE(); + +}; + +#endif //__dialog_hotkeys_editor_base__ diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index 7dc03c4c68..38e1829835 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -1384,9 +1384,9 @@ void WinEDA_DrawPanel::OnKeyEvent( wxKeyEvent& event ) /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z * They have an ascii code from 1 to 27 remapped - * GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z' + * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z' */ - if( (localkey & (GR_KB_CTRL|GR_KB_ALT|GR_KB_SHIFT)) == GR_KB_CTRL ) + if( (localkey > GR_KB_CTRL) && (localkey <= GR_KB_CTRL+26) ) localkey += 'A' - 1; INSTALL_DC( DC, this ); diff --git a/common/edaappl.cpp b/common/edaappl.cpp index c56cbb164a..5fdae6007d 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -612,8 +612,6 @@ void WinEDA_App::GetSettings(bool aReopenLastUsedDirectory) m_LanguageId = m_EDA_CommonConfig->Read( wxT( "Language" ), wxLANGUAGE_DEFAULT ); m_EditorName = m_EDA_CommonConfig->Read( wxT( "Editor" ) ); - g_ConfigFileLocationChoice = m_EDA_CommonConfig->Read( HOTKEY_CFG_PATH_OPT, - 0L ); m_fileHistory.Load( *m_EDA_Config ); diff --git a/common/hotkey_grid_table.cpp b/common/hotkey_grid_table.cpp new file mode 100644 index 0000000000..ce372e733d --- /dev/null +++ b/common/hotkey_grid_table.cpp @@ -0,0 +1,198 @@ +#include "hotkey_grid_table.h" + +/* + * Reads the hotkey table from its stored format into a format suitable + * for a wxGrid. + */ +HotkeyGridTable::HotkeyGridTable( struct + Ki_HotkeyInfoSectionDescriptor* origin ) : + wxGridTableBase(), + m_hotkeys() +{ + Ki_HotkeyInfoSectionDescriptor* section; + + for( section = origin; section->m_HK_InfoList; section++ ) + { + hotkey_spec spec( *section->m_SectionTag, 0 ); + m_hotkeys.push_back( spec ); + + Ki_HotkeyInfo** info_ptr; + for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ ) + { + Ki_HotkeyInfo* info = *info_ptr; + hotkey_spec spec( *section->m_SectionTag, + new Ki_HotkeyInfo( info ) ); + m_hotkeys.push_back( spec ); + } + } +} + + +HotkeyGridTable::hotkey_spec_vector& HotkeyGridTable::getHotkeys() +{ + return m_hotkeys; +} + + +int HotkeyGridTable::GetNumberRows() +{ + return m_hotkeys.size(); +} + + +int HotkeyGridTable::GetNumberCols() +{ + return 2; +} + + +bool HotkeyGridTable::IsEmptyCell( int row, int col ) +{ + return col == 1 && m_hotkeys[row].second == 0; +} + + +wxString HotkeyGridTable::GetValue( int row, int col ) +{ + if( col == 0 ) + { + if( m_hotkeys[row].second == 0 ) + { + // section header + return m_hotkeys[row].first; + } + else + { + return m_hotkeys[row].second->m_InfoMsg; + } + } + else + { + if( m_hotkeys[row].second == 0 ) + { + return wxString(); + } + else + { + return ReturnKeyNameFromKeyCode( m_hotkeys[row].second->m_KeyCode ); + } + } +} + + +void HotkeyGridTable::SetValue( int row, int col, const wxString& value ) +{ +} + + +wxString HotkeyGridTable::GetTypeName( int row, int col ) +{ + return wxGRID_VALUE_STRING; +} + + +bool HotkeyGridTable::CanGetValueAs( int row, int col, const wxString& typeName ) +{ + return typeName == wxGRID_VALUE_STRING && col == 2; +} + + +bool HotkeyGridTable::CanSetValueAs( int row, int col, const wxString& typeName ) +{ + return false; +} + + +long HotkeyGridTable::GetValueAsLong( int row, int col ) +{ + return -1L; +} + + +double HotkeyGridTable::GetValueAsDouble( int row, int col ) +{ + return 0.0; +} + + +bool HotkeyGridTable::GetValueAsBool( int row, int col ) +{ + return false; +} + + +void HotkeyGridTable::SetValueAsLong( int row, int col, long value ) +{ +} + + +void HotkeyGridTable::SetValueAsDouble( int row, int col, double value ) +{ +} + + +void HotkeyGridTable::SetValueAsBool( int row, int col, bool value ) +{ +} + + +void* HotkeyGridTable::GetValueAsCustom( int row, int col ) +{ + return 0; +} + + +void HotkeyGridTable::SetValueAsCustom( int row, int col, void* value ) +{ +} + + +wxString HotkeyGridTable::GetColLabelValue( int col ) +{ + return col == 0 ? _( "Command" ) : _( "Hotkey" ); +} + + +bool HotkeyGridTable::isHeader( int row ) +{ + return m_hotkeys[row].second == 0; +} + + +void HotkeyGridTable::SetKeyCode( int row, long key ) +{ + m_hotkeys[row].second->m_KeyCode = key; +} + + +void HotkeyGridTable::RestoreFrom( struct + Ki_HotkeyInfoSectionDescriptor* origin ) +{ + int row = 0; + Ki_HotkeyInfoSectionDescriptor* section; + + for( section = origin; section->m_HK_InfoList; section++ ) + { + ++row; + Ki_HotkeyInfo** info_ptr; + for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ ) + { + Ki_HotkeyInfo* info = *info_ptr; + m_hotkeys[row++].second->m_KeyCode = info->m_KeyCode; + } + } +} + + +HotkeyGridTable::~HotkeyGridTable() +{ + hotkey_spec_vector::iterator i; + + for( i = m_hotkeys.begin(); i != m_hotkeys.end(); ++i ) + { + if( i->second ) + { + delete i->second; + } + } +} diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index 0a14cdb6eb..850c536cad 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -16,10 +16,13 @@ #include "kicad_string.h" #include "gestfich.h" #include "wxstruct.h" +#include "dialog_hotkeys_editor.h" #include #include +#include +#define HOTKEYS_CONFIG_KEY wxT( "Keys" ) wxString g_CommonSectionTag( wxT( "[common]" ) ); wxString g_SchematicSectionTag( wxT( "[eeschema]" ) ); @@ -28,13 +31,6 @@ wxString g_BoardEditorSectionTag( wxT( "[pcbnew]" ) ); wxString g_ModuleEditSectionTag( wxT( "[footprinteditor]" ) ); -/* 0 = files are in Home directory (usefull under unix) - * 1 = kicad/template ( usefull only under windows ) - * 2 ... = unused - */ -int g_ConfigFileLocationChoice; - - /* Class to handle hotkey commnands. hotkeys have a default value * This class allows the real key code changed by user from a key code list * file. @@ -53,6 +49,15 @@ Ki_HotkeyInfo::Ki_HotkeyInfo( const wxChar* infomsg, int idcommand, } +Ki_HotkeyInfo::Ki_HotkeyInfo( const Ki_HotkeyInfo* base ) +{ + m_KeyCode = base->m_KeyCode; + m_InfoMsg = base->m_InfoMsg; + m_Idcommand = base->m_Idcommand; + m_IdMenuEvent = base->m_IdMenuEvent; +} + + /* class to handle the printable name and the keycode */ struct hotkey_name_descr @@ -61,154 +66,44 @@ struct hotkey_name_descr int m_KeyCode; }; +/* table giving the hotkey name from the hotkey code, for special keys + * Note : when modifiers (ATL, SHIFT, CTRL) do not modify + * the code of the key, do need to enter the modified key code + * For instance wxT( "F1" ), WXK_F1 handle F1, AltF1, CtrlF1 ... + */ static struct hotkey_name_descr s_Hotkey_Name_List[] = { - { wxT( "F1" ), WXK_F1 }, - { wxT( "F2" ), WXK_F2 }, - { wxT( "F3" ), WXK_F3 }, - { wxT( "F4" ), WXK_F4 }, - { wxT( "F5" ), WXK_F5 }, - { wxT( "F6" ), WXK_F6 }, - { wxT( "F7" ), WXK_F7 }, - { wxT( "F8" ), WXK_F8 }, - { wxT( "F9" ), WXK_F9 }, - { wxT( "F10" ), WXK_F10 }, - { wxT( "F11" ), WXK_F11 }, - { wxT( "F12" ), WXK_F12 }, + { wxT( "F1" ), WXK_F1 }, + { wxT( "F2" ), WXK_F2 }, + { wxT( "F3" ), WXK_F3 }, + { wxT( "F4" ), WXK_F4 }, + { wxT( "F5" ), WXK_F5 }, + { wxT( "F6" ), WXK_F6 }, + { wxT( "F7" ), WXK_F7 }, + { wxT( "F8" ), WXK_F8 }, + { wxT( "F9" ), WXK_F9 }, + { wxT( "F10" ), WXK_F10 }, + { wxT( "F11" ), WXK_F11 }, + { wxT( "F12" ), WXK_F12 }, - { wxT( "Esc" ), WXK_ESCAPE }, - { wxT( "Del" ), WXK_DELETE }, - { wxT( "Tab" ), '\t' }, - { wxT( "BkSp" ), WXK_BACK }, - { wxT( "Ins" ), WXK_INSERT }, + { wxT( "Esc" ), WXK_ESCAPE }, + { wxT( "Del" ), WXK_DELETE }, + { wxT( "Tab" ), '\t' }, + { wxT( "BkSp" ), WXK_BACK }, + { wxT( "Ins" ), WXK_INSERT }, - { wxT( "Home" ), WXK_HOME }, - { wxT( "End" ), WXK_END }, - { wxT( "PgUp" ), WXK_PAGEUP }, - { wxT( "PgDn" ), WXK_PAGEDOWN }, + { wxT( "Home" ), WXK_HOME }, + { wxT( "End" ), WXK_END }, + { wxT( "PgUp" ), WXK_PAGEUP }, + { wxT( "PgDn" ), WXK_PAGEDOWN }, - { wxT( "Up" ), WXK_UP }, - { wxT( "Down" ), WXK_DOWN }, - { wxT( "Left" ), WXK_LEFT }, - { wxT( "Right" ), WXK_RIGHT }, - - { wxT( "space" ), ' ' }, - { wxT( "?" ), '?' }, - { wxT( "!" ), '!' }, - { wxT( ";" ), ';' }, - { wxT( ":" ), ':' }, - { wxT( "." ), '.' }, - { wxT( "," ), ',' }, - { wxT( "*" ), '*' }, - { wxT( "+" ), '+' }, - { wxT( "=" ), '=' }, - { wxT( "-" ), '-' }, - { wxT( "%%" ), '%' }, - { wxT( "[" ), '[' }, - { wxT( "]" ), ']' }, - { wxT( "'" ), '\'' }, - { wxT( "`" ), '`' }, - { wxT( "/" ), '/' }, - { wxT( "\\" ), '\\' }, - { wxT( "0" ), '0' }, - { wxT( "1" ), '1' }, - { wxT( "2" ), '2' }, - { wxT( "3" ), '3' }, - { wxT( "4" ), '4' }, - { wxT( "5" ), '5' }, - { wxT( "6" ), '6' }, - { wxT( "7" ), '7' }, - { wxT( "8" ), '8' }, - { wxT( "9" ), '9' }, - { wxT( "A" ), 'A' }, - { wxT( "B" ), 'B' }, - { wxT( "C" ), 'C' }, - { wxT( "D" ), 'D' }, - { wxT( "E" ), 'E' }, - { wxT( "F" ), 'F' }, - { wxT( "G" ), 'G' }, - { wxT( "H" ), 'H' }, - { wxT( "I" ), 'I' }, - { wxT( "J" ), 'J' }, - { wxT( "K" ), 'K' }, - { wxT( "L" ), 'L' }, - { wxT( "M" ), 'M' }, - { wxT( "N" ), 'N' }, - { wxT( "O" ), 'O' }, - { wxT( "P" ), 'P' }, - { wxT( "Q" ), 'Q' }, - { wxT( "R" ), 'R' }, - { wxT( "S" ), 'S' }, - { wxT( "T" ), 'T' }, - { wxT( "U" ), 'U' }, - { wxT( "V" ), 'V' }, - { wxT( "W" ), 'W' }, - { wxT( "X" ), 'X' }, - { wxT( "Y" ), 'Y' }, - { wxT( "Z" ), 'Z' }, - - { wxT( "Ctrl++" ), GR_KB_CTRL + '+' }, - { wxT( "Ctrl+-" ), GR_KB_CTRL + '-' }, - - { wxT( "Ctrl+A" ), GR_KB_CTRL + 'A' }, - { wxT( "Ctrl+B" ), GR_KB_CTRL + 'B' }, - { wxT( "Ctrl+C" ), GR_KB_CTRL + 'C' }, - { wxT( "Ctrl+D" ), GR_KB_CTRL + 'D' }, - { wxT( "Ctrl+E" ), GR_KB_CTRL + 'E' }, - { wxT( "Ctrl+F" ), GR_KB_CTRL + 'F' }, - { wxT( "Ctrl+G" ), GR_KB_CTRL + 'G' }, - { wxT( "Ctrl+H" ), GR_KB_CTRL + 'H' }, - { wxT( "Ctrl+I" ), GR_KB_CTRL + 'I' }, - { wxT( "Ctrl+J" ), GR_KB_CTRL + 'J' }, - { wxT( "Ctrl+K" ), GR_KB_CTRL + 'K' }, - { wxT( "Ctrl+L" ), GR_KB_CTRL + 'L' }, - { wxT( "Ctrl+M" ), GR_KB_CTRL + 'M' }, - { wxT( "Ctrl+N" ), GR_KB_CTRL + 'N' }, - { wxT( "Ctrl+O" ), GR_KB_CTRL + 'O' }, - { wxT( "Ctrl+P" ), GR_KB_CTRL + 'P' }, - { wxT( "Ctrl+Q" ), GR_KB_CTRL + 'Q' }, - { wxT( "Ctrl+R" ), GR_KB_CTRL + 'R' }, - { wxT( "Ctrl+S" ), GR_KB_CTRL + 'S' }, - { wxT( "Ctrl+T" ), GR_KB_CTRL + 'T' }, - { wxT( "Ctrl+U" ), GR_KB_CTRL + 'U' }, - { wxT( "Ctrl+V" ), GR_KB_CTRL + 'V' }, - { wxT( "Ctrl+W" ), GR_KB_CTRL + 'W' }, - { wxT( "Ctrl+X" ), GR_KB_CTRL + 'X' }, - { wxT( "Ctrl+Y" ), GR_KB_CTRL + 'Y' }, - { wxT( "Ctrl+Z" ), GR_KB_CTRL + 'Z' }, - - { wxT( "Shift+Ctrl++" ), GR_KB_SHIFT + GR_KB_CTRL + '+' }, - { wxT( "Shift+Ctrl+-" ), GR_KB_SHIFT + GR_KB_CTRL + '-' }, - - { wxT( "Shift+Ctrl+A" ), GR_KB_SHIFT + GR_KB_CTRL + 'A' }, - { wxT( "Shift+Ctrl+B" ), GR_KB_SHIFT + GR_KB_CTRL + 'B' }, - { wxT( "Shift+Ctrl+C" ), GR_KB_SHIFT + GR_KB_CTRL + 'C' }, - { wxT( "Shift+Ctrl+D" ), GR_KB_SHIFT + GR_KB_CTRL + 'D' }, - { wxT( "Shift+Ctrl+E" ), GR_KB_SHIFT + GR_KB_CTRL + 'E' }, - { wxT( "Shift+Ctrl+F" ), GR_KB_SHIFT + GR_KB_CTRL + 'F' }, - { wxT( "Shift+Ctrl+G" ), GR_KB_SHIFT + GR_KB_CTRL + 'G' }, - { wxT( "Shift+Ctrl+H" ), GR_KB_SHIFT + GR_KB_CTRL + 'H' }, - { wxT( "Shift+Ctrl+I" ), GR_KB_SHIFT + GR_KB_CTRL + 'I' }, - { wxT( "Shift+Ctrl+J" ), GR_KB_SHIFT + GR_KB_CTRL + 'J' }, - { wxT( "Shift+Ctrl+K" ), GR_KB_SHIFT + GR_KB_CTRL + 'K' }, - { wxT( "Shift+Ctrl+L" ), GR_KB_SHIFT + GR_KB_CTRL + 'L' }, - { wxT( "Shift+Ctrl+M" ), GR_KB_SHIFT + GR_KB_CTRL + 'M' }, - { wxT( "Shift+Ctrl+N" ), GR_KB_SHIFT + GR_KB_CTRL + 'N' }, - { wxT( "Shift+Ctrl+O" ), GR_KB_SHIFT + GR_KB_CTRL + 'O' }, - { wxT( "Shift+Ctrl+P" ), GR_KB_SHIFT + GR_KB_CTRL + 'P' }, - { wxT( "Shift+Ctrl+Q" ), GR_KB_SHIFT + GR_KB_CTRL + 'Q' }, - { wxT( "Shift+Ctrl+R" ), GR_KB_SHIFT + GR_KB_CTRL + 'R' }, - { wxT( "Shift+Ctrl+S" ), GR_KB_SHIFT + GR_KB_CTRL + 'S' }, - { wxT( "Shift+Ctrl+T" ), GR_KB_SHIFT + GR_KB_CTRL + 'T' }, - { wxT( "Shift+Ctrl+U" ), GR_KB_SHIFT + GR_KB_CTRL + 'U' }, - { wxT( "Shift+Ctrl+V" ), GR_KB_SHIFT + GR_KB_CTRL + 'V' }, - { wxT( "Shift+Ctrl+W" ), GR_KB_SHIFT + GR_KB_CTRL + 'W' }, - { wxT( "Shift+Ctrl+X" ), GR_KB_SHIFT + GR_KB_CTRL + 'X' }, - { wxT( "Shift+Ctrl+Y" ), GR_KB_SHIFT + GR_KB_CTRL + 'Y' }, - { wxT( "Shift+Ctrl+Z" ), GR_KB_SHIFT + GR_KB_CTRL + 'Z' }, + { wxT( "Up" ), WXK_UP }, + { wxT( "Down" ), WXK_DOWN }, + { wxT( "Left" ), WXK_LEFT }, + { wxT( "Right" ), WXK_RIGHT }, // Do not change this line: end of list - { wxT( "" ), 0 } + { wxT( "" ), 0 } }; @@ -217,12 +112,14 @@ static struct hotkey_name_descr s_Hotkey_Name_List[] = * Only some wxWidgets key values are handled for function key ( see * s_Hotkey_Name_List[] ) * @param aKeycode = key code (ascii value, or wxWidgets value for function keys) + * @param aIsFound = a pointer to a bool to return true if found, or false. an be NULL default) * @return the key name in a wxString */ -wxString ReturnKeyNameFromKeyCode( int aKeycode ) +wxString ReturnKeyNameFromKeyCode( int aKeycode, bool* aIsFound ) { wxString keyname, modifier, fullkeyname; int ii; + bool found = false; if( (aKeycode & GR_KB_CTRL) != 0 ) modifier << wxT( "Ctrl+" ); @@ -232,20 +129,32 @@ wxString ReturnKeyNameFromKeyCode( int aKeycode ) modifier << wxT( "Shift+" ); aKeycode &= ~( GR_KB_CTRL | GR_KB_ALT | GR_KB_SHIFT ); - for( ii = 0; ; ii++ ) + + if( (aKeycode >= ' ') && (aKeycode < 0x7F ) ) { - if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) + found = true; + keyname.Append((wxChar)aKeycode); + } + else + { + for( ii = 0; ; ii++ ) { - keyname = wxT( "" ); - break; - } - if( s_Hotkey_Name_List[ii].m_KeyCode == aKeycode ) - { - keyname = s_Hotkey_Name_List[ii].m_Name; - break; + if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) // End of list + { + keyname = wxT( "" ); + break; + } + if( s_Hotkey_Name_List[ii].m_KeyCode == aKeycode ) + { + keyname = s_Hotkey_Name_List[ii].m_Name; + found = true; + break; + } } } + if( aIsFound ) + *aIsFound = found; fullkeyname = modifier + keyname; return fullkeyname; } @@ -261,23 +170,25 @@ wxString ReturnKeyNameFromKeyCode( int aKeycode ) * @return a wxString (aTest + key name) if key found or aText without modification */ wxString AddHotkeyName( const wxString& aText, Ki_HotkeyInfo** aList, - int aCommandId , bool aIsShortCut ) + int aCommandId, bool aIsShortCut ) { - wxString msg = aText; + wxString msg = aText; wxString keyname; + if( aList ) keyname = ReturnKeyNameFromCommandId( aList, aCommandId ); if( !keyname.IsEmpty() ) { - if ( aIsShortCut ) + if( aIsShortCut ) msg << wxT( "\t" ) << keyname; else - msg << wxT( " <" ) << keyname << wxT(">"); + msg << wxT( " <" ) << keyname << wxT( ">" ); } return msg; } + /** function AddHotkeyName * Add the key name from the Command id value ( m_Idcommand member value) * @param aText = a wxString. returns aText + key name @@ -304,10 +215,10 @@ wxString AddHotkeyName( const wxString& aText, keyname = ReturnKeyNameFromCommandId( List, aCommandId ); if( !keyname.IsEmpty() ) { - if ( aIsShortCut ) + if( aIsShortCut ) msg << wxT( "\t" ) << keyname; else - msg << wxT( " <" ) << keyname << wxT(">"); + msg << wxT( " <" ) << keyname << wxT( ">" ); break; } } @@ -352,6 +263,37 @@ static int ReturnKeyCodeFromKeyName( const wxString& keyname ) { int ii, keycode = 0; + // Search for modifiers: Ctrl+ Alt+ and Shift+ + wxString key = keyname; + int modifier = 0; + while( 1 ) + { + if( key.StartsWith(wxT("Ctrl+") ) ) + { + modifier |= GR_KB_CTRL; + key.Remove( 0, 5 ); + } + + else if( key.StartsWith(wxT("Alt+") ) ) + { + modifier |= GR_KB_ALT; + key.Remove( 0, 4 ); + } + else if( key.StartsWith(wxT("Shift+") ) ) + { + modifier |= GR_KB_SHIFT; + key.Remove( 0, 6 ); + } + else + break; + } + + if( (key[0] >= ' ') && (key[0] < 0x7F) ) + { + keycode = key[0]; + keycode += modifier; + } + for( ii = 0; ; ii++ ) { if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) // End of list reached @@ -359,7 +301,7 @@ static int ReturnKeyCodeFromKeyName( const wxString& keyname ) if( keyname.CmpNoCase( s_Hotkey_Name_List[ii].m_Name ) == 0 ) { - keycode = s_Hotkey_Name_List[ii].m_KeyCode; + keycode = s_Hotkey_Name_List[ii].m_KeyCode + modifier; break; } } @@ -418,189 +360,165 @@ Ki_HotkeyInfo* GetDescriptorFromHotkey( int aKey, Ki_HotkeyInfo** aList ) } -/* - * Create a configuration file (*.key) from the current hotkey list - * @param Filename = default full file name to create. If void, A filename - * will be asked - * @param List = pointer to the current hotkey list. - * the ouput format is: shortcut "key" "function" - * lines starting with # are comments +/** Function WriteHotkeyConfig + * Store the current hotkey list + * It is stored using the standard wxConfig mechanism or a file. * + * @param aDescList = pointer to the current hotkey list. + * @param aFullFileName = a wxString pointer to a fuill file name. + * if NULL, use the standard wxConfig mechanism (default) + * the output format is: shortcut "key" "function" + * lines starting with # are comments */ -int WinEDA_BasicFrame::WriteHotkeyConfigFile( - const wxString& Filename, - struct Ki_HotkeyInfoSectionDescriptor* DescList, - bool verbose ) +int WinEDA_BasicFrame::WriteHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList, + wxString* aFullFileName ) { - wxString FullFilename = Filename; - FILE* cfgfile; wxString msg; - - if( FullFilename.IsEmpty() || verbose ) - { - wxString Mask, Path, Ext; - Ext = DEFAULT_HOTKEY_FILENAME_EXT; - Mask = wxT( "*." ) + Ext; - Path = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - FullFilename = EDA_FileSelector( _( "Save Hotkey Configuration File:" ), - Path, - FullFilename, - Ext, - Mask, - this, - wxFD_SAVE, - TRUE ); - } - - if( FullFilename.IsEmpty() ) - return 0; - - cfgfile = wxFopen( FullFilename, wxT( "wt" ) ); - - if( cfgfile == NULL ) - { - if( verbose ) - { - msg = _( "Unable to create " ) + FullFilename; - DisplayError( this, msg ); - } - return 0; - } - wxString keyname, infokey; msg = wxT( "$hotkey list\n" ); - fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) ); - - /* print the allowed keys, for info - */ - msg = wxT( "# " ); msg += _( "Allowed keys:\n" ); - fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) ); - msg.Empty(); - for( int ii = 0; ; ii++ ) - { - if( s_Hotkey_Name_List[ii].m_KeyCode == 0 ) - break;; - if( msg.IsEmpty() ) - msg = wxT( "# " ); - else - msg += wxT( ", " ); - msg += s_Hotkey_Name_List[ii].m_Name; - if( msg.Len() > 60 ) - { - msg += wxT( "\n" ); - fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) ); - msg.Empty(); - } - } - - /* print the last line of the info section */ - if( !msg.IsEmpty() ) - msg += wxT( "\n" ); - msg += wxT( "#\n#\n" ); - fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) ); /* Print the current hotkey list */ Ki_HotkeyInfo** List; - for( ; DescList->m_HK_InfoList != NULL; DescList++ ) + for( ; aDescList->m_HK_InfoList != NULL; aDescList++ ) { - if( DescList->m_Comment ) + if( aDescList->m_Comment ) { - fprintf( cfgfile, "# " ); - fprintf( cfgfile, "%s\n", DescList->m_Comment ); + msg += wxT( "# " ); + msg += wxString( aDescList->m_Comment ); + msg += wxT( "\n" ); } - msg = *DescList->m_SectionTag; - fprintf( cfgfile, "%s\n", CONV_TO_UTF8( msg ) ); - List = DescList->m_HK_InfoList; + msg += *aDescList->m_SectionTag; + msg += wxT( "\n" ); + + List = aDescList->m_HK_InfoList; for( ; *List != NULL; List++ ) { Ki_HotkeyInfo* hk_decr = *List; - msg = wxT( "shortcut " ); + msg += wxT( "shortcut " ); keyname = ReturnKeyNameFromKeyCode( hk_decr->m_KeyCode ); AddDelimiterString( keyname ); infokey = hk_decr->m_InfoMsg; AddDelimiterString( infokey ); msg += keyname + wxT( ": " ) + infokey + wxT( "\n" ); - fprintf( cfgfile, "%s", CONV_TO_UTF8( msg ) ); } } - msg = wxT( "$Endlist\n" ); - fprintf( cfgfile, "%s\n", CONV_TO_UTF8( msg ) ); - fclose( cfgfile ); + msg += wxT( "$Endlist\n" ); + + if( aFullFileName ) + { + FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) ); + if( file ) + fputs( CONV_TO_UTF8( msg ), file ); + else + { + msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) ); + return 0; + } + } + else + { + wxConfig config( m_FrameName ); + config.Write( HOTKEYS_CONFIG_KEY, msg ); + } + return 1; } -/* - * Read a configuration file (.key) and fill the current hotkey list +/** Function ReadHotkeyConfigFile + * Read an old configuration file (.key) and fill the current hotkey list * with hotkeys - * @param Filename = default full file name to create. If void, A filename - * will be asked - * @param DescList = current hotkey list descr. to initialise. + * @param aFilename = file name to read. + * @param aDescList = current hotkey list descr. to initialise. + */ +int WinEDA_BasicFrame::ReadHotkeyConfigFile( + const wxString& aFilename, + struct Ki_HotkeyInfoSectionDescriptor* aDescList ) +{ + wxFile cfgfile( aFilename ); + + /* get length */ + cfgfile.SeekEnd(); + wxFileOffset size = cfgfile.Tell(); + cfgfile.Seek( 0 ); + + /* read data */ + char* buffer = new char[size]; + cfgfile.Read( buffer, size ); + + wxString data( buffer, wxConvUTF8 ); + + /* parse */ + ParseHotkeyConfig( data, aDescList ); + + /* cleanup */ + delete buffer; + cfgfile.Close(); + return 1; +} + + +void ReadHotkeyConfig( const wxString& Appname, + struct Ki_HotkeyInfoSectionDescriptor* aDescList ) +{ + wxConfig config( Appname ); + + if( !config.HasEntry( HOTKEYS_CONFIG_KEY ) ) + { + // assume defaults are ok + return; + } + + wxString data; + config.Read( HOTKEYS_CONFIG_KEY, &data ); + + ParseHotkeyConfig( data, aDescList ); +} + + +/** Function ReadHotkeyConfig + * Read configuration data and fill the current hotkey list with hotkeys + * @param aDescList = current hotkey list descr. to initialise. + */ +int WinEDA_BasicFrame::ReadHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList ) +{ + ::ReadHotkeyConfig( m_FrameName, aDescList ); + return 1; +} + + +/** Function ParseHotkeyConfig * the input format is: shortcut "key" "function" * lines starting by # are ignored (comments) * lines like [xxx] are tags (example: [common] or [libedit] which identify * sections - * */ -int WinEDA_BasicFrame::ReadHotkeyConfigFile( - const wxString& Filename, - struct Ki_HotkeyInfoSectionDescriptor* DescList, - bool verbose ) +void ParseHotkeyConfig( + const wxString& data, + struct Ki_HotkeyInfoSectionDescriptor* DescList ) { - wxString FullFilename = Filename; - FILE* cfgfile; - wxString msg; + /* Read the config */ + wxStringTokenizer tokenizer( data, L"\r\n", wxTOKEN_STRTOK ); + Ki_HotkeyInfo** CurrentHotkeyList = 0; - if( FullFilename.IsEmpty() || verbose ) + while( tokenizer.HasMoreTokens() ) { - wxString Mask, Path, Ext; - Ext = DEFAULT_HOTKEY_FILENAME_EXT; - Mask = wxT( "*." ) + Ext; - Path = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - FullFilename = EDA_FileSelector( _( "Open Hotkey Configuration File:" ), - Path, - FullFilename, - Ext, - Mask, - this, - wxFD_OPEN, - TRUE ); - if( FullFilename.IsEmpty() ) - return 0; - } + wxString line = tokenizer.GetNextToken(); + wxStringTokenizer lineTokenizer( line ); - cfgfile = wxFopen( FullFilename, wxT( "rt" ) ); + wxString line_type = lineTokenizer.GetNextToken(); + if( line_type[0] == '#' ) //comment + continue; - if( cfgfile == NULL ) - { - if( verbose ) + if( line_type[0] == '[' ) // A tag is found. search infos in list { - msg = _( "Unable to read " ) + FullFilename; - DisplayError( this, msg ); - } - return 0; - } - - wxString keyname; - char Line[1024]; - int LineNum = 0; - Ki_HotkeyInfo** CurrentHotkeyList = NULL; - - /* Read the file */ - while( GetLine( cfgfile, Line, &LineNum ) != NULL ) - { - char* line_type, * keyname, * fctname; - line_type = strtok( Line, " \t\n\r" ); - msg = CONV_FROM_UTF8( line_type ); - if( msg[0] == '[' ) // A tag is found. search infos in list - { - CurrentHotkeyList = NULL; + CurrentHotkeyList = 0; Ki_HotkeyInfoSectionDescriptor* DList = DescList; - for( ; DList->m_HK_InfoList != NULL; DList++ ) + for( ; DList->m_HK_InfoList; DList++ ) { - if( *DList->m_SectionTag == msg ) + if( *DList->m_SectionTag == line_type ) { CurrentHotkeyList = DList->m_HK_InfoList; break; @@ -609,32 +527,29 @@ int WinEDA_BasicFrame::ReadHotkeyConfigFile( continue; } - if( msg != wxT( "shortcut" ) ) - continue; - if( msg == wxT( "$Endlist" ) ) + if( line_type == wxT( "$Endlist" ) ) break; + if( line_type != wxT( "shortcut" ) ) + continue; if( CurrentHotkeyList == NULL ) continue; /* Get the key name */ - strtok( NULL, "\"\n\r" ); - keyname = strtok( NULL, "\"\n\r" ); + lineTokenizer.SetString( lineTokenizer.GetString(), L"\"\r\n\t ", wxTOKEN_STRTOK ); + wxString keyname = lineTokenizer.GetNextToken(); - strtok( NULL, "\"\n\r" ); + wxString remainder = lineTokenizer.GetString(); /* Get the command name */ - fctname = strtok( NULL, "\"\n\r" ); - msg = CONV_FROM_UTF8( fctname ); + wxString fctname = remainder.AfterFirst( '\"' ).BeforeFirst( '\"' ); /* search the hotkey in current hotkey list */ for( Ki_HotkeyInfo** List = CurrentHotkeyList; *List != NULL; List++ ) { Ki_HotkeyInfo* hk_decr = *List; - if( hk_decr->m_InfoMsg == msg ) + if( hk_decr->m_InfoMsg == fctname ) { - msg = CONV_FROM_UTF8( keyname ); - - int code = ReturnKeyCodeFromKeyName( msg ); + int code = ReturnKeyCodeFromKeyName( keyname ); if( code ) hk_decr->m_KeyCode = code; @@ -642,47 +557,67 @@ int WinEDA_BasicFrame::ReadHotkeyConfigFile( } } } - - fclose( cfgfile ); - return 1; } -/* return the hotkey config file path - * @param choice : 0 = home, 1 = kicad/share/template +/** Function ImportHotkeyConfigFromFile + * Prompt the user for an old hotkey file to read, and read it. + * @param aDescList = current hotkey list descr. to initialise. */ -wxString ReturnHotkeyConfigFilePath( int choice ) +void WinEDA_BasicFrame::ImportHotkeyConfigFromFile( + struct Ki_HotkeyInfoSectionDescriptor* aDescList ) { - wxString path; - wxAppTraits* traits = wxGetApp().GetTraits(); + wxString ext = DEFAULT_HOTKEY_FILENAME_EXT; + wxString mask = wxT( "*." ) + ext; + wxString path = wxGetCwd(); + wxString filename; - switch( choice ) - { - case 0: - path = traits->GetStandardPaths().GetUserConfigDir() + - wxFileName::GetPathSeparator(); + filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ), + path, + filename, + ext, + mask, + this, + wxFD_OPEN, + TRUE ); - case 1: + if( filename.IsEmpty() ) + return; - /* TODO: This is broken under a normal Poxis system. Users - * generally do no have write permissions to this path - * and there is no provision for prompting for the root - * password. Suggest we remove this unless someone has - * a workable solution (Wayne). - */ - path = ReturnKicadDatasPath() + wxT( "template/" ); - break; + ReadHotkeyConfigFile( filename, aDescList ); +} - default: - break; - } - return path; +/** Function ExportHotkeyConfigToFile + * Prompt the user for an old hotkey file to read, and read it. + * @param aDescList = current hotkey list descr. to initialise. + */ +void WinEDA_BasicFrame::ExportHotkeyConfigToFile( + struct Ki_HotkeyInfoSectionDescriptor* aDescList ) +{ + wxString ext = DEFAULT_HOTKEY_FILENAME_EXT; + wxString mask = wxT( "*." ) + ext; + wxString path = wxGetCwd(); + wxString filename; + + filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ), + path, + filename, + ext, + mask, + this, + wxFD_OPEN, + TRUE ); + + if( filename.IsEmpty() ) + return; + + WriteHotkeyConfig( aDescList, &filename ); } /** add hotkey config options submenu to a menu - * @param menu : initial menu + * @param menu : root menu */ void AddHotkeyConfigMenu( wxMenu* aMenu ) { @@ -700,99 +635,33 @@ void AddHotkeyConfigMenu( wxMenu* aMenu ) item->SetBitmap( info_xpm ); HotkeySubmenu->Append( item ); - /* (Re)create hotkey file */ - item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_CREATE_CONFIG, - _( "(Re)create Hotkeys File" ), + /* Call hotkeys editor*/ + item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_SHOW_EDITOR, + _( "Edit Hotkeys" ), + _( "Call the hotkeys editor" ) ); + item->SetBitmap( editor_xpm ); + HotkeySubmenu->Append( item ); + + HotkeySubmenu->AppendSeparator(); + + /* create hotkey file to export current hotkeys config */ + item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_EXPORT_CONFIG, + _( "Export Hotkeys Config" ), _( - "Create or recreate the hotkey configuration file from current hotkey list" ) + "Create a hotkey configuration file to export the current hotkey config" ) ); item->SetBitmap( save_setup_xpm ); HotkeySubmenu->Append( item ); /* Reload hotkey file */ - item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_READ_CONFIG, - _( "Reload Hotkeys File" ), - _( "Reload the hotkey configuration file" ) ); + item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_IMPORT_CONFIG, + _( "Import Hotkeys Config" ), + _( "Load an existing hotkey configuration file" ) ); item->SetBitmap( reload_xpm ); HotkeySubmenu->Append( item ); - /* Edit hotkey file */ - item = new wxMenuItem( HotkeySubmenu, ID_PREFERENCES_HOTKEY_EDIT_CONFIG, - _( "Edit Hotkeys File" ), - _( "Edit the hotkey configuration file in a text editor" ) ); - item->SetBitmap( editor_xpm ); - HotkeySubmenu->Append( item ); - /* Append HotkeySubmenu to menu */ ADD_MENUITEM_WITH_HELP_AND_SUBMENU( aMenu, HotkeySubmenu, ID_PREFERENCES_HOTKEY_SUBMENU, _( "Hotkeys" ), _( "Hotkeys configuration and preferences" ), hotkeys_xpm ); - - /* Hotkey path */ - wxMenu* HotkeyLocationSubmenu = new wxMenu(); - - /* Home directory */ - item = new wxMenuItem( HotkeyLocationSubmenu, - ID_PREFERENCES_HOTKEY_PATH_IS_HOME, - _( "Home directory" ), - _( "Use home directory to load or store Hotkey config files" ), - wxITEM_CHECK ); - HotkeyLocationSubmenu->Append( item ); - - /* KiCad template directory */ - item = new wxMenuItem( HotkeyLocationSubmenu, - ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, - _( "KiCad template directory" ), - _( "Use kicad/template directory to load or store Hotkey config files" ), - wxITEM_CHECK ); - HotkeyLocationSubmenu->Append( item ); - - /* Append location submenu to HotkeySubmenu */ - ADD_MENUITEM_WITH_HELP_AND_SUBMENU( HotkeySubmenu, HotkeyLocationSubmenu, - -1, _( "Location" ), - _( "Select hotkey configuration file location" ), - right_xpm ); - HotkeyLocationSubmenu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME, - g_ConfigFileLocationChoice == 0 ); - HotkeyLocationSubmenu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, - g_ConfigFileLocationChoice == 1 ); -} - - -/* called on hotkey file location selecton menu - * @param frame = current WinEDA_DrawFrame - * @param id = selected menu id - * @return g_ConfigFileLocationChoice (global) = new selection - */ -void HandleHotkeyConfigMenuSelection( WinEDA_DrawFrame* frame, int id ) -{ - wxMenuBar* menu = frame->GetMenuBar(); - - wxConfig* config = wxGetApp().m_EDA_CommonConfig; - - switch( id ) - { - case ID_PREFERENCES_HOTKEY_PATH_IS_HOME: - if( g_ConfigFileLocationChoice != 0 ) - { - g_ConfigFileLocationChoice = 0; - menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME, true ); - menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, false ); - config->Write( HOTKEY_CFG_PATH_OPT, g_ConfigFileLocationChoice ); - } - break; - - case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD: - if( g_ConfigFileLocationChoice != 1 ) - { - g_ConfigFileLocationChoice = 1; - menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_HOME, false ); - menu->Check( ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, true ); - config->Write( HOTKEY_CFG_PATH_OPT, g_ConfigFileLocationChoice ); - } - break; - - default: - break; - } } diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 38c4b1e545..b0cf922835 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -15,6 +15,7 @@ #include "program.h" #include "general.h" #include "protos.h" +#include "hotkeys.h" #include @@ -147,10 +148,9 @@ bool WinEDA_App::OnInit() bool reopenLastUsedDirectory = argc == 1; GetSettings( reopenLastUsedDirectory ); - Read_Hotkey_Config( frame, false ); /* Must be called before creating - * the main frame in order to - * display the real hotkeys in menus - * or tool tips */ + /* Must be called before creating the main frame in order to + * display the real hotkeys in menus or tool tips */ + ReadHotkeyConfig( wxT("SchematicFrame"), s_Eeschema_Hokeys_Descr ); // Create main frame (schematic frame) : frame = new WinEDA_SchematicFrame( NULL, wxT( "EESchema" ), diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 0de33a9571..3c81dce24c 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -18,6 +18,7 @@ #include "worksheet.h" #include "hotkeys.h" #include "dialog_eeschema_options.h" +#include "dialog_hotkeys_editor.h" #include @@ -65,30 +66,16 @@ void WinEDA_LibeditFrame::Process_Config( wxCommandEvent& event ) /* Hotkey IDs */ - case ID_PREFERENCES_HOTKEY_CREATE_CONFIG: - fn = wxFileName( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ), - HOTKEY_FILENAME, - DEFAULT_HOTKEY_FILENAME_EXT ); - WriteHotkeyConfigFile( fn.GetFullPath(), s_Eeschema_Hokeys_Descr, true ); + case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: + InstallHotkeyFrame( this, s_Eeschema_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_READ_CONFIG: - Read_Hotkey_Config( this, true ); + case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: + ExportHotkeyConfigToFile( s_Eeschema_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_EDIT_CONFIG: - { - fn = wxFileName( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ), - HOTKEY_FILENAME, DEFAULT_HOTKEY_FILENAME_EXT ); - wxString editorname = wxGetApp().GetEditorName(); - if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, QuoteFullPath( fn ) ); - } - break; - - case ID_PREFERENCES_HOTKEY_PATH_IS_HOME: - case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD: - HandleHotkeyConfigMenuSelection( this, id ); + case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: + ImportHotkeyConfigFromFile( s_Eeschema_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: @@ -141,30 +128,16 @@ void WinEDA_SchematicFrame::Process_Config( wxCommandEvent& event ) /* Hotkey IDs */ - case ID_PREFERENCES_HOTKEY_CREATE_CONFIG: - fn = wxFileName( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ), - HOTKEY_FILENAME, - DEFAULT_HOTKEY_FILENAME_EXT ); - WriteHotkeyConfigFile( fn.GetFullPath(), s_Eeschema_Hokeys_Descr, true ); + case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: + ExportHotkeyConfigToFile( s_Eeschema_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_READ_CONFIG: - Read_Hotkey_Config( this, true ); + case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: + ImportHotkeyConfigFromFile( s_Eeschema_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_EDIT_CONFIG: - { - fn = wxFileName( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ), - HOTKEY_FILENAME, DEFAULT_HOTKEY_FILENAME_EXT ); - wxString editorname = wxGetApp().GetEditorName(); - if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, QuoteFullPath( fn ) ); - } - break; - - case ID_PREFERENCES_HOTKEY_PATH_IS_HOME: - case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD: - HandleHotkeyConfigMenuSelection( this, id ); + case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: + InstallHotkeyFrame( this, s_Eeschema_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: @@ -260,25 +233,6 @@ void WinEDA_SchematicFrame::OnSetOptions( wxCommandEvent& event ) } -/* - * Read the hotkey files config for eeschema and libedit - */ -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ) -{ - wxString FullFileName = ReturnHotkeyConfigFilePath( - g_ConfigFileLocationChoice ); - - FullFileName += HOTKEY_FILENAME; - FullFileName += wxT( "." ); - FullFileName += DEFAULT_HOTKEY_FILENAME_EXT; - frame->ReadHotkeyConfigFile( FullFileName, - s_Eeschema_Hokeys_Descr, - verbose ); - - return TRUE; -} - - /** * Return project file parameter list for EESchema. * diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index cf9b0a90d1..1c8634eb5c 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -213,9 +213,9 @@ Ki_HotkeyInfo* s_LibEdit_Hotkey_List[] = // an hotkey config file) struct Ki_HotkeyInfoSectionDescriptor s_Eeschema_Hokeys_Descr[] = { - { &g_CommonSectionTag, s_Common_Hotkey_List, "Common keys" }, - { &g_SchematicSectionTag, s_Schematic_Hotkey_List, "Schematic editor keys" }, - { &g_LibEditSectionTag, s_LibEdit_Hotkey_List, "library editor keys" }, + { &g_CommonSectionTag, s_Common_Hotkey_List, L"Common keys" }, + { &g_SchematicSectionTag, s_Schematic_Hotkey_List, L"Schematic editor keys" }, + { &g_LibEditSectionTag, s_LibEdit_Hotkey_List, L"library editor keys" }, { NULL, NULL, NULL } }; diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index 9340ae3a16..7d23887512 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -23,7 +23,7 @@ static wxArrayString s_PowerNameList; */ void WinEDA_SchematicFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) { - SCH_ITEM* DrawStruct = (SCH_ITEM*) GetScreen()->GetCurItem(); + SCH_ITEM* DrawStruct = GetScreen()->GetCurItem(); if( ( m_ID_current_state == 0 ) || ( DrawStruct && DrawStruct->m_Flags ) ) { @@ -60,11 +60,15 @@ void WinEDA_SchematicFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) break; default: - DisplayError( this, - wxT( "WinEDA_SchematicFrame::OnLeftClick err: m_Flags != 0" ) ); + { + wxString msg; + msg.Printf(wxT( "WinEDA_SchematicFrame::OnLeftClick err: m_Flags != 0, itmetype %d" ), + DrawStruct->Type()); + DisplayError( this, msg ); DrawStruct->m_Flags = 0; break; } + } } else { diff --git a/eeschema/plugins/netlist_form_OrcadPcb2.xsl b/eeschema/plugins/netlist_form_OrcadPcb2.xsl new file mode 100644 index 0000000000..f8f20e7313 --- /dev/null +++ b/eeschema/plugins/netlist_form_OrcadPcb2.xsl @@ -0,0 +1,90 @@ + + + + +]> + + + + + + + ( { EESchema Netlist Version 1.1 + + + }&nl; + + )&nl;*&nl; + + + + + + + + + + + &nl; + + + + + ( + + + + + + 00000000 + + + + + + + + + $noname + + + + + + + + + + + "~" + + + &nl; + + )&nl; + + + + + ( + + = + + + + + + ? + + + )&nl; + + + diff --git a/eeschema/protos.h b/eeschema/protos.h index 895d1f0a00..01ce0abd08 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -171,11 +171,6 @@ EDA_Colors ReturnLayerColor( int Layer ); void DisplayColorSetupFrame( WinEDA_DrawFrame* parent, const wxPoint& pos ); -/***************/ -/* EECONFIG.CPP */ -/***************/ -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ); - /**************/ /* NETLIST.CPP */ diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index dc4dde033f..d1fe94db85 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -6,6 +6,7 @@ add_definitions(-DGERBVIEW -DPCBNEW) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIR} ../3d-viewer + ../common ../cvpcb ../pcbnew ../polygon) @@ -82,7 +83,7 @@ endif(APPLE) ### add_executable(gerbview WIN32 MACOSX_BUNDLE ${GERBVIEW_SRCS} - ${GERBVIEW_EXTRA_SRCS} + ${GERBVIEW_EXTRA_SRCS} ${GERBVIEW_RESOURCES}) ### diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index 5a8f681e69..fa28a03255 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -17,6 +17,7 @@ #include "zones.h" #include "class_board_design_settings.h" #include "colors_selection.h" +#include "hotkeys.h" #include "build_version.h" @@ -101,10 +102,10 @@ bool WinEDA_App::OnInit() g_DrawBgColor = BLACK; - Read_Hotkey_Config( frame, false ); /* Must be called before creating the - * main frame in order to display the - * real hotkeys in menus or tool tips - */ + /* Must be called before creating the main frame in order to + * display the real hotkeys in menus or tool tips */ + ReadHotkeyConfig( wxT("GerberFrame"), s_Gerbview_Hokeys_Descr ); + frame = new WinEDA_GerberFrame( NULL, wxT( "GerbView" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); diff --git a/gerbview/gerbview_config.cpp b/gerbview/gerbview_config.cpp index b2d3d03400..cb20696593 100644 --- a/gerbview/gerbview_config.cpp +++ b/gerbview/gerbview_config.cpp @@ -13,13 +13,8 @@ #include "pcbplot.h" #include "hotkeys.h" #include "class_board_design_settings.h" - #include "gerbview_config.h" -#include "protos.h" - - -#define HOTKEY_FILENAME wxT( "gerbview" ) - +#include "dialog_hotkeys_editor.h" void WinEDA_GerberFrame::Process_Config( wxCommandEvent& event ) { @@ -44,37 +39,20 @@ void WinEDA_GerberFrame::Process_Config( wxCommandEvent& event ) break; /* Hotkey IDs */ - case ID_PREFERENCES_HOTKEY_CREATE_CONFIG: - FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - FullFileName += HOTKEY_FILENAME; - FullFileName += wxT("."); - FullFileName += DEFAULT_HOTKEY_FILENAME_EXT; - WriteHotkeyConfigFile( FullFileName, s_Gerbview_Hokeys_Descr, true ); + case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: + ExportHotkeyConfigToFile( s_Gerbview_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_READ_CONFIG: - Read_Hotkey_Config( this, true ); + case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: + ImportHotkeyConfigFromFile( s_Gerbview_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_EDIT_CONFIG: - { - FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - FullFileName += HOTKEY_FILENAME; - FullFileName += wxT("."); - FullFileName += DEFAULT_HOTKEY_FILENAME_EXT; - AddDelimiterString( FullFileName ); - wxString editorname = wxGetApp().GetEditorName(); - if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, FullFileName ); - } - break; - - case ID_PREFERENCES_HOTKEY_PATH_IS_HOME: - case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD: - HandleHotkeyConfigMenuSelection( this, id ); + case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: + InstallHotkeyFrame( this, s_Gerbview_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: + // Display current hotkey list for eeschema. DisplayHotkeyList( this, s_Gerbview_Hokeys_Descr ); break; @@ -121,19 +99,3 @@ void WinEDA_GerberFrame::Update_config() wxGetApp().WriteProjectConfig( dlg.GetPath(), GROUP, ParamCfgList ); } - -/* - * Read the hotkey files config for pcbnew and module_edit - */ -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ) -{ - wxString FullFileName = - ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - - FullFileName += HOTKEY_FILENAME; - FullFileName += wxT("."); - FullFileName += DEFAULT_HOTKEY_FILENAME_EXT; - return frame->ReadHotkeyConfigFile( FullFileName, - s_Gerbview_Hokeys_Descr, - verbose ); -} diff --git a/gerbview/protos.h b/gerbview/protos.h index 317a7cb492..49cddc554e 100644 --- a/gerbview/protos.h +++ b/gerbview/protos.h @@ -3,8 +3,6 @@ int* InstallDialogLayerPairChoice( WinEDA_GerberFrame* parent ); bool Read_Config(); -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ); - void Print_PcbItems( BOARD* Pcb, wxDC* DC, int drawmode, int printmasklayer ); diff --git a/gerbview/tool_gerber.cpp b/gerbview/tool_gerber.cpp index a412b8f689..4862d92798 100644 --- a/gerbview/tool_gerber.cpp +++ b/gerbview/tool_gerber.cpp @@ -95,14 +95,14 @@ void WinEDA_GerberFrame::ReCreateMenuBar( void ) wxGetApp().AddMenuLanguageList( configmenu ); + AddHotkeyConfigMenu( configmenu ); + + configmenu->AppendSeparator(); ADD_MENUITEM_WITH_HELP( configmenu, ID_CONFIG_SAVE, _( "&Save Setup" ), _( "Save application preferences" ), save_setup_xpm ); - configmenu->AppendSeparator(); - AddHotkeyConfigMenu( configmenu ); - wxMenu* miscellaneous_menu = new wxMenu; ADD_MENUITEM_WITH_HELP( miscellaneous_menu, ID_GERBVIEW_SHOW_LIST_DCODES, _( "&List DCodes" ), diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h new file mode 100644 index 0000000000..24113651f6 --- /dev/null +++ b/include/dialog_hotkeys_editor.h @@ -0,0 +1,51 @@ + +#ifndef __dialog_hotkeys_editor__ +#define __dialog_hotkeys_editor__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hotkeys_basic.h" +#include "hotkey_grid_table.h" +#include "wxstruct.h" +#include "dialog_hotkeys_editor_base.h" + +class HOTKEYS_EDITOR_DIALOG : public HOTKEYS_EDITOR_DIALOG_BASE +{ +protected: + WinEDA_DrawFrame* m_parent; + struct Ki_HotkeyInfoSectionDescriptor* m_hotkeys; + HotkeyGridTable* m_table; + + int m_curEditingRow; + +public: + HOTKEYS_EDITOR_DIALOG( WinEDA_DrawFrame* parent, + Ki_HotkeyInfoSectionDescriptor* hotkeys ); + + ~HOTKEYS_EDITOR_DIALOG() {}; + +private: + void OnOKClicked( wxCommandEvent& event ); + void CancelClicked( wxCommandEvent& event ); + void UndoClicked( wxCommandEvent& event ); + void StartEditing( wxGridEvent& event ); + void KeyPressed( wxKeyEvent& event ); + void SetHotkeyCellState( int aRow, bool aHightlight ); +}; + +void InstallHotkeyFrame( WinEDA_DrawFrame* parent, + Ki_HotkeyInfoSectionDescriptor* hotkeys ); + +#endif diff --git a/include/hotkey_grid_table.h b/include/hotkey_grid_table.h new file mode 100644 index 0000000000..9c6e9eacc3 --- /dev/null +++ b/include/hotkey_grid_table.h @@ -0,0 +1,55 @@ +#ifndef __hotkeys_grid_table__ +#define __hotkeys_grid_table__ + +#include + +#include +#include + +#include +#include + +#include "fctsys.h" +#include "appl_wxstruct.h" +#include "common.h" +#include "hotkeys_basic.h" + +class HotkeyGridTable : public wxGridTableBase +{ + +public: + typedef std::pair< wxString, Ki_HotkeyInfo* > hotkey_spec; + typedef std::vector< hotkey_spec > hotkey_spec_vector; + + HotkeyGridTable( struct Ki_HotkeyInfoSectionDescriptor* origin ); + virtual ~HotkeyGridTable(); + hotkey_spec_vector& getHotkeys(); + + virtual int GetNumberRows(); + virtual int GetNumberCols(); + virtual bool IsEmptyCell( int row, int col ); + virtual wxString GetValue( int row, int col ); + virtual void SetValue( int row, int col, const wxString& value ); + virtual wxString GetTypeName( int row, int col ); + virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); + virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); + virtual long GetValueAsLong( int row, int col ); + virtual double GetValueAsDouble( int row, int col ); + virtual bool GetValueAsBool( int row, int col ); + virtual void SetValueAsLong( int row, int col, long value ); + virtual void SetValueAsDouble( int row, int col, double value ); + virtual void SetValueAsBool( int row, int col, bool value ); + virtual void* GetValueAsCustom( int row, int col ); + virtual void SetValueAsCustom( int row, int col, void* value ); + virtual wxString GetColLabelValue( int col ); + + virtual bool isHeader( int row ); + virtual void SetKeyCode( int row, long key ); + virtual void RestoreFrom( struct Ki_HotkeyInfoSectionDescriptor* origin ); + +protected: + std::vector< hotkey_spec > m_hotkeys; + +}; + +#endif diff --git a/include/hotkeys_basic.h b/include/hotkeys_basic.h index cfc7cc2882..bdb6abb7f8 100644 --- a/include/hotkeys_basic.h +++ b/include/hotkeys_basic.h @@ -10,9 +10,6 @@ #define DEFAULT_HOTKEY_FILENAME_EXT wxT( "key" ) -/* keyword idetifier in kicad config use ti store/retrieve path option */ -#define HOTKEY_CFG_PATH_OPT wxT( "HotkeyPathOption" ) - /* Class to handle hotkey commnands. hotkeys have a default value * This class allows the real key code changed by user(from a key code list file) @@ -27,6 +24,7 @@ public: public: Ki_HotkeyInfo( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent = 0 ); + Ki_HotkeyInfo( const Ki_HotkeyInfo* base); }; /* handle a Section name and the corresponding list of hotkeys (Ki_HotkeyInfo list) @@ -43,7 +41,7 @@ struct Ki_HotkeyInfoSectionDescriptor public: wxString* m_SectionTag; // The section name Ki_HotkeyInfo** m_HK_InfoList; // List of Ki_HotkeyInfo pointers - const char* m_Comment; // comment: will be printed in the config file + const wchar_t* m_Comment; // comment: will be printed in the config file // Info usage only }; @@ -56,12 +54,9 @@ extern wxString g_LibEditSectionTag; extern wxString g_BoardEditorSectionTag; extern wxString g_ModuleEditSectionTag; -extern int g_ConfigFileLocationChoice; - /* Functions: */ -wxString ReturnHotkeyConfigFilePath( int choice ); void AddHotkeyConfigMenu( wxMenu* menu ); void HandleHotkeyConfigMenuSelection( WinEDA_DrawFrame* frame, int id ); @@ -70,9 +65,10 @@ void HandleHotkeyConfigMenuSelection( WinEDA_DrawFrame* frame, int id * Only some wxWidgets key values are handled for function key ( see * s_Hotkey_Name_List[] ) * @param aKeycode = key code (ascii value, or wxWidgets value for function keys) + * @param aIsFound = a pointer to a bool to return true if found, or false. an be NULL default) * @return the key name in a wxString */ -wxString ReturnKeyNameFromKeyCode( int aKeycode ); +wxString ReturnKeyNameFromKeyCode( int aKeycode, bool * aIsFound = NULL ); /** function ReturnKeyNameFromCommandId * return the key name from the Command id value ( m_Idcommand member value) @@ -127,6 +123,18 @@ void DisplayHotkeyList( WinEDA_DrawFrame* aFrame */ Ki_HotkeyInfo* GetDescriptorFromHotkey( int aKey, Ki_HotkeyInfo** aList ); +/** function ReadHotkeyConfig * Read hotkey configuration for a given + app, possibly before the frame for that app has been created + + @param Appname = the value of the app's m_FrameName + @param DescList = the hotkey data +*/ + +void ReadHotkeyConfig( const wxString& Appname, + struct Ki_HotkeyInfoSectionDescriptor* DescList ); +void ParseHotkeyConfig( const wxString& data, + struct Ki_HotkeyInfoSectionDescriptor* DescList ); + // common hotkeys event id // these hotkey ID are used in many files, so they are define here only once. diff --git a/include/id.h b/include/id.h index e193cf426a..40ce926cd1 100644 --- a/include/id.h +++ b/include/id.h @@ -35,11 +35,9 @@ enum main_id ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_SUBMENU, - ID_PREFERENCES_HOTKEY_CREATE_CONFIG, - ID_PREFERENCES_HOTKEY_READ_CONFIG, - ID_PREFERENCES_HOTKEY_EDIT_CONFIG, - ID_PREFERENCES_HOTKEY_PATH_IS_HOME, - ID_PREFERENCES_HOTKEY_PATH_IS_KICAD, + ID_PREFERENCES_HOTKEY_EXPORT_CONFIG, + ID_PREFERENCES_HOTKEY_IMPORT_CONFIG, + ID_PREFERENCES_HOTKEY_SHOW_EDITOR, ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, ID_PREFERENCES_HOTKEY_END, diff --git a/include/wxstruct.h b/include/wxstruct.h index b3fa34f418..d5320bb5f5 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -127,12 +127,48 @@ public: virtual void LoadSettings(); virtual void SaveSettings(); - int WriteHotkeyConfigFile( const wxString& Filename, - struct Ki_HotkeyInfoSectionDescriptor* DescList, - bool verbose ); - int ReadHotkeyConfigFile( const wxString& Filename, - struct Ki_HotkeyInfoSectionDescriptor* DescList, - bool verbose ); + // Read/Save and Import/export hotkeys config + + /** Function ReadHotkeyConfig + * Read configuration data and fill the current hotkey list with hotkeys + * @param aDescList = current hotkey list descr. to initialise. + */ + int ReadHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList ); + + /** Function WriteHotkeyConfig + * Store the current hotkey list + * It is stored using the standard wxConfig mechanism or a file. + * + * @param aDescList = pointer to the current hotkey list. + * @param aFullFileName = a wxString pointer to a fuill file name. + * if NULL, use the standard wxConfig mechanism (default) + * the output format is: shortcut "key" "function" + * lines starting with # are comments + */ + int WriteHotkeyConfig( struct Ki_HotkeyInfoSectionDescriptor* aDescList, + wxString * aFullFileName = NULL); + + /** Function ReadHotkeyConfigFile + * Read an old configuration file (.key) and fill the current hotkey list + * with hotkeys + * @param aFilename = file name to read. + * @param aDescList = current hotkey list descr. to initialise. + */ + int ReadHotkeyConfigFile( const wxString& Filename, + struct Ki_HotkeyInfoSectionDescriptor* aDescList ); + + /** Function ImportHotkeyConfigFromFile + * Prompt the user for an old hotkey file to read, and read it. + * @param aDescList = current hotkey list descr. to initialise. + */ + void ImportHotkeyConfigFromFile( struct Ki_HotkeyInfoSectionDescriptor* aDescList ); + + /** Function ExportHotkeyConfigToFile + * Prompt the user for an old hotkey file to read, and read it. + * @param aDescList = current hotkey list descr. to initialise. + */ + void ExportHotkeyConfigToFile( struct Ki_HotkeyInfoSectionDescriptor* aDescList ); + /** function SetLanguage * called on a language menu selection * when using a derived function, do not forget to call this one diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index fe195be27f..db4387ba5e 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -6,6 +6,7 @@ add_definitions(-DPCBNEW) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIR} ../3d-viewer + ../common ../polygon) ### diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 8916ec771a..fc077269bc 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -176,12 +176,12 @@ Ki_HotkeyInfo* s_module_edit_Hotkey_List[] = { NULL }; // list of sections and corresponding hotkey list for pcbnew (used to create an hotkey config file) struct Ki_HotkeyInfoSectionDescriptor s_Pcbnew_Editor_Hokeys_Descr[] = { { - &g_CommonSectionTag, s_Common_Hotkey_List, "Common keys" + &g_CommonSectionTag, s_Common_Hotkey_List, L"Common keys" }, { - &g_BoardEditorSectionTag, s_board_edit_Hotkey_List, "Board editor keys" + &g_BoardEditorSectionTag, s_board_edit_Hotkey_List, L"Board editor keys" },{ - &g_ModuleEditSectionTag, s_module_edit_Hotkey_List, "Footprint editor keys" + &g_ModuleEditSectionTag, s_module_edit_Hotkey_List, L"Footprint editor keys" },{ NULL, NULL, NULL } }; diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 0a270ca562..d3cd4ee10f 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -25,6 +25,7 @@ #include "class_drawpanel.h" #include "id.h" +#include "hotkeys.h" #include "build_version.h" @@ -134,10 +135,10 @@ Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); } g_DrawBgColor = BLACK; - Read_Hotkey_Config( frame, false ); /* Must be called before creating the - * main frame in order to display the - * real hotkeys in menus or tool tips */ + /* Must be called before creating the main frame in order to + * display the real hotkeys in menus or tool tips */ + ReadHotkeyConfig( wxT("PcbFrame"), s_Board_Editor_Hokeys_Descr ); frame = new WinEDA_PcbFrame( NULL, wxT( "PcbNew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() ); diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 803eb85e31..d5f0ec73da 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -21,6 +21,7 @@ #include "dialog_general_options.h" #include "pcbnew_config.h" +#include "dialog_hotkeys_editor.h" #define HOTKEY_FILENAME wxT( "pcbnew" ) @@ -105,35 +106,22 @@ void WinEDA_PcbFrame::Process_Config( wxCommandEvent& event ) LoadProjectSettings( dlg.GetPath() ); break; } - case ID_PREFERENCES_HOTKEY_CREATE_CONFIG: - fn.SetPath( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ) ); - fn.SetName( HOTKEY_FILENAME ); - fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); - WriteHotkeyConfigFile( fn.GetFullPath(), s_Pcbnew_Editor_Hokeys_Descr, true ); + + /* Hotkey IDs */ + case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG: + ExportHotkeyConfigToFile( s_Board_Editor_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_READ_CONFIG: - Read_Hotkey_Config( this, true ); + case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG: + ImportHotkeyConfigFromFile( s_Board_Editor_Hokeys_Descr ); break; - case ID_PREFERENCES_HOTKEY_EDIT_CONFIG: - { - fn.SetPath( ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ) ); - fn.SetName( HOTKEY_FILENAME ); - fn.SetExt( DEFAULT_HOTKEY_FILENAME_EXT ); - - wxString editorname = wxGetApp().GetEditorName(); - if( !editorname.IsEmpty() ) - ExecuteFile( this, editorname, QuoteFullPath( fn ) ); - break; - } - - case ID_PREFERENCES_HOTKEY_PATH_IS_HOME: - case ID_PREFERENCES_HOTKEY_PATH_IS_KICAD: - HandleHotkeyConfigMenuSelection( this, id ); + case ID_PREFERENCES_HOTKEY_SHOW_EDITOR: + InstallHotkeyFrame( this, s_Board_Editor_Hokeys_Descr ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: + // Display current hotkey list for eeschema. DisplayHotkeyList( this, s_Board_Editor_Hokeys_Descr ); break; @@ -143,20 +131,6 @@ void WinEDA_PcbFrame::Process_Config( wxCommandEvent& event ) } -/* - * Read the hotkey files config for pcbnew and module_edit - */ -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ) -{ - wxString FullFileName = ReturnHotkeyConfigFilePath( g_ConfigFileLocationChoice ); - - FullFileName += HOTKEY_FILENAME; - FullFileName += wxT( "." ); - FullFileName += DEFAULT_HOTKEY_FILENAME_EXT; - return frame->ReadHotkeyConfigFile( FullFileName, s_Pcbnew_Editor_Hokeys_Descr, verbose ); -} - - /** * Read the project configuration file settings. * diff --git a/pcbnew/protos.h b/pcbnew/protos.h index ca5a97ffb6..21a5225c08 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -43,17 +43,6 @@ class D_PAD; void CreateSortedPadListByXCoord( BOARD* aBoard, std::vector* aVector ); -/* Create a sorted list of pointers to pads. - * This list is sorted by X coordinate value. - * The list must be freed bu user - */ - -/**************/ -/* PCBCFG.CPP */ -/**************/ -bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ); - - /***************/ /* TRPISTE.CPP */ /***************/