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

Common dialog file housekeeping. Code cleanup, and minor fixes.

parent 8257ebeb
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
                    ${CMAKE_CURRENT_SOURCE_DIR}/dialogs
                    ${Boost_INCLUDE_DIR}
                    ${Boost_INCLUDE_DIR}
                    ../3d-viewer
                    ../3d-viewer
                    ../pcbnew
                    ../pcbnew
@@ -9,6 +10,13 @@ set( COMMON_ABOUT_DLG_SRCS
    dialog_about/AboutDialog_main.cpp
    dialog_about/AboutDialog_main.cpp
    dialog_about/dialog_about.cpp
    dialog_about/dialog_about.cpp
    dialog_about/dialog_about_base.cpp
    dialog_about/dialog_about_base.cpp
    dialogs/dialog_display_info_HTML_base.cpp
    dialogs/dialog_get_component.cpp
    dialogs/dialog_get_component_base.cpp
    dialogs/dialog_hotkeys_editor.cpp
    dialogs/dialog_hotkeys_editor_base.cpp
    dialogs/dialog_load_error.cpp
    dialogs/dialog_page_settings_base.cpp
)
)


set(COMMON_SRCS
set(COMMON_SRCS
@@ -32,12 +40,7 @@ set(COMMON_SRCS
    common_plotDXF_functions.cpp
    common_plotDXF_functions.cpp
    confirm.cpp
    confirm.cpp
    copy_to_clipboard.cpp
    copy_to_clipboard.cpp
    dialog_display_info_HTML_base.cpp
    dialog_hotkeys_editor.cpp
    dialog_hotkeys_editor_base.cpp
    dialog_load_error.cpp
    dcsvg.cpp
    dcsvg.cpp
    dialog_page_settings_base.cpp
    displlst.cpp
    displlst.cpp
    dlist.cpp
    dlist.cpp
    drawframe.cpp
    drawframe.cpp
@@ -48,7 +51,6 @@ set(COMMON_SRCS
    eda_dde.cpp
    eda_dde.cpp
    eda_doc.cpp
    eda_doc.cpp
    gestfich.cpp
    gestfich.cpp
    get_component_dialog.cpp
    gr_basic.cpp
    gr_basic.cpp
    hotkeys_basic.cpp
    hotkeys_basic.cpp
    hotkey_grid_table.cpp
    hotkey_grid_table.cpp
+48 −123
Original line number Original line Diff line number Diff line
/*********************************/
/*********************************/
/*  get_component_dialog.cpp     */
/*  dialog_get_component.cpp     */
/*********************************/
/*********************************/


#include "fctsys.h"
#include "fctsys.h"
#include "gr_basic.h"
//#include "gr_basic.h"
#include "common.h"
#include "common.h"
#include "macros.h"
#include "macros.h"
#include "wxstruct.h"
#include "wxstruct.h"
#include "get_component_dialog.h"
#include "dialog_get_component.h"




/****************************************************************************/
/****************************************************************************/
@@ -18,120 +18,62 @@
static unsigned s_HistoryMaxCount = 8;  // Max number of items displayed in history list
static unsigned s_HistoryMaxCount = 8;  // Max number of items displayed in history list




BEGIN_EVENT_TABLE( WinEDA_SelectCmp, wxDialog )
    EVT_BUTTON( ID_ACCEPT_NAME, WinEDA_SelectCmp::Accept )
    EVT_BUTTON( ID_ACCEPT_KEYWORD, WinEDA_SelectCmp::Accept )
    EVT_BUTTON( wxID_CANCEL, WinEDA_SelectCmp::Accept )
    EVT_BUTTON( ID_LIST_ALL, WinEDA_SelectCmp::Accept )
    EVT_BUTTON( ID_EXTRA_TOOL, WinEDA_SelectCmp::GetExtraSelection )
    EVT_LISTBOX( ID_SEL_BY_LISTBOX, WinEDA_SelectCmp::Accept )
END_EVENT_TABLE()


/*
/*
 * Dialog frame to choose a component or a footprint
 * Dialog frame to choose a component or a footprint
 *   This dialog shows an history of last selected items
 *   This dialog shows an history of last selected items
 */
 */
WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
DIALOG_GET_COMPONENT::DIALOG_GET_COMPONENT( WinEDA_DrawFrame* parent,
                                    const wxPoint&    framepos,
                                    const wxPoint&    framepos,
                                    wxArrayString&    HistoryList,
                                    wxArrayString&    HistoryList,
                                    const wxString&   Title,
                                    const wxString&   Title,
                                    bool              show_extra_tool ) :
                                    bool              show_extra_tool ) :
    wxDialog( parent, -1, Title, framepos, wxDefaultSize, DIALOG_STYLE )
    DIALOG_GET_COMPONENT_BASE( parent, -1, Title, framepos )
{
{
    m_AuxTool = show_extra_tool;

    InitDialog( HistoryList );
#ifdef __WXMAC__
    m_auxToolSelector = false;
#else
    m_auxToolSelector = show_extra_tool;
#endif
    initDialog( HistoryList );


    GetSizer()->Fit( this );
    GetSizer()->Fit( this );
    GetSizer()->SetSizeHints( this );
    GetSizer()->SetSizeHints( this );
}
}


void WinEDA_SelectCmp::InitDialog( wxArrayString& aHistoryList )
void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList )
{
{
    
    SetFocus();
    wxButton*     Button;
    wxStaticText* Text;

    m_GetExtraFunction = false;
    m_GetExtraFunction = false;

    m_historyList->Append( aHistoryList );
    wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    if( !m_auxToolSelector )
    SetSizer( MainBoxSizer );

    wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
    MainBoxSizer->Add( LeftBoxSizer,
                       0,
                       wxALIGN_CENTER_HORIZONTAL | wxALL | wxADJUST_MINSIZE,
                       5 );
    wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
    MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );

    Text = new wxStaticText( this, -1, _( "Name:" ) );
    LeftBoxSizer->Add( Text, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5 );
    m_TextCtrl = new wxTextCtrl( this, wxID_ANY );
    m_TextCtrl->SetFocus();         // text value will be initialized later by calling GetComponentName()
    LeftBoxSizer->Add( m_TextCtrl,
                       0,
                       wxGROW | wxLEFT | wxRIGHT | wxBOTTOM | wxADJUST_MINSIZE,
                       5 );


    Text = new wxStaticText( this, -1, _( "History list:" ) );
    LeftBoxSizer->Add( Text, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5 );

    m_List = new wxListBox( this, ID_SEL_BY_LISTBOX, wxDefaultPosition,
                            wxSize( 220, -1 ), aHistoryList, wxLB_SINGLE );
    LeftBoxSizer->Add( m_List,
                       0,
                       wxGROW | wxLEFT | wxRIGHT | wxBOTTOM | wxADJUST_MINSIZE,
                       5 );

    Button = new wxButton( this, ID_ACCEPT_NAME, _( "OK" ) );
    Button->SetDefault();
    RightBoxSizer->Add( Button,
                        0,
                        wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM,
                        5 );

    Button = new wxButton( this, ID_ACCEPT_KEYWORD, _( "Search by Keyword" ) );
    RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );

    Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
    RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );

    Button = new wxButton( this, ID_LIST_ALL, _( "List All" ) );
    RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );

#ifndef __WXMAC__
    if( m_AuxTool )     /* The selection can be done by an extra function */
    {
    {
        Button = new wxButton( this, ID_EXTRA_TOOL, _( "Select by Browser" ) );
        m_buttonBrowse->Show( false );
        RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
        m_buttonBrowse->Enable( false );
    }
    }
#endif
}
}




void WinEDA_SelectCmp::Accept( wxCommandEvent& event )
void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event )
{
{
    int id = wxID_OK;
    m_Text = wxEmptyString;
    EndModal( wxID_CANCEL );
}


void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
{
    switch( event.GetId() )
    switch( event.GetId() )
    {
    {
    case ID_SEL_BY_LISTBOX:
    case ID_SEL_BY_LISTBOX:
        m_Text = m_List->GetStringSelection();
        m_Text = m_historyList->GetStringSelection();
        break;
        break;


    case ID_ACCEPT_NAME:
    case wxID_OK:
        m_Text = m_TextCtrl->GetValue();
        m_Text = m_textCmpNameCtrl->GetValue();
        break;
        break;


    case ID_ACCEPT_KEYWORD:
    case ID_ACCEPT_KEYWORD:
        m_Text = wxT( "= " ) + m_TextCtrl->GetValue();
        m_Text = wxT( "= " ) + m_textCmpNameCtrl->GetValue();
        break;

    case wxID_CANCEL:
        m_Text = wxEmptyString;
        id = wxID_CANCEL;
        break;
        break;


    case ID_LIST_ALL:
    case ID_LIST_ALL:
@@ -142,27 +84,20 @@ void WinEDA_SelectCmp::Accept( wxCommandEvent& event )
    m_Text.Trim( false );      // Remove blanks at beginning
    m_Text.Trim( false );      // Remove blanks at beginning
    m_Text.Trim( true );       // Remove blanks at end
    m_Text.Trim( true );       // Remove blanks at end


    if( IsModal() )
    EndModal( wxID_OK );
        EndModal( id );
    else
        Close( id );
}
}




/* Get the component name by the extra function */
/* Get the component name by the extra function */
void WinEDA_SelectCmp::GetExtraSelection( wxCommandEvent& event )
void DIALOG_GET_COMPONENT::GetExtraSelection( wxCommandEvent& event )
{
{
    m_GetExtraFunction = true;
    m_GetExtraFunction = true;

    if( IsModal() )
    EndModal( wxID_OK );
    EndModal( wxID_OK );
    else
        Close( wxID_OK );
}
}




// Return the component name selected by the dialog
// Return the component name selected by the dialog
wxString WinEDA_SelectCmp::GetComponentName( void )
wxString DIALOG_GET_COMPONENT::GetComponentName( void )
{
{
    return m_Text;
    return m_Text;
}
}
@@ -170,12 +105,12 @@ wxString WinEDA_SelectCmp::GetComponentName( void )


/* Initialize the default component name default choice
/* Initialize the default component name default choice
*/
*/
void WinEDA_SelectCmp::SetComponentName( const wxString& name )
void DIALOG_GET_COMPONENT::SetComponentName( const wxString& name )
{
{
    if( m_TextCtrl )
    if( m_textCmpNameCtrl )
    {
    {
        m_TextCtrl->SetValue( name );
        m_textCmpNameCtrl->SetValue( name );
        m_TextCtrl->SetSelection(-1, -1);
        m_textCmpNameCtrl->SetSelection(-1, -1);
    }
    }
}
}


@@ -206,37 +141,27 @@ wxPoint GetComponentDialogPosition( void )




/*
/*
 * Add the string "Name" to the history list HistoryList
 * Add the string "aName" to the history list aHistoryList
 */
 */
void AddHistoryComponentName( wxArrayString& HistoryList, const wxString& Name )
void AddHistoryComponentName( wxArrayString& aHistoryList, const wxString& aName )
{
    int ii, c_max;

    if( HistoryList.GetCount() > 0 )
{
{
        if( Name == HistoryList[0] )
    if( ( aHistoryList.GetCount() > 0 ) && ( aName == aHistoryList[0] ) )
        return;
        return;


        /* remove an old identical selection if exists */
    /* remove an old identical name if exists */
        for( ii = 1; (unsigned) ii < HistoryList.GetCount(); ii++ )
    for( unsigned ii = 1; ii < aHistoryList.GetCount(); ii++ )
    {
    {
            if( Name == HistoryList[ii] )
        if( aName == aHistoryList[ii] )
        {
        {
                HistoryList.RemoveAt( ii ); ii--;
            aHistoryList.RemoveAt( ii );
            ii--;
        }
        }
    }
    }


        /* shift the list */
    // Add the new name at the beginning of the history list
        if( HistoryList.GetCount() < s_HistoryMaxCount )
    aHistoryList.Insert(aName, 0);
            HistoryList.Add( wxT( "" ) );


        c_max = HistoryList.GetCount() - 2;
    // Remove extra names
        for( ii = c_max; ii >= 0; ii-- )
    while( aHistoryList.GetCount() >= s_HistoryMaxCount )
            HistoryList[ii + 1] = HistoryList[ii];
        aHistoryList.RemoveAt( aHistoryList.GetCount()-1 );

        /* Add the new name at the beginning of the history list */
        HistoryList[0] = Name;
    }
    else
        HistoryList.Add( Name );
}
}
Loading