diff --git a/common/dialogs/dialog_hotkeys_editor.cpp b/common/dialogs/dialog_hotkeys_editor.cpp index 719acc8c16..a3c274219c 100644 --- a/common/dialogs/dialog_hotkeys_editor.cpp +++ b/common/dialogs/dialog_hotkeys_editor.cpp @@ -28,8 +28,6 @@ #include #include -#include - #include @@ -57,13 +55,6 @@ HOTKEY_LIST_CTRL::HOTKEY_LIST_CTRL( wxWindow *aParent, const HOTKEYS_SECTIONS& a SetColumnWidth( 1, 100 ); Bind( wxEVT_CHAR, &HOTKEY_LIST_CTRL::OnChar, this ); - Bind( wxEVT_SIZE, &HOTKEY_LIST_CTRL::OnSize, this ); -} - - -void HOTKEY_LIST_CTRL::OnSize( wxSizeEvent& aEvent ) -{ - aEvent.Skip(); } @@ -121,8 +112,8 @@ void HOTKEY_LIST_CTRL::OnChar( wxKeyEvent& aEvent ) if( exists && data->GetHotkey().m_KeyCode != key ) { wxString tag = data->GetSectionTag(); - HOTKEY_SECTION_PAGE* parent = static_cast( m_parent ); - bool canUpdate = parent->GetDialog()->CanSetKey( key, tag ); + HOTKEYS_EDITOR_DIALOG* parent = static_cast( m_parent ); + bool canUpdate = ResolveKeyConflicts( key, tag ); if( canUpdate ) { @@ -203,20 +194,26 @@ bool HOTKEY_LIST_CTRL::TransferDataToControl() m_items.clear(); m_hotkeys.clear(); - for( size_t i_list = 0; i_list < m_sections.size(); ++i_list ) + HOTKEYS_SECTIONS::iterator sec_it; + size_t sec_index = 0; + for( sec_it = m_sections.begin(); sec_it != m_sections.end(); ++sec_it, ++sec_index ) { - LoadSection( m_sections[i_list].second ); - wxString section_tag = *( m_sections[i_list].second->m_SectionTag ); + LoadSection( sec_it->second ); + wxString section_tag = *( sec_it->second->m_SectionTag ); - HOTKEY_LIST& each_list = m_hotkeys[i_list]; - for( size_t i_hotkey = 0; i_hotkey < each_list.size(); ++i_hotkey ) + // Create parent item + wxTreeListItem parent = AppendItem( GetRootItem(), sec_it->first ); + + HOTKEY_LIST& each_list = m_hotkeys[sec_index]; + HOTKEY_LIST::iterator hk_it; + for( hk_it = each_list.begin(); hk_it != each_list.end(); ++hk_it ) { - EDA_HOTKEY* hotkey_descr = &each_list[i_hotkey]; - - wxTreeListItem item = AppendItem( GetRootItem(), wxEmptyString ); - SetItemData( item, new DIALOG_HOTKEY_CLIENT_DATA( hotkey_descr, section_tag ) ); + wxTreeListItem item = AppendItem( parent, wxEmptyString ); + SetItemData( item, new DIALOG_HOTKEY_CLIENT_DATA( &*hk_it, section_tag ) ); m_items.push_back( item ); } + + Expand( parent ); } UpdateFromClientData(); @@ -253,7 +250,41 @@ bool HOTKEY_LIST_CTRL::TransferDataFromControl() } -bool HOTKEY_LIST_CTRL::CanSetKey( long aKey, const wxString& aSectionTag, +bool HOTKEY_LIST_CTRL::ResolveKeyConflicts( long aKey, const wxString& aSectionTag ) +{ + EDA_HOTKEY* conflictingKey = NULL; + EDA_HOTKEY_CONFIG* conflictingSection = NULL; + + CheckKeyConflicts( aKey, aSectionTag, &conflictingKey, &conflictingSection ); + + if( conflictingKey != NULL ) + { + wxString info = wxGetTranslation( conflictingKey->m_InfoMsg ); + wxString msg = wxString::Format( + _( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want " + "to change its assignment?" ), + KeyNameFromKeyCode( aKey ), GetChars( info ), + *(conflictingSection->m_Title) ); + + wxMessageDialog dlg( m_parent, msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT ); + + if( dlg.ShowModal() == wxID_YES ) + { + conflictingKey->m_KeyCode = 0; + UpdateFromClientData(); + return true; + } + else + { + return false; + } + } + + return true; +} + + +bool HOTKEY_LIST_CTRL::CheckKeyConflicts( long aKey, const wxString& aSectionTag, EDA_HOTKEY** aConfKey, EDA_HOTKEY_CONFIG** aConfSect ) { EDA_HOTKEY* conflictingKey = NULL; @@ -300,39 +331,6 @@ bool HOTKEY_LIST_CTRL::CanSetKey( long aKey, const wxString& aSectionTag, } -HOTKEY_SECTION_PAGE::HOTKEY_SECTION_PAGE( HOTKEYS_EDITOR_DIALOG* aDialog, - wxNotebook* aParent, - const wxString& aTitle, - EDA_HOTKEY_CONFIG* aSection ) : - wxPanel( aParent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER ), - m_dialog( aDialog ) -{ - aParent->AddPage( this, aTitle ); - - wxBoxSizer* bMainSizer = new wxBoxSizer( wxVERTICAL ); - - SetSizer( bMainSizer ); - - HOTKEYS_SECTION section( aTitle, aSection ); - HOTKEYS_SECTIONS sections; - sections.push_back( section ); - - m_hotkeyList = new HOTKEY_LIST_CTRL( this, sections ); - bMainSizer->Add( m_hotkeyList, 1, wxALL|wxEXPAND, 5 ); - - Layout(); - bMainSizer->Fit( this ); -} - - -void HOTKEY_SECTION_PAGE::Restore() -{ - m_hotkeyList->TransferDataToControl(); - - Update(); -} - - void InstallHotkeyFrame( EDA_BASE_FRAME* aParent, EDA_HOTKEY_CONFIG* aHotkeys ) { HOTKEYS_EDITOR_DIALOG dialog( aParent, aHotkeys ); @@ -354,13 +352,17 @@ HOTKEYS_EDITOR_DIALOG::HOTKEYS_EDITOR_DIALOG( EDA_BASE_FRAME* aParent, { EDA_HOTKEY_CONFIG* section; + HOTKEYS_SECTIONS sections; for( section = m_hotkeys; section->m_HK_InfoList; section++ ) { - m_hotkeySectionPages.push_back( new HOTKEY_SECTION_PAGE( this, m_hotkeySections, - wxGetTranslation( *section->m_Title ), - section ) ); + HOTKEYS_SECTION sec( wxGetTranslation( *section->m_Title ), section ); + sections.push_back( sec ); } + m_hotkeyListCtrl = new HOTKEY_LIST_CTRL( this, sections ); + m_mainSizer->Insert( 1, m_hotkeyListCtrl, wxSizerFlags( 1 ).Expand().Border( wxALL, 5 ) ); + Layout(); + m_sdbSizerOK->SetDefault(); Center(); } @@ -371,12 +373,8 @@ bool HOTKEYS_EDITOR_DIALOG::TransferDataToWindow() if( !wxDialog::TransferDataToWindow() ) return false; - std::vector::iterator i; - for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i ) - { - if( !(*i)->GetHotkeyCtrl()->TransferDataToControl() ) - return false; - } + if( !m_hotkeyListCtrl->TransferDataToControl() ) + return false; return true; } @@ -387,12 +385,8 @@ bool HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow() if( !wxDialog::TransferDataToWindow() ) return false; - std::vector::iterator i; - for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i ) - { - if( !(*i)->GetHotkeyCtrl()->TransferDataFromControl() ) - return false; - } + if( !m_hotkeyListCtrl->TransferDataFromControl() ) + return false; // save the hotkeys m_parent->WriteHotkeyConfig( m_hotkeys ); @@ -403,56 +397,6 @@ bool HOTKEYS_EDITOR_DIALOG::TransferDataFromWindow() void HOTKEYS_EDITOR_DIALOG::ResetClicked( wxCommandEvent& aEvent ) { - std::vector::iterator i; - - for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i ) - { - (*i)->Restore(); - } + m_hotkeyListCtrl->TransferDataToControl(); } - -bool HOTKEYS_EDITOR_DIALOG::CanSetKey( long aKey, const wxString& aSectionTag ) -{ - std::vector::iterator i; - - EDA_HOTKEY* conflictingKey = NULL; - EDA_HOTKEY_CONFIG* conflictingSection = NULL; - HOTKEY_LIST_CTRL *conflictingCtrl = NULL; - - for( i = m_hotkeySectionPages.begin(); i != m_hotkeySectionPages.end(); ++i ) - { - HOTKEY_LIST_CTRL *ctrl = (*i)->GetHotkeyCtrl(); - - if ( !ctrl->CanSetKey( aKey, aSectionTag, &conflictingKey, &conflictingSection ) ) - { - conflictingCtrl = ctrl; - break; - } - } - - if( conflictingKey != NULL ) - { - wxString info = wxGetTranslation( conflictingKey->m_InfoMsg ); - wxString msg = wxString::Format( - _( "<%s> is already assigned to \"%s\" in section \"%s\". Are you sure you want " - "to change its assignment?" ), - KeyNameFromKeyCode( aKey ), GetChars( info ), - *(conflictingSection->m_Title) ); - - wxMessageDialog dlg( this, msg, _( "Confirm change" ), wxYES_NO | wxNO_DEFAULT ); - - if( dlg.ShowModal() == wxID_YES ) - { - conflictingKey->m_KeyCode = 0; - conflictingCtrl->UpdateFromClientData(); - return true; - } - else - { - return false; - } - } - - return true; -} diff --git a/common/dialogs/dialog_hotkeys_editor_base.cpp b/common/dialogs/dialog_hotkeys_editor_base.cpp index d2e99ee0fa..1293cb4b95 100644 --- a/common/dialogs/dialog_hotkeys_editor_base.cpp +++ b/common/dialogs/dialog_hotkeys_editor_base.cpp @@ -13,16 +13,11 @@ HOTKEYS_EDITOR_DIALOG_BASE::HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWind { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - wxBoxSizer* bMainSizer; - bMainSizer = new wxBoxSizer( wxVERTICAL ); + m_mainSizer = new wxBoxSizer( wxVERTICAL ); m_staticText1 = new wxStaticText( this, wxID_ANY, _("Select a row and press a new key combination to alter the binding."), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText1->Wrap( 400 ); - bMainSizer->Add( m_staticText1, 0, wxALL|wxEXPAND, 5 ); - - m_hotkeySections = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - bMainSizer->Add( m_hotkeySections, 1, wxEXPAND | wxALL, 5 ); + m_mainSizer->Add( m_staticText1, 0, wxALL|wxEXPAND, 5 ); wxBoxSizer* b_buttonsSizer; b_buttonsSizer = new wxBoxSizer( wxHORIZONTAL ); @@ -43,10 +38,10 @@ HOTKEYS_EDITOR_DIALOG_BASE::HOTKEYS_EDITOR_DIALOG_BASE( wxWindow* parent, wxWind b_buttonsSizer->Add( m_sdbSizer, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); - bMainSizer->Add( b_buttonsSizer, 0, wxALIGN_RIGHT|wxEXPAND, 5 ); + m_mainSizer->Add( b_buttonsSizer, 0, wxALIGN_RIGHT|wxEXPAND, 5 ); - this->SetSizer( bMainSizer ); + this->SetSizer( m_mainSizer ); this->Layout(); // Connect Events diff --git a/common/dialogs/dialog_hotkeys_editor_base.fbp b/common/dialogs/dialog_hotkeys_editor_base.fbp index 8bd3ca6fe8..814b3acc7b 100644 --- a/common/dialogs/dialog_hotkeys_editor_base.fbp +++ b/common/dialogs/dialog_hotkeys_editor_base.fbp @@ -90,9 +90,9 @@ - bMainSizer + m_mainSizer wxVERTICAL - none + protected 5 wxALL|wxEXPAND @@ -176,90 +176,6 @@ - - 5 - wxEXPAND | wxALL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_hotkeySections - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 wxALIGN_RIGHT|wxEXPAND diff --git a/common/dialogs/dialog_hotkeys_editor_base.h b/common/dialogs/dialog_hotkeys_editor_base.h index cfd65285fb..9c58421872 100644 --- a/common/dialogs/dialog_hotkeys_editor_base.h +++ b/common/dialogs/dialog_hotkeys_editor_base.h @@ -20,7 +20,6 @@ class DIALOG_SHIM; #include #include #include -#include #include #include #include @@ -36,8 +35,8 @@ class HOTKEYS_EDITOR_DIALOG_BASE : public DIALOG_SHIM private: protected: + wxBoxSizer* m_mainSizer; wxStaticText* m_staticText1; - wxNotebook* m_hotkeySections; wxButton* m_resetButton; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; diff --git a/include/dialog_hotkeys_editor.h b/include/dialog_hotkeys_editor.h index 30aae16038..c0da68277d 100644 --- a/include/dialog_hotkeys_editor.h +++ b/include/dialog_hotkeys_editor.h @@ -90,7 +90,26 @@ public: bool TransferDataFromControl(); /** - * Function CanSetKey + * Function ResolveKeyConflicts + * Check if we can set a hotkey, this will prompt the user if there + * is a conflict between keys. The key code should have already been + * checked that it's not for the same entry as its currently in or else + * it'll prompt the change on itself. + * The function will do conflict detection depending on aSectionTag. + * g_CommonSectionTag means the key code must be checked with all sections. + * While other tags means the key code only must be checked with the aSectionTag + * section and g_CommonSectionTag section. + * + * @param aKey is the key code that wants to be set + * @param aSectionTag is the section tag that the key code came from + * + * @return True if the user accepted the overwrite or no conflict existed + */ + bool ResolveKeyConflicts( long aKey, const wxString& aSectionTag ); + + + /** + * Function CheckKeyConflicts * Check whether the given key conflicts with anything in this HOTKEY_LIST_CTRL. * * @param aKey - key to check @@ -98,7 +117,7 @@ public: * @param aConfKey - if not NULL, outparam holding the key this one conflicts with * @param aConfSect - if not NULL, outparam holding the section this one conflicts with */ - bool CanSetKey( long aKey, const wxString& aSectionTag, + bool CheckKeyConflicts( long aKey, const wxString& aSectionTag, EDA_HOTKEY** aConfKey, EDA_HOTKEY_CONFIG** aConfSect ); /** @@ -152,59 +171,8 @@ protected: * @param aEvent is the key press event, the keycode is retrieved from it */ void OnChar( wxKeyEvent& aEvent ); - - /** - * Function OnSize - * Sizing update handler to recompute the column widths dynamically. - */ - void OnSize( wxSizeEvent& aEvent ); }; -/** - * Class HOTKEY_SECTION_PAGE - * is a class to contain the contents of a hotkey editor tab page. - */ -class HOTKEY_SECTION_PAGE : public wxPanel -{ -public: -private: - HOTKEY_LIST_CTRL *m_hotkeyList; - HOTKEYS_EDITOR_DIALOG* m_dialog; - -public: - /** Constructor to create a setup page for one netlist format. - * Used in Netlist format Dialog box creation - * @param parent = wxNotebook * parent - * @param title = title (name) of the notebook page - * @param id_NetType = netlist type id - */ - HOTKEY_SECTION_PAGE( HOTKEYS_EDITOR_DIALOG* aDialog, wxNotebook* aParent, - const wxString& aTitle, - EDA_HOTKEY_CONFIG* aSection ); - ~HOTKEY_SECTION_PAGE() {}; - - /** - * Function Restore - * Resets the hotkeys back to their original unedited state - */ - void Restore(); - - /** - * Function GetHotkeyCtrl - * Accessor to retrieve hotkey configuration control assigned to a tab control page - * - * @return Pointer to hotkey configuration control - */ - HOTKEY_LIST_CTRL* GetHotkeyCtrl() { return m_hotkeyList; } - - /** - * Function GetDialog - * Returns pointer to parent dialog window - * - * @return Pointer to parent dialog window - */ - HOTKEYS_EDITOR_DIALOG* GetDialog() { return m_dialog; } -}; /** * Class HOTKEYS_EDITOR_DIALOG @@ -217,7 +185,7 @@ protected: EDA_BASE_FRAME* m_parent; struct EDA_HOTKEY_CONFIG* m_hotkeys; - std::vector m_hotkeySectionPages; + HOTKEY_LIST_CTRL* m_hotkeyListCtrl; bool TransferDataToWindow(); bool TransferDataFromWindow(); @@ -227,24 +195,6 @@ public: ~HOTKEYS_EDITOR_DIALOG() {}; - /** - * Function CanSetKey - * Check if we can set a hotkey, this will prompt the user if there - * is a conflict between keys. The key code should have already been - * checked that it's not for the same entry as its currently in or else - * it'll prompt the change on itself. - * The function will do conflict detection depending on aSectionTag. - * g_CommonSectionTag means the key code must be checked with all sections. - * While other tags means the key code only must be checked with the aSectionTag - * section and g_CommonSectionTag section. - * - * @param aKey is the key code that wants to be set - * @param aSectionTag is the section tag that the key code came from - * - * @return True if the user accepted the overwrite or no conflict existed - */ - bool CanSetKey( long aKey, const wxString& aSectionTag ); - private: /**