52#include <wx/filedlg.h>
89 wxString* aMRUDirectory,
const wxString& aProjectPath ) :
95 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
97 wxCHECK( aRow < (
int)
size(), );
108 if( pluginType != SCH_IO_MGR::SCH_FILE_UNKNOWN )
120 return wxEmptyString;
135 return wxString::Format(
_(
"Symbol Library Tables (%s)|*" ),
140 return wxEmptyString;
149 std::function<
void( wxCommandEvent& )> aAddHandler ) :
164 const wxString& options = row.
Options();
165 wxString
result = options;
166 std::map<std::string, UTF8> choices;
170 pi->GetLibraryOptions( &choices );
193 return wxT(
"(sym_lib_table" );
209 wxString projectPath =
m_project->GetProjectPath();
215 if(
table->Path().StartsWith( projectPath ) )
223 wxString* lastGlobalLibDir =
nullptr;
227 if( cfg->m_lastSymbolLibDir.IsEmpty() )
230 lastGlobalLibDir = &cfg->m_lastSymbolLibDir;
234 lastGlobalLibDir, wxEmptyString ),
240 [
this]( wxCommandEvent& event )
248 int prevWidth =
grid->GetColSize( aCol );
250 grid->AutoSizeColumn( aCol,
false );
251 grid->SetColSize( aCol, std::max( prevWidth,
grid->GetColSize( aCol ) ) );
260 if(
grid->GetNumberRows() > 0 )
263 grid->SelectRow( 0 );
275 for(
const SCH_IO_MGR::SCH_FILE_T& type : SCH_IO_MGR::SCH_FILE_T_vector )
288 wxASSERT(
table.has_value() );
295 if( projectTable.has_value() )
296 AddTable( projectTable.value(),
_(
"Project Specific Libraries" ),
false );
353 for(
int page = 0 ; page < (int)
m_notebook->GetPageCount(); ++page )
358 [&](
int aRow,
int aCol )
364 grid->MakeCellVisible( aRow, 0 );
365 grid->SetGridCursor( aRow, aCol );
378 if( !
cur_grid()->CommitPendingChanges() )
381 wxString fileFiltersStr;
382 wxString allWildcardsStr;
384 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
396 if( !fileFiltersStr.IsEmpty() )
397 fileFiltersStr += wxChar(
'|' );
405 fileFiltersStr =
_(
"All supported formats" ) + wxT(
"|" ) + allWildcardsStr + wxT(
"|" )
417 wxWindow* topLevelParent = wxGetTopLevelParent(
this );
419 wxFileDialog dlg( topLevelParent,
_(
"Add Library" ), *lastDir, wxEmptyString, fileFiltersStr,
420 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
422 if( dlg.ShowModal() == wxID_CANCEL )
425 *lastDir = dlg.GetDirectory();
428 bool addDuplicates =
false;
429 bool applyToAll =
false;
431 wxArrayString filePathsList;
432 dlg.GetPaths( filePathsList );
434 for(
const wxString& filePath : filePathsList )
436 wxFileName fn( filePath );
440 if(
cur_model()->ContainsNickname( nickname ) )
445 addDuplicates =
OKOrCancelDialog( wxGetTopLevelParent(
this ),
_(
"Warning: Duplicate Nickname" ),
446 wxString::Format(
_(
"An item nicknamed '%s' already exists." ),
448 _(
"One of the nicknames will need to be changed." ),
449 _(
"Skip" ),
_(
"Add Anyway" ),
450 &applyToAll ) == wxID_CANCEL;
453 doAdd = addDuplicates;
456 if( doAdd &&
cur_grid()->AppendRows( 1 ) )
458 int last_row =
cur_grid()->GetNumberRows() - 1;
465 if( pluginType != SCH_IO_MGR::SCH_FILE_UNKNOWN )
473 if(
m_notebook->GetSelection() == 0 &&
path.Contains(
"${KIPRJMOD}" ) )
474 path = fn.GetFullPath();
480 if( !filePathsList.IsEmpty() )
514 if( !
cur_grid()->CommitPendingChanges() )
520 if(
grid->GetNumberRows() > 0 && !
IsOK(
this, wxString::Format(
_(
"This action will reset your global library "
521 "table on disk and cannot be undone." ) ) ) )
526 wxString* lastGlobalLibDir =
nullptr;
530 if( cfg->m_lastSymbolLibDir.IsEmpty() )
533 lastGlobalLibDir = &cfg->m_lastSymbolLibDir;
542 schface->PreloadLibraries( &
m_parent->Kiway() );
546 wxGridTableBase*
table =
grid->GetTable();
551 wxASSERT( newTable );
556 lastGlobalLibDir, wxEmptyString ),
559 m_parent->m_GlobalTableChanged =
true;
563 if(
grid->GetNumberRows() > 0 )
566 grid->SelectRow( 0 );
579 wxAuiNotebook* notebook = (wxAuiNotebook*) aEvent.GetEventObject();
580 wxWindow* page = notebook->GetPage( aEvent.GetSelection() );
584 if( panel->GetClosable() )
586 if( !panel->GetCanClose() )
599 if( !
cur_grid()->CommitPendingChanges() )
602 wxArrayInt selectedRows =
cur_grid()->GetSelectedRows();
604 if( selectedRows.empty() &&
cur_grid()->GetGridCursorRow() >= 0 )
605 selectedRows.push_back(
cur_grid()->GetGridCursorRow() );
607 wxArrayInt legacyRows;
612 for(
int row : selectedRows )
617 legacyRows.push_back( row );
621 if( legacyRows.size() <= 0 )
623 wxMessageBox(
_(
"Select one or more rows containing libraries to save as current KiCad format." ) );
628 if( legacyRows.size() == 1 )
630 msg.Printf(
_(
"Save '%s' as current KiCad format (*.kicad_sym) and replace legacy entry in table?" ),
635 msg.Printf(
_(
"Save %d libraries as current KiCad format (*.kicad_sym) and replace legacy entries "
637 (
int) legacyRows.size() );
644 for(
int row : legacyRows )
648 wxFileName legacyLib( resolvedPath );
650 if( !legacyLib.Exists() )
656 wxFileName newLib( resolvedPath );
657 newLib.SetExt(
"kicad_sym" );
659 if( newLib.Exists() )
661 msg.Printf(
_(
"File '%s' already exists. Do you want overwrite this file?" ), newLib.GetFullPath() );
663 switch( wxMessageBox( msg,
_(
"Migrate Library" ), wxYES_NO | wxCANCEL | wxICON_QUESTION,
m_parent ) )
667 case wxCANCEL:
return;
685 newLib.GetFullPath() ) );
693 if( !
cur_grid()->CommitPendingChanges() )
701 wxCHECK( optTable,
false );
704 if(
get_model( 0 )->Table() != *globalTable )
706 m_parent->m_GlobalTableChanged =
true;
709 globalTable->
Save().map_error(
712 wxMessageBox(
_(
"Error saving global library table:\n\n" ) + aError.
message,
713 _(
"File Save Error" ), wxOK | wxICON_ERROR );
719 if( optTable.has_value() &&
get_model( 1 )->Table().Path() == optTable.value()->Path() )
723 if(
get_model( 1 )->Table() != *projectTable )
725 m_parent->m_ProjectTableChanged =
true;
728 projectTable->
Save().map_error(
731 wxMessageBox(
_(
"Error saving project-specific library table:\n\n" ) + aError.
message,
732 _(
"File Save Error" ), wxOK | wxICON_ERROR );
737 for(
int ii = 0; ii < (int)
m_notebook->GetPageCount(); ++ii )
744 m_parent->m_GlobalTableChanged =
true;
745 m_parent->m_ProjectTableChanged =
true;
755 wxRegEx re(
".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED );
756 wxASSERT( re.IsValid() );
758 std::set< wxString > unique;
763 for(
int page = 0 ; page < (int)
m_notebook->GetPageCount(); ++page )
771 while( re.Matches( uri ) )
773 wxString envvar = re.GetMatch( uri, 2 );
776 if( envvar.IsEmpty() )
777 envvar = re.GetMatch( uri, 4 );
780 unique.insert( envvar );
783 uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
794 for(
const wxString& evName : unique )
799 m_path_subs_grid->SetCellValue( row, 0, wxT(
"${" ) + evName + wxT(
"}" ) );
803 wxGetEnv( evName, &evValue );
839 symbolEditor->FreezeLibraryTree();
841 if( symbolEditor->HasLibModifications() )
843 msg =
_(
"Modifications have been made to one or more symbol libraries.\n"
844 "Changes must be saved or discarded before the symbol library table can be modified." );
848 case wxID_YES: symbolEditor->SaveAll();
break;
849 case wxID_NO: symbolEditor->RevertAll();
break;
851 case wxID_CANCEL: symbolEditor->ThawLibraryTree();
return;
864 symbolEditor->ThawLibraryTree();
880 schface->PreloadLibraries( aKiway );
883 symbolEditor->ThawLibraryTree();
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
bool m_ProjectTableChanged
void InstallPanel(wxPanel *aPanel)
bool m_GlobalTableChanged
An options editor in the form of a two column name/value spreadsheet like (table) UI.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
wxString m_lastSymbolLibDir
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
WX_GRID * m_grid
I don't own the grid, but he owns me.
void SetTooltipEnable(int aCol, bool aEnable=true)
Enable the tooltip for a column.
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
static wxString ExpandURI(const wxString &aShortURI, const PROJECT &aProject)
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
static bool CreateGlobalTable(LIBRARY_TABLE_TYPE aType, bool aPopulateDefaultLibraries)
void LoadGlobalTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the global library tables in the given list, or all tables if no list is given
void ProjectChanged()
Notify all adapters that the project has changed.
void SetOptions(const wxString &aOptions)
const wxString & Type() const
static const wxString TABLE_TYPE_NAME
const wxString & URI() const
const wxString & Nickname() const
const wxString & Options() const
LIBRARY_RESULT< void > Save()
static std::map< std::string, UTF8 > ParseOptions(const std::string &aOptionsList)
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
This abstract base class mixes any object derived from #LIB_TABLE into wxGridTableBase so the result ...
virtual LIBRARY_TABLE_ROW & at(size_t aIndex)
int GetNumberRows() override
virtual size_t size() const
wxString GetValue(int aRow, int aCol) override
LIBRARY_TABLE_ROW & At(size_t aIndex)
void SetValue(int aRow, int aCol, const wxString &aValue) override
LIB_TABLE_GRID_DATA_MODEL(DIALOG_SHIM *aParent, WX_GRID *aGrid, const LIBRARY_TABLE &aTableToEdit, LIBRARY_MANAGER_ADAPTER *aAdapter, const wxArrayString &aPluginChoices, wxString *aMRUDirectory, const wxString &aProjectPath)
static void MoveUpHandler(WX_GRID *aGrid)
LIB_TABLE_GRID_TRICKS(WX_GRID *aGrid)
static void DeleteRowHandler(WX_GRID *aGrid)
static bool VerifyTable(WX_GRID *aGrid, std::function< void(int aRow, int aCol)> aErrorHandler)
static void AppendRowHandler(WX_GRID *aGrid)
static void MoveDownHandler(WX_GRID *aGrid)
static void AddTable(wxAuiNotebook *aNotebook, const wxString &aTitle, bool aClosable)
PANEL_SYM_LIB_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
STD_BITMAP_BUTTON * m_browse_button
STD_BITMAP_BUTTON * m_move_up_button
wxAuiNotebook * m_notebook
STD_BITMAP_BUTTON * m_delete_button
STD_BITMAP_BUTTON * m_move_down_button
STD_BITMAP_BUTTON * m_append_button
WX_GRID * m_path_subs_grid
Dialog to show and edit symbol library tables.
void moveUpHandler(wxCommandEvent &event) override
SYMBOL_LIB_TABLE_GRID_DATA_MODEL * get_model(int aPage) const
virtual ~PANEL_SYM_LIB_TABLE()
void onReset(wxCommandEvent &event) override
void deleteRowHandler(wxCommandEvent &event) override
WX_GRID * get_grid(int aPage) const
wxString m_lastProjectLibDir
void onNotebookPageCloseRequest(wxAuiNotebookEvent &aEvent)
void onPageChange(wxAuiNotebookEvent &event) override
void browseLibrariesHandler(wxCommandEvent &event) override
void AddTable(LIBRARY_TABLE *table, const wxString &aTitle, bool aClosable)
bool verifyTables()
Trim important fields, removes blank row entries, and checks for duplicates.
void adjustPathSubsGridColumns(int aWidth)
void onSizeGrid(wxSizeEvent &event) override
void onConvertLegacyLibraries(wxCommandEvent &event) override
bool TransferDataToWindow() override
wxArrayString m_pluginChoices
void moveDownHandler(wxCommandEvent &event) override
PANEL_SYM_LIB_TABLE(DIALOG_EDIT_LIBRARY_TABLES *aParent, PROJECT *m_project)
SYMBOL_LIB_TABLE_GRID_DATA_MODEL * cur_model() const
void populateEnvironReadOnlyTable()
Populate the readonly environment variable table with names and values by examining all the full_uri ...
WX_GRID * cur_grid() const
DIALOG_EDIT_LIBRARY_TABLES * m_parent
bool TransferDataFromWindow() override
void appendRowHandler(wxCommandEvent &event) override
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath)
Convert a schematic symbol library to the latest KiCad format.
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
The symbol library editor main window.
SYMBOL_GRID_TRICKS(PANEL_SYM_LIB_TABLE *aPanel, WX_GRID *aGrid, std::function< void(wxCommandEvent &)> aAddHandler)
bool supportsVisibilityColumn() override
wxString getTablePreamble() override
PANEL_SYM_LIB_TABLE * m_panel
void openTable(const LIBRARY_TABLE_ROW &aRow) override
void optionsEditor(int aRow) override
An interface to the global shared library manager that is schematic-specific and linked to one projec...
SYMBOL_LIB_TABLE_GRID_DATA_MODEL(DIALOG_SHIM *aParent, WX_GRID *aGrid, const LIBRARY_TABLE &aTableToEdit, SYMBOL_LIBRARY_ADAPTER *aAdapter, const wxArrayString &aPluginChoices, wxString *aMRUDirectory, const wxString &aProjectPath)
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxString getFileTypes(WX_GRID *aGrid, int aRow) override
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
int UnsavedChangesDialog(wxWindow *parent, const wxString &aMessage, bool *aApplyToAll)
A specialized version of HandleUnsavedChanges which handles an apply-to-all checkbox.
This file is part of the common library.
@ ID_END_EESCHEMA_ID_LIST
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Helper functions to substitute paths with environmental variables.
Functions related to environment variables, including help functions.
@ FRAME_SCH_SYMBOL_EDITOR
static const std::string SymbolLibraryTableFileName
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Construct a versioned environment variable based on this KiCad major version.
void InvokeSchEditSymbolLibTable(KIWAY *aKiway, wxWindow *aParent)
@ ID_PANEL_SYM_LIB_LEGACY
SETTINGS_MANAGER * GetSettingsManager()
PGM_BASE & Pgm()
The global program "get" accessor.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
Container that describes file type info.
bool m_IsFile
Whether the library is a folder or a file.
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
wxString FileFilter() const
Implement a participant in the KIWAY alchemy.
Container that describes file type info for the add a library options.
bool m_IsFile
Whether the library is a folder or a file.
wxString m_Description
Description shown in the file picker dialog.
wxString m_FileFilter
Filter used for file pickers if m_IsFile is true.
DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T m_Plugin
wxString m_FolderSearchExtension
In case of folders it stands for extensions of files stored inside.
wxString result
Test unit parsing edge cases and error handling.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
Definition of file extensions used in Kicad.