30#include <wx/filename.h>
32#include <wx/dataview.h>
39constexpr wxUIntPtr ROW_DATA_DERIVED = 1;
42constexpr unsigned int SYMBOL_COLUMN = 1;
52class IMPORT_SYMBOL_LIST_STORE :
public wxDataViewListStore
55 bool GetAttrByRow(
unsigned int aRow,
unsigned int aCol,
56 wxDataViewItemAttr& aAttr )
const override
58 if( aCol == SYMBOL_COLUMN && GetItemData( GetItem( aRow ) ) == ROW_DATA_DERIVED )
60 aAttr.SetItalic(
true );
72 const wxString& aFilePath,
73 const wxString& aDestLibrary,
74 SCH_IO_MGR::SCH_FILE_T aPluginType ) :
82 wxFileName fn( aFilePath );
83 SetTitle( wxString::Format(
_(
"Import Symbols from %s" ), fn.GetFullName() ) );
87 IMPORT_SYMBOL_LIST_STORE* store =
new IMPORT_SYMBOL_LIST_STORE();
91 m_symbolList->AppendToggleColumn( wxEmptyString, wxDATAVIEW_CELL_ACTIVATABLE, 30 );
92 m_symbolList->AppendIconTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 250 );
94 m_symbolList->Connect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
114 m_symbolList->Disconnect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
143 DisplayError(
this,
_(
"Unable to find a plugin to read this library." ) );
147 wxArrayString symbolNames;
156 wxString::Format(
_(
"Cannot read symbol library '%s'." ),
m_filePath ),
161 if( symbolNames.empty() )
171 for(
const wxString&
name : symbolNames )
174 bool isPower =
false;
198 [&libMgr,
this](
const wxString&
name ) {
228 wxVector<wxVariant> data;
232 bool isChecked =
info->m_checked ||
info->m_autoSelected;
233 data.push_back( wxVariant( isChecked ) );
235 if(
info->m_isPower )
238 icon.CopyFromBitmap( bmp );
240 else if(
info->m_existsInDest )
243 icon.CopyFromBitmap( bmp );
248 wxDataViewIconText iconText(
name, icon );
249 data.push_back( wxVariant( iconText ) );
253 wxUIntPtr rowData =
info->m_parentName.IsEmpty() ? 0 : ROW_DATA_DERIVED;
299 for(
int ii = 0; ii < unitCount; ii++ )
305 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
310 std::unique_ptr<LIB_SYMBOL> flattenedSym;
317 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
322 m_preview->DisplayPart( sym, selectedUnit );
327 m_preview->DisplayPart( sym, selectedUnit );
334 int manualCount =
m_manager.GetManualSelectionCount();
335 int autoCount =
m_manager.GetAutoSelectionCount();
341 status = wxString::Format(
_(
"%d symbols selected, %d parents auto-included" ),
342 manualCount, autoCount );
346 status = wxString::Format(
_(
"%d symbols selected" ), manualCount );
355 bool hasSelection = !
m_manager.GetSymbolsToImport().empty();
371 if( row == wxNOT_FOUND )
380 if( listIndex == row )
397 if( row == wxNOT_FOUND )
402 if( listIndex == row )
406 bool newState = value.GetBool();
419 std::vector<wxString> changed =
m_manager.SetSymbolSelected( aSymbolName,
true );
421 for(
const wxString& changedName : changed )
433 m_manager.DeselectWithDescendants( aSymbolName );
445 bool shouldBeChecked =
info->m_checked ||
info->m_autoSelected;
489 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
509 std::unique_ptr<LIB_SYMBOL> flattenedSym;
516 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
520 m_preview->DisplayPart( sym, selectedUnit );
525 m_preview->DisplayPart( sym, selectedUnit );
540 std::vector<wxString> conflicts =
m_manager.GetConflicts();
542 if( conflicts.empty() )
545 wxDialog dlg(
this, wxID_ANY,
_(
"Resolve Import Conflicts" ),
546 wxDefaultPosition, wxSize( 500, 400 ),
547 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
549 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
551 wxStaticText* label =
new wxStaticText( &dlg, wxID_ANY,
552 _(
"The following symbols already exist in the destination library. "
553 "Choose how to handle each conflict:" ) );
555 mainSizer->Add( label, 0, wxALL | wxEXPAND, 10 );
557 wxDataViewListCtrl* conflictList =
new wxDataViewListCtrl( &dlg, wxID_ANY );
558 conflictList->AppendTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 200 );
559 conflictList->AppendTextColumn(
_(
"Action" ), wxDATAVIEW_CELL_EDITABLE, 100 );
561 for(
const wxString&
name : conflicts )
563 wxVector<wxVariant> data;
564 data.push_back( wxVariant(
name ) );
565 data.push_back( wxVariant(
_(
"Overwrite" ) ) );
566 conflictList->AppendItem( data );
571 mainSizer->Add( conflictList, 1, wxALL | wxEXPAND, 10 );
573 wxBoxSizer* actionSizer =
new wxBoxSizer( wxHORIZONTAL );
574 wxButton* skipAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Skip All" ) );
575 wxButton* overwriteAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Overwrite All" ) );
576 actionSizer->Add( skipAllBtn, 0, wxRIGHT, 5 );
577 actionSizer->Add( overwriteAllBtn, 0 );
578 mainSizer->Add( actionSizer, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10 );
580 wxStdDialogButtonSizer* btnSizer =
new wxStdDialogButtonSizer();
581 btnSizer->AddButton(
new wxButton( &dlg, wxID_OK,
_(
"Import" ) ) );
582 btnSizer->AddButton(
new wxButton( &dlg, wxID_CANCEL ) );
584 mainSizer->Add( btnSizer, 0, wxALL | wxEXPAND, 10 );
586 dlg.SetSizer( mainSizer );
588 skipAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
589 for(
size_t i = 0; i < conflicts.size(); i++ )
591 conflictList->SetTextValue(
_(
"Skip" ), i, 1 );
596 overwriteAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
597 for(
size_t i = 0; i < conflicts.size(); i++ )
599 conflictList->SetTextValue(
_(
"Overwrite" ), i, 1 );
604 conflictList->Bind( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [&]( wxDataViewEvent& evt ) {
605 int row = conflictList->ItemToRow( evt.GetItem() );
607 if( row >= 0 && row < (
int) conflicts.size() )
609 wxString action = conflictList->GetTextValue( row, 1 );
616 return dlg.ShowModal() == wxID_OK;
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxStaticText * m_statusLine
wxSearchCtrl * m_searchCtrl
wxBoxSizer * m_previewSizer
DIALOG_IMPORT_SYMBOL_SELECT_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Import Symbols from %s"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 650), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxDataViewListCtrl * m_symbolList
~DIALOG_IMPORT_SYMBOL_SELECT() override
bool loadSymbols()
Load symbols from the source file and populate the manager.
SYMBOL_IMPORT_MANAGER m_manager
Manager for symbol selection logic.
void refreshList()
Refresh the list control based on current filter and selections.
std::vector< wxString > GetSelectedSymbols() const
Get the list of symbols selected for import.
bool toggleSymbolSelection(const wxString &aSymbolName, bool aChecked)
Toggle selection state for a symbol.
wxString m_filterString
Current filter string.
wxString m_selectedSymbol
Currently selected symbol for preview.
bool matchesFilter(const wxString &aSymbolName) const
Check if a symbol matches the current filter.
std::map< wxString, CONFLICT_RESOLUTION > m_conflictResolutions
Conflict resolutions chosen by user.
void OnSymbolSelected(wxDataViewEvent &event) override
bool resolveConflicts()
Show conflict resolution dialog.
void updateImportButton()
Update import button enabled state based on selection.
void updateStatusLine()
Update the status line with selection counts.
void OnFilterTextChanged(wxCommandEvent &event) override
bool TransferDataToWindow() override
void OnSelectAll(wxCommandEvent &event) override
std::map< wxString, int > m_listIndices
Map from symbol name to list index (UI-only, -1 if filtered out)
bool TransferDataFromWindow() override
SYMBOL_PREVIEW_WIDGET * m_preview
SYMBOL_EDIT_FRAME * m_frame
void OnSelectNone(wxCommandEvent &event) override
void onItemChecked(wxDataViewEvent &event)
Handle checkbox toggle in the list.
void OnUnitChanged(wxCommandEvent &event) override
DIALOG_IMPORT_SYMBOL_SELECT(SYMBOL_EDIT_FRAME *aParent, const wxString &aFilePath, const wxString &aDestLibrary, SCH_IO_MGR::SCH_FILE_T aPluginType)
void updatePreview()
Update the preview for the currently selected symbol.
IO_RELEASER< SCH_IO > m_plugin
Plugin kept alive for symbol access during dialog lifetime.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
@ GAL_TYPE_OPENGL
OpenGL implementation.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Symbol library management helper that is specific to the symbol library editor frame.
Define a library symbol object.
bool IsPower() const override
const wxString & GetParentName() const
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the user-defined display name for aUnit for symbols with units.
A factory which returns an instance of a SCH_IO.
The symbol library editor main window.
static bool MatchesFilter(const wxString &aSymbolName, const wxString &aFilter)
Check if a symbol name matches a filter string (case-insensitive contains).
bool SymbolExists(const wxString &aSymbolName, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
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.
Information about a symbol available for import.
@ OVERWRITE
Overwrite existing symbol.
@ SKIP
Don't import this symbol.