Convert to single page hotkeys editor.

This commit is contained in:
Chris Pavlina 2016-01-05 13:46:45 -05:00 committed by Wayne Stambaugh
parent 203e8156a1
commit 89cfef99c1
5 changed files with 93 additions and 289 deletions

View File

@ -28,8 +28,6 @@
#include <common.h>
#include <confirm.h>
#include <wx/dataview.h>
#include <dialog_hotkeys_editor.h>
@ -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<HOTKEY_SECTION_PAGE*>( m_parent );
bool canUpdate = parent->GetDialog()->CanSetKey( key, tag );
HOTKEYS_EDITOR_DIALOG* parent = static_cast<HOTKEYS_EDITOR_DIALOG*>( 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<HOTKEY_SECTION_PAGE*>::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<HOTKEY_SECTION_PAGE*>::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<HOTKEY_SECTION_PAGE*>::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<HOTKEY_SECTION_PAGE*>::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;
}

View File

@ -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

View File

@ -90,9 +90,9 @@
<event name="OnUpdateUI"></event>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bMainSizer</property>
<property name="name">m_mainSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
@ -176,90 +176,6 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">1</property>
<object class="wxNotebook" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmapsize"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_hotkeySections</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnNotebookPageChanged"></event>
<event name="OnNotebookPageChanging"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_RIGHT|wxEXPAND</property>

View File

@ -20,7 +20,6 @@ class DIALOG_SHIM;
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/notebook.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/dialog.h>
@ -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;

View File

@ -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<HOTKEY_SECTION_PAGE*> 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:
/**