Overhaul file locking system.
See bug report for details. Fixes https://gitlab.com/kicad/code/kicad/issues/8919
This commit is contained in:
parent
ef38642bf1
commit
b5a3385ea9
|
@ -151,6 +151,19 @@ long KIDIALOG::getStyle( KD_TYPE aType )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool OverrideLock( wxWindow* aParent, const wxString& aMessage )
|
||||||
|
{
|
||||||
|
wxRichMessageDialog dlg( aParent, aMessage, _( "File Open Error" ),
|
||||||
|
wxYES_NO | wxICON_ERROR | wxCENTER );
|
||||||
|
|
||||||
|
// Note: must use the "no" label to get the correct positioning/spacing for a (potentially)
|
||||||
|
// destructive action
|
||||||
|
dlg.SetYesNoLabels( _( "OK" ), _( "Open Anyway" ) );
|
||||||
|
|
||||||
|
return dlg.ShowModal() == wxID_NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage, bool* aApplyToAll )
|
int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage, bool* aApplyToAll )
|
||||||
{
|
{
|
||||||
static bool s_apply_to_all = false;
|
static bool s_apply_to_all = false;
|
||||||
|
|
|
@ -205,7 +205,7 @@ bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
|
||||||
{
|
{
|
||||||
m_file_checker = ::LockFile( aFileName );
|
m_file_checker = ::LockFile( aFileName );
|
||||||
|
|
||||||
return bool( m_file_checker );
|
return m_file_checker && !m_file_checker->IsAnotherRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,12 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
|
|
||||||
if( !LockFile( fullFileName ) )
|
if( !LockFile( fullFileName ) )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "Schematic file '%s' is already open." ), fullFileName );
|
msg.Printf( _( "Schematic file '%s' is already open.\n\n"
|
||||||
DisplayError( this, msg );
|
"Interleaved saves may produce very unexpected results.\n" ),
|
||||||
return false;
|
fullFileName );
|
||||||
|
|
||||||
|
if( !OverrideLock( this, msg ) )
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !AskToSaveChanges() )
|
if( !AskToSaveChanges() )
|
||||||
|
@ -1131,9 +1134,13 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
|
||||||
|
|
||||||
if( !LockFile( aFileName ) )
|
if( !LockFile( aFileName ) )
|
||||||
{
|
{
|
||||||
wxString msg = wxString::Format( _( "Schematic '%s' is already open." ), aFileName );
|
wxString msg;
|
||||||
DisplayError( this, msg );
|
msg.Printf( _( "Schematic file '%s' is already open.\n\n"
|
||||||
return false;
|
"Interleaved saves may produce very unexpected results.\n" ),
|
||||||
|
aFileName );
|
||||||
|
|
||||||
|
if( !OverrideLock( this, msg ) )
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -82,6 +82,13 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a dialog indicating the file is already open, with an option to reset the lock.
|
||||||
|
* @return true if the lock was reset.
|
||||||
|
*/
|
||||||
|
bool OverrideLock( wxWindow* aParent, const wxString& aMessage );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a dialog with Save, Cancel and Discard Changes buttons.
|
* Display a dialog with Save, Cancel and Discard Changes buttons.
|
||||||
*
|
*
|
||||||
|
|
|
@ -564,6 +564,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString fullFileName( aFileSet[0] );
|
wxString fullFileName( aFileSet[0] );
|
||||||
|
wxString msg;
|
||||||
|
|
||||||
if( Kiface().IsSingle() )
|
if( Kiface().IsSingle() )
|
||||||
{
|
{
|
||||||
|
@ -575,11 +576,14 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
|
|
||||||
std::unique_ptr<wxSingleInstanceChecker> lockFile = ::LockFile( fullFileName );
|
std::unique_ptr<wxSingleInstanceChecker> lockFile = ::LockFile( fullFileName );
|
||||||
|
|
||||||
if( !lockFile )
|
if( !lockFile || lockFile->IsAnotherRunning() )
|
||||||
{
|
{
|
||||||
wxString msg = wxString::Format( _( "PCB '%s' is already open." ), fullFileName );
|
msg.Printf( _( "PCB file '%s' is already open.\n\n"
|
||||||
DisplayError( this, msg );
|
"Interleaved saves may produce very unexpected results.\n" ),
|
||||||
return false;
|
fullFileName );
|
||||||
|
|
||||||
|
if( !OverrideLock( this, msg ) )
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( IsContentModified() )
|
if( IsContentModified() )
|
||||||
|
@ -603,9 +607,9 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
if( is_new && !( aCtl & KICTL_CREATE ) )
|
if( is_new && !( aCtl & KICTL_CREATE ) )
|
||||||
{
|
{
|
||||||
// notify user that fullFileName does not exist, ask if user wants to create it.
|
// notify user that fullFileName does not exist, ask if user wants to create it.
|
||||||
wxString ask = wxString::Format( _( "PCB '%s' does not exist. Do you wish to create it?" ),
|
msg.Printf( _( "PCB '%s' does not exist. Do you wish to create it?" ), fullFileName );
|
||||||
fullFileName );
|
|
||||||
if( !IsOK( this, ask ) )
|
if( !IsOK( this, msg ) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,7 +666,6 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
|
||||||
{
|
{
|
||||||
BOARD* loadedBoard = nullptr; // it will be set to non-NULL if loaded OK
|
BOARD* loadedBoard = nullptr; // it will be set to non-NULL if loaded OK
|
||||||
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
||||||
wxString msg;
|
|
||||||
|
|
||||||
LAYER_REMAPPABLE_PLUGIN* layerRemappablePlugin =
|
LAYER_REMAPPABLE_PLUGIN* layerRemappablePlugin =
|
||||||
dynamic_cast< LAYER_REMAPPABLE_PLUGIN* >( (PLUGIN*) pi );
|
dynamic_cast< LAYER_REMAPPABLE_PLUGIN* >( (PLUGIN*) pi );
|
||||||
|
|
Loading…
Reference in New Issue