24#include <wx/clipbrd.h>
44 std::function<
void( wxCommandEvent& )> aAddHandler ) :
63 wxString title = row.
Type() ==
"Table"
64 ? wxString::Format(
_(
"Error loading library table '%s'" ), row.
Nickname() )
65 : wxString::Format(
_(
"Error loading library '%s'" ), row.
Nickname() );
76 else if( !row.
IsOk() )
105 bool readOnly =
model->Table().IsReadOnly();
107 bool showSettings =
false;
108 bool showOpen =
false;
114 if(
m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( firstRow ) )
128 if( showSettings || showOpen )
129 menu.AppendSeparator();
131 bool showActivate =
false;
132 bool showDeactivate =
false;
133 bool showSetVisible =
false;
134 bool showUnsetVisible =
false;
135 bool showOptions =
false;
140 showDeactivate =
true;
145 showUnsetVisible =
true;
147 showSetVisible =
true;
149 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
164 if( showUnsetVisible )
172 _(
"Edit options for this library entry" ) );
175 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showOptions )
176 menu.AppendSeparator();
186 int menu_id =
event.GetId();
239 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' &&
m_grid->IsCellEditControlShown() )
243 if( wxTheClipboard->Open() )
245 if( wxTheClipboard->IsSupported( wxDF_TEXT ) || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
247 wxTextDataObject data;
248 wxTheClipboard->GetData( data );
250 wxString
text = data.GetText();
252 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
253 text.Replace(
',',
'\t' );
255 if(
text.Contains(
'\t' ) ||
text.Contains(
'\n' ) ||
text.Contains(
'\r' ) )
257 m_grid->CancelPendingChanges();
258 int row =
m_grid->GetGridCursorRow();
263 if(
table && row >= 0 && row < table->GetNumberRows() )
268 if( !nickname.IsEmpty() )
271 wxTheClipboard->Close();
279 m_grid->SetGridCursor( row, 0 );
282 wxTheClipboard->Close();
288 wxTheClipboard->Close();
304 if(
model->Table().IsReadOnly() )
310 if(
size_t ndx = cb_text.find(
getTablePreamble() ); ndx != std::string::npos )
316 std::ranges::copy( tempTable.Rows(),
317 std::inserter(
model->Table().Rows(),
model->Table().Rows().begin() ) );
319 if(
model->GetView() )
321 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, 0, 0 );
322 model->GetView()->ProcessTableMessage( msg );
333 wxString
text = cb_text;
335 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
336 text.Replace(
',',
'\t' );
338 if(
text.Contains(
'\t' ) )
340 int row =
m_grid->GetGridCursorRow();
343 m_grid->SetGridCursor( row, 0 );
350 m_grid->AutoSizeColumns(
false );
353 m_grid->AutoSizeColumns(
false );
384 [&]() -> std::pair<int, int>
388 aGrid->AppendRows( 1 );
389 aGrid->SetCellValue( aGrid->GetNumberRows() - 1,
COL_TYPE, aType );
407 wxGridUpdateLocker noUpdates( aGrid );
409 int curRow = aGrid->GetGridCursorRow();
410 int curCol = aGrid->GetGridCursorCol();
417 wxArrayInt selectedRows = aGrid->GetSelectedRows();
418 wxGridCellCoordsArray cells = aGrid->GetSelectedCells();
419 wxGridCellCoordsArray blockTopLeft = aGrid->GetSelectionBlockTopLeft();
420 wxGridCellCoordsArray blockBotRight = aGrid->GetSelectionBlockBottomRight();
423 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
424 selectedRows.Add( cells[ii].GetRow() );
427 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
429 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
430 selectedRows.Add( i );
434 if( selectedRows.size() == 0 && aGrid->GetGridCursorRow() >= 0 )
435 selectedRows.Add( aGrid->GetGridCursorRow() );
437 if( selectedRows.size() == 0 )
443 std::sort( selectedRows.begin(), selectedRows.end() );
450 aGrid->ClearSelection();
452 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
454 int row = selectedRows[ii];
456 if( row != last_row )
459 aGrid->DeleteRows( row, 1 );
464 if( aGrid->GetNumberRows() > 0 && curRow >= 0 )
465 aGrid->SetGridCursor( std::min( curRow, aGrid->GetNumberRows() - 1 ), curCol );
481 int curRow = aGrid->GetGridCursorRow();
482 std::deque<LIBRARY_TABLE_ROW>&
rows =
model->Table().Rows();
484 auto current =
rows.begin() + curRow;
485 auto prev =
rows.begin() + curRow - 1;
487 std::iter_swap( current, prev );
490 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 );
491 model->GetView()->ProcessTableMessage( msg );
509 int curRow = aGrid->GetGridCursorRow();
510 std::deque<LIBRARY_TABLE_ROW>&
rows =
model->Table().Rows();
512 auto current =
rows.begin() + curRow;
513 auto next =
rows.begin() + curRow + 1;
515 std::iter_swap( current,
next );
518 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 );
519 model->GetView()->ProcessTableMessage( msg );
526 std::function<
void(
int aRow,
int aCol )> aErrorHandler )
528 wxWindow* topLevelParent = wxGetTopLevelParent( aGrid );
532 for(
int r = 0; r <
model->GetNumberRows(); )
535 wxString uri =
model->GetValue( r,
COL_URI ).Trim(
false ).Trim();
536 unsigned illegalCh = 0;
541 model->DeleteRows( r, 1 );
546 msg =
_(
"Library must have a nickname." );
548 msg = wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ), illegalCh, nick );
562 if( !aSupportsVisibilityColumn )
573 for(
int r1 = 0; r1 <
model->GetNumberRows() - 1; ++r1 )
577 for(
int r2 = r1 + 1; r2 <
model->GetNumberRows(); ++r2 )
583 msg = wxString::Format(
_(
"Multiple libraries cannot share the same nickname ('%s')." ), nick1 );
586 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)
virtual 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 bool SupportsConfigurationDialog(const LIBRARY_TABLE_ROW &aRow) const
Configuration works from the row itself, so libraries that failed to load or are not yet committed to...
virtual int ShowConfigurationDialog(const LIBRARY_TABLE_ROW &aRow, LIBRARY_TABLE_SCOPE aScope, wxWindow *aParent)
Shows the plugin's configuration dialog for a library table row.
const wxString & ErrorDescription() const
const wxString & Type() const
static const wxString TABLE_TYPE_NAME
const wxString & Nickname() 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 LIBRARY_TABLE into wxGridTableBase so the resu...
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, const wxString &aType)
void doPopupSelection(wxCommandEvent &event) override
static bool VerifyTable(WX_GRID *aGrid, bool aSupportsVisibilityColumn, std::function< void(int aRow, int aCol)> aErrorHandler)
static void MoveDownHandler(WX_GRID *aGrid)
void onCharHook(wxKeyEvent &ev) override
@ 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< DATABASE_CONNECTION::ROW > rows