KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_text_button_helpers.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef GRID_TEXT_BUTTON_HELPERS_H
22#define GRID_TEXT_BUTTON_HELPERS_H
23
25
26#include <functional>
27#include <memory>
28
29#include <wx/combo.h>
30#include <wx/generic/gridctrl.h>
31#include <wx/generic/grideditors.h>
32#include <search_stack.h>
34#include <kicommon.h>
35
36
37class wxGrid;
38class WX_GRID;
39class DIALOG_SHIM;
40class EMBEDDED_FILES;
41
42
44{
45 // Files searched when opening an embedded URI, in lookup order.
46 // For a lib symbol row, this is going to go up the parent symbol.
47 std::vector<EMBEDDED_FILES*> m_filesStack;
48
49 // All the things that are going to end up having the newly selected
50 // file embeddeded in them. E.g. you have a lib symbol table row
51 // with a collapsed bunch of symbols and you select a datasheet for one of them,
52 // it should be embedded in all of them.
53 std::vector<EMBEDDED_FILES*> m_embedTargets;
54};
55
56
58MakeGridCellUrlEditorContext( const std::vector<EMBEDDED_FILES*>& aEmbedTargets,
59 const std::vector<EMBEDDED_FILES*>& aAdditionalLookupFiles = {} );
60
61
62KICOMMON_API bool SelectFootprintFromChooser( DIALOG_SHIM* aDialog, wxString& aFootprint,
63 const wxString& aSymbolNetlist = wxEmptyString );
64
65
67{
68public:
70 const wxString& aPreselect = wxEmptyString ) :
71 m_dlg( aParent ),
72 m_preselect( aPreselect )
73 { }
74
75 wxGridCellEditor* Clone() const override
76 {
78 }
79
80 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
81
82protected:
84 wxString m_preselect;
85};
86
87
89{
90public:
91 GRID_CELL_FPID_EDITOR( DIALOG_SHIM* aParent, const std::function<wxString( int )>& aSymbolNetlistProvider = {} ) :
92 m_dlg( aParent ),
93 m_symbolNetlistProvider( aSymbolNetlistProvider )
94 { }
95
96 wxGridCellEditor* Clone() const override { return new GRID_CELL_FPID_EDITOR( m_dlg, m_symbolNetlistProvider ); }
97
98 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
99
100protected:
102
103 std::function<wxString( int )> m_symbolNetlistProvider;
104};
105
106
108{
109public:
110 GRID_CELL_URL_EDITOR( DIALOG_SHIM* aParent, SEARCH_STACK* aSearchStack = nullptr,
111 std::vector<EMBEDDED_FILES*> aFilesStack = {} ) :
112 m_dlg( aParent ),
113 m_searchStack( aSearchStack ),
114 m_contextProvider(
115 [aFilesStack]( int )
116 {
117 std::vector<EMBEDDED_FILES*> embedTargets;
118
119 if( !aFilesStack.empty() )
120 embedTargets.push_back( aFilesStack.front() );
121
122 return MakeGridCellUrlEditorContext( embedTargets, aFilesStack );
123 } )
124 { }
125
127 const std::function<GRID_CELL_URL_EDITOR_CONTEXT( int )>& aContextProvider ) :
128 m_dlg( aParent ),
129 m_searchStack( aSearchStack ),
130 m_contextProvider( aContextProvider )
131 { }
132
133 wxGridCellEditor* Clone() const override
134 {
136 }
137
138 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
139
140protected:
142 SEARCH_STACK* m_searchStack; // No ownership.
143
145};
146
147
152{
153public:
164 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
165 bool aNormalize, const wxString& aNormalizeBasePath,
166 std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn,
167 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
168 m_dlg( aParentDialog ),
169 m_grid( aGrid ),
170 m_currentDir( aCurrentDir ),
171 m_normalize( aNormalize ),
172 m_normalizeBasePath( aNormalizeBasePath ),
173 m_fileFilterFn( std::move( aFileFilterFn ) ),
174 m_embedCallback( std::move( aEmbedCallback ) )
175 { }
176
188 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
189 const wxString& aFileFilter, bool aNormalize = false,
190 const wxString& aNormalizeBasePath = wxEmptyString,
191 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
192 m_dlg( aParentDialog ),
193 m_grid( aGrid ),
194 m_currentDir( aCurrentDir ),
195 m_normalize( aNormalize ),
196 m_normalizeBasePath( aNormalizeBasePath ),
197 m_fileFilter( aFileFilter ),
198 m_embedCallback( std::move( aEmbedCallback ) )
199 { }
200
201 wxGridCellEditor* Clone() const override
202 {
203 if( m_fileFilterFn )
204 {
207 }
208 else
209 {
212 }
213 }
214
215 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
216
217protected:
220 wxString* m_currentDir;
223
224 wxString m_fileFilter;
225 std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
226 std::function<wxString( const wxString& )> m_embedCallback;
227};
228
229
237{
238public:
239 GRID_CELL_RUN_FUNCTION_EDITOR( DIALOG_SHIM* aParent, const std::function<void( int, int )> aFunction,
240 const bool aIsNullable = false ) :
241 GRID_CELL_NULLABLE_INTERFACE( aIsNullable ),
242 m_dlg( aParent ),
243 m_row( -1 ),
244 m_col( -1 ),
245 m_function( aFunction )
246 {
247 }
248
249 wxGridCellEditor* Clone() const override
250 {
252 }
253
254 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
255 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
256
257
258protected:
260 int m_row;
261 int m_col;
262 std::function<void( int, int )> m_function;
263};
264
265#endif // GRID_TEXT_BUTTON_HELPERS_H
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:80
std::function< wxString(int)> m_symbolNetlistProvider
GRID_CELL_FPID_EDITOR(DIALOG_SHIM *aParent, const std::function< wxString(int)> &aSymbolNetlistProvider={})
wxGridCellEditor * Clone() const override
virtual bool IsNullable() const
wxGridCellEditor * Clone() const override
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParentDialog, WX_GRID *aGrid, wxString *aCurrentDir, const wxString &aFileFilter, bool aNormalize=false, const wxString &aNormalizeBasePath=wxEmptyString, std::function< wxString(const wxString &)> aEmbedCallback=nullptr)
Constructor.
std::function< wxString(WX_GRID *aGrid, int aRow)> m_fileFilterFn
std::function< wxString(const wxString &)> m_embedCallback
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParentDialog, WX_GRID *aGrid, wxString *aCurrentDir, bool aNormalize, const wxString &aNormalizeBasePath, std::function< wxString(WX_GRID *grid, int row)> aFileFilterFn, std::function< wxString(const wxString &)> aEmbedCallback=nullptr)
Constructor.
wxGridCellEditor * Clone() const override
GRID_CELL_RUN_FUNCTION_EDITOR(DIALOG_SHIM *aParent, const std::function< void(int, int)> aFunction, const bool aIsNullable=false)
std::function< void(int, int)> m_function
wxGridCellEditor * Clone() const override
GRID_CELL_SYMBOL_ID_EDITOR(DIALOG_SHIM *aParent, const wxString &aPreselect=wxEmptyString)
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
std::function< GRID_CELL_URL_EDITOR_CONTEXT(int)> m_contextProvider
GRID_CELL_URL_EDITOR(DIALOG_SHIM *aParent, SEARCH_STACK *aSearchStack, const std::function< GRID_CELL_URL_EDITOR_CONTEXT(int)> &aContextProvider)
wxGridCellEditor * Clone() const override
GRID_CELL_URL_EDITOR(DIALOG_SHIM *aParent, SEARCH_STACK *aSearchStack=nullptr, std::vector< EMBEDDED_FILES * > aFilesStack={})
Look for files in a number of paths.
GRID_CELL_URL_EDITOR_CONTEXT MakeGridCellUrlEditorContext(const std::vector< EMBEDDED_FILES * > &aEmbedTargets, const std::vector< EMBEDDED_FILES * > &aAdditionalLookupFiles)
KICOMMON_API GRID_CELL_URL_EDITOR_CONTEXT MakeGridCellUrlEditorContext(const std::vector< EMBEDDED_FILES * > &aEmbedTargets, const std::vector< EMBEDDED_FILES * > &aAdditionalLookupFiles={})
KICOMMON_API bool SelectFootprintFromChooser(DIALOG_SHIM *aDialog, wxString &aFootprint, const wxString &aSymbolNetlist=wxEmptyString)
#define KICOMMON_API
Definition kicommon.h:27
STL namespace.
std::vector< EMBEDDED_FILES * > m_embedTargets
std::vector< EMBEDDED_FILES * > m_filesStack