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() );
94 _(
"Edit options for this library entry" ) );
96 menu.AppendSeparator();
98 bool showActivate =
false;
99 bool showDeactivate =
false;
100 bool showSetVisible =
false;
101 bool showUnsetVisible =
false;
110 showDeactivate =
true;
115 showUnsetVisible =
true;
117 showSetVisible =
true;
119 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
134 if( showUnsetVisible )
138 bool showSettings =
false;
139 bool showOpen =
false;
145 if(
m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( nickname ) )
151 std::optional<LIBRARY_TABLE_ROW*> row = adapter->GetRow( nickname );
160 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings || showOpen )
161 menu.AppendSeparator();
169 int menu_id =
event.GetId();
204 row->ShowSettingsDialog(
m_grid->GetParent() );
220 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' &&
m_grid->IsCellEditControlShown() )
224 if( wxTheClipboard->Open() )
226 if( wxTheClipboard->IsSupported( wxDF_TEXT ) || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
228 wxTextDataObject data;
229 wxTheClipboard->GetData( data );
231 wxString
text = data.GetText();
233 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
234 text.Replace(
',',
'\t' );
236 if(
text.Contains(
'\t' ) ||
text.Contains(
'\n' ) ||
text.Contains(
'\r' ) )
238 m_grid->CancelPendingChanges();
239 int row =
m_grid->GetGridCursorRow();
243 if(
table && row >= 0 && row < table->GetNumberRows() )
247 if( !nickname.IsEmpty() )
250 wxTheClipboard->Close();
258 m_grid->SetGridCursor( row, 0 );
261 wxTheClipboard->Close();
267 wxTheClipboard->Close();
283 if(
size_t ndx = cb_text.find(
getTablePreamble() ); ndx != std::string::npos )
289 std::ranges::copy( tempTable.Rows(),
294 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, 0, 0 );
295 tbl->GetView()->ProcessTableMessage( msg );
305 wxString
text = cb_text;
307 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
308 text.Replace(
',',
'\t' );
310 if(
text.Contains(
'\t' ) )
312 int row =
m_grid->GetGridCursorRow();
315 m_grid->SetGridCursor( row, 0 );
321 m_grid->AutoSizeColumns(
false );
324 m_grid->AutoSizeColumns(
false );
343 [&]() -> std::pair<int, int>
345 aGrid->AppendRows( 1 );
356 wxGridUpdateLocker noUpdates( aGrid );
358 int curRow = aGrid->GetGridCursorRow();
359 int curCol = aGrid->GetGridCursorCol();
366 wxArrayInt selectedRows = aGrid->GetSelectedRows();
367 wxGridCellCoordsArray cells = aGrid->GetSelectedCells();
368 wxGridCellCoordsArray blockTopLeft = aGrid->GetSelectionBlockTopLeft();
369 wxGridCellCoordsArray blockBotRight = aGrid->GetSelectionBlockBottomRight();
372 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
373 selectedRows.Add( cells[ii].GetRow() );
376 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
378 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
379 selectedRows.Add( i );
383 if( selectedRows.size() == 0 && aGrid->GetGridCursorRow() >= 0 )
384 selectedRows.Add( aGrid->GetGridCursorRow() );
386 if( selectedRows.size() == 0 )
392 std::sort( selectedRows.begin(), selectedRows.end() );
399 aGrid->ClearSelection();
401 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
403 int row = selectedRows[ii];
405 if( row != last_row )
408 aGrid->DeleteRows( row, 1 );
412 if( aGrid->GetNumberRows() > 0 && curRow >= 0 )
413 aGrid->SetGridCursor( std::min( curRow, aGrid->GetNumberRows() - 1 ), curCol );
423 int curRow = aGrid->GetGridCursorRow();
425 std::vector<LIBRARY_TABLE_ROW>& rows = tbl->
Table().
Rows();
427 auto current = rows.begin() + curRow;
428 auto prev = rows.begin() + curRow - 1;
430 std::iter_swap( current, prev );
433 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 );
434 tbl->GetView()->ProcessTableMessage( msg );
445 int curRow = aGrid->GetGridCursorRow();
446 std::vector<LIBRARY_TABLE_ROW>& rows = tbl->
Table().
Rows();
448 auto current = rows.begin() + curRow;
449 auto next = rows.begin() + curRow + 1;
451 std::iter_swap( current,
next );
454 wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 );
455 tbl->GetView()->ProcessTableMessage( msg );
462 wxWindow* topLevelParent = wxGetTopLevelParent( aGrid );
470 unsigned illegalCh = 0;
475 msg =
_(
"A library table row nickname and path cells are empty." );
477 msg =
_(
"A library table row nickname cell is empty." );
479 msg =
_(
"A library table row path cell is empty." );
481 wxMessageDialog badCellDlg( topLevelParent, msg,
_(
"Invalid Row Definition" ),
482 wxYES_NO | wxCENTER | wxICON_QUESTION | wxYES_DEFAULT );
483 badCellDlg.SetExtendedMessage(
_(
"Empty cells will result in all rows that are "
484 "invalid to be removed from the table." ) );
485 badCellDlg.SetYesNoLabels( wxMessageDialog::ButtonLabel(
_(
"Remove Invalid Cells" ) ),
486 wxMessageDialog::ButtonLabel(
_(
"Cancel Table Update" ) ) );
488 if( badCellDlg.ShowModal() == wxID_NO )
499 msg = wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ),
503 aErrorHandler( r, 1 );
505 wxMessageDialog errdlg( topLevelParent, msg,
_(
"Library Nickname Error" ) );
533 msg = wxString::Format(
_(
"Multiple libraries cannot share the same nickname ('%s')." ), nick1 );
536 aErrorHandler( r2, 1 );
538 wxMessageDialog errdlg( topLevelParent, msg,
_(
"Library Nickname Error" ) );
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
LIBRARY_TABLE_SCOPE Scope() const
const std::vector< 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 ...
int GetNumberRows() override
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
bool DeleteRows(size_t aPos, size_t aNumRows) override
LIBRARY_TABLE_ROW & At(size_t aIndex)
void SetValue(int aRow, int aCol, const wxString &aValue) override
void onGridCellLeftClick(wxGridEvent &aEvent) override
virtual void openTable(const LIBRARY_TABLE_ROW &aRow)=0
virtual wxString getTablePreamble()=0
static void MoveUpHandler(WX_GRID *aGrid)
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 bool VerifyTable(WX_GRID *aGrid, std::function< void(int aRow, int aCol)> aErrorHandler)
virtual bool supportsVisibilityColumn()
static void AppendRowHandler(WX_GRID *aGrid)
void doPopupSelection(wxCommandEvent &event) override
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.