kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #09314
[PATCH] Prevent Pcbnew from opening the same file twice
El 04/01/13 13:20, jp charras escribió:> Le 03/01/2013 18:38, Jacobo
Aragunde Pérez a écrit :
>> Currently KiCad applications allow opening the same file more than once,
>> and they don't check if the files have changed in disk before saving. As
>> a consequence, there can be situations where the user loses some data
>> without notice.
>>
>> This patch uses wxSingleInstanceChecker to create a lock on the open
>> file. It is checked every time Eeschema tries to open a file.
>> ...
>>
>> Finally, this patch is a starting point to implement similar checks in
>> other KiCad applications.
>>
>>
>
> I committed your patch, with a small change for Windows, about file
> separator which is not the same as Unix.
> ...
Thanks Jean-Pierre. As mentioned before, I continued the work to
implement a similar patch for in Pcbnew. The new patch is attached.
--
Jacobo
=== modified file 'pcbnew/files.cpp'
--- pcbnew/files.cpp 2012-12-29 09:54:25 +0000
+++ pcbnew/files.cpp 2013-01-04 15:58:33 +0000
@@ -241,7 +241,14 @@
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() );
=== modified file 'pcbnew/pcbnew.cpp'
--- pcbnew/pcbnew.cpp 2012-12-16 13:48:54 +0000
+++ pcbnew/pcbnew.cpp 2013-01-04 15:58:33 +0000
@@ -117,16 +117,6 @@
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,9 +130,25 @@
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;
Follow ups