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 ) :
46 wxFileName fn( aFilePath );
47 SetTitle( wxString::Format(
_(
"Import Symbols from %s" ), fn.GetFullName() ) );
49 m_symbolList->AppendToggleColumn( wxEmptyString, wxDATAVIEW_CELL_ACTIVATABLE, 30 );
50 m_symbolList->AppendIconTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 250 );
52 m_symbolList->Connect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
72 m_symbolList->Disconnect( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,
101 DisplayError(
this,
_(
"Unable to find a plugin to read this library." ) );
105 wxArrayString symbolNames;
114 wxString::Format(
_(
"Cannot read symbol library '%s'." ),
m_filePath ),
119 if( symbolNames.empty() )
129 for(
const wxString&
name : symbolNames )
132 bool isPower =
false;
156 [&libMgr,
this](
const wxString&
name ) {
186 wxVector<wxVariant> data;
190 bool isChecked =
info->m_checked ||
info->m_autoSelected;
191 data.push_back( wxVariant( isChecked ) );
193 if(
info->m_isPower )
196 icon.CopyFromBitmap( bmp );
198 else if(
info->m_existsInDest )
201 icon.CopyFromBitmap( bmp );
203 else if( !
info->m_parentName.IsEmpty() )
206 icon.CopyFromBitmap( bmp );
209 wxDataViewIconText iconText(
name, icon );
210 data.push_back( wxVariant( iconText ) );
257 for(
int ii = 0; ii < unitCount; ii++ )
263 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
268 std::unique_ptr<LIB_SYMBOL> flattenedSym;
275 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
280 m_preview->DisplayPart( sym, selectedUnit );
285 m_preview->DisplayPart( sym, selectedUnit );
292 int manualCount =
m_manager.GetManualSelectionCount();
293 int autoCount =
m_manager.GetAutoSelectionCount();
299 status = wxString::Format(
_(
"%d symbols selected, %d parents auto-included" ),
300 manualCount, autoCount );
304 status = wxString::Format(
_(
"%d symbols selected" ), manualCount );
313 bool hasSelection = !
m_manager.GetSymbolsToImport().empty();
329 if( row == wxNOT_FOUND )
338 if( listIndex == row )
355 if( row == wxNOT_FOUND )
360 if( listIndex == row )
364 bool newState = value.GetBool();
377 std::vector<wxString> changed =
m_manager.SetSymbolSelected( aSymbolName,
true );
379 for(
const wxString& changedName : changed )
391 m_manager.DeselectWithDescendants( aSymbolName );
403 bool shouldBeChecked =
info->m_checked ||
info->m_autoSelected;
447 int selectedUnit = (
m_unitChoice->GetSelection() != wxNOT_FOUND )
467 std::unique_ptr<LIB_SYMBOL> flattenedSym;
474 m_preview->DisplayPart( flattenedSym.get(), selectedUnit );
478 m_preview->DisplayPart( sym, selectedUnit );
483 m_preview->DisplayPart( sym, selectedUnit );
498 std::vector<wxString> conflicts =
m_manager.GetConflicts();
500 if( conflicts.empty() )
503 wxDialog dlg(
this, wxID_ANY,
_(
"Resolve Import Conflicts" ),
504 wxDefaultPosition, wxSize( 500, 400 ),
505 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
507 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
509 wxStaticText* label =
new wxStaticText( &dlg, wxID_ANY,
510 _(
"The following symbols already exist in the destination library. "
511 "Choose how to handle each conflict:" ) );
513 mainSizer->Add( label, 0, wxALL | wxEXPAND, 10 );
515 wxDataViewListCtrl* conflictList =
new wxDataViewListCtrl( &dlg, wxID_ANY );
516 conflictList->AppendTextColumn(
_(
"Symbol" ), wxDATAVIEW_CELL_INERT, 200 );
517 conflictList->AppendTextColumn(
_(
"Action" ), wxDATAVIEW_CELL_EDITABLE, 100 );
519 for(
const wxString&
name : conflicts )
521 wxVector<wxVariant> data;
522 data.push_back( wxVariant(
name ) );
523 data.push_back( wxVariant(
_(
"Overwrite" ) ) );
524 conflictList->AppendItem( data );
529 mainSizer->Add( conflictList, 1, wxALL | wxEXPAND, 10 );
531 wxBoxSizer* actionSizer =
new wxBoxSizer( wxHORIZONTAL );
532 wxButton* skipAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Skip All" ) );
533 wxButton* overwriteAllBtn =
new wxButton( &dlg, wxID_ANY,
_(
"Overwrite All" ) );
534 actionSizer->Add( skipAllBtn, 0, wxRIGHT, 5 );
535 actionSizer->Add( overwriteAllBtn, 0 );
536 mainSizer->Add( actionSizer, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10 );
538 wxStdDialogButtonSizer* btnSizer =
new wxStdDialogButtonSizer();
539 btnSizer->AddButton(
new wxButton( &dlg, wxID_OK,
_(
"Import" ) ) );
540 btnSizer->AddButton(
new wxButton( &dlg, wxID_CANCEL ) );
542 mainSizer->Add( btnSizer, 0, wxALL | wxEXPAND, 10 );
544 dlg.SetSizer( mainSizer );
546 skipAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
547 for(
size_t i = 0; i < conflicts.size(); i++ )
549 conflictList->SetTextValue(
_(
"Skip" ), i, 1 );
554 overwriteAllBtn->Bind( wxEVT_BUTTON, [&]( wxCommandEvent& ) {
555 for(
size_t i = 0; i < conflicts.size(); i++ )
557 conflictList->SetTextValue(
_(
"Overwrite" ), i, 1 );
562 conflictList->Bind( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [&]( wxDataViewEvent& evt ) {
563 int row = conflictList->ItemToRow( evt.GetItem() );
565 if( row >= 0 && row < (
int) conflicts.size() )
567 wxString action = conflictList->GetTextValue( row, 1 );
574 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.