Commit 04e348ac authored by lifekidyeaa's avatar lifekidyeaa

modified the treeprj so that, instead of recursively scanning and adding

*all* the nested files and directories within the current working directory, it scans the first 
level of files and directories.  When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl.  This means that the little 
triangle does not appear until the user opens a directory .. but, i think this is 
a worthwile price to pay given below. 

This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or, 
in my case, it starts in my home directory, where thanks to wine & other sw,  
there are far too many directories. 

also modified the TreePrjItemData so that it stores the full pathnames in m_FileName, 
not paths relative to the CWD.  I'm not sure if this is the correct thing to do, 
especially with the python interface, so change it back if it is more complicated. 

the move and rename commands threw a segfault on my system 
(Debian etch, wxWidgets 2.8.7), 
and since there are better ways to rename and move files, this functionality 
was disabled until somebody can fix it (alas, I don't have time for this now)


parent 4a32a601
......@@ -202,7 +202,7 @@ public:
bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void Move( TreePrjItemData* dest );
void Activate();
void Activate(WinEDA_PrjFrame* prjframe);
const wxMenu* GetMenu()
{
......@@ -320,7 +320,7 @@ public:
#endif
void AddFile( const wxString& name, wxTreeItemId& root );
bool AddFile( const wxString& name, wxTreeItemId& root );
DECLARE_EVENT_TABLE()
};
......
......@@ -163,6 +163,10 @@ void TreePrjItemData::OnRename( wxTreeEvent& event, bool check )
/****************************************************************/
/* Called upon tree item rename */
{
//this segfaults on linux (in wxEvtHandler::ProcessEvent), wx version 2.8.7
//therefore, until it is fixed, we must cancel the rename.
event.Veto();
return;
if( !Rename( event.GetLabel(), check ) )
event.Veto();
}
......@@ -174,8 +178,12 @@ void TreePrjItemData::Move( TreePrjItemData* dest )
// Move the object to dest
{
//function not safe.
return;
const wxString sep = wxFileName().GetPathSeparator();
if( m_Type == TREE_DIRECTORY )
return;
if( !dest )
return;
if( m_Parent != dest->m_Parent )
......@@ -249,6 +257,9 @@ bool TreePrjItemData::Rename( const wxString& name, bool check )
/****************************************************************/
/* rename the file checking if extension change occurs */
{
//this is broken & unsafe to use on linux.
if( m_Type == TREE_DIRECTORY )
return false;
if( name.IsEmpty() )
return false;
......@@ -339,11 +350,16 @@ bool TreePrjItemData::Delete( bool check )
/**********************************/
void TreePrjItemData::Activate()
void TreePrjItemData::Activate(WinEDA_PrjFrame* prjframe)
/**********************************/
/* Called under item activation */
{
wxString FullFileName = wxGetCwd() + wxFileName().GetPathSeparator() + GetFileName();
wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName();
wxDir *dir;
wxString dir_filename;
wxTreeItemId id = GetId();
int count;
switch( GetType() )
{
......@@ -351,7 +367,29 @@ void TreePrjItemData::Activate()
break;
case TREE_DIRECTORY:
m_Parent->Toggle( GetId() );
if(prjframe){
dir = new wxDir(FullFileName);
count = 0;
if( dir && dir->IsOpened() && dir->GetFirst( &dir_filename ) )
{
do
{
wxString fil = FullFileName + sep + dir_filename;
if( prjframe->AddFile(fil, id) ){
count++;
}
} while( dir->GetNext( &dir_filename ) );
}
if(count == 0)
{
prjframe->AddFile(wxString("no kicad files found in this directory"), id);
}
/* Sort filenames by alphabetic order */
m_Parent->SortChildren( id );
if(dir) delete dir;
}
m_Parent->Toggle( id );
break;
case TREE_SCHEMA:
......
......@@ -26,6 +26,7 @@
#include "id.h"
/******************************************************************/
WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
const wxPoint& pos,
......@@ -49,6 +50,7 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
m_Filters.push_back( wxT( "^.*\\.net$" ) );
m_Filters.push_back( wxT( "^.*\\.txt$" ) );
m_Filters.push_back( wxT( "^.*\\.pho$" ) );
m_Filters.push_back( wxT( "^no kicad files found" ) );
#ifdef KICAD_PYTHON
m_Filters.push_back( wxT( "^.*\\.py$" ) );
......@@ -517,7 +519,7 @@ wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
/**************************************************************************/
void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
/**************************************************************************/
/* add filename "name" to the tree
......@@ -550,9 +552,8 @@ void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
isSchematic = true;
}
}
if( !addFile )
return;
return false;
// only show the schematic if it is a top level schematic. eeschema
// cannot open a schematic and display it properly unless it starts
......@@ -564,13 +565,13 @@ void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
char line[128]; // small because we just need a few bytes from the start of a line
FILE* fp;
wxString FullFileName = wxGetCwd() + STRING_DIR_SEP + name;
wxString FullFileName = name;
fp = wxFopen( FullFileName, wxT( "rt" ) );
if( fp == NULL )
{
//printf("Unable to open \"%s\"\n", (const char*) FullFileName.mb_str() );
return; // why show a file we cannot open?
return false; // why show a file we cannot open?
}
addFile = false;
......@@ -589,7 +590,7 @@ void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
fclose(fp);
if( !addFile )
return; // it is a non-top-level schematic
return false; // it is a non-top-level schematic
}
for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
......@@ -609,7 +610,20 @@ void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
}
}
}
//also check to see if it is already there.
wxTreeItemIdValue cookie;
wxTreeItemId kid = m_TreeProject->GetFirstChild(root, cookie);
while(kid.IsOk())
{
TreePrjItemData* itemData = (TreePrjItemData*)
m_TreeProject->GetItemData(kid);
if( itemData ){
if( itemData->m_FileName == name ){
return true; //well, we would have added it, but it is already here!
}
}
kid = m_TreeProject->GetNextChild(root, cookie);
}
// Append the item (only appending the filename not the full path):
wxString file = wxFileNameFromPath( name );
......@@ -632,24 +646,7 @@ void WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ), PyHandler::Convert( name ) );
#endif
if( TREE_DIRECTORY == type )
{
const wxString sep = wxFileName().GetPathSeparator();
wxDir dir( name );
wxString dir_filename;
if( dir.GetFirst( &dir_filename ) )
{
do
{
AddFile( name + sep + dir_filename, cellule );
} while( dir.GetNext( &dir_filename ) );
}
/* Sort filenames by alphabetic order */
m_TreeProject->SortChildren( cellule );
}
return true;
}
......@@ -701,7 +698,8 @@ void WinEDA_PrjFrame::ReCreateTreePrj()
if( prjOpened )
{
wxDir dir( wxGetCwd() );
wxString dir_str = dir.GetName();
wxString sep = wxFileName().GetPathSeparator();
wxString filename;
if( dir.GetFirst( &filename ) )
......@@ -711,7 +709,7 @@ void WinEDA_PrjFrame::ReCreateTreePrj()
if( filename == Text + wxT( ".pro" ) )
continue;
AddFile( filename, m_root );
AddFile(dir_str + sep + filename, m_root );
} while( dir.GetNext( &filename ) );
}
......@@ -936,5 +934,5 @@ void WinEDA_PrjFrame::OnSelect( wxTreeEvent& Event )
if( !tree_data )
return;
tree_data->Activate();
tree_data->Activate(this);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment