diff --git a/common/bin_mod.cpp b/common/bin_mod.cpp index a989c1587b..129f428e77 100644 --- a/common/bin_mod.cpp +++ b/common/bin_mod.cpp @@ -25,7 +25,6 @@ #include #include #include -#include // for ID_FILE1 and FILE_HISTORY_SIZE #include #include #include @@ -34,20 +33,13 @@ BIN_MOD::BIN_MOD( const char* aName ) : m_name( aName ), - m_config( nullptr ), - m_history( nullptr ) + m_config( nullptr ) { } void BIN_MOD::Init() { - // get file history size from common settings - int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size; - - m_history = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), ID_FILE1, ID_FILE_LIST_CLEAR ); - m_history->Load( *m_config ); - // Prepare On Line Help. Use only lower case for help file names, in order to // avoid problems with upper/lower case file names under windows and unix. // Help files are now using html format. @@ -62,13 +54,6 @@ void BIN_MOD::End() { if( m_config ) { - if( m_history ) - { - m_history->Save( *m_config ); - delete m_history; - m_history = nullptr; - } - // The settings manager will outlive this module so we need to clean up the module level // settings here instead of leaving it up to the manager Pgm().GetSettingsManager().FlushAndRelease( m_config ); diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 68056bb932..5298435f21 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -72,6 +72,7 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, long aStyle, const wxString& aFrameName, KIWAY* aKiway ) : wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ), KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ), + m_fileHistory( nullptr ), m_userUnits( EDA_UNITS::MILLIMETRES ) { m_Ident = aFrameType; @@ -149,6 +150,7 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) EDA_BASE_FRAME::~EDA_BASE_FRAME() { delete m_autoSaveTimer; + delete m_fileHistory; if( SupportsShutdownBlockReason() ) { @@ -321,6 +323,14 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) { TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged ); + COMMON_SETTINGS* settings = Pgm().GetCommonSettings(); + + if( m_fileHistory ) + { + int historySize = settings->m_System.file_history_size; + m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) ); + } + if( GetMenuBar() ) { // For icons in menus, icon scaling & hotkeys @@ -504,12 +514,24 @@ void EDA_BASE_FRAME::SaveWindowSettings( WINDOW_SETTINGS* aCfg ) void EDA_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { LoadWindowSettings( GetWindowSettings( aCfg ) ); + + // Get file history size from common settings + int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size; + + // Load the recently used files into the history menu + m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ), + ID_FILE1, ID_FILE_LIST_CLEAR ); + m_fileHistory->Load( *aCfg ); } void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) { SaveWindowSettings( GetWindowSettings( aCfg ) ); + + // Save the recently used files list + if( m_fileHistory ) + m_fileHistory->Save( *aCfg ); } @@ -546,12 +568,12 @@ void EDA_BASE_FRAME::PrintMsg( const wxString& text ) void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory ) { - FILE_HISTORY* fileHistory = aFileHistory; + if( !aFileHistory ) + aFileHistory = m_fileHistory; - if( !fileHistory ) - fileHistory = &Kiface().GetFileHistory(); + wxASSERT( aFileHistory ); - fileHistory->AddFileToHistory( FullFileName ); + aFileHistory->AddFileToHistory( FullFileName ); // Update the menubar to update the file history menu if( GetMenuBar() ) @@ -565,20 +587,20 @@ void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTO wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type, FILE_HISTORY* aFileHistory ) { - FILE_HISTORY* fileHistory = aFileHistory; + if( !aFileHistory ) + aFileHistory = m_fileHistory; - if( !fileHistory ) - fileHistory = &Kiface().GetFileHistory(); + wxASSERT( aFileHistory ); - int baseId = fileHistory->GetBaseId(); + int baseId = aFileHistory->GetBaseId(); - wxASSERT( cmdId >= baseId && cmdId < baseId + (int) fileHistory->GetCount() ); + wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() ); unsigned i = cmdId - baseId; - if( i < fileHistory->GetCount() ) + if( i < aFileHistory->GetCount() ) { - wxString fn = fileHistory->GetHistoryFile( i ); + wxString fn = aFileHistory->GetHistoryFile( i ); if( wxFileName::FileExists( fn ) ) return fn; @@ -587,10 +609,17 @@ wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type, wxString msg = wxString::Format( _( "File \"%s\" was not found." ), fn ); wxMessageBox( msg ); - fileHistory->RemoveFileFromHistory( i ); + aFileHistory->RemoveFileFromHistory( i ); } } + // Update the menubar to update the file history menu + if( GetMenuBar() ) + { + ReCreateMenuBar(); + GetMenuBar()->Refresh(); + } + return wxEmptyString; } @@ -598,9 +627,18 @@ wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type, void EDA_BASE_FRAME::ClearFileHistory( FILE_HISTORY* aFileHistory ) { if( !aFileHistory ) - aFileHistory = &Kiface().GetFileHistory(); + aFileHistory = m_fileHistory; + + wxASSERT( aFileHistory ); aFileHistory->ClearFileHistory(); + + // Update the menubar to update the file history menu + if( GetMenuBar() ) + { + ReCreateMenuBar(); + GetMenuBar()->Refresh(); + } } diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 8f6ff40d9c..94d5c2bdb9 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -218,9 +218,6 @@ void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) SetAutoSaveInterval( settings->m_System.autosave_interval ); - int historySize = settings->m_System.file_history_size; - Kiface().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) ); - viewControls->EnableMousewheelPan( settings->m_Input.mousewheel_pan ); viewControls->EnableCursorWarping( settings->m_Input.center_on_zoom ); viewControls->EnableAutoPan( settings->m_Input.auto_pan ); diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 3dac39e6d7..971730aa42 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -58,7 +58,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() if( Kiface().IsSingle() ) // When not under a project mgr { - FILE_HISTORY& fileHistory = Kiface().GetFileHistory(); + FILE_HISTORY& fileHistory = GetFileHistory(); // Add this menu to the list of menus managed by the file history // (the file history will be updated when adding/removing files in history) diff --git a/gerbview/menubar.cpp b/gerbview/menubar.cpp index 940e464347..8ff1a04725 100644 --- a/gerbview/menubar.cpp +++ b/gerbview/menubar.cpp @@ -51,7 +51,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar() static ACTION_MENU* openRecentJobMenu; static ACTION_MENU* openRecentZipMenu; - FILE_HISTORY& recentGbrFiles = Kiface().GetFileHistory(); + FILE_HISTORY& recentGbrFiles = GetFileHistory(); recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) ); diff --git a/include/bin_mod.h b/include/bin_mod.h index 9277019e67..0ae964a62f 100644 --- a/include/bin_mod.h +++ b/include/bin_mod.h @@ -36,7 +36,6 @@ #include class APP_SETTINGS_BASE; -class FILE_HISTORY; /** * Struct BIN_MOD @@ -63,7 +62,6 @@ struct BIN_MOD const char* m_name; ///< name of this binary module, static C string. APP_SETTINGS_BASE* m_config; ///< maybe from $HOME/.${m_name} - FILE_HISTORY* m_history; wxString m_help_file; SEARCH_STACK m_search; diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 8fdd6af268..bb3d822453 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -138,6 +138,8 @@ protected: SETTINGS_MANAGER* m_settingsManager; + FILE_HISTORY* m_fileHistory; // The frame's recently opened file list + bool m_hasAutoSave; bool m_autoSaveState; int m_autoSaveInterval; // The auto save interval time in seconds. @@ -371,7 +373,7 @@ public: * @return a wxString containing the selected filename */ wxString GetFileFromHistory( int cmdId, const wxString& type, - FILE_HISTORY* aFileHistory = NULL ); + FILE_HISTORY* aFileHistory = nullptr ); /** * Removes all files from the file history. @@ -379,7 +381,7 @@ public: * @param aFileHistory The FILE_HISTORY in use. If null, the main application file * history is used */ - void ClearFileHistory( FILE_HISTORY* aFileHistory = NULL ); + void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr ); /** * Update the list of recently opened files. @@ -390,7 +392,17 @@ public: * @param aFileHistory The FILE_HISTORY in use. * If NULL, the main application file history is used. */ - void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = NULL ); + void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr ); + + /** + * Get the frame's main file history. + * + * @return the main file history + */ + FILE_HISTORY& GetFileHistory() + { + return *m_fileHistory; + } void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; } diff --git a/include/kiface_i.h b/include/kiface_i.h index 6c54636249..888fe042a2 100644 --- a/include/kiface_i.h +++ b/include/kiface_i.h @@ -122,8 +122,6 @@ public: */ const wxString& GetHelpFileName() const { return m_bm.m_help_file; } - FILE_HISTORY& GetFileHistory() { return *m_bm.m_history; } - /// Only for DSO specific 'non-library' files. /// (The library search path is in the PROJECT class.) SEARCH_STACK& KifaceSearch() { return m_bm.m_search; } diff --git a/kicad/files-io.cpp b/kicad/files-io.cpp index 623ed5d080..25e804ac1f 100644 --- a/kicad/files-io.cpp +++ b/kicad/files-io.cpp @@ -46,8 +46,7 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) { - wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ), - &PgmTop().GetFileHistory() ); + wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) ); if( !projFileName.FileExists() ) return; @@ -57,7 +56,7 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent ) { - ClearFileHistory( &PgmTop().GetFileHistory() ); + ClearFileHistory(); } diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 7ba38694f6..740cae995a 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -118,7 +118,7 @@ bool PGM_KICAD::OnPgmInit() if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString ) m_bm.m_search.Insert( it->second.GetValue(), 0 ); - + // The KICAD_USER_TEMPLATE_DIR takes precedence over KICAD_TEMPLATE_DIR and the search // stack template path. it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" ); @@ -139,13 +139,13 @@ bool PGM_KICAD::OnPgmInit() { projToLoad = App().argv[1]; } - else if( GetFileHistory().GetCount() ) + else if( frame->GetFileHistory().GetCount() ) { - wxString last_pro = GetFileHistory().GetHistoryFile( 0 ); + wxString last_pro = frame->GetFileHistory().GetHistoryFile( 0 ); if( !wxFileExists( last_pro ) ) { - GetFileHistory().RemoveFileFromHistory( 0 ); + frame->GetFileHistory().RemoveFileFromHistory( 0 ); } else { diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 36f8889aba..c73a871062 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -312,8 +312,9 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event ) { int px, py; + // Save the currently opened file in the file history if( !GetProjectFileName().empty() ) - UpdateFileHistory( GetProjectFileName(), &PgmTop().GetFileHistory() ); + UpdateFileHistory( GetProjectFileName() ); if( !IsIconized() ) // save main frame position and size { @@ -369,7 +370,7 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName ) if( aProjectFileName.IsDirWritable() ) SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why? - UpdateFileHistory( aProjectFileName.GetFullPath(), &PgmTop().GetFileHistory() ); + UpdateFileHistory( aProjectFileName.GetFullPath() ); m_leftWin->ReCreateTreePrj(); @@ -442,6 +443,8 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName ) // wxFile dtor will close the file } + + UpdateFileHistory( aProjectFileName.GetFullPath() ); } @@ -502,7 +505,7 @@ void KICAD_MANAGER_FRAME::ShowChangedLanguage() void KICAD_MANAGER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) { int historySize = Pgm().GetCommonSettings()->m_System.file_history_size; - PgmTop().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) ); + GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) ); } diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index e8f7acd606..f2ba1bd8ad 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -47,7 +47,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar() //-- File menu ----------------------------------------------------------- // CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool ); - FILE_HISTORY& fileHistory = PgmTop().GetFileHistory(); + FILE_HISTORY& fileHistory = GetFileHistory(); fileHistory.SetClearText( _( "Clear Recent Projects" ) ); diff --git a/kicad/pgm_kicad.h b/kicad/pgm_kicad.h index 6a3f8a3ebd..e837e145d1 100644 --- a/kicad/pgm_kicad.h +++ b/kicad/pgm_kicad.h @@ -53,8 +53,6 @@ public: void MacOpenFile( const wxString& aFileName ) override; - FILE_HISTORY& GetFileHistory() { return *m_bm.m_history; } - APP_SETTINGS_BASE* PgmSettings() { return m_bm.m_config; } SEARCH_STACK& SysSearch() { return m_bm.m_search; } diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index c86d81548b..e9064c0aad 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -49,7 +49,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() }; static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu - FILE_HISTORY& recentFiles = Kiface().GetFileHistory(); + FILE_HISTORY& recentFiles = GetFileHistory(); // Create the menu if it does not exist. Adding a file to/from the history // will automatically refresh the menu. diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 61a41fe705..0639d43f88 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -208,6 +208,7 @@ void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event ) } } + void PCB_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent ) { ClearFileHistory(); diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 27e7e82133..37a5b237e3 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -64,7 +64,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() if( Kiface().IsSingle() ) // not when under a project mgr { - FILE_HISTORY& fileHistory = Kiface().GetFileHistory(); + FILE_HISTORY& fileHistory = GetFileHistory(); // Create the menu if it does not exist. Adding a file to/from the history // will automatically refresh the menu. @@ -120,7 +120,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() submenuImport->Add( PCB_ACTIONS::importSpecctraSession ); submenuImport->Add( _( "Graphics..." ), _( "Import 2D drawing file" ), ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm ); - + if( Kiface().IsSingle() ) { submenuImport->Add( _( "Non-KiCad Board File..." ),