From 300a047ffee502c67983c173157439a742272c2c Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 18 Nov 2013 13:27:27 -0600 Subject: [PATCH] more EDA_LIST_DIALOG usability enhancements, compiler warning, coding standards --- common/dialogs/dialog_list_selector_base.cpp | 2 + common/dialogs/dialog_list_selector_base.fbp | 2 +- common/displlst.cpp | 44 ++++++++-------- pcbnew/loadcmp.cpp | 54 +++++++++++--------- pcbnew/tools/selection_tool.cpp | 8 +-- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/common/dialogs/dialog_list_selector_base.cpp b/common/dialogs/dialog_list_selector_base.cpp index 9fec346120..44755adac6 100644 --- a/common/dialogs/dialog_list_selector_base.cpp +++ b/common/dialogs/dialog_list_selector_base.cpp @@ -30,6 +30,8 @@ EDA_LIST_DIALOG_BASE::EDA_LIST_DIALOG_BASE( wxWindow* parent, wxWindowID id, con bSizerMain->Add( m_staticText2, 0, wxRIGHT|wxLEFT, 5 ); m_listBox = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxALWAYS_SHOW_SB|wxVSCROLL ); + m_listBox->SetMinSize( wxSize( -1,200 ) ); + bSizerMain->Add( m_listBox, 3, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_staticTextMsg = new wxStaticText( this, wxID_ANY, _("Messages:"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/common/dialogs/dialog_list_selector_base.fbp b/common/dialogs/dialog_list_selector_base.fbp index dc016cc11b..82e5d57351 100644 --- a/common/dialogs/dialog_list_selector_base.fbp +++ b/common/dialogs/dialog_list_selector_base.fbp @@ -387,7 +387,7 @@ 0 - -1,-1 + -1,200 1 m_listBox 1 diff --git a/common/displlst.cpp b/common/displlst.cpp index 8aacb4be46..9da30cbdb1 100644 --- a/common/displlst.cpp +++ b/common/displlst.cpp @@ -35,8 +35,8 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle, const wxArrayString& aItemHeaders, const std::vector& aItemList, - const wxString& aRefText, - void(*aCallBackFunction)(wxString& Text), + const wxString& aSelection, + void( *aCallBackFunction )( wxString& ), bool aSortList ) : EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle ) { @@ -47,29 +47,15 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl for( unsigned i = 0; i < aItemHeaders.Count(); i++ ) { wxListItem column; + column.SetId( i ); column.SetText( aItemHeaders.Item( i ) ); + m_listBox->InsertColumn( i, column ); } InsertItems( aItemList, 0 ); - if( !aRefText.IsEmpty() ) // try to select the item matching aRefText - { - for( unsigned ii = 0; ii < aItemList.size(); ii++ ) - { - if( aItemList[ii][0] == aRefText ) - { - m_listBox->SetItemState( ii, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); - break; - } - } - } - - // DIALOG_SHIM needs a unique hash_key because classname is not sufficient - // because so many dialogs share this same class. - m_hash_key = TO_UTF8( aTitle ); - for( unsigned i = 0; i < aItemHeaders.Count(); i++ ) m_listBox->SetColumnWidth( i, wxLIST_AUTOSIZE ); @@ -79,9 +65,27 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl m_staticTextMsg->Show( false ); } - m_filterBox->SetFocus(); - Fit(); + + if( !!aSelection ) + { + for( unsigned row = 0; row < aItemList.size(); ++row ) + { + if( aItemList[row][0] == aSelection ) + { + m_listBox->SetItemState( row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + m_listBox->EnsureVisible( row ); + break; + } + } + } + + // DIALOG_SHIM needs a unique hash_key because classname is not sufficient + // because so many dialogs share this same class, with different numbers of + // columns, different column names, and column widths. + m_hash_key = TO_UTF8( aTitle ); + + m_filterBox->SetFocus(); } diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index cd5a1982b8..4400c2d7d5 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -470,11 +470,13 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, const wxString& aKeyWord, FP_LIB_TABLE* aTable ) { - static wxString OldName; // Save the name of the last module loaded. - wxString CmpName; - wxString msg; - wxArrayString libraries; - FP_LIB_TABLE libTable; + static wxString oldName; // Save the name of the last module loaded. + + wxString fpname; + wxString msg; + wxArrayString libraries; + FP_LIB_TABLE libTable; + std::vector< wxArrayString > rows; #if !defined( USE_FP_LIB_TABLE ) @@ -581,33 +583,33 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, msg.Printf( _( "Modules [%d items]" ), (int) rows.size() ); - EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, OldName, DisplayCmpDoc ); + EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, oldName, DisplayCmpDoc ); if( dlg.ShowModal() == wxID_OK ) { - CmpName = dlg.GetTextSelection(); + fpname = dlg.GetTextSelection(); #if defined( USE_FP_LIB_TABLE ) - CmpName = dlg.GetTextSelection( 1 ) + wxT( ":" ) + CmpName; + fpname = dlg.GetTextSelection( 1 ) + wxT( ":" ) + fpname; #endif SkipNextLeftButtonReleaseEvent(); } else - CmpName.Empty(); + fpname.Empty(); } else { DisplayError( aWindow, _( "No footprint found." ) ); - CmpName.Empty(); + fpname.Empty(); } - if( CmpName != wxEmptyString ) - OldName = CmpName; + if( fpname != wxEmptyString ) + oldName = fpname; - wxLogDebug( wxT( "Footprint '%s' was selected." ), GetChars( CmpName ) ); + wxLogDebug( wxT( "Footprint '%s' was selected." ), GetChars( fpname ) ); - return CmpName; + return fpname; } @@ -628,27 +630,29 @@ static void DisplayCmpDoc( wxString& Name ) MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprint( BOARD* aPcb ) { - MODULE* module; - static wxString OldName; // Save name of last module selected. - wxString CmpName, msg; + static wxString oldName; // Save name of last module selected. - wxArrayString listnames; + wxString fpname; + wxString msg; + wxArrayString listnames; + MODULE* module = aPcb->m_Modules; - module = aPcb->m_Modules; - - for( ; module != NULL; module = (MODULE*) module->Next() ) + for( ; module; module = module->Next() ) listnames.Add( module->GetReference() ); msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() ); wxArrayString headers; + headers.Add( _( "Module" ) ); + std::vector itemsToDisplay; // Conversion from wxArrayString to vector of ArrayString for( unsigned i = 0; i < listnames.GetCount(); i++ ) { wxArrayString item; + item.Add( listnames[i] ); itemsToDisplay.push_back( item ); } @@ -656,17 +660,17 @@ MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprint( BOARD* aPcb ) EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString, NULL, SORT_LIST ); if( dlg.ShowModal() == wxID_OK ) - CmpName = dlg.GetTextSelection(); + fpname = dlg.GetTextSelection(); else return NULL; - OldName = CmpName; + oldName = fpname; module = aPcb->m_Modules; - for( ; module != NULL; module = (MODULE*) module->Next() ) + for( ; module; module = module->Next() ) { - if( CmpName == module->GetReference() ) + if( fpname == module->GetReference() ) break; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 45523ab76a..262d93ac45 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -81,9 +81,9 @@ void SELECTION_TOOL::Reset() int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) { - BOARD* board = getModel( PCB_T ); - VIEW* view = getView(); - assert( board != NULL ); + VIEW* view = getView(); + + assert( getModel( PCB_T ) != NULL ); view->Add( m_selection.group ); @@ -503,7 +503,7 @@ void SELECTION_TOOL::selectItem( BOARD_ITEM* aItem ) { SELECTION& s; - public: + public: selectBase_( SELECTION& s_ ) : s( s_ ) {} void operator()( BOARD_ITEM* item )