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 <common.h>
#include <filehistory.h>
#include <id.h> // for ID_FILE1 and FILE_HISTORY_SIZE
#include <pgm_base.h>
#include <settings/app_settings.h>
#include <settings/common_settings.h>
@ -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 );

View File

@ -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();
}
}

View File

@ -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 );

View File

@ -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)

View File

@ -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" ) );

View File

@ -36,7 +36,6 @@
#include <memory>
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;

View File

@ -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; }

View File

@ -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; }

View File

@ -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();
}

View File

@ -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
{

View File

@ -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 ) );
}

View File

@ -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" ) );

View File

@ -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; }

View File

@ -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.

View File

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

View File

@ -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.