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() );
98 bool readOnly =
model->Table().IsReadOnly();
100 bool showSettings =
false;
101 bool showOpen =
false;
109 if(
m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( nickname ) )
123 if( showSettings || showOpen )
124 menu.AppendSeparator();
126 bool showActivate =
false;
127 bool showDeactivate =
false;
128 bool showSetVisible =
false;
129 bool showUnsetVisible =
false;
130 bool showOptions =
false;
134 if(
model->GetValueAsBool( row, 0 ) )
135 showDeactivate =
true;
139 if(
model->GetValueAsBool( row, 1 ) )
140 showUnsetVisible =
true;
142 showSetVisible =
true;
144 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
159 if( showUnsetVisible )
167 _(
"Edit options for this library entry" ) );
170 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showOptions )
171 menu.AppendSeparator();
181 int menu_id =
event.GetId();
194 model->SetValueAsBool( row, 0, selected_state );
205 model->SetValueAsBool( row, 1, selected_state );
231 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() ==
'V' &&
m_grid->IsCellEditControlShown() )
235 if( wxTheClipboard->Open() )
237 if( wxTheClipboard->IsSupported( wxDF_TEXT ) || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
239 wxTextDataObject data;
240 wxTheClipboard->GetData( data );
242 wxString
text = data.GetText();
244 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
245 text.Replace(
',',
'\t' );
247 if(
text.Contains(
'\t' ) ||
text.Contains(
'\n' ) ||
text.Contains(
'\r' ) )
249 m_grid->CancelPendingChanges();
250 int row =
m_grid->GetGridCursorRow();
255 if(
table && row >= 0 && row < table->GetNumberRows() )
260 if( !nickname.IsEmpty() )
263 wxTheClipboard->Close();
271 m_grid->SetGridCursor( row, 0 );
274 wxTheClipboard->Close();
280 wxTheClipboard->Close();
296 if(
model->Table().IsReadOnly() )
302 if(
size_t ndx = cb_text.find(
getTablePreamble() ); ndx != std::string::npos )
308 std::ranges::copy( tempTable.Rows(),
309 std::inserter(
model->Table().Rows(),
model->Table().Rows().begin() ) );
311 if(
model->GetView() )
313 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, 0, 0 );
314 model->GetView()->ProcessTableMessage( msg );
325 wxString
text = cb_text;
327 if( !
text.Contains(
'\t' ) &&
text.Contains(
',' ) )
328 text.Replace(
',',
'\t' );
330 if(
text.Contains(
'\t' ) )
332 int row =
m_grid->GetGridCursorRow();
335 m_grid->SetGridCursor( row, 0 );
342 m_grid->AutoSizeColumns(
false );
345 m_grid->AutoSizeColumns(
false );
377 [&]() -> std::pair<int, int>
381 aGrid->AppendRows( 1 );
382 aGrid->SetCellValue( aGrid->GetNumberRows() - 1,
COL_TYPE, aType );
400 wxGridUpdateLocker noUpdates( aGrid );
402 int curRow = aGrid->GetGridCursorRow();
403 int curCol = aGrid->GetGridCursorCol();
410 wxArrayInt selectedRows = aGrid->GetSelectedRows();
411 wxGridCellCoordsArray cells = aGrid->GetSelectedCells();
412 wxGridCellCoordsArray blockTopLeft = aGrid->GetSelectionBlockTopLeft();
413 wxGridCellCoordsArray blockBotRight = aGrid->GetSelectionBlockBottomRight();
416 for(
unsigned ii = 0; ii < cells.GetCount(); ii++ )
417 selectedRows.Add( cells[ii].GetRow() );
420 if( !blockTopLeft.IsEmpty() && !blockBotRight.IsEmpty() )
422 for(
int i = blockTopLeft[0].GetRow(); i <= blockBotRight[0].GetRow(); ++i )
423 selectedRows.Add( i );
427 if( selectedRows.size() == 0 && aGrid->GetGridCursorRow() >= 0 )
428 selectedRows.Add( aGrid->GetGridCursorRow() );
430 if( selectedRows.size() == 0 )
436 std::sort( selectedRows.begin(), selectedRows.end() );
443 aGrid->ClearSelection();
445 for(
int ii = selectedRows.GetCount()-1; ii >= 0; ii-- )
447 int row = selectedRows[ii];
449 if( row != last_row )
452 aGrid->DeleteRows( row, 1 );
457 if( aGrid->GetNumberRows() > 0 && curRow >= 0 )
458 aGrid->SetGridCursor( std::min( curRow, aGrid->GetNumberRows() - 1 ), curCol );
474 int curRow = aGrid->GetGridCursorRow();
475 std::deque<LIBRARY_TABLE_ROW>& rows =
model->Table().Rows();
477 auto current = rows.begin() + curRow;
478 auto prev = rows.begin() + curRow - 1;
480 std::iter_swap( current, prev );
483 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 );
484 model->GetView()->ProcessTableMessage( msg );
502 int curRow = aGrid->GetGridCursorRow();
503 std::deque<LIBRARY_TABLE_ROW>& rows =
model->Table().Rows();
505 auto current = rows.begin() + curRow;
506 auto next = rows.begin() + curRow + 1;
508 std::iter_swap( current,
next );
511 wxGridTableMessage msg(
model, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 );
512 model->GetView()->ProcessTableMessage( msg );
519 std::function<
void(
int aRow,
int aCol )> aErrorHandler )
521 wxWindow* topLevelParent = wxGetTopLevelParent( aGrid );
525 for(
int r = 0; r <
model->GetNumberRows(); )
528 wxString uri =
model->GetValue( r,
COL_URI ).Trim(
false ).Trim();
529 unsigned illegalCh = 0;
534 model->DeleteRows( r, 1 );
539 msg =
_(
"Library must have a nickname." );
541 msg = wxString::Format(
_(
"Illegal character '%c' in nickname '%s'." ), illegalCh, nick );
555 if( !aSupportsVisibilityColumn )
566 for(
int r1 = 0; r1 <
model->GetNumberRows() - 1; ++r1 )
570 for(
int r2 = r1 + 1; r2 <
model->GetNumberRows(); ++r2 )
576 msg = wxString::Format(
_(
"Multiple libraries cannot share the same nickname ('%s')." ), nick1 );
579 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 wxString &aNickname) const
virtual int ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const
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 #LIB_TABLE into wxGridTableBase so the result ...
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)