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:
165 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
166 bool aNormalize, const wxString& aNormalizeBasePath,
167 std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn,
168 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
169 m_dlg( aParentDialog ),
170 m_grid( aGrid ),
171 m_currentDir( aCurrentDir ),
172 m_normalize( aNormalize ),
173 m_normalizeBasePath( aNormalizeBasePath ),
174 m_fileFilterFn( std::move( aFileFilterFn ) ),
175 m_embedCallback( std::move( aEmbedCallback ) )
176 { }
177
190 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
191 const wxString& aFileFilter, bool aNormalize = false,
192 const wxString& aNormalizeBasePath = wxEmptyString,
193 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
194 m_dlg( aParentDialog ),
195 m_grid( aGrid ),
196 m_currentDir( aCurrentDir ),
197 m_normalize( aNormalize ),
198 m_normalizeBasePath( aNormalizeBasePath ),
199 m_fileFilter( aFileFilter ),
200 m_embedCallback( std::move( aEmbedCallback ) )
201 { }
202
203 wxGridCellEditor* Clone() const override
204 {
205 if( m_fileFilterFn )
206 {
209 }
210 else
211 {
214 }
215 }
216
217 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
218
219protected:
222 wxString* m_currentDir;
225
226 wxString m_fileFilter;
227 std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
228 std::function<wxString( const wxString& )> m_embedCallback;
229};
230
231
239{
240public:
241 GRID_CELL_RUN_FUNCTION_EDITOR( DIALOG_SHIM* aParent, const std::function<void( int, int )> aFunction,
242 const bool aIsNullable = false ) :
243 GRID_CELL_NULLABLE_INTERFACE( aIsNullable ),
244 m_dlg( aParent ),
245 m_row( -1 ),
246 m_col( -1 ),
247 m_function( aFunction )
248 {
249 }
250
251 wxGridCellEditor* Clone() const override
252 {
254 }
255
256 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
257 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
258
259
260protected:
262 int m_row;
263 int m_col;
264 std::function<void( int, int )> m_function;
265};
266
267#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)
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)
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