38#include <wx/checkbox.h>
40#include <wx/choicdlg.h>
42#include <wx/textdlg.h>
48 std::vector<LIB_ID>& aHistoryList ) :
WX_PANEL( aParent ), m_frame( aParent )
77 if( IsShownOnScreen() )
113 wxCHECK_MSG( prjLibs,
nullptr, wxS(
"Invalid design block library table." ) );
125 wxString msg = wxString::Format(
_(
"Error loading design block %s from library '%s'." ),
153 if( aTable ==
nullptr )
154 return wxEmptyString;
159 wxString initialPath = aProposedName;
161 if( initialPath.IsEmpty() )
164 if( aLibName.IsEmpty() )
171 return wxEmptyString;
180 if( !fn.IsAbsolute() )
182 fn.SetName( aLibName );
183 fn.MakeAbsolute( initialPath );
189 wxString libPath = fn.GetFullPath();
195 bool writable =
false;
200 writable = pi->IsLibraryWritable( libPath );
201 exists = fn.Exists();
212 wxString msg = wxString::Format(
_(
"Library %s is read only." ), libPath );
214 return wxEmptyString;
218 wxString msg = wxString::Format(
_(
"Library %s already exists." ), libPath );
219 KIDIALOG dlg(
m_frame, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
220 dlg.SetOKLabel(
_(
"Overwrite" ) );
224 return wxEmptyString;
226 pi->DeleteLibrary( libPath );
230 pi->CreateLibrary( libPath );
235 return wxEmptyString;
247 if( aTable ==
nullptr )
250 if( aTable ==
nullptr )
251 return wxEmptyString;
255 wxFileName fn( aFilename );
257 if( aFilename.IsEmpty() )
267 wxString libPath = fn.GetFullPath();
268 wxString libName = fn.GetName();
270 if( libName.IsEmpty() )
274 wxString description = wxGetTextFromUser(
_(
"Enter a description for the library:" ),
_(
"Library Description" ),
287 libName = fn.GetFullName();
309 LIB_ID libID( libName, wxEmptyString );
319 if( aLibName.IsEmpty() )
327 wxString msg = wxString::Format(
_(
"Library '%s' is read only." ), aLibName );
333 wxString msg = wxString::Format(
_(
"Delete design block library '%s' from disk? This will "
334 "delete all design blocks within the library." ),
335 aLibName.GetData() );
350 msg.Printf(
_(
"Design block library '%s' deleted" ), aLibName.GetData() );
369 wxString msg = wxString::Format(
_(
"Library '%s' is read only." ), libname );
375 wxString msg = wxString::Format(
_(
"Delete design block '%s' in library '%s' from disk?" ),
376 dbname.GetData(), libname.GetData() );
391 msg.Printf(
_(
"Design block '%s' deleted from library '%s'" ), dbname.GetData(), libname.GetData() );
411 wxString msg = wxString::Format(
_(
"Library '%s' is read only." ), libname );
431 if( originalName != newName )
458 wxString msg = wxString::Format(
_(
"Design block '%s' already exists in library '%s'." ),
459 newName.GetData(), libname.GetData() );
461 if(
OKOrCancelDialog( aFrame,
_(
"Confirmation" ), msg,
_(
"Overwrite existing design block?" ),
_(
"Overwrite" ) )
480 wxMessageDialog dlg(
m_frame,
_(
"Add the library to the global library table?" ),
481 _(
"Add To Global Library Table" ), wxYES_NO );
483 if( dlg.ShowModal() != wxID_OK )
490 wxArrayString libTableNames;
491 libTableNames.Add(
_(
"Global" ) );
492 libTableNames.Add(
_(
"Project" ) );
494 wxSingleChoiceDialog dlg(
m_frame,
_(
"Choose the Library Table to add the library to:" ),
495 _(
"Add To Library Table" ), libTableNames );
499 dlg.FindWindow( wxID_CANCEL )->SetLabel(
_(
"Skip" ) );
500 dlg.FindWindow( wxID_OK )->SetLabel(
_(
"Add" ) );
503 if( dlg.ShowModal() != wxID_OK )
506 switch( dlg.GetSelection() )
510 default:
return nullptr;
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
@ KICAD_SEXP
S-expression KiCad file format.
static const wxString ShowType(DESIGN_BLOCK_FILE_T aFileType)
static DESIGN_BLOCK_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
static DESIGN_BLOCK_IO * FindPlugin(DESIGN_BLOCK_FILE_T aFileType)
Hold a record identifying a library accessed by the appropriate design block library #PLUGIN object i...
void DesignBlockLibDelete(const wxString &aNickname)
static wxString GetGlobalTableFileName()
bool IsDesignBlockLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
void DesignBlockDelete(const wxString &aNickname, const wxString &aDesignBlockName)
Delete the aDesignBlockName from the library given by aNickname.
SAVE_T DesignBlockSave(const wxString &aNickname, const DESIGN_BLOCK *aDesignBlock, bool aOverwrite=true)
Write aDesignBlock to an existing library given by aNickname.
DESIGN_BLOCK * DesignBlockLoadWithOptionalNickname(const LIB_ID &aDesignBlockId, bool aKeepUUID=false)
Load a design block having aDesignBlockId with possibly an empty nickname.
bool DesignBlockExists(const wxString &aNickname, const wxString &aDesignBlockName)
Indicates whether or not the given design block already exists in the given library.
static DESIGN_BLOCK_LIB_TABLE & GetGlobalLibTable()
bool AddDesignBlockLibrary(const wxString &aFilename, DESIGN_BLOCK_LIB_TABLE *aTable)
Add an existing library to either the global or project library table.
bool DeleteDesignBlockLibrary(const wxString &aLibName, bool aConfirm)
bool checkOverwrite(wxWindow *aFrame, wxString &libname, wxString &newName)
bool DeleteDesignBlockFromLibrary(const LIB_ID &aLibId, bool aConfirm)
~DESIGN_BLOCK_PANE() override
void SelectLibId(const LIB_ID &aLibId)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
DESIGN_BLOCK_PANE(EDA_DRAW_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg)
Load design block from design block library table.
DESIGN_BLOCK_LIB_TABLE * selectDesignBlockLibTable(bool aOptional=false)
PANEL_DESIGN_BLOCK_CHOOSER * m_chooserPanel
bool EditDesignBlockProperties(const LIB_ID &aLibId)
virtual void setLabelsAndTooltips()=0
wxString createNewDesignBlockLibrary(const wxString &aLibName, const wxString &aProposedName, DESIGN_BLOCK_LIB_TABLE *aTable)
wxString CreateNewDesignBlockLibrary(const wxString &aLibName=wxEmptyString, const wxString &aProposedName=wxEmptyString)
If a library name is given, creates a new design block library in the project folder with the given n...
virtual void OnLanguageChanged(wxCommandEvent &aEvent)
DESIGN_BLOCK * GetSelectedDesignBlock(bool aUseCacheLib, bool aShowErrorMsg)
void OnClosed(wxAuiManagerEvent &aEvent)
const LIB_ID & GetLibId() const
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
The base class for create windows for drawing purpose.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
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()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void ShowChangedLanguage()
void RefreshLibs(bool aProgress=false)
void SelectLibId(const LIB_ID &aLibId)
static wxString GetDefaultUserDesignBlocksPath()
Gets the default path we point users to create projects.
virtual const wxString DesignBlockLibTblName() const
Return the path and file name of this projects design block library table.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual DESIGN_BLOCK_LIB_TABLE * DesignBlockLibs()
Return the table of design block libraries.
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
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.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
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.
static const std::string KiCadDesignBlockLibPathExtension
static wxString KiCadDesignBlockLibPathWildcard()
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
This file is part of the common library.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition of file extensions used in Kicad.