24#include <wx/clipbrd.h>
40 m_grid->Disconnect( wxEVT_CHAR_HOOK );
46 std::function<
void( wxCommandEvent& )> aAddHandler ) :
49 m_grid->Disconnect( wxEVT_CHAR_HOOK );
67 wxString title = row.
Type() ==
"Table"
68 ? wxString::Format(
_(
"Error loading library table '%s'" ), row.
Nickname() )
69 : wxString::Format(
_(
"Error loading library '%s'" ), row.
Nickname() );
80 else if( !row.
IsOk() )
109 bool readOnly =
model->Table().IsReadOnly();
111 bool showSettings =
false;
112 bool showOpen =
false;
118 if(
m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( firstRow ) )
132 if( showSettings || showOpen )
133 menu.AppendSeparator();
135 bool showActivate =
false;
136 bool showDeactivate =
false;
137 bool showSetVisible =
false;
138 bool showUnsetVisible =
false;
139 bool showOptions =
false;
144 showDeactivate =
true;
149 showUnsetVisible =
true;
151 showSetVisible =
true;
153 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
168 if( showUnsetVisible )
176 _(
"Edit options for this library entry" ) );
179 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showOptions )
180 menu.AppendSeparator();
190 int menu_id =
event.GetId();
243 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' &&
m_grid->IsCellEditControlShown() )
247 if( wxTheClipboard->Open() )
249 if( wxTheClipboard->IsSupported( wxDF_TEXT ) || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
251 wxTextDataObject data;
252 wxTheClipboard->GetData( data );
254 wxString
text = data.GetText();
256 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
257 text.Replace(
',',
'\t' );
259 if(
text.Contains(
'\t' ) ||
text.Contains(
'\n' ) ||
text.Contains(
'\r' ) )
261 m_grid->CancelPendingChanges();
262 int row =
m_grid->GetGridCursorRow();
267 if(
table && row >= 0 && row < table->GetNumberRows() )
272 if( !nickname.IsEmpty() )
275 wxTheClipboard->Close();
283 m_grid->SetGridCursor( row, 0 );
286 wxTheClipboard->Close();
292 wxTheClipboard->Close();
308 if(
model->Table().IsReadOnly() )
314 if(
size_t ndx = cb_text.find(
getTablePreamble() ); ndx != std::string::npos )
320 std::ranges::copy( tempTable.Rows(),
321 std::inserter(
model->Table().Rows(),
model->Table().Rows().begin() ) );
323 if(
model->GetView() )
325 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, 0, 0 );
326 model->GetView()->ProcessTableMessage( msg );
337 wxString
text = cb_text;
339 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
340 text.Replace(
',',
'\t' );
342 if(
text.Contains(
'\t' ) )
344 int row =
m_grid->GetGridCursorRow();
347 m_grid->SetGridCursor( row, 0 );
354 m_grid->AutoSizeColumns(
false );
357 m_grid->AutoSizeColumns(
false );
388 [&]() -> std::pair<int, int>
392 aGrid->AppendRows( 1 );
393 aGrid->SetCellValue( aGrid->GetNumberRows() - 1,
COL_TYPE, aType );
411 wxGridUpdateLocker noUpdates( aGrid );
413 int curRow = aGrid->GetGridCursorRow();
414 int curCol = aGrid->GetGridCursorCol();
421 wxArrayInt selectedRows = aGrid->GetSelectedRows();
422 wxGridCellCoordsArray cells = aGrid->GetSelectedCells();
423 wxGridCellCoordsArray blockTopLeft = aGrid->GetSelectionBlockTopLeft();
424 wxGridCellCoordsArray blockBotRight = aGrid->GetSelectionBlockBottomRight();
427 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
428 selectedRows.Add( cells[ii].GetRow() );
431 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
433 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
434 selectedRows.Add( i );
438 if( selectedRows.size() == 0 && aGrid->GetGridCursorRow() >= 0 )
439 selectedRows.Add( aGrid->GetGridCursorRow() );
441 if( selectedRows.size() == 0 )
447 std::sort( selectedRows.begin(), selectedRows.end() );
454 aGrid->ClearSelection();
456 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
458 int row = selectedRows[ii];
460 if( row != last_row )
463 aGrid->DeleteRows( row, 1 );
468 if( aGrid->GetNumberRows() > 0 && curRow >= 0 )
469 aGrid->SetGridCursor( std::min( curRow, aGrid->GetNumberRows() - 1 ), curCol );
485 int curRow = aGrid->GetGridCursorRow();
486 std::deque<LIBRARY_TABLE_ROW>& rows =
model->Table().Rows();
488 auto current = rows.begin() + curRow;
489 auto prev = rows.begin() + curRow - 1;
491 std::iter_swap( current, prev );
494 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 );
495 model->GetView()->ProcessTableMessage( msg );
513 int curRow = aGrid->GetGridCursorRow();
514 std::deque<LIBRARY_TABLE_ROW>& rows =
model->Table().Rows();
516 auto current = rows.begin() + curRow;
517 auto next = rows.begin() + curRow + 1;
519 std::iter_swap( current,
next );
522 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 );
523 model->GetView()->ProcessTableMessage( msg );
530 std::function<
void(
int aRow,
int aCol )> aErrorHandler )
532 wxWindow* topLevelParent = wxGetTopLevelParent( aGrid );
536 for(
int r = 0; r <
model->GetNumberRows(); )
539 wxString uri =
model->GetValue( r,
COL_URI ).Trim(
false ).Trim();
540 unsigned illegalCh = 0;
545 model->DeleteRows( r, 1 );
550 msg =
_(
"Library must have a nickname." );
552 msg = wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ), illegalCh, nick );
566 if( !aSupportsVisibilityColumn )
577 for(
int r1 = 0; r1 <
model->GetNumberRows() - 1; ++r1 )
581 for(
int r2 = r1 + 1; r2 <
model->GetNumberRows(); ++r2 )
587 msg = wxString::Format(
_(
"Multiple libraries cannot share the same nickname ('%s')." ), nick1 );
590 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 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)
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)