24#include <wx/clipbrd.h>
33 m_grid->Disconnect( wxEVT_CHAR_HOOK );
39 std::function<
void( wxCommandEvent& )> aAddHandler ) :
42 m_grid->Disconnect( wxEVT_CHAR_HOOK );
60 wxString title = row.
Type() ==
"Table"
61 ? wxString::Format(
_(
"Error loading library table '%s'" ), row.
Nickname() )
62 : wxString::Format(
_(
"Error loading library '%s'" ), row.
Nickname() );
99 bool showSettings =
false;
100 bool showOpen =
false;
108 if(
m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( nickname ) )
122 if( showSettings || showOpen )
123 menu.AppendSeparator();
125 bool showActivate =
false;
126 bool showDeactivate =
false;
127 bool showSetVisible =
false;
128 bool showUnsetVisible =
false;
129 bool showOptions =
false;
134 showDeactivate =
true;
139 showUnsetVisible =
true;
141 showSetVisible =
true;
143 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
158 if( showUnsetVisible )
166 _(
"Edit options for this library entry" ) );
169 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showOptions )
170 menu.AppendSeparator();
180 int menu_id =
event.GetId();
229 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' &&
m_grid->IsCellEditControlShown() )
233 if( wxTheClipboard->Open() )
235 if( wxTheClipboard->IsSupported( wxDF_TEXT ) || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
237 wxTextDataObject data;
238 wxTheClipboard->GetData( data );
240 wxString
text = data.GetText();
242 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
243 text.Replace(
',',
'\t' );
245 if(
text.Contains(
'\t' ) ||
text.Contains(
'\n' ) ||
text.Contains(
'\r' ) )
247 m_grid->CancelPendingChanges();
248 int row =
m_grid->GetGridCursorRow();
252 if(
table && row >= 0 && row < table->GetNumberRows() )
256 if( !nickname.IsEmpty() )
259 wxTheClipboard->Close();
267 m_grid->SetGridCursor( row, 0 );
270 wxTheClipboard->Close();
276 wxTheClipboard->Close();
298 if(
size_t ndx = cb_text.find(
getTablePreamble() ); ndx != std::string::npos )
304 std::ranges::copy( tempTable.Rows(),
309 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, 0, 0 );
310 tbl->GetView()->ProcessTableMessage( msg );
320 wxString
text = cb_text;
322 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
323 text.Replace(
',',
'\t' );
325 if(
text.Contains(
'\t' ) )
327 int row =
m_grid->GetGridCursorRow();
330 m_grid->SetGridCursor( row, 0 );
336 m_grid->AutoSizeColumns(
false );
339 m_grid->AutoSizeColumns(
false );
371 [&]() -> std::pair<int, int>
373 aGrid->AppendRows( 1 );
390 wxGridUpdateLocker noUpdates( aGrid );
392 int curRow = aGrid->GetGridCursorRow();
393 int curCol = aGrid->GetGridCursorCol();
400 wxArrayInt selectedRows = aGrid->GetSelectedRows();
401 wxGridCellCoordsArray cells = aGrid->GetSelectedCells();
402 wxGridCellCoordsArray blockTopLeft = aGrid->GetSelectionBlockTopLeft();
403 wxGridCellCoordsArray blockBotRight = aGrid->GetSelectionBlockBottomRight();
406 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
407 selectedRows.Add( cells[ii].GetRow() );
410 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
412 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
413 selectedRows.Add( i );
417 if( selectedRows.size() == 0 && aGrid->GetGridCursorRow() >= 0 )
418 selectedRows.Add( aGrid->GetGridCursorRow() );
420 if( selectedRows.size() == 0 )
426 std::sort( selectedRows.begin(), selectedRows.end() );
433 aGrid->ClearSelection();
435 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
437 int row = selectedRows[ii];
439 if( row != last_row )
442 aGrid->DeleteRows( row, 1 );
446 if( aGrid->GetNumberRows() > 0 && curRow >= 0 )
447 aGrid->SetGridCursor( std::min( curRow, aGrid->GetNumberRows() - 1 ), curCol );
463 int curRow = aGrid->GetGridCursorRow();
465 std::deque<LIBRARY_TABLE_ROW>& rows = tbl->
Table().
Rows();
467 auto current = rows.begin() + curRow;
468 auto prev = rows.begin() + curRow - 1;
470 std::iter_swap( current, prev );
473 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 );
474 tbl->GetView()->ProcessTableMessage( msg );
491 int curRow = aGrid->GetGridCursorRow();
492 std::deque<LIBRARY_TABLE_ROW>& rows = tbl->
Table().
Rows();
494 auto current = rows.begin() + curRow;
495 auto next = rows.begin() + curRow + 1;
497 std::iter_swap( current,
next );
500 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 );
501 tbl->GetView()->ProcessTableMessage( msg );
507 std::function<
void(
int aRow,
int aCol )> aErrorHandler )
509 wxWindow* topLevelParent = wxGetTopLevelParent( aGrid );
513 for(
int r = 0; r <
model->GetNumberRows(); )
516 wxString uri =
model->GetValue( r,
COL_URI ).Trim(
false ).Trim();
517 unsigned illegalCh = 0;
522 model->DeleteRows( r, 1 );
527 msg =
_(
"Library must have a nickname." );
529 msg = wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ), illegalCh, nick );
543 if( !aSupportsVisibilityColumn )
554 for(
int r1 = 0; r1 <
model->GetNumberRows() - 1; ++r1 )
558 for(
int r2 = r1 + 1; r2 <
model->GetNumberRows(); ++r2 )
564 msg = wxString::Format(
_(
"Multiple libraries cannot share the same nickname ('%s')." ), nick1 );
567 aErrorHandler( r2, 1 );
virtual void paste_text(const wxString &cb_text)
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
GRID_TRICKS(WX_GRID *aGrid)
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
virtual void onGridCellLeftClick(wxGridEvent &event)
void onCharHook(wxKeyEvent &event)
The interface used by the classes that actually can load IO plugins for the different parts of KiCad ...
virtual std::optional< LIBRARY_ERROR > LibraryError(const wxString &aNickname) const
virtual void ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const
virtual bool SupportsConfigurationDialog(const wxString &aNickname) const
const wxString & ErrorDescription() const
const wxString & Type() const
static const wxString TABLE_TYPE_NAME
const wxString & Nickname() const
bool IsReadOnly() const
Returns true if the underlying file exists but is not writable.
LIBRARY_TABLE_SCOPE Scope() const
const std::deque< LIBRARY_TABLE_ROW > & Rows() const
static unsigned FindIllegalLibraryNameChar(const UTF8 &aLibraryName)
Looks for characters that are illegal in library nicknames.
This abstract base class mixes any object derived from #LIB_TABLE into wxGridTableBase so the result ...
virtual LIBRARY_TABLE_ROW & at(size_t aIndex)
LIBRARY_MANAGER_ADAPTER * Adapter() const
void SetValueAsBool(int aRow, int aCol, bool aValue) override
wxString GetValue(int aRow, int aCol) override
bool GetValueAsBool(int aRow, int aCol) override
LIBRARY_TABLE_ROW & At(size_t aIndex)
void onGridCellLeftClick(wxGridEvent &aEvent) override
virtual void openTable(const LIBRARY_TABLE_ROW &aRow)=0
virtual wxString getTablePreamble()=0
static void MoveUpHandler(WX_GRID *aGrid)
virtual bool supportsVisibilityColumn()=0
void paste_text(const wxString &cb_text) override
bool handleDoubleClick(wxGridEvent &aEvent) override
LIB_TABLE_GRID_TRICKS(WX_GRID *aGrid)
static void DeleteRowHandler(WX_GRID *aGrid)
virtual void optionsEditor(int aRow)=0
static void AppendRowHandler(WX_GRID *aGrid)
void doPopupSelection(wxCommandEvent &event) override
static bool VerifyTable(WX_GRID *aGrid, bool aSupportsVisibilityColumn, std::function< void(int aRow, int aCol)> aErrorHandler)
void onCharHook(wxKeyEvent &ev)
static void MoveDownHandler(WX_GRID *aGrid)
@ LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
@ LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR
@ LIB_TABLE_GRID_TRICKS_SET_VISIBLE
@ LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS
@ LIB_TABLE_GRID_TRICKS_OPEN_TABLE
@ LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED
@ LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
void OnMoveRowUp(const std::function< void(int row)> &aMover)
void OnMoveRowDown(const std::function< void(int row)> &aMover)
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
static bool isGridReadOnly(WX_GRID *aGrid)
std::vector< std::vector< std::string > > table