From 0c88507dcfcd2302f63e056cd0a0c4ca559a7a5e Mon Sep 17 00:00:00 2001 From: Jacobo Aragunde Perez Date: Fri, 4 Jan 2013 18:47:59 +0100 Subject: [PATCH] Prevent Pcbnew from opening the same file twice. --- pcbnew/files.cpp | 7 +++++++ pcbnew/pcbnew.cpp | 30 ++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 1eda4f603d..ee5122bf10 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -241,7 +241,14 @@ the changes?" ) ) ) fileName.SetExt( pi->GetFileExtension() ); if( !aAppend ) + { + if( !wxGetApp().LockFile( fileName.GetFullPath() ) ) + { + DisplayError( this, _( "This file is already open." ) ); + return false; + } Clear_Pcb( false ); // pass false since we prompted above for a modified board + } CheckForAutoSaveFile( fileName, fileName.GetExt() ); diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 32fc1e2883..ff20d3c600 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -117,16 +117,6 @@ bool EDA_APP::OnInit() InitEDA_Appl( wxT( "Pcbnew" ), APP_PCBNEW_T ); - if( m_Checker && m_Checker->IsAnotherRunning() ) - { - if( !IsOK( NULL, _( "Pcbnew is already running, Continue?" ) ) ) - return false; - } - - // read current setup and reopen last directory if no filename to open in command line - bool reopenLastUsedDirectory = argc == 1; - GetSettings( reopenLastUsedDirectory ); - if( argc > 1 ) { fn = argv[1]; @@ -140,10 +130,26 @@ Changing extension to .%s." ), GetChars( fn.GetFullPath() ), wxMessageBox( msg ); } - if( fn.IsOk() && fn.DirExists() ) - wxSetWorkingDirectory( fn.GetPath() ); + if( !wxGetApp().LockFile( fn.GetFullPath() ) ) + { + DisplayError( NULL, _( "This file is already open." ) ); + return false; + } } + if( m_Checker && m_Checker->IsAnotherRunning() ) + { + if( !IsOK( NULL, _( "Pcbnew is already running, Continue?" ) ) ) + return false; + } + + // read current setup and reopen last directory if no filename to open in command line + bool reopenLastUsedDirectory = argc == 1; + GetSettings( reopenLastUsedDirectory ); + + if( fn.IsOk() && fn.DirExists() ) + wxSetWorkingDirectory( fn.GetPath() ); + g_DrawBgColor = BLACK; /* Must be called before creating the main frame in order to