2018-07-20 15:03:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-02-17 14:06:19 +00:00
|
|
|
* Copyright (C) 2021 CERN
|
2022-07-24 22:40:47 +00:00
|
|
|
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-20 15:03:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRID_TEXT_BUTTON_HELPERS_H
|
|
|
|
#define GRID_TEXT_BUTTON_HELPERS_H
|
|
|
|
|
2023-04-12 16:14:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-07-20 19:02:45 +00:00
|
|
|
#include <wx/combo.h>
|
2018-07-20 15:03:43 +00:00
|
|
|
#include <wx/generic/gridctrl.h>
|
|
|
|
#include <wx/generic/grideditors.h>
|
|
|
|
|
|
|
|
|
|
|
|
class wxGrid;
|
2021-02-17 14:06:19 +00:00
|
|
|
class WX_GRID;
|
2018-07-20 15:03:43 +00:00
|
|
|
class DIALOG_SHIM;
|
|
|
|
|
|
|
|
|
|
|
|
class GRID_CELL_TEXT_BUTTON : public wxGridCellEditor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_CELL_TEXT_BUTTON() {};
|
|
|
|
|
|
|
|
wxString GetValue() const override;
|
|
|
|
|
|
|
|
void SetSize( const wxRect& aRect ) override;
|
|
|
|
|
2018-07-21 20:23:13 +00:00
|
|
|
void StartingKey( wxKeyEvent& event ) override;
|
2018-07-20 15:03:43 +00:00
|
|
|
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;
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
void SetValidator( const wxValidator& validator );
|
|
|
|
#endif
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
protected:
|
|
|
|
wxComboCtrl* Combo() const { return static_cast<wxComboCtrl*>( m_control ); }
|
|
|
|
|
2019-05-10 12:21:08 +00:00
|
|
|
#if wxUSE_VALIDATORS
|
2023-04-12 16:14:45 +00:00
|
|
|
std::unique_ptr< wxValidator > m_validator;
|
2019-05-10 12:21:08 +00:00
|
|
|
#endif
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
wxString m_value;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS( GRID_CELL_TEXT_BUTTON );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-29 16:18:55 +00:00
|
|
|
class GRID_CELL_SYMBOL_ID_EDITOR : public GRID_CELL_TEXT_BUTTON
|
2018-07-20 15:03:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-31 01:07:53 +00:00
|
|
|
GRID_CELL_SYMBOL_ID_EDITOR( DIALOG_SHIM* aParent,
|
|
|
|
const wxString& aPreselect = wxEmptyString ) :
|
|
|
|
m_dlg( aParent ),
|
|
|
|
m_preselect( aPreselect )
|
2018-07-20 15:03:43 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
wxGridCellEditor* Clone() const override
|
|
|
|
{
|
2019-01-31 01:07:53 +00:00
|
|
|
return new GRID_CELL_SYMBOL_ID_EDITOR( m_dlg, m_preselect );
|
2018-09-29 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2019-01-31 01:07:53 +00:00
|
|
|
wxString m_preselect;
|
2018-09-29 16:18:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-24 22:40:47 +00:00
|
|
|
class GRID_CELL_FPID_EDITOR : public GRID_CELL_TEXT_BUTTON
|
2018-09-29 16:18:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-07-24 22:40:47 +00:00
|
|
|
GRID_CELL_FPID_EDITOR( DIALOG_SHIM* aParent, const wxString& aSymbolNetlist,
|
|
|
|
const wxString& aPreselect = wxEmptyString ) :
|
2019-01-31 01:07:53 +00:00
|
|
|
m_dlg( aParent ),
|
2022-07-24 22:40:47 +00:00
|
|
|
m_preselect( aPreselect ),
|
|
|
|
m_symbolNetlist( aSymbolNetlist )
|
2018-09-29 16:18:55 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
wxGridCellEditor* Clone() const override
|
|
|
|
{
|
2022-07-24 22:40:47 +00:00
|
|
|
return new GRID_CELL_FPID_EDITOR( m_dlg, m_symbolNetlist );
|
2018-07-20 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2019-01-31 01:07:53 +00:00
|
|
|
wxString m_preselect;
|
2022-07-24 22:40:47 +00:00
|
|
|
wxString m_symbolNetlist;
|
2018-07-20 15:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GRID_CELL_URL_EDITOR : public GRID_CELL_TEXT_BUTTON
|
|
|
|
{
|
|
|
|
public:
|
2022-05-11 01:28:48 +00:00
|
|
|
GRID_CELL_URL_EDITOR( DIALOG_SHIM* aParent, SEARCH_STACK* aSearchStack = nullptr ) :
|
|
|
|
m_dlg( aParent ), m_searchStack( aSearchStack )
|
2018-07-20 15:03:43 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
wxGridCellEditor* Clone() const override
|
|
|
|
{
|
|
|
|
return new GRID_CELL_URL_EDITOR( m_dlg );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2022-05-11 01:28:48 +00:00
|
|
|
SEARCH_STACK* m_searchStack;
|
2018-07-20 15:03:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-01 02:00:38 +00:00
|
|
|
/**
|
|
|
|
* Editor for wxGrid cells that adds a file/folder browser to the grid input field
|
|
|
|
*/
|
2018-08-24 18:28:11 +00:00
|
|
|
class GRID_CELL_PATH_EDITOR : public GRID_CELL_TEXT_BUTTON
|
|
|
|
{
|
|
|
|
public:
|
2020-09-01 02:00:38 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param aCurrentDir is current directory the path editor will open at
|
2021-02-17 14:06:19 +00:00
|
|
|
* @param aExt is the file extension(s) to filter by. If empty, the path editor will switch
|
|
|
|
* to folder mode instead of file.
|
|
|
|
* @param aNormalize indicates whether to normalize the selected path (replace part of path
|
|
|
|
* with variables or relative path)
|
|
|
|
* @param aNormalizeBasePath is the path to use when trying to base variables (generally
|
|
|
|
* current project path)
|
2020-09-01 02:00:38 +00:00
|
|
|
*/
|
2021-02-17 14:06:19 +00:00
|
|
|
GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
|
|
|
|
const wxString& aExt, bool aNormalize = false,
|
2021-07-27 12:22:27 +00:00
|
|
|
const wxString& aNormalizeBasePath = wxEmptyString ) :
|
2021-02-17 14:06:19 +00:00
|
|
|
m_dlg( aParentDialog ),
|
|
|
|
m_grid( aGrid ),
|
2020-03-06 20:02:58 +00:00
|
|
|
m_currentDir( aCurrentDir ),
|
2020-09-01 02:00:38 +00:00
|
|
|
m_ext( aExt ),
|
|
|
|
m_normalize( aNormalize ),
|
|
|
|
m_normalizeBasePath( aNormalizeBasePath )
|
2018-08-24 18:28:11 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
wxGridCellEditor* Clone() const override
|
|
|
|
{
|
2021-02-17 14:06:19 +00:00
|
|
|
return new GRID_CELL_PATH_EDITOR( m_dlg, m_grid, m_currentDir, m_ext );
|
2018-08-24 18:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DIALOG_SHIM* m_dlg;
|
2021-02-17 14:06:19 +00:00
|
|
|
WX_GRID* m_grid;
|
2018-08-24 18:28:11 +00:00
|
|
|
wxString* m_currentDir;
|
2020-03-06 20:02:58 +00:00
|
|
|
wxString m_ext;
|
2020-09-01 02:00:38 +00:00
|
|
|
bool m_normalize;
|
|
|
|
wxString m_normalizeBasePath;
|
2019-03-03 04:04:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-07-20 15:03:43 +00:00
|
|
|
#endif // GRID_TEXT_BUTTON_HELPERS_H
|