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

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
...@@ -22,6 +22,7 @@ set(COMMON_ABOUT_DLG_SRCS ...@@ -22,6 +22,7 @@ set(COMMON_ABOUT_DLG_SRCS
dialogs/dialog_get_component_base.cpp dialogs/dialog_get_component_base.cpp
dialogs/dialog_hotkeys_editor.cpp dialogs/dialog_hotkeys_editor.cpp
dialogs/dialog_hotkeys_editor_base.cpp dialogs/dialog_hotkeys_editor_base.cpp
dialogs/dialog_list_selector_base.cpp
dialogs/dialog_page_settings_base.cpp dialogs/dialog_page_settings_base.cpp
) )
......
...@@ -22,11 +22,10 @@ static unsigned s_HistoryMaxCount = 8; // Max number of items displayed in hist ...@@ -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 * This dialog shows an history of last selected items
*/ */
DIALOG_GET_COMPONENT::DIALOG_GET_COMPONENT( EDA_DRAW_FRAME* parent, DIALOG_GET_COMPONENT::DIALOG_GET_COMPONENT( EDA_DRAW_FRAME* parent,
const wxPoint& framepos, wxArrayString& HistoryList,
wxArrayString& HistoryList,
const wxString& Title, const wxString& Title,
bool show_extra_tool ) : bool show_extra_tool ) :
DIALOG_GET_COMPONENT_BASE( parent, -1, Title, framepos ) DIALOG_GET_COMPONENT_BASE( parent, -1, Title )
{ {
#ifdef __WXMAC__ #ifdef __WXMAC__
...@@ -118,31 +117,6 @@ void DIALOG_GET_COMPONENT::SetComponentName( const wxString& name ) ...@@ -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 * Add the string "aName" to the history list aHistoryList
*/ */
......
...@@ -8,43 +8,19 @@ ...@@ -8,43 +8,19 @@
#include <dialog_helpers.h> #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, EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemList, const wxString& aRefText, const wxArrayString& aItemList, const wxString& aRefText,
void(* aCallBackFunction)(wxString& Text), wxPoint aPos ) : void(* aCallBackFunction)(wxString& Text),
DIALOG_SHIM( aParent, wxID_ANY, aTitle, aPos, wxDefaultSize, bool aSortList ) :
wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER ) EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
{ {
m_sortList = aSortList;
m_callBackFct = aCallBackFunction; m_callBackFct = aCallBackFunction;
m_messages = NULL; m_itemsListCp = &aItemList;
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 );
InsertItems( aItemList, 0 ); InsertItems( aItemList, 0 );
if( m_sortList )
sortList();
if( !aRefText.IsEmpty() ) // try to select the item matching aRefText 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 ...@@ -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, m_messages->Show(false);
wxDefaultPosition, wxDefaultSize, m_staticTextMsg->Show(false);
wxTE_READONLY | wxTE_MULTILINE );
m_messages->SetMinSize( wxSize( -1, 60 ) );
GeneralBoxSizer->Add( m_messages, 1, wxGROW | wxALL, 5 );
} }
wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL ); m_filterBox->SetFocus();
if( buttonSizer )
GeneralBoxSizer->Add( buttonSizer, 0, wxGROW | wxALL, 5 );
GetSizer()->Fit( this ); GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this ); GetSizer()->SetSizeHints( this );
...@@ -82,18 +51,28 @@ EDA_LIST_DIALOG::~EDA_LIST_DIALOG() ...@@ -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; wxString filter;
wxSize list_size = m_listBox->GetSize(); wxString itemName;
int orgx = m_listBox->GetRect().GetLeft();
int orgy = m_listBox->GetRect().GetTop();
wxClientDisplayRect( &x, &y, &w, &h ); filter = wxT("*") + m_filterBox->GetLineText(0).MakeLower() + wxT("*");
WarpPointer( x + orgx + 20, y + orgy + (list_size.y / 2) ); m_listBox->Clear();
}
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() wxString EDA_LIST_DIALOG::GetTextSelection()
{ {
...@@ -111,16 +90,19 @@ void EDA_LIST_DIALOG::Append( const wxString& item ) ...@@ -111,16 +90,19 @@ void EDA_LIST_DIALOG::Append( const wxString& item )
void EDA_LIST_DIALOG::InsertItems( const wxArrayString& itemlist, int position ) void EDA_LIST_DIALOG::InsertItems( const wxArrayString& itemlist, int position )
{ {
m_listBox->InsertItems( itemlist, 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 ); EndModal( wxID_CANCEL );
} }
void EDA_LIST_DIALOG::ClickOnList( wxCommandEvent& event ) void EDA_LIST_DIALOG::onClickOnList( wxCommandEvent& event )
{ {
wxString text; wxString text;
...@@ -134,19 +116,19 @@ void EDA_LIST_DIALOG::ClickOnList( wxCommandEvent& event ) ...@@ -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 ); EndModal( wxID_OK );
} }
void EDA_LIST_DIALOG::OnOkClick( wxCommandEvent& event ) void EDA_LIST_DIALOG::onOkClick( wxCommandEvent& event )
{ {
EndModal( wxID_OK ); EndModal( wxID_OK );
} }
void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event ) void EDA_LIST_DIALOG::onClose( wxCloseEvent& event )
{ {
EndModal( wxID_CANCEL ); EndModal( wxID_CANCEL );
} }
...@@ -154,28 +136,20 @@ void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event ) ...@@ -154,28 +136,20 @@ void EDA_LIST_DIALOG::OnClose( wxCloseEvent& event )
/* Sort alphabetically, case insensitive. /* 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 ); return StrNumCmp( item1, item2, INT_MAX, true );
} }
void EDA_LIST_DIALOG::SortList() void EDA_LIST_DIALOG::sortList()
{ {
wxArrayString list = m_listBox->GetStrings(); wxArrayString list = m_listBox->GetStrings();
if( list.IsEmpty() ) if( list.IsEmpty() )
return; return;
list.Sort( SortItems ); list.Sort( sortItems );
m_listBox->Clear(); m_listBox->Clear();
m_listBox->Append( list ); m_listBox->Append( list );
} }
void EDA_LIST_DIALOG::OnKeyEvent( wxKeyEvent& event )
{
event.Skip();
}
...@@ -119,8 +119,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, ...@@ -119,8 +119,8 @@ wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
/* Ask for a component name or key words */ /* Ask for a component name or key words */
msg.Printf( _( "component selection (%d items loaded):" ), CmpCount ); msg.Printf( _( "component selection (%d items loaded):" ), CmpCount );
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), aHistoryList, DIALOG_GET_COMPONENT dlg( this, aHistoryList, msg, aUseLibBrowser );
msg, aUseLibBrowser );
if( aHistoryList.GetCount() ) if( aHistoryList.GetCount() )
dlg.SetComponentName( aHistoryList[0] ); dlg.SetComponentName( aHistoryList[0] );
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include <../common/dialogs/dialog_get_component_base.h> #include <../common/dialogs/dialog_get_component_base.h>
wxPoint GetComponentDialogPosition( void );
void AddHistoryComponentName( wxArrayString& HistoryList, void AddHistoryComponentName( wxArrayString& HistoryList,
const wxString& Name ); const wxString& Name );
...@@ -26,7 +24,7 @@ public: ...@@ -26,7 +24,7 @@ public:
public: public:
// Constructor and destructor // 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, wxArrayString& HistoryList, const wxString& Title,
bool show_extra_tool ); bool show_extra_tool );
~DIALOG_GET_COMPONENT() {}; ~DIALOG_GET_COMPONENT() {};
......
...@@ -10,56 +10,58 @@ ...@@ -10,56 +10,58 @@
#include <common.h> // EDA_UNITS_T #include <common.h> // EDA_UNITS_T
#include <dialog_shim.h> #include <dialog_shim.h>
#include <../common/dialogs/dialog_list_selector_base.h>
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
#define SORT_LIST true
/** /**
* class EDA_LIST_DIALOG * class EDA_LIST_DIALOG
* *
* Used to display a list of elements for selection, and an help of info line * A dialog which shows:
* about the selected item. * a list of elements for selection,
* a text control to display help or info about the selected item.
* 2 buttons (OK and Cancel)
*
*/ */
class EDA_LIST_DIALOG : public DIALOG_SHIM class EDA_LIST_DIALOG : public EDA_LIST_DIALOG_BASE
{ {
private: private:
wxListBox* m_listBox; bool m_sortList;
wxTextCtrl* m_messages;
void (*m_callBackFct)( wxString& Text ); void (*m_callBackFct)( wxString& Text );
const wxArrayString* m_itemsListCp;
public: public:
/** /**
* Constructor: * Constructor:
* @param aParent Pointer to the parent window. * @param aParent Pointer to the parent window.
* @param aTitle The title shown on top. * @param aTitle = The title shown on top.
* @param aItemList A wxArrayString of the list of elements. * @param aItemList = A wxArrayString of the list of elements.
* @param aRefText An item name if an item must be preselected. * @param aRefText = An item name if an item must be preselected.
* @param aCallBackFunction callback function to display comments * @param aCallBackFunction = callback function to display comments
* @param aPos The position of the dialog. * @param aSortList = true to sort list items by alphabetic order.
*/ */
EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle, EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemList, const wxString& aRefText, const wxArrayString& aItemList, const wxString& aRefText,
void(* aCallBackFunction)(wxString& Text) = NULL, void(* aCallBackFunction)(wxString& Text) = NULL,
wxPoint aPos = wxDefaultPosition ); bool aSortList = false );
~EDA_LIST_DIALOG(); ~EDA_LIST_DIALOG();
void SortList();
void Append( const wxString& aItemStr ); void Append( const wxString& aItemStr );
void InsertItems( const wxArrayString& aItemList, int aPosition = 0 ); void InsertItems( const wxArrayString& aItemList, int aPosition = 0 );
void MoveMouseToOrigin();
wxString GetTextSelection(); wxString GetTextSelection();
private: private:
void OnClose( wxCloseEvent& event ); void onClose( wxCloseEvent& event );
void OnCancelClick( wxCommandEvent& event ); void onCancelClick( wxCommandEvent& event );
void OnOkClick( wxCommandEvent& event ); void onOkClick( wxCommandEvent& event );
void ClickOnList( wxCommandEvent& event ); void onClickOnList( wxCommandEvent& event );
void D_ClickOnList( wxCommandEvent& event ); void onDClickOnList( wxCommandEvent& event );
void OnKeyEvent( wxKeyEvent& event ); void textChangeInFilterBox(wxCommandEvent& event);
DECLARE_EVENT_TABLE() void sortList();
}; };
......
...@@ -590,9 +590,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) ...@@ -590,9 +590,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
if( module == NULL ) if( module == NULL )
return false; return false;
if( !IsOK( this, _( "Delete module?" ) ) )
return false;
RemoveStruct( module, aDC ); RemoveStruct( module, aDC );
} }
else else
...@@ -607,9 +604,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) ...@@ -607,9 +604,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
if( item == NULL ) if( item == NULL )
return false; return false;
if( (item->Type() == PCB_MODULE_T) && !IsOK( this, _( "Delete module?" ) ) )
return false;
RemoveStruct( item, aDC ); RemoveStruct( item, aDC );
} }
else else
......
...@@ -152,7 +152,7 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, ...@@ -152,7 +152,7 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary,
static wxString lastComponentName; static wxString lastComponentName;
// Ask for a component name or key words // Ask for a component name or key words
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList, DIALOG_GET_COMPONENT dlg( this, HistoryList,
_( "Load Module" ), aUseFootprintViewer ); _( "Load Module" ), aUseFootprintViewer );
dlg.SetComponentName( lastComponentName ); dlg.SetComponentName( lastComponentName );
...@@ -440,10 +440,13 @@ wxString PCB_BASE_FRAME::Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow, ...@@ -440,10 +440,13 @@ wxString PCB_BASE_FRAME::Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow,
{ {
msg.Printf( _( "Modules [%d items]" ), (int) footprint_names_list.GetCount() ); msg.Printf( _( "Modules [%d items]" ), (int) footprint_names_list.GetCount() );
EDA_LIST_DIALOG dlg( aWindow, msg, footprint_names_list, OldName, EDA_LIST_DIALOG dlg( aWindow, msg, footprint_names_list, OldName,
DisplayCmpDoc, GetComponentDialogPosition() ); DisplayCmpDoc );
if( dlg.ShowModal() == wxID_OK ) if( dlg.ShowModal() == wxID_OK )
{
CmpName = dlg.GetTextSelection(); CmpName = dlg.GetTextSelection();
SkipNextLeftButtonReleaseEvent();
}
else else
CmpName.Empty(); CmpName.Empty();
} }
...@@ -494,8 +497,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb ) ...@@ -494,8 +497,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb )
msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() ); msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() );
EDA_LIST_DIALOG dlg( this, msg, listnames, wxEmptyString ); EDA_LIST_DIALOG dlg( this, msg, listnames, wxEmptyString, NULL, SORT_LIST );
dlg.SortList();
if( dlg.ShowModal() == wxID_OK ) if( dlg.ShowModal() == wxID_OK )
CmpName = dlg.GetTextSelection(); CmpName = dlg.GetTextSelection();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment