KiCad PCB EDA Suite
GRID_CELL_PATH_EDITOR Class Reference

Editor for wxGrid cells that adds a file/folder browser to the grid input field. More...

#include <grid_text_button_helpers.h>

Inheritance diagram for GRID_CELL_PATH_EDITOR:
GRID_CELL_TEXT_BUTTON

Public Member Functions

 GRID_CELL_PATH_EDITOR (DIALOG_SHIM *aParent, wxString *aCurrentDir, const wxString &aExt, bool aNormalize=false, wxString aNormalizeBasePath=wxEmptyString)
 Constructor. More...
 
wxGridCellEditor * Clone () const override
 
void Create (wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
 
wxString GetValue () const override
 
void SetSize (const wxRect &aRect) override
 
void StartingKey (wxKeyEvent &event) override
 
void BeginEdit (int aRow, int aCol, wxGrid *aGrid) override
 
bool EndEdit (int, int, const wxGrid *, const wxString &, wxString *aNewVal) override
 
void ApplyEdit (int aRow, int aCol, wxGrid *aGrid) override
 
void Reset () override
 

Protected Member Functions

wxComboCtrl * Combo () const
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_TEXT_BUTTON)
 

Protected Attributes

DIALOG_SHIMm_dlg
 
wxString * m_currentDir
 
wxString m_ext
 
bool m_normalize
 
wxString m_normalizeBasePath
 
wxString m_value
 

Detailed Description

Editor for wxGrid cells that adds a file/folder browser to the grid input field.

Definition at line 134 of file grid_text_button_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_PATH_EDITOR()

GRID_CELL_PATH_EDITOR::GRID_CELL_PATH_EDITOR ( DIALOG_SHIM aParent,
wxString *  aCurrentDir,
const wxString &  aExt,
bool  aNormalize = false,
wxString  aNormalizeBasePath = wxEmptyString 
)
inline

Constructor.

Parameters
aCurrentDiris current directory the path editor will open at
aExtis the file extension(s) to filter by. If empty, the path editor will switch to folder mode instead of file.
aNormalizeindicates whether to normalize the selected path (replace part of path with variables or relative path)
aNormalizeBasePathis the path to use when trying to base variables (generally current project path)

Definition at line 145 of file grid_text_button_helpers.h.

146  :
147  m_dlg( aParent ),
148  m_currentDir( aCurrentDir ),
149  m_ext( aExt ),
150  m_normalize( aNormalize ),
151  m_normalizeBasePath( aNormalizeBasePath )
152  { }

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

void GRID_CELL_TEXT_BUTTON::ApplyEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
overrideinherited

Definition at line 149 of file grid_text_button_helpers.cpp.

150 {
151  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
152 }

References GRID_CELL_TEXT_BUTTON::m_value.

◆ BeginEdit()

void GRID_CELL_TEXT_BUTTON::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
overrideinherited

Definition at line 119 of file grid_text_button_helpers.cpp.

120 {
121  auto evtHandler = static_cast< wxGridCellEditorEvtHandler* >( m_control->GetEventHandler() );
122 
123  // Don't immediately end if we get a kill focus event within BeginEdit
124  evtHandler->SetInSetFocus( true );
125 
126  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
127 
128  Combo()->SetValue( m_value );
129  Combo()->SetFocus();
130 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo(), and GRID_CELL_TEXT_BUTTON::m_value.

◆ Clone()

wxGridCellEditor* GRID_CELL_PATH_EDITOR::Clone ( ) const
inlineoverride

Definition at line 154 of file grid_text_button_helpers.h.

155  {
157  }
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParent, wxString *aCurrentDir, const wxString &aExt, bool aNormalize=false, wxString aNormalizeBasePath=wxEmptyString)
Constructor.

References GRID_CELL_PATH_EDITOR(), m_currentDir, m_dlg, and m_ext.

◆ Combo()

◆ Create()

void GRID_CELL_PATH_EDITOR::Create ( wxWindow *  aParent,
wxWindowID  aId,
wxEvtHandler *  aEventHandler 
)
override

Definition at line 409 of file grid_text_button_helpers.cpp.

411 {
412  if( m_ext.IsEmpty() )
413  m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, nullptr,
415  else
416  m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_currentDir, &m_ext,
418 
419 #if wxUSE_VALIDATORS
420  // validate text in textctrl, if validator is set
421  if ( m_validator )
422  {
423  Combo()->SetValidator( *m_validator );
424  }
425 #endif
426 
427  wxGridCellEditor::Create( aParent, aId, aEventHandler );
428 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo(), m_currentDir, m_dlg, m_ext, m_normalize, and m_normalizeBasePath.

◆ EndEdit()

bool GRID_CELL_TEXT_BUTTON::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
overrideinherited

Definition at line 133 of file grid_text_button_helpers.cpp.

134 {
135  const wxString value = Combo()->GetValue();
136 
137  if( value == m_value )
138  return false;
139 
140  m_value = value;
141 
142  if( aNewVal )
143  *aNewVal = value;
144 
145  return true;
146 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo(), and GRID_CELL_TEXT_BUTTON::m_value.

◆ GetValue()

wxString GRID_CELL_TEXT_BUTTON::GetValue ( ) const
overrideinherited

Definition at line 50 of file grid_text_button_helpers.cpp.

51 {
52  return Combo()->GetValue();
53 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo().

◆ Reset()

void GRID_CELL_TEXT_BUTTON::Reset ( )
overrideinherited

Definition at line 155 of file grid_text_button_helpers.cpp.

156 {
157  Combo()->SetValue( m_value );
158 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo(), and GRID_CELL_TEXT_BUTTON::m_value.

◆ SetSize()

void GRID_CELL_TEXT_BUTTON::SetSize ( const wxRect &  aRect)
overrideinherited

Definition at line 56 of file grid_text_button_helpers.cpp.

57 {
58  wxRect rect( aRect );
59  rect.Inflate( -1 );
60 
61 #if defined( __WXMAC__ )
62  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
63 #endif
64 
65  Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
66 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo().

◆ StartingKey()

void GRID_CELL_TEXT_BUTTON::StartingKey ( wxKeyEvent &  event)
overrideinherited

Definition at line 69 of file grid_text_button_helpers.cpp.

70 {
71  // Note: this is a copy of wxGridCellTextEditor's StartingKey()
72 
73  // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
74  // longer an appropriate way to get the character into the text control.
75  // Do it ourselves instead. We know that if we get this far that we have
76  // a valid character, so not a whole lot of testing needs to be done.
77 
78  // wxComboCtrl inherits from wxTextEntry, so can staticly cast
79  wxTextEntry* textEntry = static_cast<wxTextEntry*>( Combo() );
80  int ch;
81 
82  bool isPrintable;
83 
84 #if wxUSE_UNICODE
85  ch = event.GetUnicodeKey();
86 
87  if( ch != WXK_NONE )
88  isPrintable = true;
89  else
90 #endif // wxUSE_UNICODE
91  {
92  ch = event.GetKeyCode();
93  isPrintable = ch >= WXK_SPACE && ch < WXK_START;
94  }
95 
96  switch( ch )
97  {
98  case WXK_DELETE:
99  // Delete the initial character when starting to edit with DELETE.
100  textEntry->Remove( 0, 1 );
101  break;
102 
103  case WXK_BACK:
104  // Delete the last character when starting to edit with BACKSPACE.
105  {
106  const long pos = textEntry->GetLastPosition();
107  textEntry->Remove( pos - 1, pos );
108  }
109  break;
110 
111  default:
112  if( isPrintable )
113  textEntry->WriteText( static_cast<wxChar>( ch ) );
114  break;
115  }
116 }
wxComboCtrl * Combo() const

References GRID_CELL_TEXT_BUTTON::Combo().

◆ wxDECLARE_NO_COPY_CLASS()

GRID_CELL_TEXT_BUTTON::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_TEXT_BUTTON  )
protectedinherited

Member Data Documentation

◆ m_currentDir

wxString* GRID_CELL_PATH_EDITOR::m_currentDir
protected

Definition at line 163 of file grid_text_button_helpers.h.

Referenced by Clone(), and Create().

◆ m_dlg

DIALOG_SHIM* GRID_CELL_PATH_EDITOR::m_dlg
protected

Definition at line 162 of file grid_text_button_helpers.h.

Referenced by Clone(), and Create().

◆ m_ext

wxString GRID_CELL_PATH_EDITOR::m_ext
protected

Definition at line 164 of file grid_text_button_helpers.h.

Referenced by Clone(), and Create().

◆ m_normalize

bool GRID_CELL_PATH_EDITOR::m_normalize
protected

Definition at line 165 of file grid_text_button_helpers.h.

Referenced by Create().

◆ m_normalizeBasePath

wxString GRID_CELL_PATH_EDITOR::m_normalizeBasePath
protected

Definition at line 166 of file grid_text_button_helpers.h.

Referenced by Create().

◆ m_value

wxString GRID_CELL_TEXT_BUTTON::m_value
protectedinherited

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