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 #ifdef __WXMAC__
32  m_auxToolSelector = false;
33 #else
34  m_auxToolSelector = show_extra_tool;
35 #endif
36  initDialog( HistoryList );
37 
38  m_textCmpNameCtrl->SetFocus();
39  GetSizer()->Fit( this );
40  GetSizer()->SetSizeHints( this );
41 }
42 
43 void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList )
44 {
45  SetFocus();
46  m_GetExtraFunction = false;
47  m_selectionIsKeyword = false;
48  m_historyList->Append( aHistoryList );
49  if( !m_auxToolSelector )
50  {
51  m_buttonBrowse->Show( false );
52  m_buttonBrowse->Enable( false );
53  }
54 }
55 
56 
57 void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event )
58 {
59  m_Text = wxEmptyString;
60  EndModal( wxID_CANCEL );
61 }
62 
63 void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
64 {
65  m_selectionIsKeyword = false;
66  switch( event.GetId() )
67  {
68  case ID_SEL_BY_LISTBOX:
69  m_Text = m_historyList->GetStringSelection();
70  break;
71 
72  case wxID_OK:
73  m_Text = m_textCmpNameCtrl->GetValue();
74  break;
75 
76  case ID_ACCEPT_KEYWORD:
77  m_selectionIsKeyword = true;
78  m_Text = m_textCmpNameCtrl->GetValue();
79  break;
80 
81  case ID_LIST_ALL:
82  m_Text = wxT( "*" );
83  break;
84  }
85 
86  m_Text.Trim( false ); // Remove blanks at beginning
87  m_Text.Trim( true ); // Remove blanks at end
88 
89  EndModal( wxID_OK );
90 }
91 
92 
93 /* Get the component name by the extra function */
94 void DIALOG_GET_COMPONENT::GetExtraSelection( wxCommandEvent& event )
95 {
96  m_GetExtraFunction = true;
97  EndModal( wxID_OK );
98 }
99 
100 
101 // Return the component name selected by the dialog
103 {
104  return m_Text;
105 }
106 
107 
108 /* Initialize the default component name default choice
109 */
110 void DIALOG_GET_COMPONENT::SetComponentName( const wxString& name )
111 {
112  if( m_textCmpNameCtrl )
113  {
114  m_textCmpNameCtrl->SetValue( name );
115  m_textCmpNameCtrl->SetSelection(-1, -1);
116  }
117 }
118 
119 
120 /*
121  * Add the string "aName" to the history list aHistoryList
122  */
123 void AddHistoryComponentName( wxArrayString& aHistoryList, const wxString& aName )
124 {
125  if( ( aHistoryList.GetCount() > 0 ) && ( aName == aHistoryList[0] ) )
126  return;
127 
128  /* remove an old identical name if exists */
129  for( unsigned ii = 1; ii < aHistoryList.GetCount(); ii++ )
130  {
131  if( aName == aHistoryList[ii] )
132  {
133  aHistoryList.RemoveAt( ii );
134  ii--;
135  }
136  }
137 
138  // Add the new name at the beginning of the history list
139  aHistoryList.Insert(aName, 0);
140 
141  // Remove extra names
142  while( aHistoryList.GetCount() >= s_HistoryMaxCount )
143  aHistoryList.RemoveAt( aHistoryList.GetCount()-1 );
144 }
#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:53
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
static unsigned s_HistoryMaxCount
#define ID_SEL_BY_LISTBOX
wxString GetComponentName(void)
Function GetComponentName.
The common library.