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, const 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 139 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,
const 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 153 of file grid_text_button_helpers.h.

155 :
156 m_dlg( aParentDialog ),
157 m_grid( aGrid ),
158 m_currentDir( aCurrentDir ),
159 m_ext( aExt ),
160 m_normalize( aNormalize ),
161 m_normalizeBasePath( aNormalizeBasePath )
162 { }

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

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

Definition at line 160 of file grid_text_button_helpers.cpp.

161{
162 aGrid->GetTable()->SetValue( aRow, aCol, m_value );
163}

References GRID_CELL_TEXT_BUTTON::m_value.

◆ BeginEdit()

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

Definition at line 130 of file grid_text_button_helpers.cpp.

131{
132 auto evtHandler = static_cast< wxGridCellEditorEvtHandler* >( m_control->GetEventHandler() );
133
134 // Don't immediately end if we get a kill focus event within BeginEdit
135 evtHandler->SetInSetFocus( true );
136
137 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
138
139 Combo()->SetValue( m_value );
140 Combo()->SetFocus();
141}
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 164 of file grid_text_button_helpers.h.

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

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

◆ Combo()

wxComboCtrl * GRID_CELL_TEXT_BUTTON::Combo ( ) const
inlineprotectedinherited

◆ Create()

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

Definition at line 476 of file grid_text_button_helpers.cpp.

478{
479 if( m_ext.IsEmpty() )
480 m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, nullptr,
482 else
483 m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, &m_ext,
485
486#if wxUSE_VALIDATORS
487 // validate text in textctrl, if validator is set
488 if ( m_validator )
489 {
490 Combo()->SetValidator( *m_validator );
491 }
492#endif
493
494 wxGridCellEditor::Create( aParent, aId, aEventHandler );
495}

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 144 of file grid_text_button_helpers.cpp.

145{
146 const wxString value = Combo()->GetValue();
147
148 if( value == m_value )
149 return false;
150
151 m_value = value;
152
153 if( aNewVal )
154 *aNewVal = value;
155
156 return true;
157}

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 54 of file grid_text_button_helpers.cpp.

55{
56 return Combo()->GetValue();
57}

References GRID_CELL_TEXT_BUTTON::Combo().

◆ Reset()

void GRID_CELL_TEXT_BUTTON::Reset ( )
overrideinherited

Definition at line 166 of file grid_text_button_helpers.cpp.

167{
168 Combo()->SetValue( m_value );
169}

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 60 of file grid_text_button_helpers.cpp.

61{
62 wxRect rect( aRect );
63
64#if defined( __WXMAC__ )
65 rect.Inflate( 2 ); // ignore FOCUS_RING
66#elif defined( __WXGTK__ )
67 rect.Inflate( -3 ); // The -3 is a very sad hack here. Some GTK themes overrun the
68 // default -1, preventing display. Unfortunately, we don't appear to
69 // have a good method of finding the current margin needed.
70 // Some GTK resize events seem to update the cell size but not all and
71 // not consistently.
72#else
73 rect.Inflate( -1 );
74#endif
75
76 Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
77}

References GRID_CELL_TEXT_BUTTON::Combo().

◆ StartingKey()

void GRID_CELL_TEXT_BUTTON::StartingKey ( wxKeyEvent &  event)
overrideinherited

Definition at line 80 of file grid_text_button_helpers.cpp.

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

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 174 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 172 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 175 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 173 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 176 of file grid_text_button_helpers.h.

Referenced by Create().

◆ m_normalizeBasePath

wxString GRID_CELL_PATH_EDITOR::m_normalizeBasePath
protected

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