KiCad PCB EDA Suite
dialog_get_component.cpp
Go to the documentation of this file.
1 /*********************************/
2 /* dialog_get_component.cpp */
3 /*********************************/
4 
5 #include <fctsys.h>
6 #include <common.h>
7 #include <macros.h>
8 #include <draw_frame.h>
9 #include <dialog_get_component.h>
10 
11 
12 /****************************************************************************/
13 /* Show a dialog frame to choose a name from an history list, or a new name */
14 /* to select a component or a module */
15 /****************************************************************************/
16 
17 static unsigned s_HistoryMaxCount = 8; // Max number of items displayed in history list
18 
19 
20 /*
21  * Dialog frame to choose a component or a footprint
22  * This dialog shows an history of last selected items
23  */
25  wxArrayString& HistoryList,
26  const wxString& Title,
27  bool show_extra_tool ) :
28  DIALOG_GET_COMPONENT_BASE( parent, -1, Title )
29 {
30 
31  m_auxToolSelector = show_extra_tool;
32  initDialog( HistoryList );
33 
34  m_textCmpNameCtrl->SetFocus();
35  GetSizer()->Fit( this );
36  GetSizer()->SetSizeHints( this );
37 }
38 
39 void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList )
40 {
41  SetFocus();
42  m_GetExtraFunction = false;
43  m_selectionIsKeyword = false;
44  m_historyList->Append( aHistoryList );
45  if( !m_auxToolSelector )
46  {
47  m_buttonBrowse->Show( false );
48  m_buttonBrowse->Enable( false );
49  }
50 }
51 
52 
53 void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event )
54 {
55  m_Text = wxEmptyString;
56  EndModal( wxID_CANCEL );
57 }
58 
59 void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
60 {
61  m_selectionIsKeyword = false;
62  switch( event.GetId() )
63  {
64  case ID_SEL_BY_LISTBOX:
65  m_Text = m_historyList->GetStringSelection();
66  break;
67 
68  case wxID_OK:
69  m_Text = m_textCmpNameCtrl->GetValue();
70  break;
71 
72  case ID_ACCEPT_KEYWORD:
73  m_selectionIsKeyword = true;
74  m_Text = m_textCmpNameCtrl->GetValue();
75  break;
76 
77  case ID_LIST_ALL:
78  m_Text = wxT( "*" );
79  break;
80  }
81 
82  m_Text.Trim( false ); // Remove blanks at beginning
83  m_Text.Trim( true ); // Remove blanks at end
84 
85  EndModal( wxID_OK );
86 }
87 
88 
89 /* Get the component name by the extra function */
90 void DIALOG_GET_COMPONENT::GetExtraSelection( wxCommandEvent& event )
91 {
92  m_GetExtraFunction = true;
93  EndModal( wxID_OK );
94 }
95 
96 
97 // Return the component name selected by the dialog
99 {
100  return m_Text;
101 }
102 
103 
104 /* Initialize the default component name default choice
105 */
107 {
108  if( m_textCmpNameCtrl )
109  {
110  m_textCmpNameCtrl->SetValue( name );
111  m_textCmpNameCtrl->SetSelection(-1, -1);
112  }
113 }
114 
115 
116 /*
117  * Add the string "aName" to the history list aHistoryList
118  */
119 void AddHistoryComponentName( wxArrayString& aHistoryList, const wxString& aName )
120 {
121  if( ( aHistoryList.GetCount() > 0 ) && ( aName == aHistoryList[0] ) )
122  return;
123 
124  /* remove an old identical name if exists */
125  for( unsigned ii = 1; ii < aHistoryList.GetCount(); ii++ )
126  {
127  if( aName == aHistoryList[ii] )
128  {
129  aHistoryList.RemoveAt( ii );
130  ii--;
131  }
132  }
133 
134  // Add the new name at the beginning of the history list
135  aHistoryList.Insert(aName, 0);
136 
137  // Remove extra names
138  while( aHistoryList.GetCount() >= s_HistoryMaxCount )
139  aHistoryList.RemoveAt( aHistoryList.GetCount()-1 );
140 }
#define ID_LIST_ALL
void GetExtraSelection(wxCommandEvent &event) override
void AddHistoryComponentName(wxArrayString &aHistoryList, const wxString &aName)
#define ID_ACCEPT_KEYWORD
void Accept(wxCommandEvent &event) override
Class DIALOG_GET_COMPONENT_BASE.
This file is part of the common libary.
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:55
This file contains miscellaneous commonly used macros and functions.
void initDialog(wxArrayString &aHistoryList)
void SetComponentName(const wxString &name)
DIALOG_GET_COMPONENT(EDA_DRAW_FRAME *parent, wxArrayString &HistoryList, const wxString &Title, bool show_extra_tool)
void OnCancel(wxCommandEvent &event) override
const char * name
Definition: DXF_plotter.cpp:61
static unsigned s_HistoryMaxCount
#define ID_SEL_BY_LISTBOX
wxString GetComponentName(void)
Function GetComponentName.
The common library.