30#include <wx/filename.h>
32#include <wx/dataview.h>
36 const wxString& aFilePath,
37 const wxString& aDestLibrary,
38 SCH_IO_MGR::SCH_FILE_T aPluginType ) :
47 wxFileName fn( aFilePath );
48 SetTitle( wxString::Format(
_(
"Import Symbols from %s" ), fn.GetFullName() ) );
50 m_symbolList->AppendToggleColumn( wxEmptyString, wxDATAVIEW_CELL_ACTIVATABLE, 30 );
51 m_symbolList->AppendIconTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 250 );
53 m_symbolList->Connect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
73 m_symbolList->Disconnect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
102 DisplayError(
this,
_(
"Unable to find a plugin to read this library." ) );
106 wxArrayString symbolNames;
115 wxString::Format(
_(
"Cannot read symbol library '%s'." ),
m_filePath ),
120 if( symbolNames.empty() )
130 for(
const wxString&
name : symbolNames )
133 bool isPower =
false;
157 [&libMgr,
this](
const wxString&
name ) {
187 wxVector<wxVariant> data;
191 bool isChecked =
info->m_checked ||
info->m_autoSelected;
192 data.push_back( wxVariant( isChecked ) );
194 if(
info->m_isPower )
197 icon.CopyFromBitmap( bmp );
199 else if(
info->m_existsInDest )
202 icon.CopyFromBitmap( bmp );
204 else if( !
info->m_parentName.IsEmpty() )
207 icon.CopyFromBitmap( bmp );
210 wxDataViewIconText iconText(
name, icon );
211 data.push_back( wxVariant( iconText ) );
258 for(
int ii = 0; ii < unitCount; ii++ )
264 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
269 std::unique_ptr<LIB_SYMBOL> flattenedSym;
276 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
281 m_preview->DisplayPart( sym, selectedUnit );
286 m_preview->DisplayPart( sym, selectedUnit );
293 int manualCount =
m_manager.GetManualSelectionCount();
294 int autoCount =
m_manager.GetAutoSelectionCount();
300 status = wxString::Format(
_(
"%d symbols selected, %d parents auto-included" ),
301 manualCount, autoCount );
305 status = wxString::Format(
_(
"%d symbols selected" ), manualCount );
314 bool hasSelection = !
m_manager.GetSymbolsToImport().empty();
330 if( row == wxNOT_FOUND )
339 if( listIndex == row )
356 if( row == wxNOT_FOUND )
361 if( listIndex == row )
365 bool newState = value.GetBool();
378 std::vector<wxString> changed =
m_manager.SetSymbolSelected( aSymbolName,
true );
380 for(
const wxString& changedName : changed )
392 m_manager.DeselectWithDescendants( aSymbolName );
404 bool shouldBeChecked =
info->m_checked ||
info->m_autoSelected;
448 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
468 std::unique_ptr<LIB_SYMBOL> flattenedSym;
475 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
479 m_preview->DisplayPart( sym, selectedUnit );
484 m_preview->DisplayPart( sym, selectedUnit );
499 std::vector<wxString> conflicts =
m_manager.GetConflicts();
501 if( conflicts.empty() )
504 wxDialog dlg(
this, wxID_ANY,
_(
"Resolve Import Conflicts" ),
505 wxDefaultPosition, wxSize( 500, 400 ),
506 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
508 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
510 wxStaticText* label =
new wxStaticText( &dlg, wxID_ANY,
511 _(
"The following symbols already exist in the destination library. "
512 "Choose how to handle each conflict:" ) );
514 mainSizer->Add( label, 0, wxALL | wxEXPAND, 10 );
516 wxDataViewListCtrl* conflictList =
new wxDataViewListCtrl( &dlg, wxID_ANY );
517 conflictList->AppendTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 200 );
518 conflictList->AppendTextColumn(
_(
"Action" ), wxDATAVIEW_CELL_EDITABLE, 100 );
520 for(
const wxString&
name : conflicts )
522 wxVector<wxVariant> data;
523 data.push_back( wxVariant(
name ) );
524 data.push_back( wxVariant(
_(
"Overwrite" ) ) );
525 conflictList->AppendItem( data );
530 mainSizer->Add( conflictList, 1, wxALL | wxEXPAND, 10 );
532 wxBoxSizer* actionSizer =
new wxBoxSizer( wxHORIZONTAL );
533 wxButton* skipAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Skip All" ) );
534 wxButton* overwriteAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Overwrite All" ) );
535 actionSizer->Add( skipAllBtn, 0, wxRIGHT, 5 );
536 actionSizer->Add( overwriteAllBtn, 0 );
537 mainSizer->Add( actionSizer, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10 );
539 wxStdDialogButtonSizer* btnSizer =
new wxStdDialogButtonSizer();
540 btnSizer->AddButton(
new wxButton( &dlg, wxID_OK,
_(
"Import" ) ) );
541 btnSizer->AddButton(
new wxButton( &dlg, wxID_CANCEL ) );
543 mainSizer->Add( btnSizer, 0, wxALL | wxEXPAND, 10 );
545 dlg.SetSizer( mainSizer );
547 skipAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
548 for(
size_t i = 0; i < conflicts.size(); i++ )
550 conflictList->SetTextValue(
_(
"Skip" ), i, 1 );
555 overwriteAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
556 for(
size_t i = 0; i < conflicts.size(); i++ )
558 conflictList->SetTextValue(
_(
"Overwrite" ), i, 1 );
563 conflictList->Bind( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [&]( wxDataViewEvent& evt ) {
564 int row = conflictList->ItemToRow( evt.GetItem() );
566 if( row >= 0 && row < (
int) conflicts.size() )
568 wxString action = conflictList->GetTextValue( row, 1 );
575 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
SCH_IO_MGR::SCH_FILE_T m_pluginType
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.