From ff68ae0bf88a5141fed6acfe80da002d109a50bd Mon Sep 17 00:00:00 2001 From: charras Date: Sat, 18 Apr 2009 14:14:40 +0000 Subject: [PATCH] Added: handling multiple user paths in library path list (currently, only in Eeschema) --- common/edaappl.cpp | 168 ++++++++++++++---------- eeschema/dialog_eeschema_config.cpp | 113 +++++++++++++--- eeschema/dialog_eeschema_config_fbp.cpp | 52 ++++---- eeschema/dialog_eeschema_config_fbp.fbp | 135 +++++++++++++------ eeschema/dialog_eeschema_config_fbp.h | 14 +- include/appl_wxstruct.h | 16 ++- 6 files changed, 324 insertions(+), 174 deletions(-) diff --git a/common/edaappl.cpp b/common/edaappl.cpp index a260a9b743..bbc97ef41f 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "appl_wxstruct.h" #include "common.h" @@ -46,7 +47,7 @@ static const wxChar* CommonConfigPath = wxT( "kicad_common" ); /* Just add new languages to the list. This macro will properly recalculate * the size of the array. */ #define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / \ - sizeof( struct LANGUAGE_DESCR ) ) + sizeof( struct LANGUAGE_DESCR ) ) /* Default font size */ #define FONT_DEFAULT_SIZE 10 /* Default font size. */ @@ -222,14 +223,14 @@ static struct LANGUAGE_DESCR s_Language_List[] = */ WinEDA_App::WinEDA_App() { - m_Checker = NULL; - m_HtmlCtrl = NULL; + m_Checker = NULL; + m_HtmlCtrl = NULL; m_EDA_Config = NULL; m_Env_Defined = FALSE; m_LanguageId = wxLANGUAGE_DEFAULT; m_PdfBrowserIsDefault = TRUE; m_Locale = NULL; - m_ProjectConfig = NULL; + m_ProjectConfig = NULL; m_EDA_CommonConfig = NULL; } @@ -267,9 +268,10 @@ WinEDA_App::~WinEDA_App() void WinEDA_App::InitEDA_Appl( const wxString& aName, id_app_type aId ) { wxString EnvLang; + m_Id = aId; m_Checker = new wxSingleInstanceChecker( aName.Lower() + wxT( "-" ) + - wxGetUserId() ); + wxGetUserId() ); /* Init kicad environment * the environment variable KICAD (if exists) gives the kicad path: @@ -297,7 +299,7 @@ void WinEDA_App::InitEDA_Appl( const wxString& aName, id_app_type aId ) SetVendorName( wxT( "kicad" ) ); SetAppName( aName.Lower() ); SetTitle( aName ); - m_EDA_Config = new wxConfig( ); + m_EDA_Config = new wxConfig(); wxASSERT( m_EDA_Config != NULL ); m_EDA_CommonConfig = new wxConfig( CommonConfigPath ); wxASSERT( m_EDA_CommonConfig != NULL ); @@ -443,7 +445,7 @@ bool WinEDA_App::SetBinDir() /* Use unix notation for paths. I am not sure this is a good idea, * but it simplify compatibility between Windows and Unices * However it is a potential problem in path handling under Windows - */ + */ m_BinDir.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); // Remove file name form command line: @@ -456,7 +458,7 @@ bool WinEDA_App::SetBinDir() wxLogDebug( wxT( "Windows path: " ) + wfn.GetFullPath() ); wxLogDebug( wxT( "Executable path the Kicad way: " ) + m_BinDir ); wxLogDebug( wxT( "Executable path the wxWidgets way: " ) + - GetTraits()->GetStandardPaths().GetExecutablePath() ); + GetTraits()->GetStandardPaths().GetExecutablePath() ); return TRUE; } @@ -474,6 +476,7 @@ void WinEDA_App::SetDefaultSearchPaths( void ) m_searchPaths.Clear(); #ifdef __WINDOWS__ + /* m_BinDir path is in unix notation. * But wxFileName expect (to work fine) native notation * specifically when using a path including a server, like @@ -509,10 +512,10 @@ void WinEDA_App::SetDefaultSearchPaths( void ) m_searchPaths.Add( fn.GetPath() ); /* The normal OS program file install paths allow for binary to be - * installed in a different path from the library files. This is - * useful for development purposes so the library and documentation - * files do not need to be installed separately. If someone can - * figure out a way to implement this without #ifdef, please do. */ + * installed in a different path from the library files. This is + * useful for development purposes so the library and documentation + * files do not need to be installed separately. If someone can + * figure out a way to implement this without #ifdef, please do. */ #ifdef __WXMSW__ tmp.AddEnvList( wxT( "PROGRAMFILES" ) ); #else @@ -545,7 +548,7 @@ void WinEDA_App::SetDefaultSearchPaths( void ) if( !wxFileName::IsDirReadable( m_searchPaths[i] ) ) { wxLogDebug( wxT( "Removing <" ) + m_searchPaths[i] + - wxT( "> from search path list." ) ); + wxT( "> from search path list." ) ); m_searchPaths.RemoveAt( i ); i -= 1; } @@ -553,25 +556,26 @@ void WinEDA_App::SetDefaultSearchPaths( void ) { fn.Clear(); fn.SetPath( m_searchPaths[i] ); + /* Add schematic library file path to search path list. - * we must add /library and /library/doc - */ - if ( m_Id == APP_TYPE_EESCHEMA ) + * we must add /library and /library/doc + */ + if( m_Id == APP_TYPE_EESCHEMA ) { - fn.AppendDir( wxT( "library") ); + fn.AppendDir( wxT( "library" ) ); if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to search path list" ), - fn.GetPath().c_str() ); + fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } /* Add schematic doc file path (library/doc)to search path list. */ - fn.AppendDir( wxT( "doc") ); + fn.AppendDir( wxT( "doc" ) ); if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to search path list" ), - fn.GetPath().c_str() ); + fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } fn.RemoveLastDir(); @@ -584,20 +588,20 @@ void WinEDA_App::SetDefaultSearchPaths( void ) if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to search path list" ), - fn.GetPath().c_str() ); + fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } fn.RemoveLastDir(); /* Add PCB library file path to search path list. */ - if ( ( m_Id == APP_TYPE_PCBNEW ) || ( m_Id == APP_TYPE_CVPCB ) ) + if( ( m_Id == APP_TYPE_PCBNEW ) || ( m_Id == APP_TYPE_CVPCB ) ) { fn.AppendDir( wxT( "modules" ) ); if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to library search path list" ), - fn.GetPath().c_str() ); + fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } @@ -607,7 +611,7 @@ void WinEDA_App::SetDefaultSearchPaths( void ) if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to search path list" ), - fn.GetPath().c_str() ); + fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } } @@ -791,21 +795,21 @@ void WinEDA_App::SetLanguagePath( void ) if( fn.DirExists() ) { wxLogDebug( wxT( "Adding locale lookup path: " ) + - fn.GetPath() ); + fn.GetPath() ); wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() ); } - // Append path for unix standard install + // Append path for unix standard install fn.RemoveLastDir(); - // Append path for unix standard install + // Append path for unix standard install fn.AppendDir( wxT( "kicad" ) ); fn.AppendDir( wxT( "internat" ) ); if( fn.DirExists() ) { wxLogDebug( wxT( "Adding locale lookup path: " ) + - fn.GetPath() ); + fn.GetPath() ); wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() ); } } @@ -834,7 +838,7 @@ void WinEDA_App::AddMenuLanguageList( wxMenu* MasterMenu ) for( ii = 0; ii < LANGUAGE_DESCR_COUNT; ii++ ) { wxString label; - if ( s_Language_List[ii].m_DoNotTranslate ) + if( s_Language_List[ii].m_DoNotTranslate ) label = s_Language_List[ii].m_Lang_Label; else label = wxGetTranslation( s_Language_List[ii].m_Lang_Label ); @@ -888,7 +892,7 @@ wxString WinEDA_App::FindFileInSearchPaths( const wxString& filename, if( fn.DirExists() ) { wxLogDebug( _T( "Adding <" ) + fn.GetPath() + _T( "> to " ) + - _T( "file \"" ) + filename + _T( "\" search path." ) ); + _T( "file \"" ) + filename + _T( "\" search path." ) ); paths.Add( fn.GetPath() ); } } @@ -963,11 +967,12 @@ wxString WinEDA_App::GetHelpFile( void ) { subdirs.RemoveAt( subdirs.GetCount() - 1 ); altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 ); - // wxLocale::GetName() does not return always the short name + + // wxLocale::GetName() does not return always the short name subdirs.Add( m_Locale->GetName().BeforeLast( '_' ) ); altsubdirs.Add( m_Locale->GetName().BeforeLast( '_' ) ); fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs ); - if ( ! fn ) + if( !fn ) fn = FindFileInSearchPaths( m_HelpFileName, &subdirs ); } @@ -979,7 +984,7 @@ wxString WinEDA_App::GetHelpFile( void ) subdirs.Add( _T( "en" ) ); altsubdirs.Add( _T( "en" ) ); fn = FindFileInSearchPaths( m_HelpFileName, &altsubdirs ); - if ( ! fn ) + if( !fn ) fn = FindFileInSearchPaths( m_HelpFileName, &subdirs ); } @@ -1001,38 +1006,39 @@ wxString WinEDA_App::GetLibraryFile( const wxString& filename ) return FindFileInSearchPaths( filename, &subdirs ); } + /** ReturnLastVisitedLibraryPath * Returns the last visited library directory, or (if void) the first * path in lib path list ( but not the CWD ) * @param aSubPathToSearch = Prefered sub path to search in path list (defualt = empty string) */ -wxString WinEDA_App::ReturnLastVisitedLibraryPath( const wxString & aSubPathToSearch ) +wxString WinEDA_App::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch ) { - if ( ! m_LastVisitedLibPath.IsEmpty() ) + if( !m_LastVisitedLibPath.IsEmpty() ) return m_LastVisitedLibPath; wxString path; - /* Initialize default path to the main default lib path - * this is the second path in list (the first is the project path) - */ + /* Initialize default path to the main default lib path + * this is the second path in list (the first is the project path) + */ unsigned pcount = m_libSearchPaths.GetCount(); - if ( pcount ) + if( pcount ) { unsigned ipath = 0; - if ( m_libSearchPaths[0] == wxGetCwd() ) + if( m_libSearchPaths[0] == wxGetCwd() ) ipath = 1; // First choice of path: - if ( ipath < pcount ) + if( ipath < pcount ) path = m_libSearchPaths[ipath]; // Search a sub path matching aSubPathToSearch - if ( ! aSubPathToSearch.IsEmpty() ) + if( !aSubPathToSearch.IsEmpty() ) { - for ( ; ipath < pcount; ipath++ ) + for( ; ipath < pcount; ipath++ ) { - if ( m_libSearchPaths[ipath].Contains( aSubPathToSearch ) ) + if( m_libSearchPaths[ipath].Contains( aSubPathToSearch ) ) { path = m_libSearchPaths[ipath]; break; @@ -1041,24 +1047,26 @@ wxString WinEDA_App::ReturnLastVisitedLibraryPath( const wxString & aSubPathToSe } } - if ( path.IsEmpty() ) + if( path.IsEmpty() ) path = wxGetCwd(); return path; } -void WinEDA_App::SaveLastVisitedLibraryPath( const wxString & aPath) + +void WinEDA_App::SaveLastVisitedLibraryPath( const wxString& aPath ) { m_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) +wxString WinEDA_App::ReturnFilenameWithRelativePathInLibPath( const wxString& aFullFilename ) { - /* If the library path is already in the library search paths + /* 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, @@ -1066,16 +1074,17 @@ wxString WinEDA_App::ReturnFilenameWithRelativePathInLibPath(const wxString & aF * */ wxFileName fn = aFullFilename; - wxString filename = aFullFilename; - int pathlen = -1; // path len, used to find the better subpath within defualts paths - if( m_libSearchPaths.Index( fn.GetPath() ) != wxNOT_FOUND ) // Ok, trivial case + wxString filename = aFullFilename; + int pathlen = -1; // path len, used to find the better subpath within defualts paths + + if( m_libSearchPaths.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 < m_libSearchPaths.GetCount(); kk++ ) { - if( fn.MakeRelativeTo(m_libSearchPaths[kk] ) ) + if( fn.MakeRelativeTo( m_libSearchPaths[kk] ) ) { if( pathlen < 0 // a subpath is found || pathlen > (int) fn.GetPath().Len() ) // a better subpath if found @@ -1108,37 +1117,50 @@ wxString WinEDA_App::FindLibraryPath( const wxString& aFileName ) return m_libSearchPaths.FindValidPath( aFileName ); } + /** Function RemoveLibraryPath - * Removes the given path from the library path list - * @param path = the path to remove + * Removes the given path(s) from the library path list + * @param aPaths = path or path list to remove. paths must be separated by ";" */ -void WinEDA_App::RemoveLibraryPath( const wxString& path ) +void WinEDA_App::RemoveLibraryPath( const wxString& aPaths ) { - if( m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND ) + wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) ); + + while( Token.HasMoreTokens() ) { - wxLogDebug( wxT( "Removing path <%s> from library path search list." ), - path.c_str() ); - m_libSearchPaths.Remove( path ); + wxString path = Token.GetNextToken(); + if( m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND ) + { + m_libSearchPaths.Remove( path ); + } } } -void WinEDA_App::InsertLibraryPath( const wxString& path, size_t index ) + +/** Function InsertLibraryPath + * insert path(s) int lib paths list. + * @param aPaths = path or path list to add. paths must be separated by ";" + * @param aIndex = insertion point + */ +void WinEDA_App::InsertLibraryPath( const wxString& aPaths, size_t aIndex ) { - if( wxFileName::DirExists( path ) - && m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND ) + wxStringTokenizer Token( aPaths, wxT( ";\n\r" ) ); + + while( Token.HasMoreTokens() ) { - if( index >= m_libSearchPaths.GetCount() ) + wxString path = Token.GetNextToken(); + if( wxFileName::DirExists( path ) + && m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND ) { - wxLogDebug( wxT( "Adding path <%s> to library path search list." ), - path.c_str() ); - m_libSearchPaths.Add( path ); - } - else - { - wxLogDebug( wxT( "Inserting path <%s> in library path search " \ - "list at index position %d." ), - path.c_str(), index ); - m_libSearchPaths.Insert( path, index ); + if( aIndex >= m_libSearchPaths.GetCount() ) + { + m_libSearchPaths.Add( path ); + } + else + { + m_libSearchPaths.Insert( path, aIndex ); + } + aIndex++; } } } diff --git a/eeschema/dialog_eeschema_config.cpp b/eeschema/dialog_eeschema_config.cpp index f1a2f80997..169d302bf5 100644 --- a/eeschema/dialog_eeschema_config.cpp +++ b/eeschema/dialog_eeschema_config.cpp @@ -9,6 +9,7 @@ ///////////////////////////////////////////////////////////////////////////// #include "fctsys.h" +#include #include "appl_wxstruct.h" #include "common.h" #include "confirm.h" @@ -30,6 +31,8 @@ class DIALOG_EESCHEMA_CONFIG : public DIALOG_EESCHEMA_CONFIG_FBP private: WinEDA_SchematicFrame* m_Parent; bool m_LibListChanged; + bool m_LibPathChanged; + wxString m_UserLibDirBufferImg; // Copy of original g_UserLibDirBuffer private: @@ -39,7 +42,7 @@ private: void OnSaveCfgClick( wxCommandEvent& event ); void OnRemoveLibClick( wxCommandEvent& event ); void OnAddOrInsertLibClick( wxCommandEvent& event ); - void OnLibPathSelClick( wxCommandEvent& event ); + void OnAddOrInsertPath( wxCommandEvent& event ); void OnOkClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event ); void OnRemoveUserPath( wxCommandEvent& event ); @@ -69,7 +72,6 @@ DIALOG_EESCHEMA_CONFIG::DIALOG_EESCHEMA_CONFIG( WinEDA_SchematicFrame* parent ) wxString msg; m_Parent = parent; - m_LibListChanged = false; Init(); @@ -88,6 +90,10 @@ void DIALOG_EESCHEMA_CONFIG::Init() SetFont( *g_DialogFont ); SetFocus(); + m_LibListChanged = false; + m_LibPathChanged = false; + m_UserLibDirBufferImg = g_UserLibDirBuffer; // Save the original lib path + // Display current files extension (info) wxString msg = m_InfoCmpFileExt->GetLabel() + g_NetCmpExtBuffer; m_InfoCmpFileExt->SetLabel( msg ); @@ -126,7 +132,15 @@ void DIALOG_EESCHEMA_CONFIG::Init() m_NetFormatBox->SetSelection( g_NetFormat - NET_TYPE_PCBNEW ); m_ListLibr->InsertItems( g_LibName_List, 0 ); - m_LibDirCtrl->SetValue( g_UserLibDirBuffer ); + + // Load user libs paths: + wxStringTokenizer Token( m_UserLibDirBufferImg, wxT( ";\n\r" ) ); + while( Token.HasMoreTokens() ) + { + wxString path = Token.GetNextToken(); + if( wxFileName::DirExists( path ) ) + m_listUserPaths->Append(path); + } // Display actual libraries paths: wxPathList libpaths = wxGetApp().GetLibraryPathList(); @@ -134,6 +148,10 @@ void DIALOG_EESCHEMA_CONFIG::Init() { m_DefaultLibraryPathslistBox->Append( libpaths[ii]); } + + // select the first path afer the current path project + if ( libpaths.GetCount() > 1 ) + m_DefaultLibraryPathslistBox->Select( 1 ); } @@ -141,6 +159,13 @@ void DIALOG_EESCHEMA_CONFIG::Init() void DIALOG_EESCHEMA_CONFIG::OnCancelClick( wxCommandEvent& event ) /******************************************************************/ { + // Recreate the user lib path + if ( m_LibPathChanged ) + { + for ( unsigned ii = 0; ii < m_ListLibr->GetCount(); ii ++ ) + wxGetApp().RemoveLibraryPath( m_listUserPaths->GetString(ii)) ; + wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1); + } EndModal( -1 ); } @@ -152,17 +177,21 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) // Set new netlist format g_NetFormat = m_NetFormatBox->GetSelection() + NET_TYPE_PCBNEW; - // Set new default path lib - if ( g_UserLibDirBuffer != m_LibDirCtrl->GetValue() ) + // Recreate the user lib path + if ( m_LibPathChanged ) { - wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer ); - g_UserLibDirBuffer = m_LibDirCtrl->GetValue(); - wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 ); - m_LibListChanged = true; + g_UserLibDirBuffer.Empty(); + for ( unsigned ii = 0; ii < m_listUserPaths->GetCount(); ii ++ ) + { + if ( ii > 0 ) + g_UserLibDirBuffer << wxT(";"); + g_UserLibDirBuffer << m_listUserPaths->GetString(ii); + } } - // Set new active library list if the list of default path was modified - if( m_LibListChanged ) + + // Set new active library list if the lib list of if default path list was modified + if( m_LibListChanged || m_LibPathChanged ) { // Recreate lib list g_LibName_List.Clear(); @@ -223,7 +252,8 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) if( ii == wxNOT_FOUND && event.GetId() != ID_ADD_LIB ) ii = 0; - wxString libpath = m_LibDirCtrl->GetValue(); + wxString libpath; + libpath = m_DefaultLibraryPathslistBox->GetStringSelection(); if ( libpath.IsEmpty() ) libpath = wxGetApp().ReturnLastVisitedLibraryPath(); @@ -295,14 +325,12 @@ void DIALOG_EESCHEMA_CONFIG::OnSaveCfgClick( wxCommandEvent& event ) /***********************************************************************/ -void DIALOG_EESCHEMA_CONFIG::OnLibPathSelClick( wxCommandEvent& event ) +void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event ) /***********************************************************************/ { - wxString path = m_LibDirCtrl->GetValue(); - if ( path.IsEmpty() ) - path = wxGetApp().ReturnLastVisitedLibraryPath(); + wxString path = wxGetApp().ReturnLastVisitedLibraryPath(); - bool select = EDA_DirectorySelector( _( " Default Path for libraries" ), /* Titre de la fenetre */ + bool select = EDA_DirectorySelector( _( "Default Path for Libraries" ), /* Titre de la fenetre */ path, /* Chemin par defaut */ wxDD_DEFAULT_STYLE, this, /* parent frame */ @@ -311,7 +339,36 @@ void DIALOG_EESCHEMA_CONFIG::OnLibPathSelClick( wxCommandEvent& event ) if( !select ) return; - m_LibDirCtrl->SetValue( path ); + if( ! wxFileName::DirExists( path ) ) // Should not occurs + return; + + // Add or insert path if not already in list + if( m_listUserPaths->FindString( path ) == wxNOT_FOUND ) + { + int ipos = m_listUserPaths->GetCount(); + if ( event.GetId() == wxID_INSERT_PATH ) + { + if ( ipos ) ipos--; + int jj = m_listUserPaths->GetSelection(); + if ( jj >= 0 ) + ipos = jj; + } + m_listUserPaths->Insert(path, ipos); + m_LibPathChanged = true; + wxGetApp().InsertLibraryPath( path, ipos+1 ); + + // Display actual libraries paths: + wxPathList libpaths = wxGetApp().GetLibraryPathList(); + m_DefaultLibraryPathslistBox->Clear(); + for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ ) + { + m_DefaultLibraryPathslistBox->Append( libpaths[ii]); + } + } + + else + DisplayError(this, _("Path already in use") ); + wxGetApp().SaveLastVisitedLibraryPath( path ); } @@ -321,5 +378,21 @@ void DIALOG_EESCHEMA_CONFIG::OnLibPathSelClick( wxCommandEvent& event ) void DIALOG_EESCHEMA_CONFIG::OnRemoveUserPath( wxCommandEvent& event ) /***********************************************************************/ { - m_LibDirCtrl->Clear( ); - } + int ii = m_listUserPaths->GetSelection(); + if ( ii < 0 ) + ii = m_listUserPaths->GetCount()-1; + if ( ii >= 0 ) + { + wxGetApp().RemoveLibraryPath( m_listUserPaths->GetStringSelection() ); + m_listUserPaths->Delete( ii ); + m_LibPathChanged = true; + } + + // Display actual libraries paths: + wxPathList libpaths = wxGetApp().GetLibraryPathList(); + m_DefaultLibraryPathslistBox->Clear(); + for( unsigned ii = 0; ii < libpaths.GetCount(); ii++ ) + { + m_DefaultLibraryPathslistBox->Append( libpaths[ii]); + } +} diff --git a/eeschema/dialog_eeschema_config_fbp.cpp b/eeschema/dialog_eeschema_config_fbp.cpp index e43d829072..0317377b0d 100644 --- a/eeschema/dialog_eeschema_config_fbp.cpp +++ b/eeschema/dialog_eeschema_config_fbp.cpp @@ -83,38 +83,33 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind bRightSizer = new wxBoxSizer( wxVERTICAL ); m_buttonRemoveLib = new wxButton( this, ID_REMOVE_LIB, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonRemoveLib->SetForegroundColour( wxColour( 186, 1, 38 ) ); m_buttonRemoveLib->SetToolTip( _("Unload the selected library") ); - bRightSizer->Add( m_buttonRemoveLib, 0, wxALL, 5 ); + bRightSizer->Add( m_buttonRemoveLib, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); - m_buttonAdd = new wxButton( this, ID_ADD_LIB, _("Add"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonAdd->SetForegroundColour( wxColour( 13, 118, 1 ) ); - m_buttonAdd->SetToolTip( _("Add a new library after the selected library, and load it") ); + m_buttonAddLib = new wxButton( this, ID_ADD_LIB, _("Add"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonAddLib->SetToolTip( _("Add a new library after the selected library, and load it") ); - bRightSizer->Add( m_buttonAdd, 0, wxRIGHT|wxLEFT, 5 ); + bRightSizer->Add( m_buttonAddLib, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_HORIZONTAL, 5 ); - m_buttonIns = new wxButton( this, wxID_ANY, _("Ins"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonIns->SetForegroundColour( wxColour( 0, 65, 130 ) ); + m_buttonIns = new wxButton( this, wxID_ANY, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonIns->SetToolTip( _("Add a new library before the selected library, and load it") ); - bRightSizer->Add( m_buttonIns, 0, wxALL, 5 ); + bRightSizer->Add( m_buttonIns, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); bRightSizer->Add( 0, 20, 1, wxEXPAND, 5 ); m_buttonOk = new wxButton( this, wxID_OK, _("Ok"), wxDefaultPosition, wxDefaultSize, 0 ); - bRightSizer->Add( m_buttonOk, 0, wxALL, 5 ); + bRightSizer->Add( m_buttonOk, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonCancel->SetForegroundColour( wxColour( 14, 0, 179 ) ); - - bRightSizer->Add( m_buttonCancel, 0, wxRIGHT|wxLEFT, 5 ); + bRightSizer->Add( m_buttonCancel, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_HORIZONTAL, 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") ); - bRightSizer->Add( m_buttonSave, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 ); + bRightSizer->Add( m_buttonSave, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); bUpperSizer->Add( bRightSizer, 0, wxALIGN_CENTER_VERTICAL, 5 ); @@ -135,21 +130,22 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind wxBoxSizer* bUserListSizer; bUserListSizer = new wxBoxSizer( wxVERTICAL ); - m_LibDirCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); - m_LibDirCtrl->SetToolTip( _("Default path to search libraries which have no absolute path in name,\nor a name which does not start by ./ or ../\nIf void, the default path is kicad/share/library") ); + m_listUserPaths = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); + bUserListSizer->Add( m_listUserPaths, 1, wxALL|wxEXPAND, 5 ); - bUserListSizer->Add( m_LibDirCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); - - sbSizer4->Add( bUserListSizer, 1, wxALIGN_CENTER_VERTICAL, 5 ); + sbSizer4->Add( bUserListSizer, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); wxBoxSizer* bUserPathsButtonsSizer; bUserPathsButtonsSizer = new wxBoxSizer( wxVERTICAL ); - m_buttonBrowse = new wxButton( this, ID_LIB_PATH_SEL, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 ); - bUserPathsButtonsSizer->Add( m_buttonBrowse, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); + m_buttonRemovePath = new wxButton( this, wxID_REMOVE_PATH, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 ); + bUserPathsButtonsSizer->Add( m_buttonRemovePath, 0, wxRIGHT|wxLEFT, 5 ); - m_buttonRemovePath = new wxButton( this, wxID_ANY, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 ); - bUserPathsButtonsSizer->Add( m_buttonRemovePath, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_buttonAddPath = new wxButton( this, ID_LIB_PATH_SEL, _("Add"), wxDefaultPosition, wxDefaultSize, 0 ); + bUserPathsButtonsSizer->Add( m_buttonAddPath, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); + + m_buttonInsPath = new wxButton( this, wxID_INSERT_PATH, _("Insert"), wxDefaultPosition, wxDefaultSize, 0 ); + bUserPathsButtonsSizer->Add( m_buttonInsPath, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); sbSizer4->Add( bUserPathsButtonsSizer, 0, wxEXPAND, 5 ); @@ -175,13 +171,14 @@ DIALOG_EESCHEMA_CONFIG_FBP::DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWind // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnCloseWindow ) ); m_buttonRemoveLib->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnRemoveLibClick ), NULL, this ); - m_buttonAdd->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); + m_buttonAddLib->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); m_buttonIns->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); m_buttonOk->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnOkClick ), NULL, this ); m_buttonCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnCancelClick ), NULL, this ); m_buttonSave->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnSaveCfgClick ), NULL, this ); - m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnLibPathSelClick ), NULL, this ); m_buttonRemovePath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnRemoveUserPath ), NULL, this ); + m_buttonAddPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertPath ), NULL, this ); + m_buttonInsPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertPath ), NULL, this ); } DIALOG_EESCHEMA_CONFIG_FBP::~DIALOG_EESCHEMA_CONFIG_FBP() @@ -189,11 +186,12 @@ DIALOG_EESCHEMA_CONFIG_FBP::~DIALOG_EESCHEMA_CONFIG_FBP() // Disconnect Events this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnCloseWindow ) ); m_buttonRemoveLib->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnRemoveLibClick ), NULL, this ); - m_buttonAdd->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); + m_buttonAddLib->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); m_buttonIns->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertLibClick ), NULL, this ); m_buttonOk->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnOkClick ), NULL, this ); m_buttonCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnCancelClick ), NULL, this ); m_buttonSave->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnSaveCfgClick ), NULL, this ); - m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnLibPathSelClick ), NULL, this ); m_buttonRemovePath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnRemoveUserPath ), NULL, this ); + m_buttonAddPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertPath ), NULL, this ); + m_buttonInsPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EESCHEMA_CONFIG_FBP::OnAddOrInsertPath ), NULL, this ); } diff --git a/eeschema/dialog_eeschema_config_fbp.fbp b/eeschema/dialog_eeschema_config_fbp.fbp index 90005e57b4..9015d26758 100644 --- a/eeschema/dialog_eeschema_config_fbp.fbp +++ b/eeschema/dialog_eeschema_config_fbp.fbp @@ -32,7 +32,7 @@ DIALOG_EESCHEMA_CONFIG_FBP - 593,500 + 593,559 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER @@ -616,14 +616,14 @@ none 5 - wxALL + wxALL|wxALIGN_CENTER_HORIZONTAL 0 0 1 - 186,1,38 + 0 ID_REMOVE_LIB @@ -668,21 +668,21 @@ 5 - wxRIGHT|wxLEFT + wxRIGHT|wxLEFT|wxALIGN_CENTER_HORIZONTAL 0 0 1 - 13,118,1 + 0 ID_ADD_LIB Add - m_buttonAdd + m_buttonAddLib protected @@ -720,18 +720,18 @@ 5 - wxALL + wxALL|wxALIGN_CENTER_HORIZONTAL 0 0 1 - 0,65,130 + 0 wxID_ANY - Ins + Insert m_buttonIns @@ -782,7 +782,7 @@ 5 - wxALL + wxALL|wxALIGN_CENTER_HORIZONTAL 0 @@ -834,14 +834,14 @@ 5 - wxRIGHT|wxLEFT + wxRIGHT|wxLEFT|wxALIGN_CENTER_HORIZONTAL 0 0 1 - 14,0,179 + 0 wxID_CANCEL @@ -886,7 +886,7 @@ 5 - wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND + wxALL|wxALIGN_CENTER_HORIZONTAL 0 @@ -1024,7 +1024,7 @@ 5 - wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxEXPAND 1 @@ -1033,10 +1033,11 @@ none 5 - wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND - 0 - + wxALL|wxEXPAND + 1 + + 1 @@ -1044,16 +1045,14 @@ 0 wxID_ANY - 0 - m_LibDirCtrl + m_listUserPaths protected - Default path to search libraries which have no absolute path in name, or a name which does not start by ./ or ../ If void, the default path is kicad/share/library - + @@ -1067,6 +1066,71 @@ + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 0 + + + bUserPathsButtonsSizer + wxVERTICAL + none + + 5 + wxRIGHT|wxLEFT + 0 + + + + 0 + 1 + + + 0 + wxID_REMOVE_PATH + Remove + + + m_buttonRemovePath + protected + + + + + + + + + OnRemoveUserPath + + + + + + + + + + @@ -1079,24 +1143,9 @@ - - - - - - - - 5 - wxEXPAND - 0 - - - bUserPathsButtonsSizer - wxVERTICAL - none 5 wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT @@ -1110,10 +1159,10 @@ 0 ID_LIB_PATH_SEL - Browse + Add - m_buttonBrowse + m_buttonAddPath protected @@ -1123,7 +1172,7 @@ - OnLibPathSelClick + OnAddOrInsertPath @@ -1161,11 +1210,11 @@ 0 - wxID_ANY - Remove + wxID_INSERT_PATH + Insert - m_buttonRemovePath + m_buttonInsPath protected @@ -1175,7 +1224,7 @@ - OnRemoveUserPath + OnAddOrInsertPath diff --git a/eeschema/dialog_eeschema_config_fbp.h b/eeschema/dialog_eeschema_config_fbp.h index 3f8dda9128..79e32a010e 100644 --- a/eeschema/dialog_eeschema_config_fbp.h +++ b/eeschema/dialog_eeschema_config_fbp.h @@ -21,7 +21,6 @@ #include #include #include -#include #include /////////////////////////////////////////////////////////////////////////// @@ -39,7 +38,9 @@ class DIALOG_EESCHEMA_CONFIG_FBP : public wxDialog ID_REMOVE_LIB = 1000, ID_ADD_LIB, ID_SAVE_CFG, + wxID_REMOVE_PATH, ID_LIB_PATH_SEL, + wxID_INSERT_PATH, }; wxStaticText* m_staticTextNetListFormats; @@ -53,16 +54,17 @@ class DIALOG_EESCHEMA_CONFIG_FBP : public wxDialog wxStaticText* m_staticTextlibList; wxListBox* m_ListLibr; wxButton* m_buttonRemoveLib; - wxButton* m_buttonAdd; + wxButton* m_buttonAddLib; wxButton* m_buttonIns; wxButton* m_buttonOk; wxButton* m_buttonCancel; wxButton* m_buttonSave; wxStaticLine* m_staticline1; - wxTextCtrl* m_LibDirCtrl; - wxButton* m_buttonBrowse; + wxListBox* m_listUserPaths; wxButton* m_buttonRemovePath; + wxButton* m_buttonAddPath; + wxButton* m_buttonInsPath; wxStaticText* m_staticTextcurrenpaths; wxListBox* m_DefaultLibraryPathslistBox; @@ -73,12 +75,12 @@ class DIALOG_EESCHEMA_CONFIG_FBP : public wxDialog virtual void OnOkClick( wxCommandEvent& event ){ event.Skip(); } virtual void OnCancelClick( wxCommandEvent& event ){ event.Skip(); } virtual void OnSaveCfgClick( wxCommandEvent& event ){ event.Skip(); } - virtual void OnLibPathSelClick( wxCommandEvent& event ){ event.Skip(); } virtual void OnRemoveUserPath( wxCommandEvent& event ){ event.Skip(); } + virtual void OnAddOrInsertPath( wxCommandEvent& event ){ event.Skip(); } public: - DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 593,500 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_EESCHEMA_CONFIG_FBP( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 593,559 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_EESCHEMA_CONFIG_FBP(); }; diff --git a/include/appl_wxstruct.h b/include/appl_wxstruct.h index 88ccba510d..5d2c1a61b3 100644 --- a/include/appl_wxstruct.h +++ b/include/appl_wxstruct.h @@ -185,13 +185,19 @@ public: * @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 + * Removes the given path(s) from the library path list + * @param aPaths = path or path list to remove. paths must be separated by ";" */ - void RemoveLibraryPath( const wxString& path ); - void InsertLibraryPath( const wxString& path, size_t index ); + void RemoveLibraryPath( const wxString& aPaths ); + + /** Function InsertLibraryPath + * insert path(s) int lib paths list. + * @param aPaths = path or path list to add. paths must be separated by ";" + * @param aIndex = insertion point + */ + void InsertLibraryPath( const wxString& aPaths, size_t aIndex ); }; /*