Fix a few issues with legacy project loading
- Prevent crash on project tree for "Empty project" item - Correctly handle loading of legacy projects in tree view - Fix an issue where legacy projects would not get saved Fixes https://gitlab.com/kicad/code/kicad/-/issues/4944
This commit is contained in:
parent
1790c536ef
commit
a107f7ce5b
|
@ -311,7 +311,8 @@ bool JSON_SETTINGS::SaveToFile( const std::string& aDirectory, bool aForce )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !path.IsFileWritable() )
|
if( ( path.FileExists() && !path.IsFileWritable() ) ||
|
||||||
|
( !path.FileExists() && !path.IsDirWritable() ) )
|
||||||
{
|
{
|
||||||
wxLogTrace( traceSettings, "File for %s is read-only; not saving", GetFullFilename() );
|
wxLogTrace( traceSettings, "File for %s is read-only; not saving", GetFullFilename() );
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -544,6 +544,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxFileName fn = pro_dir;
|
wxFileName fn = pro_dir;
|
||||||
|
bool prjReset = false;
|
||||||
|
|
||||||
if( !fn.IsOk() )
|
if( !fn.IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -551,10 +552,22 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
||||||
fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
|
fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
|
||||||
fn.SetName( NAMELESS_PROJECT );
|
fn.SetName( NAMELESS_PROJECT );
|
||||||
fn.SetExt( ProjectFileExtension );
|
fn.SetExt( ProjectFileExtension );
|
||||||
|
prjReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool prjOpened = fn.FileExists();
|
bool prjOpened = fn.FileExists();
|
||||||
|
|
||||||
|
// We may have opened a legacy project, in which case GetProjectFileName will return the
|
||||||
|
// name of the migrated (new format) file, which may not have been saved to disk yet.
|
||||||
|
if( !prjOpened && !prjReset )
|
||||||
|
{
|
||||||
|
fn.SetExt( LegacyProjectFileExtension );
|
||||||
|
prjOpened = fn.FileExists();
|
||||||
|
|
||||||
|
// Set the ext back so that in the tree view we see the (not-yet-saved) new file
|
||||||
|
fn.SetExt( ProjectFileExtension );
|
||||||
|
}
|
||||||
|
|
||||||
// root tree:
|
// root tree:
|
||||||
m_root = m_TreeProject->AddRoot( fn.GetFullName(), TREE_ROOT, TREE_ROOT );
|
m_root = m_TreeProject->AddRoot( fn.GetFullName(), TREE_ROOT, TREE_ROOT );
|
||||||
m_TreeProject->SetItemBold( m_root, true );
|
m_TreeProject->SetItemBold( m_root, true );
|
||||||
|
@ -631,6 +644,16 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
||||||
|
|
||||||
for( TREEPROJECT_ITEM* item_data : tree_data )
|
for( TREEPROJECT_ITEM* item_data : tree_data )
|
||||||
{
|
{
|
||||||
|
// Check for empty project
|
||||||
|
if( !item_data )
|
||||||
|
{
|
||||||
|
can_switch_to_project = false;
|
||||||
|
can_edit = false;
|
||||||
|
can_rename = false;
|
||||||
|
can_print = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int tree_id = item_data->GetType();
|
int tree_id = item_data->GetType();
|
||||||
wxString full_file_name = item_data->GetFileName();
|
wxString full_file_name = item_data->GetFileName();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue