KiCad PCB EDA Suite
PANEL_TEXT_VARIABLES Class Reference

#include <panel_text_variables.h>

Inheritance diagram for PANEL_TEXT_VARIABLES:
PANEL_TEXT_VARIABLES_BASE

Public Member Functions

 PANEL_TEXT_VARIABLES (wxWindow *aParent, PROJECT *aProject)
 
 ~PANEL_TEXT_VARIABLES () override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 

Protected Member Functions

void OnGridCellChange (wxGridEvent &event) override
 
void OnGridSize (wxSizeEvent &event) override
 
void OnUpdateUI (wxUpdateUIEvent &event) override
 
void OnGridCellChanging (wxGridEvent &event)
 
void OnAddTextVar (wxCommandEvent &event) override
 
void OnRemoveTextVar (wxCommandEvent &event) override
 
void AppendTextVar (const wxString &aName, const wxString &aValue)
 

Protected Attributes

WX_GRIDm_TextVars
 
wxBitmapButton * m_btnAddTextVar
 
wxBitmapButton * m_btnDeleteTextVar
 

Private Attributes

PROJECTm_project
 
wxString m_errorMsg
 
int m_errorRow
 
int m_errorCol
 
wxTextValidator m_nameValidator
 
bool m_gridWidthsDirty
 

Detailed Description

Definition at line 33 of file panel_text_variables.h.

Constructor & Destructor Documentation

◆ PANEL_TEXT_VARIABLES()

PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES ( wxWindow *  aParent,
PROJECT aProject 
)

Definition at line 42 of file panel_text_variables.cpp.

42  :
43  PANEL_TEXT_VARIABLES_BASE( aParent ),
44  m_project( aProject ),
45  m_errorRow( -1 ), m_errorCol( -1 ),
46  m_gridWidthsDirty( true )
47 {
48  m_btnAddTextVar->SetBitmap( KiBitmap( small_plus_xpm ) );
49  m_btnDeleteTextVar->SetBitmap( KiBitmap( trash_xpm ) );
50 
51  m_TextVars->DeleteRows( 0, m_TextVars->GetNumberRows() );
52 
53  // prohibit these characters in the alias names: []{}()%~<>"='`;:.,&?/\|$
54  m_nameValidator.SetStyle( wxFILTER_EXCLUDE_CHAR_LIST );
55  m_nameValidator.SetCharExcludes( wxT( "{}[]()%~<>\"='`;:.,&?/\\|$" ) );
56 
57  m_TextVars->PushEventHandler( new GRID_TRICKS( m_TextVars ) );
58  m_TextVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
59 
60  // wxFormBuilder doesn't include this event...
61  m_TextVars->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), NULL, this );
62 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
#define NULL
PANEL_TEXT_VARIABLES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxTextValidator m_nameValidator
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20
void OnGridCellChanging(wxGridEvent &event)

References KiBitmap(), PANEL_TEXT_VARIABLES_BASE::m_btnAddTextVar, PANEL_TEXT_VARIABLES_BASE::m_btnDeleteTextVar, m_nameValidator, PANEL_TEXT_VARIABLES_BASE::m_TextVars, NULL, OnGridCellChanging(), small_plus_xpm, and trash_xpm.

◆ ~PANEL_TEXT_VARIABLES()

PANEL_TEXT_VARIABLES::~PANEL_TEXT_VARIABLES ( )
override

Definition at line 65 of file panel_text_variables.cpp.

66 {
67  // Delete the GRID_TRICKS.
68  m_TextVars->PopEventHandler( true );
69 
70  m_TextVars->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), NULL, this );
71 }
#define NULL
void OnGridCellChanging(wxGridEvent &event)

References PANEL_TEXT_VARIABLES_BASE::m_TextVars, NULL, and OnGridCellChanging().

Member Function Documentation

◆ AppendTextVar()

void PANEL_TEXT_VARIABLES::AppendTextVar ( const wxString &  aName,
const wxString &  aValue 
)
protected

Definition at line 85 of file panel_text_variables.cpp.

86 {
87  int i = m_TextVars->GetNumberRows();
88 
89  m_TextVars->AppendRows( 1 );
90 
91  m_TextVars->SetCellValue( i, TV_NAME_COL, aName );
92 
93  wxGridCellAttr* nameCellAttr = m_TextVars->GetOrCreateCellAttr( i, TV_NAME_COL );
94  wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR();
95  nameTextEditor->SetValidator( m_nameValidator );
96  nameCellAttr->SetEditor( nameTextEditor );
97  nameCellAttr->DecRef();
98 
99  m_TextVars->SetCellValue( i, TV_VALUE_COL, aValue );
100 }
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Definition: validators.h:44
wxTextValidator m_nameValidator

References m_nameValidator, PANEL_TEXT_VARIABLES_BASE::m_TextVars, TV_NAME_COL, and TV_VALUE_COL.

Referenced by OnAddTextVar(), and TransferDataToWindow().

◆ OnAddTextVar()

void PANEL_TEXT_VARIABLES::OnAddTextVar ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_TEXT_VARIABLES_BASE.

Definition at line 151 of file panel_text_variables.cpp.

152 {
154  return;
155 
156  AppendTextVar( wxEmptyString, wxEmptyString );
157 
158  m_TextVars->MakeCellVisible( m_TextVars->GetNumberRows() - 1, TV_NAME_COL );
159  m_TextVars->SetGridCursor( m_TextVars->GetNumberRows() - 1, TV_NAME_COL );
160 
161  m_TextVars->EnableCellEditControl( true );
162  m_TextVars->ShowCellEditControl();
163 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
void AppendTextVar(const wxString &aName, const wxString &aValue)

References AppendTextVar(), WX_GRID::CommitPendingChanges(), PANEL_TEXT_VARIABLES_BASE::m_TextVars, and TV_NAME_COL.

◆ OnGridCellChange()

void PANEL_TEXT_VARIABLES::OnGridCellChange ( wxGridEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_TEXT_VARIABLES_BASE.

Definition at line 181 of file panel_text_variables.cpp.

182 {
183  m_gridWidthsDirty = true;
184 
185  aEvent.Skip();
186 }

References m_gridWidthsDirty.

◆ OnGridCellChanging()

void PANEL_TEXT_VARIABLES::OnGridCellChanging ( wxGridEvent &  event)
protected

Definition at line 134 of file panel_text_variables.cpp.

135 {
136  int row = event.GetRow();
137  int col = event.GetCol();
138  wxString text = event.GetString();
139 
140  if( text.IsEmpty() && col == TV_NAME_COL )
141  {
142  m_errorMsg = _( "Variable name cannot be empty." );
143  m_errorRow = row;
144  m_errorCol = col;
145 
146  event.Veto();
147  }
148 }
#define _(s)
Definition: 3d_actions.cpp:33

References _, m_errorCol, m_errorMsg, m_errorRow, and TV_NAME_COL.

Referenced by PANEL_TEXT_VARIABLES(), and ~PANEL_TEXT_VARIABLES().

◆ OnGridSize()

void PANEL_TEXT_VARIABLES::OnGridSize ( wxSizeEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_TEXT_VARIABLES_BASE.

Definition at line 225 of file panel_text_variables.cpp.

226 {
227  m_gridWidthsDirty = true;
228 
229  event.Skip();
230 }

References m_gridWidthsDirty.

◆ OnRemoveTextVar()

void PANEL_TEXT_VARIABLES::OnRemoveTextVar ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_TEXT_VARIABLES_BASE.

Definition at line 166 of file panel_text_variables.cpp.

167 {
168  int curRow = m_TextVars->GetGridCursorRow();
169 
170  if( curRow < 0 || m_TextVars->GetNumberRows() <= curRow )
171  return;
172 
173  m_TextVars->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ );
174  m_TextVars->DeleteRows( curRow, 1 );
175 
176  m_TextVars->MakeCellVisible( std::max( 0, curRow-1 ), m_TextVars->GetGridCursorCol() );
177  m_TextVars->SetGridCursor( std::max( 0, curRow-1 ), m_TextVars->GetGridCursorCol() );
178 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

References WX_GRID::CommitPendingChanges(), and PANEL_TEXT_VARIABLES_BASE::m_TextVars.

◆ OnUpdateUI()

void PANEL_TEXT_VARIABLES::OnUpdateUI ( wxUpdateUIEvent &  event)
overrideprotectedvirtual

Reimplemented from PANEL_TEXT_VARIABLES_BASE.

Definition at line 189 of file panel_text_variables.cpp.

190 {
191  if( m_gridWidthsDirty && ( !m_TextVars->IsCellEditControlShown() ) )
192  {
193  int width = m_TextVars->GetClientRect().GetWidth();
194 
195  m_TextVars->AutoSizeColumn( TV_NAME_COL );
196  m_TextVars->SetColSize( TV_NAME_COL, std::max( m_TextVars->GetColSize( TV_NAME_COL ), 120 ) );
197 
198  m_TextVars->SetColSize( TV_VALUE_COL, width - m_TextVars->GetColSize( TV_NAME_COL ) );
199  m_gridWidthsDirty = false;
200  }
201 
202  // Handle a grid error. This is delayed to OnUpdateUI so that we can change focus
203  // even when the original validation was triggered from a killFocus event (and for
204  // dialog with notebooks, so that the corresponding notebook page can be shown in
205  // the background when triggered from an OK).
206  if( !m_errorMsg.IsEmpty() )
207  {
208  // We will re-enter this routine when the error dialog is displayed, so make
209  // sure we don't keep putting up more dialogs.
210  wxString errorMsg = m_errorMsg;
211  m_errorMsg = wxEmptyString;
212 
213  DisplayErrorMessage( this, errorMsg );
214 
215  m_TextVars->SetFocus();
216  m_TextVars->MakeCellVisible( m_errorRow, m_errorCol );
217  m_TextVars->SetGridCursor( m_errorRow, m_errorCol );
218 
219  m_TextVars->EnableCellEditControl( true );
220  m_TextVars->ShowCellEditControl();
221  }
222 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252

References DisplayErrorMessage(), m_errorCol, m_errorMsg, m_errorRow, m_gridWidthsDirty, PANEL_TEXT_VARIABLES_BASE::m_TextVars, TV_NAME_COL, and TV_VALUE_COL.

◆ TransferDataFromWindow()

bool PANEL_TEXT_VARIABLES::TransferDataFromWindow ( )
override

Definition at line 103 of file panel_text_variables.cpp.

104 {
106  return false;
107 
108  for( int row = 0; row < m_TextVars->GetNumberRows(); ++row )
109  {
110  if( m_TextVars->GetCellValue( row, TV_NAME_COL ).IsEmpty() )
111  {
112  m_errorRow = row;
114  m_errorMsg = _( "Variable name cannot be empty." );
115  return false;
116  }
117  }
118 
119  std::map<wxString, wxString>& variables = m_project->GetTextVars();
120 
121  variables.clear();
122 
123  for( int row = 0; row < m_TextVars->GetNumberRows(); ++row )
124  {
125  wxString name = m_TextVars->GetCellValue( row, TV_NAME_COL );
126  wxString value = m_TextVars->GetCellValue( row, TV_VALUE_COL );
127  variables[ name ] = value;
128  }
129 
130  return true;
131 }
VTBL_ENTRY std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:78
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
const char * name
Definition: DXF_plotter.cpp:60
#define _(s)
Definition: 3d_actions.cpp:33

References _, WX_GRID::CommitPendingChanges(), PROJECT::GetTextVars(), m_errorCol, m_errorMsg, m_errorRow, m_project, PANEL_TEXT_VARIABLES_BASE::m_TextVars, name, TV_NAME_COL, and TV_VALUE_COL.

◆ TransferDataToWindow()

bool PANEL_TEXT_VARIABLES::TransferDataToWindow ( )
override

Definition at line 74 of file panel_text_variables.cpp.

75 {
76  std::map<wxString, wxString>& variables = m_project->GetTextVars();
77 
78  for( const auto& var : variables )
79  AppendTextVar( var.first, var.second );
80 
81  return true;
82 }
VTBL_ENTRY std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:78
void AppendTextVar(const wxString &aName, const wxString &aValue)

References AppendTextVar(), PROJECT::GetTextVars(), and m_project.

Member Data Documentation

◆ m_btnAddTextVar

wxBitmapButton* PANEL_TEXT_VARIABLES_BASE::m_btnAddTextVar
protectedinherited

◆ m_btnDeleteTextVar

wxBitmapButton* PANEL_TEXT_VARIABLES_BASE::m_btnDeleteTextVar
protectedinherited

◆ m_errorCol

int PANEL_TEXT_VARIABLES::m_errorCol
private

Definition at line 58 of file panel_text_variables.h.

Referenced by OnGridCellChanging(), OnUpdateUI(), and TransferDataFromWindow().

◆ m_errorMsg

wxString PANEL_TEXT_VARIABLES::m_errorMsg
private

Definition at line 56 of file panel_text_variables.h.

Referenced by OnGridCellChanging(), OnUpdateUI(), and TransferDataFromWindow().

◆ m_errorRow

int PANEL_TEXT_VARIABLES::m_errorRow
private

Definition at line 57 of file panel_text_variables.h.

Referenced by OnGridCellChanging(), OnUpdateUI(), and TransferDataFromWindow().

◆ m_gridWidthsDirty

bool PANEL_TEXT_VARIABLES::m_gridWidthsDirty
private

Definition at line 62 of file panel_text_variables.h.

Referenced by OnGridCellChange(), OnGridSize(), and OnUpdateUI().

◆ m_nameValidator

wxTextValidator PANEL_TEXT_VARIABLES::m_nameValidator
private

Definition at line 60 of file panel_text_variables.h.

Referenced by AppendTextVar(), and PANEL_TEXT_VARIABLES().

◆ m_project

PROJECT* PANEL_TEXT_VARIABLES::m_project
private

Definition at line 54 of file panel_text_variables.h.

Referenced by TransferDataFromWindow(), and TransferDataToWindow().

◆ m_TextVars


The documentation for this class was generated from the following files: