cvpcb: Refactor events and cleanup formatting

This commit is contained in:
Ian McInerney 2019-08-10 11:17:42 +02:00 committed by Wayne Stambaugh
parent c0204e90b1
commit 36b430562d
3 changed files with 114 additions and 110 deletions

View File

@ -57,23 +57,6 @@ wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 );
static const wxString FilterFootprintEntry = "FilterFootprint"; static const wxString FilterFootprintEntry = "FilterFootprint";
///@} ///@}
BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
// Control events
EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
EVT_BUTTON( wxID_OK, CVPCB_MAINFRAME::OnOK )
EVT_BUTTON( wxID_CANCEL, CVPCB_MAINFRAME::OnCancel )
// Toolbar events
EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText )
// Frame events
EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
EVT_SIZE( CVPCB_MAINFRAME::OnSize )
END_EVENT_TABLE()
#define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" ) #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
@ -200,7 +183,10 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
CVPCB_MAINFRAME::~CVPCB_MAINFRAME() CVPCB_MAINFRAME::~CVPCB_MAINFRAME()
{ {
// No events to disconnect since they are using lambdas as the handlers // Clean up the tool infrastructure
delete m_actions;
delete m_toolManager;
delete m_toolDispatcher;
m_auimgr.UnInit(); m_auimgr.UnInit();
} }
@ -261,38 +247,50 @@ void CVPCB_MAINFRAME::setupEventHandlers()
this->GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations ); this->GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations );
} ); } );
// Connect the handlers for the ok/cancel buttons
Bind( wxEVT_BUTTON,
[this]( wxCommandEvent& )
{
this->GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations );
Close( true );
}, wxID_OK );
Bind( wxEVT_BUTTON,
[this]( wxCommandEvent& )
{
// Throw away modifications on a Cancel
m_modified = false;
Close( false );
}, wxID_CANCEL );
// Connect the handlers for the close events
Bind( wxEVT_CLOSE_WINDOW, &CVPCB_MAINFRAME::OnCloseWindow, this );
Bind( wxEVT_MENU,
[this]( wxCommandEvent& )
{
Close( false );
}, wxID_CLOSE );
Bind( wxEVT_MENU,
[this]( wxCommandEvent& )
{
Close( false );
}, wxID_EXIT );
// Toolbar events
Bind( wxEVT_TEXT, &CVPCB_MAINFRAME::OnEnterFilteringText, this, ID_CVPCB_FILTER_TEXT_EDIT );
// Just skip the resize events
Bind( wxEVT_SIZE,
[]( wxSizeEvent& aEvent )
{
aEvent.Skip();
} );
// Attach the events to the tool dispatcher // Attach the events to the tool dispatcher
Bind( wxEVT_TOOL, &TOOL_DISPATCHER::DispatchWxCommand, m_toolDispatcher ); Bind( wxEVT_TOOL, &TOOL_DISPATCHER::DispatchWxCommand, m_toolDispatcher );
Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher ); Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher ); Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
} }
void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
{
EDA_BASE_FRAME::LoadSettings( aCfg );
wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
if( m_FrameSize == wxDefaultSize )
m_FrameSize = frame_default;
aCfg->Read( FilterFootprintEntry, &m_filteringOptions, FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST );
}
void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
{
EDA_BASE_FRAME::SaveSettings( aCfg );
aCfg->Write( FilterFootprintEntry, m_filteringOptions );
}
void CVPCB_MAINFRAME::OnSize( wxSizeEvent& event )
{
event.Skip();
}
void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
@ -321,26 +319,61 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
} }
void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent ) void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
{ {
SaveFootprintAssociation( false ); // Called when changing the filter string in main toolbar.
// If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
// available footprints which match the filter
Close( true ); m_currentSearchPattern = m_tcFilterString->GetValue();
if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ) == 0 )
return;
wxListEvent l_event;
OnSelectComponent( l_event );
} }
void CVPCB_MAINFRAME::OnCancel( wxCommandEvent& event ) void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
{ {
// Throw away modifications on a Cancel if( m_skipComponentSelect )
m_modified = false; return;
Close( false ); wxString libraryName;
COMPONENT* component = GetSelectedComponent();
libraryName = m_libListBox->GetSelectedLibrary();
m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
m_currentSearchPattern, m_filteringOptions);
if( component && component->GetFPID().IsValid() )
m_footprintListBox->SetSelectedFootprint( component->GetFPID() );
else
m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false );
refreshAfterComponentSearch( component );
} }
void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event ) void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg )
{ {
Close( false ); EDA_BASE_FRAME::LoadSettings( aCfg );
wxSize const frame_default( ConvertDialogToPixels( FRAME_DEFAULT_SIZE_DU ) );
if( m_FrameSize == wxDefaultSize )
m_FrameSize = frame_default;
aCfg->Read( FilterFootprintEntry, &m_filteringOptions, FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST );
}
void CVPCB_MAINFRAME::SaveSettings( wxConfigBase* aCfg )
{
EDA_BASE_FRAME::SaveSettings( aCfg );
aCfg->Write( FilterFootprintEntry, m_filteringOptions );
} }
@ -452,27 +485,6 @@ bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, i
} }
void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
{
if( m_skipComponentSelect )
return;
wxString libraryName;
COMPONENT* component = GetSelectedComponent();
libraryName = m_libListBox->GetSelectedLibrary();
m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, component,
m_currentSearchPattern, m_filteringOptions);
if( component && component->GetFPID().IsValid() )
m_footprintListBox->SetSelectedFootprint( component->GetFPID() );
else
m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false );
refreshAfterComponentSearch (component);
}
void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component ) void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component )
{ {
// Tell AuiMgr that objects are changed ! // Tell AuiMgr that objects are changed !
@ -561,22 +573,6 @@ void CVPCB_MAINFRAME::SetFootprintFilter(
} }
void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
{
// Called when changing the filter string in main toolbar.
// If the option FOOTPRINTS_LISTBOX::FILTERING_BY_NAME is set, update the list of
// available footprints which match the filter
m_currentSearchPattern = m_tcFilterString->GetValue();
if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ) == 0 )
return;
wxListEvent l_event;
OnSelectComponent( l_event );
}
void CVPCB_MAINFRAME::DisplayStatus() void CVPCB_MAINFRAME::DisplayStatus()
{ {
if( !m_initialized ) if( !m_initialized )

View File

@ -169,17 +169,22 @@ public:
* * Updates the current selected footprint in footprint list * * Updates the current selected footprint in footprint list
* * Updates the footprint shown in footprint display window (if opened) * * Updates the footprint shown in footprint display window (if opened)
*/ */
void OnSelectComponent( wxListEvent& event ); void OnSelectComponent( wxListEvent& event );
void OnCancel( wxCommandEvent& aEvent ); /**
void OnOK( wxCommandEvent& aEvent ); * OnCloseWindow
void OnQuit( wxCommandEvent& event ); *
void OnCloseWindow( wxCloseEvent& Event ); * Called by a close event to close the window
void OnSize( wxSizeEvent& SizeEvent ); */
void OnKeyDown( wxKeyEvent& aEvent ); void OnCloseWindow( wxCloseEvent& Event );
void ReCreateHToolbar();
void ReCreateMenuBar() override; /*
void ShowChangedLanguage() override; * Functions to rebuild the toolbars and menubars
*/
void ReCreateHToolbar();
void ReCreateMenuBar() override;
void ShowChangedLanguage() override;
/** /**
* Called by the automatic association button * Called by the automatic association button
@ -205,7 +210,7 @@ public:
* Function OnEnterFilteringText * Function OnEnterFilteringText
* Is called each time the text of m_tcFilterString is changed. * Is called each time the text of m_tcFilterString is changed.
*/ */
void OnEnterFilteringText( wxCommandEvent& event ); void OnEnterFilteringText( wxCommandEvent& event );
/** /**
@ -232,9 +237,12 @@ public:
void AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, bool aNewEntry = true, void AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, bool aNewEntry = true,
bool aAddUndoItem = true ); bool aAddUndoItem = true );
void BuildCmpListBox(); /*
void BuildFOOTPRINTS_LISTBOX(); * Functions to build the listboxes and their contents
void BuildLIBRARY_LISTBOX(); */
void BuildCmpListBox();
void BuildFOOTPRINTS_LISTBOX();
void BuildLIBRARY_LISTBOX();
/** /**
* Function SaveFootprintAssociation * Function SaveFootprintAssociation
@ -251,7 +259,7 @@ public:
* @param aNetlist is the netlist from eeschema in kicad s-expr format. * @param aNetlist is the netlist from eeschema in kicad s-expr format.
* (see CVPCB_MAINFRAME::KiwayMailIn() to know how to get this netlist) * (see CVPCB_MAINFRAME::KiwayMailIn() to know how to get this netlist)
*/ */
bool ReadNetListAndFpFiles( const std::string& aNetlist ); bool ReadNetListAndFpFiles( const std::string& aNetlist );
/** /**
* Function ReadSchematicNetlist * Function ReadSchematicNetlist
@ -260,7 +268,7 @@ public:
* It is the same netlist as the .net file created by Eeschema. * It is the same netlist as the .net file created by Eeschema.
* (This method is called by ReadNetListAndFpFiles) * (This method is called by ReadNetListAndFpFiles)
*/ */
int ReadSchematicNetlist( const std::string& aNetlist ); int ReadSchematicNetlist( const std::string& aNetlist );
/** /**
* Function LoadProjectFile * Function LoadProjectFile
@ -290,7 +298,7 @@ public:
* displayed in the second status bar pane. The third status bar pane always displays the * displayed in the second status bar pane. The third status bar pane always displays the
* current footprint list filtering. * current footprint list filtering.
*/ */
void DisplayStatus(); void DisplayStatus();
/** /**
* Function LoadFootprintFiles * Function LoadFootprintFiles
@ -303,7 +311,7 @@ public:
* fills m_footprints * fills m_footprints
* @return true if libraries are found, false otherwise. * @return true if libraries are found, false otherwise.
*/ */
bool LoadFootprintFiles(); bool LoadFootprintFiles();
/** /**
* Function GetProjectFileParameters * Function GetProjectFileParameters
@ -411,8 +419,6 @@ private:
// Undo/Redo item lists // Undo/Redo item lists
CVPCB_UNDO_REDO_LIST m_undoList; CVPCB_UNDO_REDO_LIST m_undoList;
CVPCB_UNDO_REDO_LIST m_redoList; CVPCB_UNDO_REDO_LIST m_redoList;
DECLARE_EVENT_TABLE()
}; };
#endif //#ifndef _CVPCB_MAINFRAME_H_ #endif //#ifndef _CVPCB_MAINFRAME_H_

View File

@ -46,6 +46,8 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool ); CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool );
fileMenu->AddItem( CVPCB_ACTIONS::saveAssociations, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddItem( CVPCB_ACTIONS::saveAssociations, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
fileMenu->AddItem( wxID_CLOSE, _( "Close" ), "", exit_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->Resolve(); fileMenu->Resolve();