Move the file history into the frames

This commit is contained in:
Ian McInerney 2020-05-16 22:47:01 +01:00
parent 3656297f99
commit 613c020920
16 changed files with 86 additions and 57 deletions

View File

@ -25,7 +25,6 @@
#include <bin_mod.h> #include <bin_mod.h>
#include <common.h> #include <common.h>
#include <filehistory.h> #include <filehistory.h>
#include <id.h> // for ID_FILE1 and FILE_HISTORY_SIZE
#include <pgm_base.h> #include <pgm_base.h>
#include <settings/app_settings.h> #include <settings/app_settings.h>
#include <settings/common_settings.h> #include <settings/common_settings.h>
@ -34,20 +33,13 @@
BIN_MOD::BIN_MOD( const char* aName ) : BIN_MOD::BIN_MOD( const char* aName ) :
m_name( aName ), m_name( aName ),
m_config( nullptr ), m_config( nullptr )
m_history( nullptr )
{ {
} }
void BIN_MOD::Init() 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 // 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. // avoid problems with upper/lower case file names under windows and unix.
// Help files are now using html format. // Help files are now using html format.
@ -62,13 +54,6 @@ void BIN_MOD::End()
{ {
if( m_config ) 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 // 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 // settings here instead of leaving it up to the manager
Pgm().GetSettingsManager().FlushAndRelease( m_config ); Pgm().GetSettingsManager().FlushAndRelease( m_config );

View File

@ -72,6 +72,7 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
long aStyle, const wxString& aFrameName, KIWAY* aKiway ) : long aStyle, const wxString& aFrameName, KIWAY* aKiway ) :
wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ), wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ), KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
m_fileHistory( nullptr ),
m_userUnits( EDA_UNITS::MILLIMETRES ) m_userUnits( EDA_UNITS::MILLIMETRES )
{ {
m_Ident = aFrameType; m_Ident = aFrameType;
@ -149,6 +150,7 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
EDA_BASE_FRAME::~EDA_BASE_FRAME() EDA_BASE_FRAME::~EDA_BASE_FRAME()
{ {
delete m_autoSaveTimer; delete m_autoSaveTimer;
delete m_fileHistory;
if( SupportsShutdownBlockReason() ) if( SupportsShutdownBlockReason() )
{ {
@ -321,6 +323,14 @@ void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
{ {
TOOLS_HOLDER::CommonSettingsChanged( 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() ) if( GetMenuBar() )
{ {
// For icons in menus, icon scaling & hotkeys // 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 ) void EDA_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{ {
LoadWindowSettings( GetWindowSettings( 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 ) void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{ {
SaveWindowSettings( GetWindowSettings( 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 ) void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
{ {
FILE_HISTORY* fileHistory = aFileHistory; if( !aFileHistory )
aFileHistory = m_fileHistory;
if( !fileHistory ) wxASSERT( aFileHistory );
fileHistory = &Kiface().GetFileHistory();
fileHistory->AddFileToHistory( FullFileName ); aFileHistory->AddFileToHistory( FullFileName );
// Update the menubar to update the file history menu // Update the menubar to update the file history menu
if( GetMenuBar() ) 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, wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
FILE_HISTORY* aFileHistory ) FILE_HISTORY* aFileHistory )
{ {
FILE_HISTORY* fileHistory = aFileHistory; if( !aFileHistory )
aFileHistory = m_fileHistory;
if( !fileHistory ) wxASSERT( aFileHistory );
fileHistory = &Kiface().GetFileHistory();
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; 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 ) ) if( wxFileName::FileExists( fn ) )
return 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 ); wxString msg = wxString::Format( _( "File \"%s\" was not found." ), fn );
wxMessageBox( msg ); wxMessageBox( msg );
fileHistory->RemoveFileFromHistory( i ); aFileHistory->RemoveFileFromHistory( i );
} }
} }
// Update the menubar to update the file history menu
if( GetMenuBar() )
{
ReCreateMenuBar();
GetMenuBar()->Refresh();
}
return wxEmptyString; return wxEmptyString;
} }
@ -598,9 +627,18 @@ wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
void EDA_BASE_FRAME::ClearFileHistory( FILE_HISTORY* aFileHistory ) void EDA_BASE_FRAME::ClearFileHistory( FILE_HISTORY* aFileHistory )
{ {
if( !aFileHistory ) if( !aFileHistory )
aFileHistory = &Kiface().GetFileHistory(); aFileHistory = m_fileHistory;
wxASSERT( aFileHistory );
aFileHistory->ClearFileHistory(); aFileHistory->ClearFileHistory();
// Update the menubar to update the file history menu
if( GetMenuBar() )
{
ReCreateMenuBar();
GetMenuBar()->Refresh();
}
} }

View File

@ -218,9 +218,6 @@ void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
SetAutoSaveInterval( settings->m_System.autosave_interval ); 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->EnableMousewheelPan( settings->m_Input.mousewheel_pan );
viewControls->EnableCursorWarping( settings->m_Input.center_on_zoom ); viewControls->EnableCursorWarping( settings->m_Input.center_on_zoom );
viewControls->EnableAutoPan( settings->m_Input.auto_pan ); viewControls->EnableAutoPan( settings->m_Input.auto_pan );

View File

@ -58,7 +58,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar()
if( Kiface().IsSingle() ) // When not under a project mgr 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 // 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) // (the file history will be updated when adding/removing files in history)

View File

@ -51,7 +51,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
static ACTION_MENU* openRecentJobMenu; static ACTION_MENU* openRecentJobMenu;
static ACTION_MENU* openRecentZipMenu; static ACTION_MENU* openRecentZipMenu;
FILE_HISTORY& recentGbrFiles = Kiface().GetFileHistory(); FILE_HISTORY& recentGbrFiles = GetFileHistory();
recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) ); recentGbrFiles.SetClearText( _( "Clear Recent Gerber Files" ) );

View File

@ -36,7 +36,6 @@
#include <memory> #include <memory>
class APP_SETTINGS_BASE; class APP_SETTINGS_BASE;
class FILE_HISTORY;
/** /**
* Struct BIN_MOD * Struct BIN_MOD
@ -63,7 +62,6 @@ struct BIN_MOD
const char* m_name; ///< name of this binary module, static C string. const char* m_name; ///< name of this binary module, static C string.
APP_SETTINGS_BASE* m_config; ///< maybe from $HOME/.${m_name} APP_SETTINGS_BASE* m_config; ///< maybe from $HOME/.${m_name}
FILE_HISTORY* m_history;
wxString m_help_file; wxString m_help_file;
SEARCH_STACK m_search; SEARCH_STACK m_search;

View File

@ -138,6 +138,8 @@ protected:
SETTINGS_MANAGER* m_settingsManager; SETTINGS_MANAGER* m_settingsManager;
FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
bool m_hasAutoSave; bool m_hasAutoSave;
bool m_autoSaveState; bool m_autoSaveState;
int m_autoSaveInterval; // The auto save interval time in seconds. int m_autoSaveInterval; // The auto save interval time in seconds.
@ -371,7 +373,7 @@ public:
* @return a wxString containing the selected filename * @return a wxString containing the selected filename
*/ */
wxString GetFileFromHistory( int cmdId, const wxString& type, wxString GetFileFromHistory( int cmdId, const wxString& type,
FILE_HISTORY* aFileHistory = NULL ); FILE_HISTORY* aFileHistory = nullptr );
/** /**
* Removes all files from the file history. * 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 * @param aFileHistory The FILE_HISTORY in use. If null, the main application file
* history is used * history is used
*/ */
void ClearFileHistory( FILE_HISTORY* aFileHistory = NULL ); void ClearFileHistory( FILE_HISTORY* aFileHistory = nullptr );
/** /**
* Update the list of recently opened files. * Update the list of recently opened files.
@ -390,7 +392,17 @@ public:
* @param aFileHistory The FILE_HISTORY in use. * @param aFileHistory The FILE_HISTORY in use.
* If NULL, the main application file history is used. * 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; } void SetMruPath( const wxString& aPath ) { m_mruPath = aPath; }

View File

@ -122,8 +122,6 @@ public:
*/ */
const wxString& GetHelpFileName() const { return m_bm.m_help_file; } 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. /// Only for DSO specific 'non-library' files.
/// (The library search path is in the PROJECT class.) /// (The library search path is in the PROJECT class.)
SEARCH_STACK& KifaceSearch() { return m_bm.m_search; } SEARCH_STACK& KifaceSearch() { return m_bm.m_search; }

View File

@ -46,8 +46,7 @@
void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
{ {
wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ), wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
&PgmTop().GetFileHistory() );
if( !projFileName.FileExists() ) if( !projFileName.FileExists() )
return; return;
@ -57,7 +56,7 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent ) void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
{ {
ClearFileHistory( &PgmTop().GetFileHistory() ); ClearFileHistory();
} }

View File

@ -118,7 +118,7 @@ bool PGM_KICAD::OnPgmInit()
if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString ) if( it != GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString )
m_bm.m_search.Insert( it->second.GetValue(), 0 ); m_bm.m_search.Insert( it->second.GetValue(), 0 );
// The KICAD_USER_TEMPLATE_DIR takes precedence over KICAD_TEMPLATE_DIR and the search // The KICAD_USER_TEMPLATE_DIR takes precedence over KICAD_TEMPLATE_DIR and the search
// stack template path. // stack template path.
it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" ); it = GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" );
@ -139,13 +139,13 @@ bool PGM_KICAD::OnPgmInit()
{ {
projToLoad = App().argv[1]; 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 ) ) if( !wxFileExists( last_pro ) )
{ {
GetFileHistory().RemoveFileFromHistory( 0 ); frame->GetFileHistory().RemoveFileFromHistory( 0 );
} }
else else
{ {

View File

@ -312,8 +312,9 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
int px, py; int px, py;
// Save the currently opened file in the file history
if( !GetProjectFileName().empty() ) if( !GetProjectFileName().empty() )
UpdateFileHistory( GetProjectFileName(), &PgmTop().GetFileHistory() ); UpdateFileHistory( GetProjectFileName() );
if( !IsIconized() ) // save main frame position and size if( !IsIconized() ) // save main frame position and size
{ {
@ -369,7 +370,7 @@ void KICAD_MANAGER_FRAME::LoadProject( const wxFileName& aProjectFileName )
if( aProjectFileName.IsDirWritable() ) if( aProjectFileName.IsDirWritable() )
SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why? SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. Why?
UpdateFileHistory( aProjectFileName.GetFullPath(), &PgmTop().GetFileHistory() ); UpdateFileHistory( aProjectFileName.GetFullPath() );
m_leftWin->ReCreateTreePrj(); m_leftWin->ReCreateTreePrj();
@ -442,6 +443,8 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName )
// wxFile dtor will close the file // 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 ) void KICAD_MANAGER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged )
{ {
int historySize = Pgm().GetCommonSettings()->m_System.file_history_size; int historySize = Pgm().GetCommonSettings()->m_System.file_history_size;
PgmTop().GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) ); GetFileHistory().SetMaxFiles( (unsigned) std::max( 0, historySize ) );
} }

View File

@ -47,7 +47,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
//-- File menu ----------------------------------------------------------- //-- File menu -----------------------------------------------------------
// //
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool ); CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool );
FILE_HISTORY& fileHistory = PgmTop().GetFileHistory(); FILE_HISTORY& fileHistory = GetFileHistory();
fileHistory.SetClearText( _( "Clear Recent Projects" ) ); fileHistory.SetClearText( _( "Clear Recent Projects" ) );

View File

@ -53,8 +53,6 @@ public:
void MacOpenFile( const wxString& aFileName ) override; void MacOpenFile( const wxString& aFileName ) override;
FILE_HISTORY& GetFileHistory() { return *m_bm.m_history; }
APP_SETTINGS_BASE* PgmSettings() { return m_bm.m_config; } APP_SETTINGS_BASE* PgmSettings() { return m_bm.m_config; }
SEARCH_STACK& SysSearch() { return m_bm.m_search; } SEARCH_STACK& SysSearch() { return m_bm.m_search; }

View File

@ -49,7 +49,7 @@ void PL_EDITOR_FRAME::ReCreateMenuBar()
}; };
static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu 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 // Create the menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu. // will automatically refresh the menu.

View File

@ -208,6 +208,7 @@ void PCB_EDIT_FRAME::OnFileHistory( wxCommandEvent& event )
} }
} }
void PCB_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent ) void PCB_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
{ {
ClearFileHistory(); ClearFileHistory();

View File

@ -64,7 +64,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
if( Kiface().IsSingle() ) // not when under a project mgr 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 // Create the menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu. // will automatically refresh the menu.
@ -120,7 +120,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
submenuImport->Add( PCB_ACTIONS::importSpecctraSession ); submenuImport->Add( PCB_ACTIONS::importSpecctraSession );
submenuImport->Add( _( "Graphics..." ), _( "Import 2D drawing file" ), submenuImport->Add( _( "Graphics..." ), _( "Import 2D drawing file" ),
ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm ); ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm );
if( Kiface().IsSingle() ) if( Kiface().IsSingle() )
{ {
submenuImport->Add( _( "Non-KiCad Board File..." ), submenuImport->Add( _( "Non-KiCad Board File..." ),