Fix showing new formats in project tree
* Differentiate between new JSON and old project files * Show both old and new schematic files in the tree
This commit is contained in:
parent
ccc0ceb32f
commit
f3e44fb029
|
@ -43,9 +43,10 @@ class KICAD_SETTINGS;
|
||||||
|
|
||||||
enum TreeFileType {
|
enum TreeFileType {
|
||||||
TREE_ROOT = 0,
|
TREE_ROOT = 0,
|
||||||
TREE_PROJECT,
|
TREE_LEGACY_PROJECT, // Legacy project file (.pro)
|
||||||
|
TREE_JSON_PROJECT, // JSON formatted project file (.kicad_pro)
|
||||||
TREE_LEGACY_SCHEMATIC, // Schematic file (.sch)
|
TREE_LEGACY_SCHEMATIC, // Schematic file (.sch)
|
||||||
TREE_SEXPR_SCHEMATIC, // Schematic file (.sch)
|
TREE_SEXPR_SCHEMATIC, // Schematic file (.kicad_sch)
|
||||||
TREE_LEGACY_PCB, // board file (.brd) legacy format
|
TREE_LEGACY_PCB, // board file (.brd) legacy format
|
||||||
TREE_SEXPR_PCB, // board file (.kicad_brd) new s expression format
|
TREE_SEXPR_PCB, // board file (.kicad_brd) new s expression format
|
||||||
TREE_GERBER, // Gerber file (.pho, .g*)
|
TREE_GERBER, // Gerber file (.pho, .g*)
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
// Add extensions in a compatible regex format to see others files types
|
// Add extensions in a compatible regex format to see others files types
|
||||||
static const wxChar* s_allowedExtensionsToList[] = {
|
static const wxChar* s_allowedExtensionsToList[] = {
|
||||||
wxT( "^.*\\.pro$" ),
|
wxT( "^.*\\.pro$" ),
|
||||||
|
wxT( "^.*\\.kicad_pro$" ),
|
||||||
wxT( "^.*\\.pdf$" ),
|
wxT( "^.*\\.pdf$" ),
|
||||||
wxT( "^.*\\.sch$" ), // Legacy Eeschema files
|
wxT( "^.*\\.sch$" ), // Legacy Eeschema files
|
||||||
wxT( "^.*\\.kicad_sch$" ), // S-expr Eeschema files
|
wxT( "^.*\\.kicad_sch$" ), // S-expr Eeschema files
|
||||||
|
@ -264,7 +265,8 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
|
||||||
{
|
{
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case TREE_PROJECT: return ProjectFileExtension;
|
case TREE_LEGACY_PROJECT: return LegacyProjectFileExtension;
|
||||||
|
case TREE_JSON_PROJECT: return ProjectFileExtension;
|
||||||
case TREE_LEGACY_SCHEMATIC: return LegacySchematicFileExtension;
|
case TREE_LEGACY_SCHEMATIC: return LegacySchematicFileExtension;
|
||||||
case TREE_SEXPR_SCHEMATIC: return KiCadSchematicFileExtension;
|
case TREE_SEXPR_SCHEMATIC: return KiCadSchematicFileExtension;
|
||||||
case TREE_LEGACY_PCB: return LegacyPcbFileExtension;
|
case TREE_LEGACY_PCB: return LegacyPcbFileExtension;
|
||||||
|
@ -294,8 +296,8 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
const wxString& aName, wxTreeItemId& aRoot, bool aCanResetFileWatcher, bool aRecurse )
|
const wxString& aName, wxTreeItemId& aRoot, bool aCanResetFileWatcher, bool aRecurse )
|
||||||
{
|
{
|
||||||
wxTreeItemId newItemId;
|
wxTreeItemId newItemId;
|
||||||
TreeFileType type = TREE_UNKNOWN;
|
TreeFileType type = TREE_UNKNOWN;
|
||||||
wxFileName fn( aName );
|
wxFileName fn( aName );
|
||||||
|
|
||||||
// Files/dirs names starting by "." are not visible files under unices.
|
// Files/dirs names starting by "." are not visible files under unices.
|
||||||
// Skip them also under Windows
|
// Skip them also under Windows
|
||||||
|
@ -374,7 +376,8 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
addFile = true;
|
addFile = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if( fn.GetExt() == "kicad_sch" )
|
}
|
||||||
|
else if( fn.GetExt() == "kicad_sch" )
|
||||||
{
|
{
|
||||||
char* start = line;
|
char* start = line;
|
||||||
|
|
||||||
|
@ -396,14 +399,14 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
|
for( int i = TREE_LEGACY_PROJECT; i < TREE_MAX; i++ )
|
||||||
{
|
{
|
||||||
wxString ext = GetFileExt( (TreeFileType) i );
|
wxString ext = GetFileExt( (TreeFileType) i );
|
||||||
|
|
||||||
if( ext == wxT( "" ) )
|
if( ext == wxT( "" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
|
reg.Compile( wxString::FromAscii( "^.*\\." ) + ext +
|
||||||
wxString::FromAscii( "$" ), wxRE_ICASE );
|
wxString::FromAscii( "$" ), wxRE_ICASE );
|
||||||
|
|
||||||
if( reg.Matches( aName ) )
|
if( reg.Matches( aName ) )
|
||||||
|
@ -414,9 +417,17 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString file = wxFileNameFromPath( aName );
|
||||||
|
wxFileName currfile( file );
|
||||||
|
wxFileName project( m_Parent->GetProjectFileName() );
|
||||||
|
|
||||||
|
// Ignore legacy projects with the same name as the current project
|
||||||
|
if( ( type == TREE_LEGACY_PROJECT ) && ( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) )
|
||||||
|
return newItemId;
|
||||||
|
|
||||||
// also check to see if it is already there.
|
// also check to see if it is already there.
|
||||||
wxTreeItemIdValue cookie;
|
wxTreeItemIdValue cookie;
|
||||||
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
||||||
|
|
||||||
while( kid.IsOk() )
|
while( kid.IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -431,8 +442,41 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only show the JSON project files if both legacy and JSON files are present
|
||||||
|
if( ( type == TREE_LEGACY_PROJECT ) || ( type == TREE_JSON_PROJECT ) )
|
||||||
|
{
|
||||||
|
kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
||||||
|
|
||||||
|
while( kid.IsOk() )
|
||||||
|
{
|
||||||
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
||||||
|
|
||||||
|
if( itemData )
|
||||||
|
{
|
||||||
|
wxFileName fname( itemData->GetFileName() );
|
||||||
|
|
||||||
|
if( fname.GetName().CmpNoCase( currfile.GetName() ) == 0 )
|
||||||
|
{
|
||||||
|
// If the tree item is the legacy project remove it.
|
||||||
|
if( itemData->GetType() == TREE_LEGACY_PROJECT )
|
||||||
|
{
|
||||||
|
m_TreeProject->Delete( kid );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If we are the legacy project and the tree was the JSON project, ignore this file
|
||||||
|
else if( ( itemData->GetType() == TREE_JSON_PROJECT )
|
||||||
|
&& ( type == TREE_LEGACY_PROJECT ) )
|
||||||
|
{
|
||||||
|
return newItemId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Append the item (only appending the filename not the full path):
|
// Append the item (only appending the filename not the full path):
|
||||||
wxString file = wxFileNameFromPath( aName );
|
|
||||||
newItemId = m_TreeProject->AppendItem( aRoot, file );
|
newItemId = m_TreeProject->AppendItem( aRoot, file );
|
||||||
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
|
||||||
|
|
||||||
|
@ -440,9 +484,6 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
data->SetState( 0 );
|
data->SetState( 0 );
|
||||||
|
|
||||||
// Mark root files (files which have the same aName as the project)
|
// Mark root files (files which have the same aName as the project)
|
||||||
wxFileName project( m_Parent->GetProjectFileName() );
|
|
||||||
wxFileName currfile( file );
|
|
||||||
|
|
||||||
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
||||||
data->SetRootFile( true );
|
data->SetRootFile( true );
|
||||||
else
|
else
|
||||||
|
@ -456,11 +497,11 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
|
||||||
// in this case AddFile is recursive, but for the first level only.
|
// in this case AddFile is recursive, but for the first level only.
|
||||||
if( TREE_DIRECTORY == type && aRecurse )
|
if( TREE_DIRECTORY == type && aRecurse )
|
||||||
{
|
{
|
||||||
wxDir dir( aName );
|
wxDir dir( aName );
|
||||||
|
|
||||||
if( dir.IsOpened() ) // protected dirs will not open properly.
|
if( dir.IsOpened() ) // protected dirs will not open properly.
|
||||||
{
|
{
|
||||||
wxString dir_filename;
|
wxString dir_filename;
|
||||||
|
|
||||||
data->SetPopulated( true );
|
data->SetPopulated( true );
|
||||||
#ifndef __WINDOWS__
|
#ifndef __WINDOWS__
|
||||||
|
@ -517,7 +558,9 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
||||||
// 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 );
|
||||||
m_TreeProject->SetItemData( m_root, new TREEPROJECT_ITEM( TREE_PROJECT, fn.GetFullPath(),
|
|
||||||
|
// The main project file is now a JSON file
|
||||||
|
m_TreeProject->SetItemData( m_root, new TREEPROJECT_ITEM( TREE_JSON_PROJECT, fn.GetFullPath(),
|
||||||
m_TreeProject ) );
|
m_TreeProject ) );
|
||||||
|
|
||||||
// Now adding all current files if available
|
// Now adding all current files if available
|
||||||
|
@ -593,7 +636,8 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
||||||
|
|
||||||
switch( tree_id )
|
switch( tree_id )
|
||||||
{
|
{
|
||||||
case TREE_PROJECT:
|
case TREE_LEGACY_PROJECT:
|
||||||
|
case TREE_JSON_PROJECT:
|
||||||
can_edit = false;
|
can_edit = false;
|
||||||
can_rename = false;
|
can_rename = false;
|
||||||
can_delete = false;
|
can_delete = false;
|
||||||
|
|
|
@ -158,10 +158,12 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame )
|
||||||
|
|
||||||
switch( GetType() )
|
switch( GetType() )
|
||||||
{
|
{
|
||||||
case TREE_PROJECT:
|
case TREE_LEGACY_PROJECT:
|
||||||
|
case TREE_JSON_PROJECT:
|
||||||
// Select a new project if this is not the current project:
|
// Select a new project if this is not the current project:
|
||||||
if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
|
if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
|
||||||
frame->LoadProject( fullFileName );
|
frame->LoadProject( fullFileName );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_DIRECTORY:
|
case TREE_DIRECTORY:
|
||||||
|
@ -170,28 +172,22 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame )
|
||||||
|
|
||||||
case TREE_LEGACY_SCHEMATIC:
|
case TREE_LEGACY_SCHEMATIC:
|
||||||
case TREE_SEXPR_SCHEMATIC:
|
case TREE_SEXPR_SCHEMATIC:
|
||||||
if( fullFileName == frame->SchFileName() )
|
// Schematics not part of the project are opened in a separate process.
|
||||||
{
|
if( fullFileName == frame->SchFileName() || fullFileName == frame->SchLegacyFileName() )
|
||||||
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editSchematic, true );
|
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editSchematic, true );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// schematics not part of the project are opened in a separate process.
|
|
||||||
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
|
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_LEGACY_PCB:
|
case TREE_LEGACY_PCB:
|
||||||
case TREE_SEXPR_PCB:
|
case TREE_SEXPR_PCB:
|
||||||
|
// Boards not part of the project are opened in a separate process.
|
||||||
if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
|
if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
|
||||||
{
|
|
||||||
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
|
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// boards not part of the project are opened in a separate process.
|
|
||||||
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
|
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TREE_GERBER:
|
case TREE_GERBER:
|
||||||
|
|
|
@ -55,7 +55,8 @@ TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent )
|
||||||
// Make an image list containing small icons
|
// Make an image list containing small icons
|
||||||
m_ImageList = new wxImageList( iconsize.x, iconsize.y, true, TREE_MAX );
|
m_ImageList = new wxImageList( iconsize.x, iconsize.y, true, TREE_MAX );
|
||||||
|
|
||||||
m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_PROJECT
|
m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_LEGACY_PROJECT
|
||||||
|
m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_JSON_PROJECT
|
||||||
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC
|
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC
|
||||||
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC
|
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC
|
||||||
m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB
|
m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB
|
||||||
|
|
Loading…
Reference in New Issue