Commit 6f631976 authored by charras's avatar charras

eeschema: now display lib list in alphabetic order in viewlib and get component.

Solved a minor bug in Search in lib command when attempt to search a component name in non loaded libraries
parent d31c0995
...@@ -257,30 +257,6 @@ void FreeCmpLibrary (wxWindow* frame, const wxString& LibName) ...@@ -257,30 +257,6 @@ void FreeCmpLibrary (wxWindow* frame, const wxString& LibName)
} }
/******************************/
/** GetLibNames()
* Routine to return pointers to all library names.
* User is responsible to deallocate memory
*/
/******************************/
const wxChar** GetLibNames()
{
int ii, NumOfLibs = NumOfLibraries();
const wxChar** Names;
LibraryStruct* Lib;
Names = (const wxChar**) MyZMalloc( sizeof(wxChar*) * (NumOfLibs + 1) );
for( ii = 0, Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext, ii++ )
{
Names[ii] = Lib->m_Name.GetData();
}
Names[ii] = NULL;
return Names;
}
/** Function LibraryEntryCompare /** Function LibraryEntryCompare
* Routine to compare two EDA_LibComponentStruct for the PriorQue module. * Routine to compare two EDA_LibComponentStruct for the PriorQue module.
* Comparison (insensitive case) is based on Part name. * Comparison (insensitive case) is based on Part name.
......
...@@ -627,12 +627,12 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem( ...@@ -627,12 +627,12 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
/*************************************************************/ /*************************************************************/
/* Recherche exhaustive d'un composant en librairies, meme non chargees /* Search for a given component.
* The serach is made in loaded libraries,
* and if not found in all libraries found in lib paths.
*/ */
{ {
wxString Text, FindList; wxString Text, FindList;
const wxChar** ListNames;
LibraryStruct* Lib = NULL;
EDA_LibComponentStruct* LibEntry; EDA_LibComponentStruct* LibEntry;
bool FoundInLib = FALSE; // True si reference trouvee ailleurs qu'en cache bool FoundInLib = FALSE; // True si reference trouvee ailleurs qu'en cache
...@@ -643,33 +643,23 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) ...@@ -643,33 +643,23 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
} }
s_OldStringFound = Text; s_OldStringFound = Text;
int ii, nbitems, NumOfLibs = NumOfLibraries(); if( NumOfLibraries() == 0 )
if( NumOfLibs == 0 )
{ {
DisplayError( this, _( "No libraries are loaded" ) ); DisplayError( this, _( "No libraries are loaded" ) );
Close(); return; Close(); return;
} }
ListNames = GetLibNames();
int nbitemsFound = 0;
nbitems = 0; for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
for( ii = 0; ii < NumOfLibs; ii++ ) /* Recherche de la librairie */
{ {
bool IsLibCache;
Lib = FindLibrary( ListNames[ii] );
if( Lib == NULL )
break;
if( Lib->m_Name.Contains( wxT( ".cache" ) ) )
IsLibCache = TRUE;
else
IsLibCache = FALSE;
LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE ); LibEntry = (EDA_LibComponentStruct*) PQFirst( &Lib->m_Entries, FALSE );
while( LibEntry ) while( LibEntry )
{ {
if( WildCompareString( Text, LibEntry->m_Name.m_Text, FALSE ) ) if( WildCompareString( Text, LibEntry->m_Name.m_Text, FALSE ) )
{ {
nbitems++; nbitemsFound++;
if( !IsLibCache ) if( !Lib->m_IsLibCache )
FoundInLib = TRUE; FoundInLib = TRUE;
if( !FindList.IsEmpty() ) if( !FindList.IsEmpty() )
FindList += wxT( "\n" ); FindList += wxT( "\n" );
...@@ -681,11 +671,9 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) ...@@ -681,11 +671,9 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event )
} }
} }
free( ListNames );
if( !FoundInLib ) if( !FoundInLib )
{ {
if( nbitems ) if( nbitemsFound )
FindList = wxT( "\n" ) + Text + _( " found only in cache" ); FindList = wxT( "\n" ) + Text + _( " found only in cache" );
else else
FindList = Text + _( " not found" ); FindList = Text + _( " not found" );
...@@ -719,7 +707,7 @@ int WinEDA_FindFrame::ExploreAllLibraries( const wxString& wildmask, wxString& F ...@@ -719,7 +707,7 @@ int WinEDA_FindFrame::ExploreAllLibraries( const wxString& wildmask, wxString& F
for( unsigned ii = 0; ii < wxGetApp().GetLibraryPathList().GetCount(); ii++ ) for( unsigned ii = 0; ii < wxGetApp().GetLibraryPathList().GetCount(); ii++ )
{ {
path = wxGetApp().GetLibraryPathList()[ii]; path = wxGetApp().GetLibraryPathList()[ii] + STRING_DIR_SEP;
FullFileName = wxFindFirstFile( path + wxT( "*." ) + CompLibFileExtension ); FullFileName = wxFindFirstFile( path + wxT( "*." ) + CompLibFileExtension );
while( !FullFileName.IsEmpty() ) while( !FullFileName.IsEmpty() )
......
...@@ -80,7 +80,6 @@ LibraryStruct * LoadLibraryName(WinEDA_DrawFrame * frame, ...@@ -80,7 +80,6 @@ LibraryStruct * LoadLibraryName(WinEDA_DrawFrame * frame,
const wxString & FullLibName, const wxString & LibName); const wxString & FullLibName, const wxString & LibName);
void LoadLibraries( WinEDA_SchematicFrame* frame ); void LoadLibraries( WinEDA_SchematicFrame* frame );
void FreeCmpLibrary(wxWindow * frame, const wxString & LibName); void FreeCmpLibrary(wxWindow * frame, const wxString & LibName);
const wxChar **GetLibNames();
void SnapLibItemPoint(int OrigX, int OrigY, int *ClosestX, int *ClosestY, void SnapLibItemPoint(int OrigX, int OrigY, int *ClosestX, int *ClosestY,
SCH_COMPONENT *DrawLibItem); SCH_COMPONENT *DrawLibItem);
......
...@@ -114,22 +114,19 @@ bool SCH_SCREEN::Save( FILE* aFile ) const ...@@ -114,22 +114,19 @@ bool SCH_SCREEN::Save( FILE* aFile ) const
* @return bool - true if success writing else false. * @return bool - true if success writing else false.
*/ */
{ {
const wxChar** LibNames;
wxString Name, msg; wxString Name, msg;
Ki_PageDescr* PlotSheet; Ki_PageDescr* PlotSheet;
wxString datetime = DateAndTime( ); wxString datetime = DateAndTime( );
bool first = true;
LibNames = GetLibNames(); for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
for( int ii = 0; LibNames[ii] != NULL; ii++ )
{ {
if( ii > 0 ) if( first )
Name += wxT( "," ); Name += wxT( "," );
Name += LibNames[ii]; Name += Lib->m_Name;
first = false;
} }
MyFree( LibNames );
// Creates header // Creates header
if( fprintf( aFile, "%s %s %d", EESCHEMA_FILE_STAMP, if( fprintf( aFile, "%s %s %d", EESCHEMA_FILE_STAMP,
SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) == EOF ) SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) == EOF )
......
...@@ -24,15 +24,15 @@ ...@@ -24,15 +24,15 @@
/***************************************************************/ /***************************************************************/
LibraryStruct * SelectLibraryFromList(WinEDA_DrawFrame * frame) LibraryStruct * SelectLibraryFromList(WinEDA_DrawFrame * frame)
/***************************************************************/ /***************************************************************/
/* Routine pour selectionner une librairie a partir d'une liste /** Function SelectLibraryFromList
* Displays a list of current loaded libraries, and allows the user to select a library
* This list is sorted, with the library cache always at end of the list
*/ */
{ {
int ii, NumOfLibs = NumOfLibraries(); int ii, NumOfLibs = NumOfLibraries();
LibraryStruct *Lib = NULL; LibraryStruct *Lib = NULL;
static wxString OldLibName; static wxString OldLibName;
WinEDAListBox * ListBox;
wxString LibName; wxString LibName;
const wxChar ** ListNames;
if (NumOfLibs == 0) if (NumOfLibs == 0)
{ {
...@@ -40,20 +40,38 @@ const wxChar ** ListNames; ...@@ -40,20 +40,38 @@ const wxChar ** ListNames;
return(NULL) ; return(NULL) ;
} }
ListNames = GetLibNames(); WinEDAListBox ListBox(frame, _("Select Lib"),
ListBox = new WinEDAListBox(frame, _("Select Lib"), NULL, OldLibName, NULL,
ListNames, OldLibName, NULL,
wxColour(255,255,255)); // Library browser background color wxColour(255,255,255)); // Library browser background color
ListBox->MoveMouseToOrigin();
ii = ListBox->ShowModal(); ListBox->Destroy(); wxArrayString libNamesList;
LibraryStruct * libcache = NULL;
for( LibraryStruct * Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{
if ( Lib->m_IsLibCache )
libcache = Lib;
else
libNamesList.Add( Lib->m_Name );
}
libNamesList.Sort();
// Add lib cache
if ( libcache )
libNamesList.Add( libcache->m_Name );
ListBox.InsertItems(libNamesList);
ListBox.MoveMouseToOrigin();
ii = ListBox.ShowModal();
if (ii >= 0) /* Recherche de la librairie */ if (ii >= 0) /* Recherche de la librairie */
{ {
Lib = FindLibrary(ListNames[ii]); Lib = FindLibrary(libNamesList[ii]);
} }
free (ListNames);
return(Lib); return(Lib);
} }
......
...@@ -302,22 +302,44 @@ int WinEDA_ViewlibFrame::BestZoom() ...@@ -302,22 +302,44 @@ int WinEDA_ViewlibFrame::BestZoom()
/******************************************/ /******************************************/
void WinEDA_ViewlibFrame::ReCreateListLib() void WinEDA_ViewlibFrame::ReCreateListLib()
/******************************************/ /******************************************/
/** Function ReCreateListLib
* Creates or recreates the list of current loaded libraries.
* This list is sorted, with the library cache always at end of the list
*/
{ {
int ii; LibraryStruct * libcache = NULL;
LibraryStruct* Lib;
bool found = FALSE; bool found = FALSE;
if( m_LibList == NULL ) if( m_LibList == NULL )
return; return;
m_LibList->Clear(); m_LibList->Clear();
for( ii = 0, Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext, ii++ )
wxArrayString libNamesList;
for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{ {
m_LibList->Append(Lib->m_Name); if ( Lib->m_IsLibCache )
if( g_CurrentViewLibraryName.Cmp( Lib->m_Name ) == 0 ) libcache = Lib;
else
libNamesList.Add( Lib->m_Name );
}
libNamesList.Sort();
// Add lib cache
if ( libcache )
libNamesList.Add( libcache->m_Name );
m_LibList->Append(libNamesList);
// Search for a previous selection:
for ( unsigned ii = 0; ii < m_LibList->GetCount(); ii++ )
{
if( g_CurrentViewLibraryName.Cmp( m_LibList->GetString(ii) ) == 0 )
{ {
m_LibList->SetSelection( ii, TRUE ); m_LibList->SetSelection( ii, TRUE );
found = TRUE; found = TRUE;
break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment