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

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
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -69,5 +69,9 @@ Dick's Final TODO List:
    https://blueprints.launchpad.net/kicad/+spec/modular-kicad
    https://blueprints.launchpad.net/kicad/+spec/modular-kicad


    Issues as a result of minimal testing:
    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.
        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.
+19 −4
Original line number Original line Diff line number Diff line
@@ -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 );
    unsigned ndx = unsigned( aIndex );


    if( ndx < DIM( m_rpaths ) )
    if( ndx < DIM( m_rstrings ) )
    {
    {
        return m_rpaths[ndx];
        m_rstrings[ndx] = aString;
    }
    }
    else
    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
        wxASSERT( 0 );      // bad index


+9 −24
Original line number Original line Diff line number Diff line
@@ -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;
    wxString path;


    // Initialize default path to the main default lib path
    // Initialize default path to the main default lib path
    // this is the second path in list (the first is the project path)
    // this is the second path in list (the first is the project path).
    unsigned pcount = aSStack.GetCount();
    unsigned pcount = GetCount();


    if( pcount )
    if( pcount )
    {
    {
        unsigned ipath = 0;
        unsigned ipath = 0;


        if( aSStack[0] == wxGetCwd() )
        if( (*this)[0] == wxGetCwd() )
            ipath = 1;
            ipath = 1;


        // First choice of path:
        // First choice of path:
        if( ipath < pcount )
        if( ipath < pcount )
            path = aSStack[ipath];
            path = (*this)[ipath];


        // Search a sub path matching aSubPathToSearch
        // Search a sub path matching this SEARCH_PATH
        if( !aSubPathToSearch.IsEmpty() )
        if( !IsEmpty() )
        {
        {
            for( ; ipath < pcount; ipath++ )
            for( ; ipath < pcount; ipath++ )
            {
            {
                if( aSStack[ipath].Contains( aSubPathToSearch ) )
                if( (*this)[ipath].Contains( aSubPathToSearch ) )
                {
                {
                    path = aSStack[ipath];
                    path = (*this)[ipath];
                    break;
                    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)
#if defined(DEBUG)
void SEARCH_STACK::Show( const char* aPrefix ) const
void SEARCH_STACK::Show( const char* aPrefix ) const
{
{
+5 −2
Original line number Original line Diff line number Diff line
@@ -439,8 +439,11 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
    PROJECT&        prj = Prj();
    PROJECT&        prj = Prj();
    SEARCH_STACK&   search = prj.SchSearchS();
    SEARCH_STACK&   search = prj.SchSearchS();


    wxString    docpath = prj.RPath(PROJECT::DOC).LastVisitedPath( search, wxT( "doc" ) );
    wxString    mask = wxT( "*" );
    wxString    mask = wxT( "*" );
    wxString    docpath = prj.GetRString( PROJECT::DOC_PATH );

    if( !docpath )
        docpath = search.LastVisitedPath( wxT( "doc" ) );


    wxString    fullFileName = EDA_FileSelector( _( "Doc Files" ),
    wxString    fullFileName = EDA_FileSelector( _( "Doc Files" ),
                                     docpath,
                                     docpath,
@@ -463,7 +466,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& e
     */
     */
    wxFileName fn = fullFileName;
    wxFileName fn = fullFileName;


    prj.RPath(PROJECT::DOC).SaveLastVisitedPath( fn.GetPath() );
    prj.SetRString( PROJECT::DOC_PATH, fn.GetPath() );


    wxString filename = search.FilenameWithRelativePathInSearchList( fullFileName );
    wxString filename = search.FilenameWithRelativePathInSearchList( fullFileName );


+12 −6
Original line number Original line Diff line number Diff line
@@ -321,8 +321,12 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )


    wxString libpath = m_DefaultLibraryPathslistBox->GetStringSelection();
    wxString libpath = m_DefaultLibraryPathslistBox->GetStringSelection();


    if( libpath.IsEmpty() )
    if( !libpath )
        libpath = prj.RPath(PROJECT::SCH_LIB).LastVisitedPath( search );
    {
        libpath = prj.GetRString( PROJECT::SCH_LIB_PATH );
        if( !libpath )
            libpath = search.LastVisitedPath();
    }


    wxFileDialog filesDialog( this, _( "Library files:" ), libpath,
    wxFileDialog filesDialog( this, _( "Library files:" ), libpath,
                              wxEmptyString, SchematicLibraryFileWildcard,
                              wxEmptyString, SchematicLibraryFileWildcard,
@@ -340,7 +344,7 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event )
        fn = filenames[jj];
        fn = filenames[jj];


        if( jj == 0 )
        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
        /* If the library path is already in the library search paths
         * list, just add the library name to the list.  Otherwise, add
         * 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 )
void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
{
{
    PROJECT&        prj = Prj();
    PROJECT&        prj = Prj();
    SEARCH_STACK&   search = Prj().SchSearchS();
    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" ),
    bool select = EDA_DirectorySelector( _( "Default Path for Libraries" ),
                                         path, wxDD_DEFAULT_STYLE,
                                         path, wxDD_DEFAULT_STYLE,
@@ -439,7 +445,7 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath( wxCommandEvent& event )
        DisplayError( this, _("Path already in use") );
        DisplayError( this, _("Path already in use") );
    }
    }


    prj.RPath(PROJECT::SCH_LIB).SaveLastVisitedPath( path );
    prj.SetRString( PROJECT::SCH_LIB_PATH, path );
}
}




Loading