Eeschema:commit patch <Prevent Eeschema from opening the same file twice> with a small fix for windows.
This commit is contained in:
parent
16402d8180
commit
f914cd0dec
|
@ -273,6 +273,7 @@ static struct LANGUAGE_DESCR s_Language_List[] =
|
|||
EDA_APP::EDA_APP()
|
||||
{
|
||||
m_Checker = NULL;
|
||||
m_oneInstancePerFileChecker = NULL;
|
||||
m_HtmlCtrl = NULL;
|
||||
m_settings = NULL;
|
||||
m_LanguageId = wxLANGUAGE_DEFAULT;
|
||||
|
@ -298,6 +299,9 @@ EDA_APP::~EDA_APP()
|
|||
if( m_Checker )
|
||||
delete m_Checker;
|
||||
|
||||
if( m_oneInstancePerFileChecker )
|
||||
delete m_oneInstancePerFileChecker;
|
||||
|
||||
delete m_Locale;
|
||||
}
|
||||
|
||||
|
@ -1124,3 +1128,25 @@ void EDA_APP::InsertLibraryPath( const wxString& aPaths, size_t aIndex )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EDA_APP::LockFile( const wxString& fileName )
|
||||
{
|
||||
// semaphore to protect the edition of the file by more than one instance
|
||||
if( m_oneInstancePerFileChecker != NULL )
|
||||
{
|
||||
// it means that we had an open file and we are opening a different one
|
||||
delete m_oneInstancePerFileChecker;
|
||||
}
|
||||
wxString lockFileName = fileName + wxT( ".lock" );
|
||||
lockFileName.Replace( wxT( "/" ), wxT( "_" ) );
|
||||
// We can have filenames coming from Windows, so also convert Windows separator
|
||||
lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
|
||||
m_oneInstancePerFileChecker = new wxSingleInstanceChecker( lockFileName );
|
||||
if( m_oneInstancePerFileChecker &&
|
||||
m_oneInstancePerFileChecker->IsAnotherRunning() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -89,18 +89,33 @@ bool EDA_APP::OnInit()
|
|||
{
|
||||
wxFileName filename;
|
||||
SCH_EDIT_FRAME* frame = NULL;
|
||||
bool fileReady = false;
|
||||
|
||||
InitEDA_Appl( wxT( "Eeschema" ), APP_EESCHEMA_T );
|
||||
|
||||
if( m_Checker && m_Checker->IsAnotherRunning() )
|
||||
{
|
||||
if( !IsOK( NULL, _( "Eeschema is already running, Continue?" ) ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( argc > 1 )
|
||||
filename = argv[1];
|
||||
|
||||
if( filename.IsOk() )
|
||||
{
|
||||
if( filename.GetExt() != SchematicFileExtension )
|
||||
filename.SetExt( SchematicFileExtension );
|
||||
|
||||
if( !wxGetApp().LockFile( filename.GetFullPath() ) )
|
||||
{
|
||||
DisplayError( NULL, _( "This file is already open." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
fileReady = true;
|
||||
}
|
||||
|
||||
if( m_Checker && m_Checker->IsAnotherRunning() )
|
||||
{
|
||||
if( !IsOK( NULL, _( "Eeschema is already running, Continue?" ) ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Give a default colour for all layers
|
||||
// (actual color will beinitialized by config)
|
||||
for( int ii = 0; ii < MAX_LAYERS; ii++ )
|
||||
|
@ -130,11 +145,8 @@ bool EDA_APP::OnInit()
|
|||
frame->Zoom_Automatique( true );
|
||||
|
||||
/* Load file specified in the command line. */
|
||||
if( filename.IsOk() )
|
||||
if( fileReady )
|
||||
{
|
||||
if( filename.GetExt() != SchematicFileExtension )
|
||||
filename.SetExt( SchematicFileExtension );
|
||||
|
||||
wxSetWorkingDirectory( filename.GetPath() );
|
||||
|
||||
if( frame->LoadOneEEProject( filename.GetFullPath(), false ) )
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <confirm.h>
|
||||
#include <gestfich.h>
|
||||
#include <wxEeschemaStruct.h>
|
||||
#include <appl_wxstruct.h>
|
||||
|
||||
#include <general.h>
|
||||
#include <protos.h>
|
||||
|
@ -204,14 +205,6 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
|
|||
FullFileName = dlg.GetPath();
|
||||
}
|
||||
|
||||
if( g_RootSheet )
|
||||
{
|
||||
SAFE_DELETE( g_RootSheet );
|
||||
}
|
||||
|
||||
CreateScreens();
|
||||
screen = GetScreen();
|
||||
|
||||
wxFileName fn = FullFileName;
|
||||
|
||||
if( fn.IsRelative() )
|
||||
|
@ -220,6 +213,21 @@ bool SCH_EDIT_FRAME::LoadOneEEProject( const wxString& aFileName, bool aIsNew )
|
|||
FullFileName = fn.GetFullPath();
|
||||
}
|
||||
|
||||
if( !wxGetApp().LockFile( FullFileName ) )
|
||||
{
|
||||
DisplayError( this, _( "This file is already open." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear the screen before open a new file
|
||||
if( g_RootSheet )
|
||||
{
|
||||
SAFE_DELETE( g_RootSheet );
|
||||
}
|
||||
|
||||
CreateScreens();
|
||||
screen = GetScreen();
|
||||
|
||||
wxLogDebug( wxT( "Loading schematic " ) + FullFileName );
|
||||
wxSetWorkingDirectory( fn.GetPath() );
|
||||
|
||||
|
|
|
@ -67,6 +67,9 @@ protected:
|
|||
/// Used to prevent multiple instances of an application from being run at the same time.
|
||||
wxSingleInstanceChecker* m_Checker;
|
||||
|
||||
/// Used to prevent opening the same file multiple times.
|
||||
wxSingleInstanceChecker* m_oneInstancePerFileChecker;
|
||||
|
||||
wxString m_Project;
|
||||
|
||||
/// The application specific configuration settings.
|
||||
|
@ -410,6 +413,13 @@ public:
|
|||
*/
|
||||
void InsertLibraryPath( const wxString& aPaths, size_t aIndex );
|
||||
|
||||
/**
|
||||
* Function LockFile
|
||||
* Locks the access to a file.
|
||||
* @param fileName = full path to the file.
|
||||
* @return false if the file was already locked, true otherwise.
|
||||
*/
|
||||
bool LockFile( const wxString& fileName );
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue