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
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
)
......
......@@ -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,
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
*/
......
......@@ -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;
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()
{
......@@ -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();
}
......@@ -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] );
......
......@@ -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() {};
......
......@@ -10,56 +10,58 @@
#include <common.h> // EDA_UNITS_T
#include <dialog_shim.h>
#include <../common/dialogs/dialog_list_selector_base.h>
class EDA_DRAW_FRAME;
#define SORT_LIST true
/**
* class EDA_LIST_DIALOG
*
* Used to display a list of elements for selection, and an help of info line
* about the selected item.
* A dialog which shows:
* 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:
wxListBox* m_listBox;
wxTextCtrl* m_messages;
bool m_sortList;
void (*m_callBackFct)( wxString& Text );
const wxArrayString* m_itemsListCp;
public:
/**
* Constructor:
* @param aParent Pointer to the parent window.
* @param aTitle The title shown on top.
* @param aItemList A wxArrayString of the list of elements.
* @param aRefText An item name if an item must be preselected.
* @param aCallBackFunction callback function to display comments
* @param aPos The position of the dialog.
* @param aTitle = The title shown on top.
* @param aItemList = A wxArrayString of the list of elements.
* @param aRefText = An item name if an item must be preselected.
* @param aCallBackFunction = callback function to display comments
* @param aSortList = true to sort list items by alphabetic order.
*/
EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemList, const wxString& aRefText,
void(* aCallBackFunction)(wxString& Text) = NULL,
wxPoint aPos = wxDefaultPosition );
bool aSortList = false );
~EDA_LIST_DIALOG();
void SortList();
void Append( const wxString& aItemStr );
void InsertItems( const wxArrayString& aItemList, int aPosition = 0 );
void MoveMouseToOrigin();
wxString GetTextSelection();
private:
void OnClose( wxCloseEvent& event );
void OnCancelClick( wxCommandEvent& event );
void OnOkClick( wxCommandEvent& event );
void ClickOnList( wxCommandEvent& event );
void D_ClickOnList( wxCommandEvent& event );
void OnKeyEvent( wxKeyEvent& event );
DECLARE_EVENT_TABLE()
void onClose( wxCloseEvent& event );
void onCancelClick( wxCommandEvent& event );
void onOkClick( wxCommandEvent& event );
void onClickOnList( wxCommandEvent& event );
void onDClickOnList( wxCommandEvent& event );
void textChangeInFilterBox(wxCommandEvent& event);
void sortList();
};
......
......@@ -590,9 +590,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
if( module == NULL )
return false;
if( !IsOK( this, _( "Delete module?" ) ) )
return false;
RemoveStruct( module, aDC );
}
else
......@@ -607,9 +604,6 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
if( item == NULL )
return false;
if( (item->Type() == PCB_MODULE_T) && !IsOK( this, _( "Delete module?" ) ) )
return false;
RemoveStruct( item, aDC );
}
else
......
......@@ -152,7 +152,7 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary,
static wxString lastComponentName;
// Ask for a component name or key words
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList,
DIALOG_GET_COMPONENT dlg( this, HistoryList,
_( "Load Module" ), aUseFootprintViewer );
dlg.SetComponentName( lastComponentName );
......@@ -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() );
EDA_LIST_DIALOG dlg( aWindow, msg, footprint_names_list, OldName,
DisplayCmpDoc, GetComponentDialogPosition() );
DisplayCmpDoc );
if( dlg.ShowModal() == wxID_OK )
{
CmpName = dlg.GetTextSelection();
SkipNextLeftButtonReleaseEvent();
}
else
CmpName.Empty();
}
......@@ -494,8 +497,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Select_1_Module_From_BOARD( BOARD* aPcb )
msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() );
EDA_LIST_DIALOG dlg( this, msg, listnames, wxEmptyString );
dlg.SortList();
EDA_LIST_DIALOG dlg( this, msg, listnames, wxEmptyString, NULL, SORT_LIST );
if( dlg.ShowModal() == wxID_OK )
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