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 *aParentDialog, WX_GRID *aGrid, 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
 
WX_GRIDm_grid
 
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 136 of file grid_text_button_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_PATH_EDITOR()

GRID_CELL_PATH_EDITOR::GRID_CELL_PATH_EDITOR ( DIALOG_SHIM aParentDialog,
WX_GRID aGrid,
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 150 of file grid_text_button_helpers.h.

152  :
153  m_dlg( aParentDialog ),
154  m_grid( aGrid ),
155  m_currentDir( aCurrentDir ),
156  m_ext( aExt ),
157  m_normalize( aNormalize ),
158  m_normalizeBasePath( aNormalizeBasePath )
159  { }

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

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

Definition at line 150 of file grid_text_button_helpers.cpp.

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

References GRID_CELL_TEXT_BUTTON::m_value.

◆ BeginEdit()

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

Definition at line 120 of file grid_text_button_helpers.cpp.

121 {
122  auto evtHandler = static_cast< wxGridCellEditorEvtHandler* >( m_control->GetEventHandler() );
123 
124  // Don't immediately end if we get a kill focus event within BeginEdit
125  evtHandler->SetInSetFocus( true );
126 
127  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
128 
129  Combo()->SetValue( m_value );
130  Combo()->SetFocus();
131 }
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 161 of file grid_text_button_helpers.h.

162  {
164  }
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParentDialog, WX_GRID *aGrid, wxString *aCurrentDir, const wxString &aExt, bool aNormalize=false, wxString aNormalizeBasePath=wxEmptyString)
Constructor.

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

◆ Combo()

◆ Create()

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

Definition at line 421 of file grid_text_button_helpers.cpp.

423 {
424  if( m_ext.IsEmpty() )
425  m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, nullptr,
427  else
428  m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, &m_ext,
430 
431 #if wxUSE_VALIDATORS
432  // validate text in textctrl, if validator is set
433  if ( m_validator )
434  {
435  Combo()->SetValidator( *m_validator );
436  }
437 #endif
438 
439  wxGridCellEditor::Create( aParent, aId, aEventHandler );
440 }
wxComboCtrl * Combo() const

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

◆ EndEdit()

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

Definition at line 134 of file grid_text_button_helpers.cpp.

135 {
136  const wxString value = Combo()->GetValue();
137 
138  if( value == m_value )
139  return false;
140 
141  m_value = value;
142 
143  if( aNewVal )
144  *aNewVal = value;
145 
146  return true;
147 }
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 51 of file grid_text_button_helpers.cpp.

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

References GRID_CELL_TEXT_BUTTON::Combo().

◆ Reset()

void GRID_CELL_TEXT_BUTTON::Reset ( )
overrideinherited

Definition at line 156 of file grid_text_button_helpers.cpp.

157 {
158  Combo()->SetValue( m_value );
159 }
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 57 of file grid_text_button_helpers.cpp.

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

References GRID_CELL_TEXT_BUTTON::Combo().

◆ StartingKey()

void GRID_CELL_TEXT_BUTTON::StartingKey ( wxKeyEvent &  event)
overrideinherited

Definition at line 70 of file grid_text_button_helpers.cpp.

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

Referenced by Clone(), and Create().

◆ m_grid

WX_GRID* GRID_CELL_PATH_EDITOR::m_grid
protected

Definition at line 170 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 173 of file grid_text_button_helpers.h.

Referenced by Create().

◆ m_normalizeBasePath

wxString GRID_CELL_PATH_EDITOR::m_normalizeBasePath
protected

Definition at line 174 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: