Store the current filename in the history on close

This commit is contained in:
Ian McInerney 2020-05-17 00:08:01 +01:00
parent 0e54128146
commit e662e33104
13 changed files with 58 additions and 20 deletions

View File

@ -531,7 +531,15 @@ void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
// Save the recently used files list
if( m_fileHistory )
{
// Save the currently opened file in the file history
wxString currentlyOpenedFile = GetCurrentFileName();
if( !currentlyOpenedFile.IsEmpty() )
UpdateFileHistory( currentlyOpenedFile );
m_fileHistory->Save( *aCfg );
}
}

View File

@ -1224,3 +1224,14 @@ void SCH_EDIT_FRAME::ConvertTimeStampUuids()
timeStampSheetPaths.ReplaceLegacySheetPaths( oldSheetPaths );
}
wxString SCH_EDIT_FRAME::GetCurrentFileName() const
{
SCH_SCREEN* screen = g_RootSheet->GetScreen();
if( screen )
return screen->GetFileName();
return wxEmptyString;
}

View File

@ -567,6 +567,8 @@ public:
bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl = 0 ) override;
wxString GetCurrentFileName() const override;
void ParseArgs( wxCmdLineParser& aParser ) override;
/**

View File

@ -408,6 +408,14 @@ public:
wxString GetMruPath() const { return m_mruPath; }
/**
* Get the full filename + path of the currently opened file in the frame.
* If no file is open, an empty string is returned.
*
* @return the filename and full path to the open file
*/
virtual wxString GetCurrentFileName() const { return wxEmptyString; }
/**
* Recreates the menu bar.
*

View File

@ -215,7 +215,7 @@ void KICAD_MANAGER_FRAME::SetProjectFileName( const wxString& aFullProjectProFil
}
const wxString KICAD_MANAGER_FRAME::GetProjectFileName()
const wxString KICAD_MANAGER_FRAME::GetProjectFileName() const
{
return Prj().GetProjectFullName();
}
@ -310,10 +310,6 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
if( Kiway().PlayersClose( false ) )
{
// Save the currently opened file in the file history
if( !GetProjectFileName().empty() )
UpdateFileHistory( GetProjectFileName() );
Event.SetCanVeto( true );
m_leftWin->Show( false );

View File

@ -97,6 +97,11 @@ public:
void RecreateBaseHToolbar();
void RecreateLauncher();
wxString GetCurrentFileName() const override
{
return GetProjectFileName();
}
/**
* Open dialog to import Eagle schematic and board files.
*/
@ -153,7 +158,7 @@ public:
void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
void SetProjectFileName( const wxString& aFullProjectProFileName );
const wxString GetProjectFileName();
const wxString GetProjectFileName() const;
// read only accessors
const wxString SchFileName();

View File

@ -207,7 +207,7 @@ void DIALOG_INSPECTOR::ReCreateDesignList()
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
wxFileName fn( ((PL_EDITOR_FRAME*) GetParent())->GetCurrFileName() );
wxFileName fn( ((PL_EDITOR_FRAME*) GetParent())->GetCurrentFileName() );
if( fn.GetName().IsEmpty() )
SetTitle( "<default page layout>" );

View File

@ -90,7 +90,7 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
{
wxString msg;
int id = event.GetId();
wxString filename = GetCurrFileName();
wxString filename = GetCurrentFileName();
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
if( filename.IsEmpty() && id == wxID_SAVE )
@ -110,7 +110,7 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
{
case wxID_NEW:
pglayout.AllowVoidList( true );
SetCurrFileName( wxEmptyString );
SetCurrentFileName( wxEmptyString );
pglayout.ClearList();
OnNewPageLayout();
break;
@ -207,8 +207,8 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
msg.Printf( _("File \"%s\" written"), GetChars( filename ) );
SetStatusText( msg );
if( GetCurrFileName().IsEmpty() )
SetCurrFileName( filename );
if( GetCurrentFileName().IsEmpty() )
SetCurrentFileName( filename );
}
}
break;
@ -225,7 +225,7 @@ bool PL_EDITOR_FRAME::LoadPageLayoutDescrFile( const wxString& aFullFileName )
if( wxFileExists( aFullFileName ) )
{
WS_DATA_MODEL::GetTheInstance().SetPageLayout( aFullFileName );
SetCurrFileName( aFullFileName );
SetCurrentFileName( aFullFileName );
UpdateFileHistory( aFullFileName );
GetScreen()->ClrModify();
return true;

View File

@ -282,7 +282,7 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
if( IsContentModified() )
{
wxFileName filename = GetCurrFileName();
wxFileName filename = GetCurrentFileName();
wxString msg = _( "Save changes to \"%s\" before closing?" );
if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
@ -449,7 +449,7 @@ void PL_EDITOR_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
void PL_EDITOR_FRAME::UpdateTitleAndInfo()
{
wxString title;
wxString file = GetCurrFileName();
wxString file = GetCurrentFileName();
title.Printf( _( "Page Layout Editor" ) + wxT( " \u2014 %s" ),
file.Length() ? file : _( "no file selected" ) );
@ -457,13 +457,13 @@ void PL_EDITOR_FRAME::UpdateTitleAndInfo()
}
const wxString& PL_EDITOR_FRAME::GetCurrFileName() const
wxString PL_EDITOR_FRAME::GetCurrentFileName() const
{
return BASE_SCREEN::m_PageLayoutDescrFileName;
}
void PL_EDITOR_FRAME::SetCurrFileName( const wxString& aName )
void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
{
BASE_SCREEN::m_PageLayoutDescrFileName = aName;
}
@ -774,7 +774,7 @@ void PL_EDITOR_FRAME::OnNewPageLayout()
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
if( GetCurrFileName().IsEmpty() )
if( GetCurrentFileName().IsEmpty() )
{
// Default shutdown reason until a file is loaded
SetShutdownBlockReason( _( "New page layout file is unsaved" ) );

View File

@ -259,12 +259,12 @@ public:
* If this is the default (no loaded file) returns a emtpy name
* or a new design.
*/
const wxString& GetCurrFileName() const;
wxString GetCurrentFileName() const override;
/**
* Stores the current layout descr file filename
*/
void SetCurrFileName( const wxString& aName );
void SetCurrentFileName( const wxString& aName );
/**
* Refresh the library tree and redraw the window

View File

@ -88,7 +88,7 @@ int PL_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
m_frame->SaveCopyInUndoList( true );
DIALOG_PAGES_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) );
dlg.SetWksFileName( m_frame->GetCurrFileName() );
dlg.SetWksFileName( m_frame->GetCurrentFileName() );
dlg.EnableWksFileNamePicker( false );
if( dlg.ShowModal() != wxID_OK )

View File

@ -1257,3 +1257,9 @@ void PCB_EDIT_FRAME::OnExportHyperlynx( wxCommandEvent& event )
ExportBoardToHyperlynx( GetBoard(), fn );
}
wxString PCB_EDIT_FRAME::GetCurrentFileName() const
{
return GetBoard()->GetFileName();
}

View File

@ -952,6 +952,8 @@ public:
void SyncToolbars() override;
wxString GetCurrentFileName() const override;
DECLARE_EVENT_TABLE()
};