Commit 8cb34232 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Remove class RETAINED_PATH, put is main member function into SEARCH_STACK.

Change class PROJECT to use a generalized wxString in place of the
RETAINED_PATH items, so that new session and project specific strings
of any purpose can be saved there, for the life of a session.
parent 53cd19a6
......@@ -69,5 +69,9 @@ Dick's Final TODO List:
https://blueprints.launchpad.net/kicad/+spec/modular-kicad
Issues as a result of minimal testing:
If eeschema launched from C++ project manager and does not find all libraries,
* If eeschema launched from C++ project manager and does not find all libraries,
then the dialog showing the names of missing libraries is shown twice.
* Clear all/some? retained strings on project change.
* Clear the FP_LIB_TABLE when the last KIWAY_PLAYER using it is closed.
......@@ -133,17 +133,32 @@ const wxString PROJECT::FootprintLibTblName() const
}
RETAINED_PATH& PROJECT::RPath( RETPATH_T aIndex )
void PROJECT::SetRString( RSTRING_T aIndex, const wxString& aString )
{
unsigned ndx = unsigned( aIndex );
if( ndx < DIM( m_rpaths ) )
if( ndx < DIM( m_rstrings ) )
{
return m_rpaths[ndx];
m_rstrings[ndx] = aString;
}
else
{
static RETAINED_PATH no_cookie_for_you;
wxASSERT( 0 ); // bad index
}
}
const wxString& PROJECT::GetRString( RSTRING_T aIndex )
{
unsigned ndx = unsigned( aIndex );
if( ndx < DIM( m_rstrings ) )
{
return m_rstrings[ndx];
}
else
{
static wxString no_cookie_for_you;
wxASSERT( 0 ); // bad index
......
......@@ -104,42 +104,33 @@ void SEARCH_STACK::AddPaths( const wxString& aPaths, int aIndex )
}
void RETAINED_PATH::Clear()
const wxString SEARCH_STACK::LastVisitedPath( const wxString& aSubPathToSearch )
{
m_retained_path.Clear();
}
wxString RETAINED_PATH::LastVisitedPath( const SEARCH_STACK& aSStack, const wxString& aSubPathToSearch )
{
if( !!m_retained_path )
return m_retained_path;
wxString 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 = aSStack.GetCount();
// this is the second path in list (the first is the project path).
unsigned pcount = GetCount();
if( pcount )
{
unsigned ipath = 0;
if( aSStack[0] == wxGetCwd() )
if( (*this)[0] == wxGetCwd() )
ipath = 1;
// First choice of path:
if( ipath < pcount )
path = aSStack[ipath];
path = (*this)[ipath];
// Search a sub path matching aSubPathToSearch
if( !aSubPathToSearch.IsEmpty() )
// Search a sub path matching this SEARCH_PATH
if( !IsEmpty() )
{
for( ; ipath < pcount; ipath++ )
{
if( aSStack[ipath].Contains( aSubPathToSearch ) )
if( (*this)[ipath].Contains( aSubPathToSearch ) )
{
path = aSStack[ipath];
path = (*this)[ipath];
break;
}
}
......@@ -153,12 +144,6 @@ wxString RETAINED_PATH::LastVisitedPath( const SEARCH_STACK& aSStack, const wxSt
}
void RETAINED_PATH::SaveLastVisitedPath( const wxString& aPath )
{
m_retained_path = aPath;
}
#if defined(DEBUG)
void SEARCH_STACK::Show( const char* aPrefix ) const
{
......
......@@ -439,8 +439,11 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
PROJECT& prj = Prj();
SEARCH_STACK& search = prj.SchSearchS();
wxString docpath = prj.RPath(PROJECT::DOC).LastVisitedPath( search, wxT( "doc" ) );
wxString mask = wxT( "*" );
wxString docpath = prj.GetRString( PROJECT::DOC_PATH );
if( !docpath )
docpath = search.LastVisitedPath( wxT( "doc" ) );
wxString fullFileName = EDA_FileSelector( _( "Doc Files" ),
docpath,
......@@ -463,7 +466,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
*/
wxFileName fn = fullFileName;
prj.RPath(PROJECT::DOC).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::DOC_PATH, fn.GetPath() );
wxString filename = search.FilenameWithRelativePathInSearchList( fullFileName );
......
......@@ -321,8 +321,12 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
wxString libpath = m_DefaultLibraryPathslistBox->GetStringSelection();
if( libpath.IsEmpty() )
libpath = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
if( !libpath )
{
libpath = prj.GetRString( PROJECT::SCH_LIB_PATH );
if( !libpath )
libpath = search.LastVisitedPath();
}
wxFileDialog filesDialog( this, _( "Library files:" ), libpath,
wxEmptyString, SchematicLibraryFileWildcard,
......@@ -340,7 +344,7 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
fn = filenames[jj];
if( jj == 0 )
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
/* If the library path is already in the library search paths
* list, just add the library name to the list. Otherwise, add
......@@ -376,12 +380,14 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
}
void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
{
PROJECT& prj = Prj();
SEARCH_STACK& search = Prj().SchSearchS();
wxString path = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
wxString path = prj.GetRString( PROJECT::SCH_LIB_PATH );
if( !path )
path = search.LastVisitedPath();
bool select = EDA_DirectorySelector( _( "Default Path for Libraries" ),
path, wxDD_DEFAULT_STYLE,
......@@ -439,7 +445,7 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
DisplayError( this, _("Path already in use") );
}
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( path );
prj.SetRString( PROJECT::SCH_LIB_PATH, path );
}
......
......@@ -308,7 +308,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
if( m_library == NULL )
if( !m_library )
{
DisplayError( this, _( "No library specified." ) );
return false;
......@@ -326,7 +326,9 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
SEARCH_STACK& search = prj.SchSearchS();
// Get a new name for the library
wxString default_path = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
if( !default_path )
default_path = search.LastVisitedPath();
wxFileDialog dlg( this, _( "Component Library Name:" ), default_path,
wxEmptyString, SchematicLibraryFileExtension,
......@@ -342,7 +344,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
if( fn.GetExt().IsEmpty() )
fn.SetExt( SchematicLibraryFileExtension );
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
}
else
{
......
......@@ -60,7 +60,9 @@ void LIB_EDIT_FRAME::LoadOneSymbol()
m_canvas->SetIgnoreMouseEvents( true );
wxString default_path = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
if( !default_path )
default_path = search.LastVisitedPath();
wxFileDialog dlg( this, _( "Import Symbol Drawings" ), default_path,
wxEmptyString, SchematicSymbolFileWildcard,
......@@ -75,7 +77,7 @@ void LIB_EDIT_FRAME::LoadOneSymbol()
wxFileName fn = dlg.GetPath();
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
Lib = new CMP_LIBRARY( LIBRARY_TYPE_SYMBOL, fn );
......@@ -143,7 +145,9 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
if( m_component->GetDrawItemList().empty() )
return;
wxString default_path = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
if( !default_path )
default_path = search.LastVisitedPath();
wxFileDialog dlg( this, _( "Export Symbol Drawings" ), default_path,
m_component->GetName(), SchematicSymbolFileWildcard,
......@@ -159,7 +163,7 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
if( fn.GetExt().IsEmpty() )
fn.SetExt( SchematicSymbolFileExtension );
prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
msg.Printf( _( "Saving symbol in '%s'" ), GetChars( fn.GetPath() ) );
SetStatusText( msg );
......
......@@ -137,19 +137,32 @@ public:
VTBL_ENTRY wxString GetModuleLibraryNickname() { return m_module_library_nickname; }
VTBL_ENTRY void SetModuleLibraryNickname( const wxString& aNickName ) { m_module_library_nickname = aNickName; }
/// Retain a number of paths for user convienience, enumerated here:
enum RETPATH_T
/// Retain a number of project specific wxStrings, enumerated here:
enum RSTRING_T
{
DOC,
SCH_LIB,
PCB_LIB,
VIEWER_3D,
DOC_PATH,
SCH_LIB_PATH,
PCB_LIB_NICKNAME,
VIEWER_3D_PATH,
RPATH_COUNT
RSTRING_COUNT
};
/// Give acess to a RETAINED_PATH using enum RETPATH_T
VTBL_ENTRY RETAINED_PATH& RPath( RETPATH_T aPath );
/**
* Function GetRString
* returns a "retained string", which is any session and project specific string
* identified in enum RSTRING_T. Retained strings are not written to disk, and
* are therefore good only for the current session.
*/
VTBL_ENTRY const wxString& GetRString( RSTRING_T aStringId );
/**
* Function SetRString
* stores a "retained string", which is any session and project specific string
* identified in enum RSTRING_T. Retained strings are not written to disk, and
* are therefore good only for the current session.
*/
VTBL_ENTRY void SetRString( RSTRING_T aStringId, const wxString& aString );
/**
* Enum ELEM_T
......@@ -241,8 +254,8 @@ private:
wxString m_module_library_nickname; ///< @todo move this into m_rpaths[]
/// @see this::RPath() and enum RETPATH_T.
RETAINED_PATH m_rpaths[RPATH_COUNT];
/// @see this::SetRString(), GetRString(), and enum RSTRING_T.
wxString m_rstrings[RSTRING_COUNT];
/// @see this::Elem() and enum ELEM_T.
_ELEM* m_elems[ELEM_COUNT];
......
......@@ -57,38 +57,19 @@ public:
* ";" on windows, or ":" | ";" on unix.
*/
void RemovePaths( const wxString& aPaths );
};
/**
* Class RETAINED_PATH
* is a glamorous way to save a path you might need in the future.
* It is simply a container for the two functions, if you can figure them out.
* This whole concept is awkward, and the two function might have better been
* non-member functions, simply globals.
*/
class RETAINED_PATH
{
public:
/**
* Function LastVisitedPath
* returns the last visited directory, or aSubPathToSearch is empty, the first
* path in lib path list ( but not the CWD ).
* is a quirky function inherited from old code that seems to serve particular
* needs in the UI. It returns what is called the last visited directory, or
* if aSubPathToSearch is empty, the first path in this SEARCH_STACK
* ( but not the CWD ).
*
* @todo add more here if you can figure it out.
*
* @param aSearchStack gives the set of directories to consider.
* @param aSubPathToSearch is the preferred sub path to search in path list
*/
wxString LastVisitedPath( const SEARCH_STACK& aSStack,
const wxString& aSubPathToSearch = wxEmptyString );
void SaveLastVisitedPath( const wxString& aPath );
void Clear();
private:
wxString m_retained_path;
const wxString LastVisitedPath( const wxString& aSubPathToSearch = wxEmptyString );
};
#endif // SEARCH_STACK_H_
......@@ -440,7 +440,11 @@ void DIALOG_MODULE_BOARD_EDITOR::Browse3DLib( wxCommandEvent& event )
}
if( !fullpath )
fullpath = prj.RPath(PROJECT::VIEWER_3D).LastVisitedPath( search, LIB3D_PATH );
{
fullpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
if( !fullpath )
fullpath = search.LastVisitedPath( LIB3D_PATH );
}
#ifdef __WINDOWS__
fullpath.Replace( wxT( "/" ), wxT( "\\" ) );
......@@ -469,7 +473,7 @@ void DIALOG_MODULE_BOARD_EDITOR::Browse3DLib( wxCommandEvent& event )
wxFileName fn = fullfilename;
prj.RPath(PROJECT::VIEWER_3D).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::VIEWER_3D_PATH, fn.GetPath() );
/* If the file path is already in the library search paths
* list, just add the library name to the list. Otherwise, add
......
......@@ -303,7 +303,11 @@ void DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DLib( wxCommandEvent& event )
}
if( !fullpath )
fullpath = prj.RPath(PROJECT::VIEWER_3D).LastVisitedPath( search, LIB3D_PATH );
{
fullpath = prj.GetRString( PROJECT::VIEWER_3D_PATH );
if( !fullpath )
fullpath = search.LastVisitedPath( LIB3D_PATH );
}
#ifdef __WINDOWS__
fullpath.Replace( wxT( "/" ), wxT( "\\" ) );
......@@ -330,7 +334,7 @@ void DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DLib( wxCommandEvent& event )
wxFileName fn = fullfilename;
prj.RPath(PROJECT::VIEWER_3D).SaveLastVisitedPath( fn.GetPath() );
prj.SetRString( PROJECT::VIEWER_3D_PATH, fn.GetPath() );
/* If the file path is already in the library search paths
* list, just add the library name to the list. Otherwise, add
......
......@@ -522,16 +522,15 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
}
PROJECT& prj = Prj();
SEARCH_STACK& search = Kiface().KifaceSearch();
wxString last_nickname = prj.RPath(PROJECT::PCB_LIB).LastVisitedPath( search );
wxString last_nickname = prj.GetRString( PROJECT::PCB_LIB_NICKNAME );
wxString nickname = SelectLibrary( last_nickname );
if( !nickname )
return;
prj.RPath(PROJECT::PCB_LIB).SaveLastVisitedPath( nickname );
prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname );
if( !aNewModulesOnly )
{
......@@ -545,7 +544,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
try
{
FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs();
FP_LIB_TABLE* tbl = prj.PcbFootprintLibs();
// Delete old library if we're replacing it entirely.
if( !aNewModulesOnly )
......
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