diff --git a/TODO.txt b/TODO.txt index 2972328835..ee0b19e8a1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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. + diff --git a/common/project.cpp b/common/project.cpp index 2e10d8a661..5ec1245737 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -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 diff --git a/common/search_stack.cpp b/common/search_stack.cpp index d9f6a5c870..a4722a574f 100644 --- a/common/search_stack.cpp +++ b/common/search_stack.cpp @@ -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 { diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index 8866b25c1f..de0ff02b11 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -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 ); diff --git a/eeschema/dialogs/dialog_eeschema_config.cpp b/eeschema/dialogs/dialog_eeschema_config.cpp index efe5464282..1e2a85ed9a 100644 --- a/eeschema/dialogs/dialog_eeschema_config.cpp +++ b/eeschema/dialogs/dialog_eeschema_config.cpp @@ -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 ); } diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 82afe32532..8e60b0d44e 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -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 { diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index 7836f5cbd8..8d6a744cdf 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -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 ); diff --git a/include/project.h b/include/project.h index c7f7a7f3dd..b4415619f4 100644 --- a/include/project.h +++ b/include/project.h @@ -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]; diff --git a/include/search_stack.h b/include/search_stack.h index 42534bb74a..8c36c90849 100644 --- a/include/search_stack.h +++ b/include/search_stack.h @@ -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 + * @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_ diff --git a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp index d8b6648b7a..8f9f822e47 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_BoardEditor.cpp @@ -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 @@ -482,7 +486,7 @@ void DIALOG_MODULE_BOARD_EDITOR::Browse3DLib( wxCommandEvent& event ) wxFileName aux = shortfilename; if( aux.IsAbsolute() ) - { + { // Absolute path, ask if the user wants a relative one int diag = wxMessageBox( _( "Use a relative path?" ), @@ -490,7 +494,7 @@ void DIALOG_MODULE_BOARD_EDITOR::Browse3DLib( wxCommandEvent& event ) wxYES_NO | wxICON_QUESTION, this ); if( diag == wxYES ) - { + { // Make it relative aux.MakeRelativeTo( wxT(".") ); shortfilename = aux.GetPathWithSep() + aux.GetFullName(); diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 6e0ee4bd19..6cc15e9aa6 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -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 diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 548b4b3a07..cc682e485d 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -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 )