more about management of lib files in defualt paths
This commit is contained in:
parent
dd4e90215e
commit
50d1bcb171
|
@ -26,7 +26,7 @@
|
|||
#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE wxDEFAULT_FRAME_STYLE|wxWANTS_CHARS
|
||||
|
||||
|
||||
#define LIB3D_PATH wxT("packages3d/")
|
||||
#define LIB3D_PATH wxT("packages3d")
|
||||
|
||||
class Pcb3D_GLCanvas;
|
||||
class WinEDA3D_DrawFrame;
|
||||
|
|
|
@ -1081,6 +1081,47 @@ void WinEDA_App::SaveLastVisitedLibraryPath( const wxString & aPath)
|
|||
s_LastVisitedLibPath = aPath;
|
||||
}
|
||||
|
||||
/** ReturnFilenameWithRelativePathInLibPath
|
||||
* @return a short filename (with extension) with only a relative path if this filename
|
||||
* can be found in library paths
|
||||
* @param aFullFilename = filename with path and extension.
|
||||
*/
|
||||
wxString WinEDA_App::ReturnFilenameWithRelativePathInLibPath(const wxString & aFullFilename)
|
||||
{
|
||||
/* If the library path is already in the library search paths
|
||||
* list, just add the library name to the list. Otherwise, add
|
||||
* the library name with the full or relative path.
|
||||
* the relative path, when possible is preferable,
|
||||
* because it preserve use of default libraries paths, when the path is a sub path of these default paths
|
||||
*
|
||||
*/
|
||||
wxFileName fn = aFullFilename;
|
||||
wxString filename = aFullFilename;
|
||||
int pathlen = -1; // path len, used to find the better subpath within defualts paths
|
||||
if( GetLibraryPathList().Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case
|
||||
filename = fn.GetName();
|
||||
else // not in the default, : see if this file is in a subpath:
|
||||
{
|
||||
filename = fn.GetPathWithSep() + fn.GetFullName();
|
||||
for( unsigned kk = 0; kk < wxGetApp().GetLibraryPathList().GetCount(); kk++ )
|
||||
{
|
||||
if( fn.MakeRelativeTo(GetLibraryPathList()[kk] ) )
|
||||
{
|
||||
if( pathlen < 0 // a subpath is found
|
||||
|| pathlen > (int) fn.GetPath().Len() ) // a better subpath if found
|
||||
{
|
||||
filename = fn.GetPathWithSep() + fn.GetFullName();
|
||||
pathlen = fn.GetPath().Len();
|
||||
}
|
||||
fn = aFullFilename; //Try to find a better subpath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** FindLibraryPath
|
||||
* Kicad saves user defined library files that are not in the standard
|
||||
|
|
|
@ -92,7 +92,7 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind
|
|||
m_buttonAdd->SetForegroundColour( wxColour( 13, 118, 1 ) );
|
||||
m_buttonAdd->SetToolTip( _("Add a new library after the selected library, and load it") );
|
||||
|
||||
bRightSizer->Add( m_buttonAdd, 0, wxALL, 5 );
|
||||
bRightSizer->Add( m_buttonAdd, 0, wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
m_buttonIns = new wxButton( this, wxID_ANY, _("Ins"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_buttonIns->SetForegroundColour( wxColour( 0, 65, 130 ) );
|
||||
|
@ -109,7 +109,7 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind
|
|||
m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_buttonCancel->SetForegroundColour( wxColour( 14, 0, 179 ) );
|
||||
|
||||
bRightSizer->Add( m_buttonCancel, 0, wxALL, 5 );
|
||||
bRightSizer->Add( m_buttonCancel, 0, wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
m_buttonSave = new wxButton( this, ID_SAVE_CFG, _("Save Cfg"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_buttonSave->SetToolTip( _("Accept and save current configuration setting in the local .pro file") );
|
||||
|
@ -146,10 +146,10 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind
|
|||
bUserPathsButtonsSizer = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_buttonBrowse = new wxButton( this, ID_LIB_PATH_SEL, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bUserPathsButtonsSizer->Add( m_buttonBrowse, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
|
||||
bUserPathsButtonsSizer->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
m_buttonRemovePath = new wxButton( this, wxID_ANY, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bUserPathsButtonsSizer->Add( m_buttonRemovePath, 0, wxALL, 5 );
|
||||
bUserPathsButtonsSizer->Add( m_buttonRemovePath, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
sbSizer4->Add( bUserPathsButtonsSizer, 0, wxEXPAND, 5 );
|
||||
|
||||
|
|
|
@ -668,7 +668,7 @@
|
|||
</object>
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="flag">wxRIGHT|wxLEFT</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="1">
|
||||
<property name="bg"></property>
|
||||
|
@ -834,7 +834,7 @@
|
|||
</object>
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="flag">wxRIGHT|wxLEFT</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="1">
|
||||
<property name="bg"></property>
|
||||
|
@ -1099,7 +1099,7 @@
|
|||
<property name="permission">none</property>
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL</property>
|
||||
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="1">
|
||||
<property name="bg"></property>
|
||||
|
@ -1151,7 +1151,7 @@
|
|||
</object>
|
||||
<object class="sizeritem" expanded="1">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="1">
|
||||
<property name="bg"></property>
|
||||
|
|
|
@ -774,30 +774,11 @@ void WinEDA_PartPropertiesFrame::BrowseAndSelectDocFile( wxCommandEvent& event )
|
|||
* the library name with the full or relative path.
|
||||
* the relative path, when possible is preferable,
|
||||
* because it preserve use of default libraries paths, when the path is a sub path of these default paths
|
||||
*
|
||||
*/
|
||||
wxFileName fn = FullFileName;
|
||||
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
||||
int pathlen = -1; // path len, used to find the better subpath within defualts paths
|
||||
if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case
|
||||
filename = fn.GetName();
|
||||
else // not in the default, : see if this file is in a subpath:
|
||||
{
|
||||
filename = fn.GetPathWithSep() + fn.GetName();
|
||||
for( unsigned kk = 0; kk < wxGetApp().GetLibraryPathList().GetCount(); kk++ )
|
||||
{
|
||||
if( fn.MakeRelativeTo( wxGetApp().GetLibraryPathList()[kk] ) )
|
||||
{
|
||||
if( pathlen < 0 // a subpath is found
|
||||
|| pathlen > (int) fn.GetPath().Len() ) // a better subpath if found
|
||||
{
|
||||
filename = fn.GetPathWithSep() + fn.GetFullName();
|
||||
pathlen = fn.GetPath().Len();
|
||||
}
|
||||
fn = FullFileName; //Try to find a better subpath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filename = wxGetApp().ReturnFilenameWithRelativePathInLibPath(FullFileName);
|
||||
m_Docfile->SetValue( filename );
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,13 @@ public:
|
|||
wxString ReturnLastVisitedLibraryPath( const wxString & aSubPathToSearch = wxEmptyString);
|
||||
void SaveLastVisitedLibraryPath( const wxString & aPath);
|
||||
|
||||
|
||||
/** ReturnFilenameWithRelativePathInLibPath
|
||||
* @return a short filename (with extension) with only a relative path if this filename
|
||||
* can be found in library paths
|
||||
* @param aFullFilename = filename with path and extension.
|
||||
*/
|
||||
wxString ReturnFilenameWithRelativePathInLibPath(const wxString & aFullFilename);
|
||||
|
||||
/** Function RemoveLibraryPath
|
||||
* Removes the given ptah from the libary path list
|
||||
* @param path = the path to remove
|
||||
|
|
|
@ -506,8 +506,16 @@ void Panel3D_Ctrl::Browse3DLib( wxCommandEvent& event )
|
|||
if( fullfilename == wxEmptyString )
|
||||
return;
|
||||
|
||||
shortfilename = MakeReducedFileName( fullfilename,
|
||||
fullpath, wxEmptyString );
|
||||
wxFileName fn = fullfilename;
|
||||
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
||||
|
||||
/* If the file path is already in the library search paths
|
||||
* list, just add the library name to the list. Otherwise, add
|
||||
* the library name with the full or relative path.
|
||||
* the relative path, when possible is preferable,
|
||||
* because it preserve use of default libraries paths, when the path is a sub path of these default paths
|
||||
*/
|
||||
shortfilename = wxGetApp().ReturnFilenameWithRelativePathInLibPath(fullfilename);
|
||||
m_3D_ShapeName->SetValue( shortfilename );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue