Commit ccfd2369 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

EDA_LIST_DIALOG: add a filter option to select names to display is list, from...

EDA_LIST_DIALOG: add a filter option to select names to display is list, from a  kamil zorychta's patch <kamil.zorychta@gmail.com>
Use wxFormBuilder to create EDA_LIST_DIALOG_BASE, like other dialogs.
Minor code cleanup (remove unused functions and coding style fixes) and minor bug fixes.
parent 8a5ea7ec
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ set(COMMON_ABOUT_DLG_SRCS
    dialogs/dialog_get_component_base.cpp
    dialogs/dialog_hotkeys_editor.cpp
    dialogs/dialog_hotkeys_editor_base.cpp
    dialogs/dialog_list_selector_base.cpp
    dialogs/dialog_page_settings_base.cpp
    )

+2 −28
Original line number Diff line number Diff line
@@ -22,11 +22,10 @@ static unsigned s_HistoryMaxCount = 8; // Max number of items displayed in hist
 *   This dialog shows an history of last selected items
 */
DIALOG_GET_COMPONENT::DIALOG_GET_COMPONENT( EDA_DRAW_FRAME* parent,
                                            const wxPoint&  framepos,
                                           wxArrayString&  HistoryList,
                                            const wxString& Title,
                                            bool            show_extra_tool ) :
    DIALOG_GET_COMPONENT_BASE( parent, -1, Title, framepos )
    DIALOG_GET_COMPONENT_BASE( parent, -1, Title )
{

#ifdef __WXMAC__
@@ -118,31 +117,6 @@ void DIALOG_GET_COMPONENT::SetComponentName( const wxString& name )
}


wxPoint GetComponentDialogPosition( void )
{
    wxPoint pos;
    int     x, y, w, h;

    pos = wxGetMousePosition();
    wxClientDisplayRect( &x, &y, &w, &h );
    pos.x -= 100;
    pos.y -= 50;
    if( pos.x < x )
        pos.x = x;
    if( pos.y < y )
        pos.y = y;
    if( pos.x < x )
        pos.x = x;
    x += w - 350;
    if( pos.x > x )
        pos.x = x;
    if( pos.y < y )
        pos.y = y;

    return pos;
}


/*
 * Add the string "aName" to the history list aHistoryList
 */
+40 −66
Original line number Diff line number Diff line
@@ -8,43 +8,19 @@
#include <dialog_helpers.h>


enum listbox {
    ID_LISTBOX_LIST = 8000
};


BEGIN_EVENT_TABLE( EDA_LIST_DIALOG, wxDialog )
    EVT_BUTTON( wxID_OK, EDA_LIST_DIALOG::OnOkClick )
    EVT_BUTTON( wxID_CANCEL, EDA_LIST_DIALOG::OnCancelClick )
    EVT_LISTBOX( ID_LISTBOX_LIST, EDA_LIST_DIALOG::ClickOnList )
    EVT_LISTBOX_DCLICK( ID_LISTBOX_LIST, EDA_LIST_DIALOG::D_ClickOnList )
    EVT_CHAR( EDA_LIST_DIALOG::OnKeyEvent )
    EVT_CHAR_HOOK( EDA_LIST_DIALOG::OnKeyEvent )
    EVT_CLOSE( EDA_LIST_DIALOG::OnClose )
END_EVENT_TABLE()


EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
                                  const wxArrayString& aItemList, const wxString& aRefText,
                                  void(* aCallBackFunction)(wxString& Text), wxPoint aPos ) :
    DIALOG_SHIM( aParent, wxID_ANY, aTitle, aPos, wxDefaultSize,
              wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
                                  void(* aCallBackFunction)(wxString& Text),
                                  bool aSortList ) :
    EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
{
    m_sortList = aSortList;
    m_callBackFct = aCallBackFunction;
    m_messages    = NULL;

    wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );

    SetSizer( GeneralBoxSizer );

    m_listBox = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
                               wxDefaultSize, 0, NULL,
                               wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );
    m_listBox->SetMinSize( wxSize( 200, 200 ) );

    GeneralBoxSizer->Add( m_listBox, 2, wxGROW | wxALL, 5 );
    m_itemsListCp = &aItemList;

    InsertItems( aItemList, 0 );
    if( m_sortList )
        sortList();

    if( !aRefText.IsEmpty() )    // try to select the item matching aRefText
    {
@@ -56,20 +32,13 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
            }
    }

    if( m_callBackFct )
    if( m_callBackFct == NULL )
    {
        m_messages = new wxTextCtrl( this, -1, wxEmptyString,
                                     wxDefaultPosition, wxDefaultSize,
                                     wxTE_READONLY | wxTE_MULTILINE );
        m_messages->SetMinSize( wxSize( -1, 60 ) );

        GeneralBoxSizer->Add( m_messages, 1, wxGROW | wxALL, 5 );
        m_messages->Show(false);
        m_staticTextMsg->Show(false);
    }

    wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL );

    if( buttonSizer )
        GeneralBoxSizer->Add( buttonSizer, 0, wxGROW | wxALL, 5 );
    m_filterBox->SetFocus();

    GetSizer()->Fit( this );
    GetSizer()->SetSizeHints( this );
@@ -82,18 +51,28 @@ EDA_LIST_DIALOG::~EDA_LIST_DIALOG()
}


void EDA_LIST_DIALOG::MoveMouseToOrigin()
void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
{
    int    x, y, w, h;
    wxSize list_size = m_listBox->GetSize();
    int    orgx = m_listBox->GetRect().GetLeft();
    int    orgy = m_listBox->GetRect().GetTop();
    wxString filter;
    wxString itemName;

    filter = wxT("*") + m_filterBox->GetLineText(0).MakeLower() + wxT("*");

    wxClientDisplayRect( &x, &y, &w, &h );
    m_listBox->Clear();

    WarpPointer( x + orgx + 20, y + orgy + (list_size.y / 2) );
    for(unsigned i = 0; i < m_itemsListCp->GetCount(); i++)
    {
        itemName = m_itemsListCp->Item(i);

        if( itemName.MakeLower().Matches(filter) )
        {
            m_listBox->Insert(m_itemsListCp->Item(i),m_listBox->GetCount());
        }
    }

    if( m_sortList )
        sortList();
}

wxString EDA_LIST_DIALOG::GetTextSelection()
{
@@ -111,16 +90,19 @@ void EDA_LIST_DIALOG::Append( const wxString& item )
void EDA_LIST_DIALOG::InsertItems( const wxArrayString& itemlist, int position )
{
    m_listBox->InsertItems( itemlist, position );

    if( m_sortList )
        sortList();
}


void EDA_LIST_DIALOG::OnCancelClick( wxCommandEvent& event )
void EDA_LIST_DIALOG::onCancelClick( wxCommandEvent& event )
{
    EndModal( wxID_CANCEL );
}


void EDA_LIST_DIALOG::ClickOnList( wxCommandEvent& event )
void EDA_LIST_DIALOG::onClickOnList( wxCommandEvent& event )
{
    wxString text;

@@ -134,19 +116,19 @@ void EDA_LIST_DIALOG::ClickOnList( wxCommandEvent& event )
}


void EDA_LIST_DIALOG::D_ClickOnList( wxCommandEvent& event )
void EDA_LIST_DIALOG::onDClickOnList( wxCommandEvent& event )
{
    EndModal( wxID_OK );
}


void EDA_LIST_DIALOG::OnOkClick( wxCommandEvent& event )
void EDA_LIST_DIALOG::onOkClick( wxCommandEvent& event )
{
    EndModal( wxID_OK );
}


void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event )
void EDA_LIST_DIALOG::onClose( wxCloseEvent& event )
{
    EndModal( wxID_CANCEL );
}
@@ -154,28 +136,20 @@ void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event )

/* Sort alphabetically, case insensitive.
 */
static int SortItems( const wxString& item1, const wxString& item2 )
static int sortItems( const wxString& item1, const wxString& item2 )
{
    return StrNumCmp( item1, item2, INT_MAX, true );
}


void EDA_LIST_DIALOG::SortList()
void EDA_LIST_DIALOG::sortList()
{
    wxArrayString list = m_listBox->GetStrings();

    if( list.IsEmpty() )
        return;

    list.Sort( SortItems );

    list.Sort( sortItems );
    m_listBox->Clear();

    m_listBox->Append( list );
}


void EDA_LIST_DIALOG::OnKeyEvent( wxKeyEvent& event )
{
    event.Skip();
}
+2 −2
Original line number Diff line number Diff line
@@ -119,8 +119,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
    /* Ask for a component name or key words */
    msg.Printf( _( "component selection (%d items loaded):" ), CmpCount );

    DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), aHistoryList,
                              msg, aUseLibBrowser );
    DIALOG_GET_COMPONENT dlg( this, aHistoryList, msg, aUseLibBrowser );

    if( aHistoryList.GetCount() )
        dlg.SetComponentName( aHistoryList[0] );

+1 −3
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@

#include <../common/dialogs/dialog_get_component_base.h>

wxPoint  GetComponentDialogPosition( void );

void     AddHistoryComponentName( wxArrayString& HistoryList,
                                  const wxString& Name );

@@ -26,7 +24,7 @@ public:

public:
    // Constructor and destructor
    DIALOG_GET_COMPONENT( EDA_DRAW_FRAME* parent, const wxPoint& framepos,
    DIALOG_GET_COMPONENT( EDA_DRAW_FRAME* parent,
                          wxArrayString& HistoryList, const wxString& Title,
                          bool show_extra_tool );
    ~DIALOG_GET_COMPONENT() {};
Loading