2010-02-19 15:01:32 +00:00
|
|
|
/*
|
|
|
|
* file class_treeprojectfiles.cpp
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
#include <pyhandler.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "bitmaps.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#include "kicad.h"
|
2010-02-19 15:01:32 +00:00
|
|
|
#include "tree_project_frame.h"
|
|
|
|
#include "class_treeprojectfiles.h"
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#include "wx/treectrl.h"
|
|
|
|
#include "wx/regex.h"
|
|
|
|
#include "wx/dir.h"
|
|
|
|
|
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
IMPLEMENT_ABSTRACT_CLASS( TREEPROJECTFILES, wxTreeCtrl )
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeCtrl( parent, ID_PROJECT_TREE,
|
2009-02-04 15:25:03 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS, wxDefaultValidator,
|
|
|
|
wxT( "EDATreeCtrl" ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
|
|
|
|
// Make an image list containing small icons
|
|
|
|
m_ImageList = new wxImageList( 16, 16, TRUE, TREE_MAX );
|
|
|
|
|
|
|
|
m_ImageList->Add( wxBitmap( kicad_icon_small_xpm ) ); // TREE_PROJECT
|
|
|
|
m_ImageList->Add( wxBitmap( eeschema_xpm ) ); // TREE_SCHEMA
|
|
|
|
m_ImageList->Add( wxBitmap( pcbnew_xpm ) ); // TREE_PCB
|
|
|
|
m_ImageList->Add( wxBitmap( icon_python_small_xpm ) ); // TREE_PY
|
|
|
|
m_ImageList->Add( wxBitmap( icon_gerbview_small_xpm ) ); // TREE_GERBER
|
|
|
|
m_ImageList->Add( wxBitmap( datasheet_xpm ) ); // TREE_PDF
|
|
|
|
m_ImageList->Add( wxBitmap( icon_txt_xpm ) ); // TREE_TXT
|
|
|
|
m_ImageList->Add( wxBitmap( icon_cvpcb_small_xpm ) ); // TREE_NET
|
|
|
|
m_ImageList->Add( wxBitmap( unknown_xpm ) ); // TREE_UNKNOWN
|
|
|
|
m_ImageList->Add( wxBitmap( directory_xpm ) ); // TREE_DIRECTORY
|
|
|
|
|
|
|
|
SetImageList( m_ImageList );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TREEPROJECTFILES::~TREEPROJECTFILES()
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
|
|
|
if( m_ImageList )
|
|
|
|
delete m_ImageList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* sort function for tree items.
|
2007-09-13 11:55:46 +00:00
|
|
|
* items are sorted :
|
|
|
|
* directory names first by alphabetic order
|
|
|
|
* root file names after
|
|
|
|
* file names last by alphabetic order
|
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData* myitem1 = (TreePrjItemData*) GetItemData( item1 );
|
|
|
|
TreePrjItemData* myitem2 = (TreePrjItemData*) GetItemData( item2 );
|
|
|
|
|
|
|
|
if( (myitem1->m_Type == TREE_DIRECTORY) && ( myitem2->m_Type != TREE_DIRECTORY ) )
|
|
|
|
return -1;
|
|
|
|
if( (myitem2->m_Type == TREE_DIRECTORY) && ( myitem1->m_Type != TREE_DIRECTORY ) )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if( myitem1->m_IsRootFile && !myitem2->m_IsRootFile )
|
|
|
|
return -1;
|
|
|
|
if( myitem2->m_IsRootFile && !myitem1->m_IsRootFile )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return myitem1->m_FileName.CmpNoCase( myitem2->m_FileName );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData::TreePrjItemData( enum TreeFileType type, const wxString& data,
|
|
|
|
wxTreeCtrl* parent ) :
|
|
|
|
wxTreeItemData()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
m_Type = type;
|
|
|
|
m_Parent = parent;
|
|
|
|
m_FileName = data;
|
|
|
|
m_IsRootFile = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
using namespace boost::python;
|
|
|
|
|
|
|
|
// Convert the data to an id
|
2009-11-12 15:43:38 +00:00
|
|
|
object TreePrjItemData::GetIdPy() const
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId* id = new wxTreeItemId();
|
|
|
|
|
|
|
|
*id = GetId();
|
2009-11-12 15:43:38 +00:00
|
|
|
return object( handle<>( borrowed( wxPyConstructObject( id,
|
|
|
|
wxT( "wxTreeItemId" ),
|
|
|
|
true ) ) ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
// Set the state used in the icon list
|
2009-11-12 15:43:38 +00:00
|
|
|
void TreePrjItemData::SetState( int state )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxImageList* imglist = m_Parent->GetImageList();
|
|
|
|
|
|
|
|
if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
|
|
|
|
return;
|
|
|
|
m_State = state;
|
|
|
|
int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
|
|
|
|
m_Parent->SetItemImage( GetId(), imgid );
|
|
|
|
m_Parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* Get the directory containing the file */
|
2009-11-12 15:43:38 +00:00
|
|
|
wxString TreePrjItemData::GetDir() const
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
if( TREE_DIRECTORY == m_Type )
|
|
|
|
return m_FileName;
|
|
|
|
|
2007-12-17 21:19:03 +00:00
|
|
|
wxFileName filename = wxFileName( m_FileName );
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
filename.MakeRelativeTo( wxGetCwd() );
|
2007-12-17 21:19:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
wxArrayString dirs = filename.GetDirs();
|
|
|
|
|
|
|
|
wxString dir;
|
|
|
|
for( unsigned int i = 0; i < dirs.Count(); i++ )
|
|
|
|
{
|
|
|
|
dir += dirs[i] + filename.GetPathSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* Called upon tree item rename */
|
2009-11-12 15:43:38 +00:00
|
|
|
void TreePrjItemData::OnRename( wxTreeEvent& event, bool check )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
//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;
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !Rename( event.GetLabel(), check ) )
|
|
|
|
event.Veto();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
// Move the object to dest
|
2009-11-12 15:43:38 +00:00
|
|
|
void TreePrjItemData::Move( TreePrjItemData* dest )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
//function not safe.
|
|
|
|
return;
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
2007-12-17 21:19:03 +00:00
|
|
|
|
|
|
|
if( m_Type == TREE_DIRECTORY )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !dest )
|
|
|
|
return;
|
|
|
|
if( m_Parent != dest->m_Parent )
|
2007-12-17 21:19:03 +00:00
|
|
|
return; // Can not cross move!
|
2007-09-13 11:55:46 +00:00
|
|
|
if( dest == this )
|
2007-12-17 21:19:03 +00:00
|
|
|
return; // Can not move to ourself...
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
wxTreeItemId parent = m_Parent->GetItemParent( GetId() );
|
|
|
|
if( dest == dynamic_cast<TreePrjItemData*>( m_Parent->GetItemData( parent ) ) )
|
2007-12-17 21:19:03 +00:00
|
|
|
return; // same parent ?
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// We need to create a new item from us, and move
|
|
|
|
// data to there ...
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// First move file on the disk
|
|
|
|
wxFileName fname( m_FileName );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString destName;
|
|
|
|
if( !dest->GetDir().IsEmpty() )
|
|
|
|
destName = dest->GetDir() + sep;
|
|
|
|
destName += fname.GetFullName();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( destName == GetFileName() )
|
2007-12-17 21:19:03 +00:00
|
|
|
return; // Same place ??
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// Move the file on the disk:
|
2009-11-12 15:43:38 +00:00
|
|
|
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
|
|
|
|
&& ( wxMINOR_VERSION < 7 ) ) )
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !wxRenameFile( GetFileName(), destName ) )
|
2007-06-05 17:43:34 +00:00
|
|
|
#else
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !wxRenameFile( GetFileName(), destName, false ) )
|
2007-06-05 17:43:34 +00:00
|
|
|
#endif
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
wxMessageDialog( m_Parent, _( "Unable to move file ... " ),
|
|
|
|
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
2007-09-13 11:55:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
object param = make_tuple( PyHandler::Convert( m_FileName ),
|
2009-11-12 15:43:38 +00:00
|
|
|
PyHandler::Convert( destName ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::MoveFile" ), param );
|
|
|
|
#endif
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
SetFileName( destName );
|
|
|
|
|
|
|
|
if( TREE_DIRECTORY != GetType() )
|
|
|
|
{
|
|
|
|
// Move the tree item itself now:
|
|
|
|
wxTreeItemId oldId = GetId();
|
|
|
|
int i = m_Parent->GetItemImage( oldId );
|
|
|
|
wxString text = m_Parent->GetItemText( oldId );
|
|
|
|
|
|
|
|
// Bye bye old Id :'(
|
|
|
|
wxTreeItemId newId = m_Parent->AppendItem( dest->GetId(), text, i );
|
|
|
|
m_Parent->SetItemData( newId, this );
|
|
|
|
m_Parent->SetItemData( oldId, NULL );
|
|
|
|
m_Parent->Delete( oldId );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We should move recursively all files, but that's quite boring
|
|
|
|
// let's just refresh that's all ... TODO (change this to a better code ...)
|
|
|
|
wxCommandEvent dummy;
|
2010-02-19 15:01:32 +00:00
|
|
|
dynamic_cast<TREEPROJECTFILES*>( m_Parent )->GetParent()->m_Parent->OnRefresh( dummy );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* rename the file checking if extension change occurs */
|
2009-11-12 15:43:38 +00:00
|
|
|
bool TreePrjItemData::Rename( const wxString& name, bool check )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
//this is broken & unsafe to use on linux.
|
|
|
|
if( m_Type == TREE_DIRECTORY )
|
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( name.IsEmpty() )
|
|
|
|
return false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString newFile;
|
|
|
|
wxString dirs = GetDir();
|
|
|
|
|
|
|
|
if( !dirs.IsEmpty() && GetType() != TREE_DIRECTORY )
|
|
|
|
newFile = dirs + sep + name;
|
|
|
|
else
|
|
|
|
newFile = name;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( newFile == m_FileName )
|
|
|
|
return false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
wxRegEx reg( wxT ( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
|
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
wxMessageDialog dialog( m_Parent,
|
2009-11-12 15:43:38 +00:00
|
|
|
_( "Changing file extension will change file \
|
|
|
|
type.\n Do you want to continue ?" ),
|
|
|
|
_( "Rename File" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( wxID_YES != dialog.ShowModal() )
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
#if ( ( wxMAJOR_VERSION < 2 ) || ( ( wxMAJOR_VERSION == 2 ) \
|
|
|
|
&& ( wxMINOR_VERSION < 7 ) ) )
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !wxRenameFile( m_FileName, newFile ) )
|
2007-06-05 17:43:34 +00:00
|
|
|
#else
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !wxRenameFile( m_FileName, newFile, false ) )
|
2007-06-05 17:43:34 +00:00
|
|
|
#endif
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
wxMessageDialog( m_Parent, _( "Unable to rename file ... " ),
|
|
|
|
_( "Permission error ?" ), wxICON_ERROR | wxOK );
|
2007-09-13 11:55:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SetFileName( newFile );
|
|
|
|
|
2007-12-17 21:19:03 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2007-09-13 11:55:46 +00:00
|
|
|
object param = make_tuple( PyHandler::Convert( m_FileName ),
|
|
|
|
PyHandler::Convert( newFile ) );
|
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::RenameFile" ), param );
|
2007-12-17 21:19:03 +00:00
|
|
|
#endif
|
2007-09-13 11:55:46 +00:00
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/*******************************************/
|
|
|
|
bool TreePrjItemData::Delete( bool check )
|
|
|
|
/*******************************************/
|
|
|
|
/* delete a file */
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
wxMessageDialog dialog( m_Parent,
|
|
|
|
_ ("Do you really want to delete ") + GetFileName(),
|
2007-12-17 21:19:03 +00:00
|
|
|
_( "Delete File" ), wxYES_NO | wxICON_QUESTION );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( !check || wxID_YES == dialog.ShowModal() )
|
|
|
|
{
|
|
|
|
if( !wxDirExists( m_FileName ) )
|
|
|
|
{
|
|
|
|
wxRemoveFile( m_FileName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxArrayString filelist;
|
2007-12-17 21:19:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
wxDir::GetAllFiles( m_FileName, &filelist );
|
2007-12-17 21:19:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
for( unsigned int i = 0; i < filelist.Count(); i++ )
|
|
|
|
wxRemoveFile( filelist[i] );
|
|
|
|
|
|
|
|
wxRmdir( m_FileName );
|
|
|
|
}
|
|
|
|
m_Parent->Delete( GetId() );
|
2007-12-17 21:19:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::DeleteFile" ),
|
2009-11-12 15:43:38 +00:00
|
|
|
PyHandler::Convert( m_FileName ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* Called under item activation */
|
2010-02-19 15:01:32 +00:00
|
|
|
void TreePrjItemData::Activate( TREE_PROJECT_FRAME* prjframe )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-12-17 21:19:03 +00:00
|
|
|
wxString sep = wxFileName().GetPathSeparator();
|
|
|
|
wxString FullFileName = GetFileName();
|
|
|
|
wxDir* dir;
|
|
|
|
wxString dir_filename;
|
|
|
|
wxTreeItemId id = GetId();
|
|
|
|
int count;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
switch( GetType() )
|
|
|
|
{
|
|
|
|
case TREE_PROJECT:
|
|
|
|
break;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_DIRECTORY:
|
2007-12-17 21:19:03 +00:00
|
|
|
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 ) );
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2007-12-17 21:19:03 +00:00
|
|
|
if( count == 0 )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
/* The AddFile() text below should match the filter added to
|
|
|
|
* handle it in treeprj_frame.cpp in the line looking like this:
|
|
|
|
* m_Filters.push_back( wxT( "^no kicad files found" ) );
|
|
|
|
*/
|
|
|
|
prjframe->AddFile( _( "no kicad files found in this directory" ),
|
|
|
|
id );
|
2007-12-17 21:19:03 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2007-12-17 21:19:03 +00:00
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_Parent->SortChildren( id );
|
|
|
|
delete dir;
|
|
|
|
}
|
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)
2007-12-16 18:44:12 +00:00
|
|
|
m_Parent->Toggle( id );
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_SCHEMA:
|
|
|
|
AddDelimiterString( FullFileName );
|
|
|
|
ExecuteFile( m_Parent, EESCHEMA_EXE, FullFileName );
|
|
|
|
break;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_PCB:
|
|
|
|
AddDelimiterString( FullFileName );
|
|
|
|
ExecuteFile( m_Parent, PCBNEW_EXE, FullFileName );
|
|
|
|
break;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-12-17 21:19:03 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_PY:
|
|
|
|
PyHandler::GetInstance()->RunScript( FullFileName );
|
|
|
|
break;
|
2007-12-17 21:19:03 +00:00
|
|
|
#endif
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
case TREE_GERBER:
|
|
|
|
AddDelimiterString( FullFileName );
|
|
|
|
ExecuteFile( m_Parent, GERBVIEW_EXE, FullFileName );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
|
|
|
OpenPDF( FullFileName );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_NET:
|
|
|
|
AddDelimiterString( FullFileName );
|
|
|
|
ExecuteFile( m_Parent, CVPCB_EXE, FullFileName );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString editorname = wxGetApp().GetEditorName();
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !editorname.IsEmpty() )
|
|
|
|
ExecuteFile( m_Parent, editorname, FullFileName );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
OpenFile( FullFileName );
|
|
|
|
break;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TreePrjItemData* TREE_PROJECT_FRAME::GetSelectedData()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
return dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( m_TreeProject->GetSelection() ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|