Commit e7cd29ec authored by jerryjacobs's avatar jerryjacobs

Beautify code for kicad.cpp, kicad/mainframe.cpp, treeprj_frame.cpp

parent 365dbe15
/********************************/ /*****************************************************************************/
/* kicad.cpp - module principal */ /**
/********************************/ * @file kicad.cpp
* @brief Main kicad library manager file
*/
/*****************************************************************************/
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
...@@ -13,13 +18,9 @@ ...@@ -13,13 +18,9 @@
#include <wx/image.h> #include <wx/image.h>
//#define SPLASH_OK
#ifdef SPLASH_OK #ifdef USE_SPLASH_IMAGE
/* Define Splash Image */
#define SPLASH_IMAGE logo_kicad.png #define SPLASH_IMAGE logo_kicad.png
#include "wx/splash.h" #include "wx/splash.h"
#include "wx/mediactrl.h" #include "wx/mediactrl.h"
#endif #endif
...@@ -35,95 +36,174 @@ ...@@ -35,95 +36,174 @@
#include <pyhandler.h> #include <pyhandler.h>
#endif #endif
/* Routines exportees */ /* Export functions */
/* fonctions importees */ /* Import functions */
char *GetFileName(char *FullPathName); char *GetFileName(char *FullPathName);
void ShowLogo(char * FonteFileName); void ShowLogo(char * FonteFileName);
/* Routines locales */ /* Local functions */
/************************************/
/* Called to initialize the program */
/************************************/
/************************************/
/* Called to initialize the program */
/************************************/
// Create a new application object // Create a new application object
IMPLEMENT_APP(WinEDA_App) IMPLEMENT_APP(WinEDA_App)
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
using namespace boost::python; using namespace boost::python;
/*****************************************************************************/
// Global functions: // Global functions:
/*****************************************************************************/
static WinEDA_MainFrame& GetMainFrame() { return *( wxGetApp().m_MainFrame ); } static WinEDA_MainFrame& GetMainFrame() { return *( wxGetApp().m_MainFrame ); }
static void WinEDAPrint( str msg ) { GetMainFrame().PrintMsg( PyHandler::MakeStr( msg ) + wxT("\n") ); } static void WinEDAPrint( str msg ) { GetMainFrame().PrintMsg( PyHandler::MakeStr( msg ) + wxT("\n") ); }
static void WinEDAClear() { GetMainFrame().ClearMsg(); } static void WinEDAClear() { GetMainFrame().ClearMsg(); }
static object GetTypeExt( enum TreeFileType type ) { return PyHandler::Convert( WinEDA_PrjFrame::GetFileExt( type ) ); } static object GetTypeExt( enum TreeFileType type ) { return PyHandler::Convert( WinEDA_PrjFrame::GetFileExt( type ) ); }
/*****************************************************************************/
// WinEDA_MainFrame Special binding functions: // WinEDA_MainFrame Special binding functions:
// (one line functions are simple wrappers) // (one line functions are simple wrappers)
/*****************************************************************************/
object WinEDA_MainFrame::GetPrjName() const { return PyHandler::Convert( m_PrjFileName ); } object WinEDA_MainFrame::GetPrjName() const { return PyHandler::Convert( m_PrjFileName ); }
object WinEDA_MainFrame::ToWx() { return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); } object WinEDA_MainFrame::ToWx() { return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
WinEDA_PrjFrame* WinEDA_MainFrame::GetTree() const { return m_LeftWin; } WinEDA_PrjFrame* WinEDA_MainFrame::GetTree() const { return m_LeftWin; }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_MainFrame::AddFastLaunchPy( object & button ) void WinEDA_MainFrame::AddFastLaunchPy( object & button )
/*****************************************************************************/
{ {
wxBitmapButton * btn; wxBitmapButton * btn;
bool success = wxPyConvertSwigPtr( button.ptr(), (void**)&btn, _T("wxBitmapButton")); bool success = wxPyConvertSwigPtr( button.ptr(), (void**)&btn, _T("wxBitmapButton"));
if ( !success ) return; if(!success)
return;
Py_INCREF( button.ptr() ); Py_INCREF( button.ptr() );
btn->Reparent( m_CommandWin ); btn->Reparent( m_CommandWin );
m_CommandWin->AddFastLaunch( btn ); m_CommandWin->AddFastLaunch( btn );
} }
/*****************************************************************************/
// WinEDA_PrjFrame Special binding functions: // WinEDA_PrjFrame Special binding functions:
// (one line functions are simple wrappers) // (one line functions are simple wrappers)
/*****************************************************************************/
// TODO To WxWidgets ?
object WinEDA_PrjFrame::ToWx()
{ return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
// TODO Get ?
object WinEDA_PrjFrame::GetFtExPy( enum TreeFileType type ) const
{ return PyHandler::Convert( GetFileExt( type ) ); }
// Get python menu
object WinEDA_PrjFrame::GetMenuPy( enum TreeFileType type )
{ return object( handle<>( borrowed( wxPyMake_wxObject( GetContextMenu( (int) type ), false ) ) ) ); }
// Get tree control
object WinEDA_PrjFrame::GetTreeCtrl()
{ return object( handle<>( borrowed( wxPyMake_wxObject( m_TreeProject, false ) ) ) ); }
// Get current menu
object WinEDA_PrjFrame::GetCurrentMenu()
{ return object( handle<>( borrowed( wxPyMake_wxObject( m_PopupMenu, false ) ) ) ); }
object WinEDA_PrjFrame::ToWx() { return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
object WinEDA_PrjFrame::GetFtExPy( enum TreeFileType type ) const { return PyHandler::Convert( GetFileExt( type ) ); }
object WinEDA_PrjFrame::GetMenuPy( enum TreeFileType type ) { return object( handle<>( borrowed( wxPyMake_wxObject( GetContextMenu( (int) type ), false ) ) ) ); }
object WinEDA_PrjFrame::GetTreeCtrl() { return object( handle<>( borrowed( wxPyMake_wxObject( m_TreeProject, false ) ) ) ); }
object WinEDA_PrjFrame::GetCurrentMenu() { return object( handle<>( borrowed( wxPyMake_wxObject( m_PopupMenu, false ) ) ) ); }
void WinEDA_PrjFrame::NewFilePy( const str & name, enum TreeFileType type, object & id ) /**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::NewFilePy( const str & name,
enum TreeFileType type,
object & id )
/*****************************************************************************/
{ {
wxTreeItemId root; wxTreeItemId root;
if (! wxPyConvertSwigPtr( id.ptr(), (void**)&root, _T("wxTreeItemId") ) ) return; if (! wxPyConvertSwigPtr( id.ptr(), (void**)&root, _T("wxTreeItemId") ) ) return;
NewFile( PyHandler::MakeStr( name ), type, root ); NewFile( PyHandler::MakeStr( name ), type, root );
} }
/**
* @brief Add a file to the tree under root, or m_root if conversion is wrong
*/
/*****************************************************************************/
void WinEDA_PrjFrame::AddFilePy( const str & file, object & root ) void WinEDA_PrjFrame::AddFilePy( const str & file, object & root )
/* Add a file to the tree under root, or m_root if conversion is wrong */ /*****************************************************************************/
{ {
wxTreeItemId * theroot = &m_root; wxTreeItemId * theroot = &m_root;
if ( !wxPyConvertSwigPtr( root.ptr(), (void**)&root, _T("wxTreeItemId") ) ) if ( !wxPyConvertSwigPtr( root.ptr(), (void**)&root, _T("wxTreeItemId") ) )
{ {
theroot = &m_root; theroot = &m_root;
} }
AddFile( PyHandler::MakeStr( file ), *theroot ); AddFile( PyHandler::MakeStr( file ), *theroot );
} }
/**
* @brief convert wxTreeItem into TreePrjItemData
*/
/*****************************************************************************/
TreePrjItemData * WinEDA_PrjFrame::GetItemData( const object & item ) TreePrjItemData * WinEDA_PrjFrame::GetItemData( const object & item )
/* convert wxTreeItem into TreePrjItemData */ /*****************************************************************************/
{ {
wxTreeItemId *id = NULL; wxTreeItemId *id = NULL;
if ( !wxPyConvertSwigPtr( item.ptr(), (void**)&id, _T("wxTreeItemId") ) ) return NULL;
if (!wxPyConvertSwigPtr( item.ptr(), (void**)&id, _T("wxTreeItemId")))
{
return NULL;
}
return dynamic_cast<TreePrjItemData *>( m_TreeProject->GetItemData( *id ) ); return dynamic_cast<TreePrjItemData *>( m_TreeProject->GetItemData( *id ) );
} }
/*****************************************************************************/
// TreePrjItemData Special binding functions // TreePrjItemData Special binding functions
// (one line functions are simple wrappers) // (one line functions are simple wrappers)
/*****************************************************************************/
// Python rename
bool TreePrjItemData::RenamePy( const str & newname, bool check )
{ return Rename( PyHandler::MakeStr(newname), check ); }
// Get python directory
object TreePrjItemData::GetDirPy() const
{ return PyHandler::Convert( GetDir() ); }
bool TreePrjItemData::RenamePy( const str & newname, bool check ) { return Rename( PyHandler::MakeStr(newname), check ); } // Get python filename
object TreePrjItemData::GetDirPy() const { return PyHandler::Convert( GetDir() ); } object TreePrjItemData::GetFileNamePy() const
object TreePrjItemData::GetFileNamePy() const { return PyHandler::Convert( GetFileName() ); } { return PyHandler::Convert( GetFileName() ); }
object TreePrjItemData::GetMenuPy() { return object( handle<>( borrowed( wxPyMake_wxObject( &m_fileMenu, false ) ) ) ); }
// kicad module init function // Get python menu
// ( this function is called from PyHandler to init the kicad module ) object TreePrjItemData::GetMenuPy()
{ return object( handle<>( borrowed( wxPyMake_wxObject( &m_fileMenu, false ) ) ) ); }
/**
* @brief KiCad python module init, \n
* This function is called from PyHandler to init the kicad module
*/
/*****************************************************************************/
static void py_kicad_init() static void py_kicad_init()
/*****************************************************************************/
{ {
def( "GetMainFrame", &GetMainFrame, return_value_policy< reference_existing_object >() ); def( "GetMainFrame", &GetMainFrame, return_value_policy< reference_existing_object >() );
def( "GetTypeExtension", &GetTypeExt ); def( "GetTypeExtension", &GetTypeExt );
...@@ -156,6 +236,7 @@ static void py_kicad_init() ...@@ -156,6 +236,7 @@ static void py_kicad_init()
.value( "DIRECTORY", TREE_DIRECTORY ) .value( "DIRECTORY", TREE_DIRECTORY )
.value( "MAX", TREE_MAX ); .value( "MAX", TREE_MAX );
class_<WinEDA_PrjFrame>( "TreeWindow" ) class_<WinEDA_PrjFrame>( "TreeWindow" )
// wx Interface // wx Interface
.def( "ToWx", &WinEDA_PrjFrame::ToWx ) .def( "ToWx", &WinEDA_PrjFrame::ToWx )
...@@ -168,14 +249,38 @@ static void py_kicad_init() ...@@ -168,14 +249,38 @@ static void py_kicad_init()
.def( "RemoveFilter", &WinEDA_PrjFrame::RemoveFilterPy ) .def( "RemoveFilter", &WinEDA_PrjFrame::RemoveFilterPy )
.def( "GetFilters", &WinEDA_PrjFrame::GetFilters, return_value_policy < copy_const_reference >() ) .def( "GetFilters", &WinEDA_PrjFrame::GetFilters, return_value_policy < copy_const_reference >() )
.def( "GetCurrentMenu", &WinEDA_PrjFrame::GetCurrentMenu ) .def( "GetCurrentMenu", &WinEDA_PrjFrame::GetCurrentMenu )
// Project tree control
.def( "AddState", &WinEDA_PrjFrame::AddStatePy )
.def( "GetTreeCtrl", &WinEDA_PrjFrame::GetTreeCtrl ) /** Project tree control **/
.def( "GetItemData", &WinEDA_PrjFrame::GetItemData, return_value_policy < reference_existing_object >() )
.def( "FindItemData", &WinEDA_PrjFrame::FindItemData, return_value_policy < reference_existing_object >() ) // AddState
.def( "NewFile", &WinEDA_PrjFrame::NewFilePy ) .def( "AddState",
.def( "AddFile", &WinEDA_PrjFrame::AddFilePy ) &WinEDA_PrjFrame::AddStatePy )
;
// GetTreeCtrl
.def( "GetTreeCtrl",
&WinEDA_PrjFrame::GetTreeCtrl )
// GetItemData
.def( "GetItemData",
&WinEDA_PrjFrame::GetItemData,
return_value_policy < reference_existing_object >() )
// FindItemData
.def( "FindItemData",
&WinEDA_PrjFrame::FindItemData,
return_value_policy < reference_existing_object >() )
// NewFile
.def( "NewFile",
&WinEDA_PrjFrame::NewFilePy )
// AddFile
.def( "AddFile",
&WinEDA_PrjFrame::AddFilePy )
; /* ENDOF class_<WinEDA_PrjFrame>( "TreeWindow" ) */
class_<WinEDA_MainFrame>( "MainFrame" ) class_<WinEDA_MainFrame>( "MainFrame" )
// Wx interface // Wx interface
...@@ -188,18 +293,25 @@ static void py_kicad_init() ...@@ -188,18 +293,25 @@ static void py_kicad_init()
} }
// common module init function
/**
* @brief Common python module init
*/
/*****************************************************************************/
static void py_common_init() static void py_common_init()
/*****************************************************************************/
{ {
def( "Print", &WinEDAPrint ); def( "Print", &WinEDAPrint );
def( "Clear", &WinEDAClear ); def( "Clear", &WinEDAClear );
} }
#endif #endif
/*****************************************************************************/
bool WinEDA_App::OnInit() bool WinEDA_App::OnInit()
/*****************************************************************************/
{ {
wxImage::AddHandler(new wxPNGHandler); wxImage::AddHandler(new wxPNGHandler);
...@@ -236,8 +348,8 @@ bool WinEDA_App::OnInit() ...@@ -236,8 +348,8 @@ bool WinEDA_App::OnInit()
m_MainFrame->m_LeftWin->ReCreateTreePrj(); m_MainFrame->m_LeftWin->ReCreateTreePrj();
SetTopWindow(m_MainFrame); SetTopWindow(m_MainFrame);
/* Splash Screen Logo */ /* Splash screen logo */
#ifdef SPLASH_OK #ifdef USE_SPLASH_IMAGE
wxString logoname( wxString(m_BinDir) + _T("logokicad.png") ); wxString logoname( wxString(m_BinDir) + _T("logokicad.png") );
wxBitmap splash_screen; wxBitmap splash_screen;
if ( splash_screen.LoadFile( logoname, wxBITMAP_TYPE_PNG ) ) if ( splash_screen.LoadFile( logoname, wxBITMAP_TYPE_PNG ) )
...@@ -247,7 +359,7 @@ bool WinEDA_App::OnInit() ...@@ -247,7 +359,7 @@ bool WinEDA_App::OnInit()
3000, m_MainFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize, 3000, m_MainFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxSIMPLE_BORDER|wxSTAY_ON_TOP); wxSIMPLE_BORDER|wxSTAY_ON_TOP);
} }
#endif #endif /* USE_SPLASH_IMAGE */
m_MainFrame->Show(TRUE); m_MainFrame->Show(TRUE);
m_MainFrame->Raise(); m_MainFrame->Raise();
...@@ -265,5 +377,3 @@ bool WinEDA_App::OnInit() ...@@ -265,5 +377,3 @@ bool WinEDA_App::OnInit()
return TRUE; return TRUE;
} }
// vim: tabstop=4 : noexpandtab :
...@@ -21,16 +21,19 @@ ...@@ -21,16 +21,19 @@
#include "kicad.h" #include "kicad.h"
/****************/
/* Constructor */
/****************/
// Constructor
/*****************************************************************************/
WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app, WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
wxWindow* parent, const wxString& title, wxWindow* parent,
const wxPoint& pos, const wxSize& size ) : const wxString& title,
WinEDA_BasicFrame( parent, KICAD_MAIN_FRAME, eda_app, title, pos, size ) const wxPoint& pos,
const wxSize& size ) :
WinEDA_BasicFrame( parent, KICAD_MAIN_FRAME, eda_app, title, pos, size )
/*****************************************************************************/
{ {
wxString msg; wxString msg;
wxString line;
wxSize clientsize; wxSize clientsize;
m_FrameName = wxT( "KicadFrame" ); m_FrameName = wxT( "KicadFrame" );
...@@ -44,8 +47,10 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app, ...@@ -44,8 +47,10 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
GetSettings(); GetSettings();
if( m_Parent->m_EDA_Config ) if( m_Parent->m_EDA_Config )
{ {
m_Parent->m_EDA_Config->Read( wxT( "LeftWinWidth" ), &m_LeftWin_Width ); m_Parent->m_EDA_Config->Read( wxT( "LeftWinWidth" ),
m_Parent->m_EDA_Config->Read( wxT( "CommandWinWidth" ), &m_CommandWin_Height ); &m_LeftWin_Width );
m_Parent->m_EDA_Config->Read( wxT( "CommandWinWidth" ),
&m_CommandWin_Height );
} }
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
...@@ -78,7 +83,7 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app, ...@@ -78,7 +83,7 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
wxNO_BORDER | wxSW_3D ); wxNO_BORDER | wxSW_3D );
m_BottomWin->SetDefaultSize( wxSize( clientsize.x, 150 ) ); m_BottomWin->SetDefaultSize( wxSize( clientsize.x, 150 ) );
m_BottomWin->SetOrientation( wxLAYOUT_HORIZONTAL ); m_BottomWin->SetOrientation( wxLAYOUT_HORIZONTAL );
m_BottomWin->SetAlignment( wxLAYOUT_BOTTOM ); m_BottomWin->SetAlignment ( wxLAYOUT_BOTTOM );
m_BottomWin->SetSashVisible( wxSASH_TOP, TRUE ); m_BottomWin->SetSashVisible( wxSASH_TOP, TRUE );
m_BottomWin->SetSashVisible( wxSASH_LEFT, TRUE ); m_BottomWin->SetSashVisible( wxSASH_LEFT, TRUE );
m_BottomWin->SetExtraBorderSize( 2 ); m_BottomWin->SetExtraBorderSize( 2 );
...@@ -91,28 +96,27 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app, ...@@ -91,28 +96,27 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
m_DialogWin->SetFont( *g_StdFont ); m_DialogWin->SetFont( *g_StdFont );
// m_CommandWin is the box with buttons which launch eechema, pcbnew ... // m_CommandWin is the box with buttons which launch eechema, pcbnew ...
m_CommandWin = new WinEDA_CommandFrame( this, ID_MAIN_COMMAND, m_CommandWin = new WinEDA_CommandFrame( this,
ID_MAIN_COMMAND,
wxPoint( m_LeftWin_Width, wxPoint( m_LeftWin_Width,
0 ), 0 ),
wxSize( clientsize.x, m_CommandWin_Height ), wxSize( clientsize.x,
m_CommandWin_Height ),
wxNO_BORDER | wxSW_3D ); wxNO_BORDER | wxSW_3D );
wxString line;
msg = wxGetCwd(); msg = wxGetCwd();
line.Printf( _( "Ready\nWorking dir: %s\n" ), msg.GetData() ); line.Printf( _( "Ready\nWorking dir: %s\n" ), msg.GetData() );
PrintMsg( line ); PrintMsg( line );
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::LoadProject" ) ); PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::LoadProject" ) );
#endif #endif
} }
/***************/ /*****************************************************************************/
/* Destructor */
/***************/
WinEDA_MainFrame::~WinEDA_MainFrame() WinEDA_MainFrame::~WinEDA_MainFrame()
/*****************************************************************************/
{ {
if( m_Parent->m_EDA_Config ) if( m_Parent->m_EDA_Config )
{ {
...@@ -127,7 +131,6 @@ WinEDA_MainFrame::~WinEDA_MainFrame() ...@@ -127,7 +131,6 @@ WinEDA_MainFrame::~WinEDA_MainFrame()
/*******************************************************/ /*******************************************************/
void WinEDA_MainFrame::PrintMsg( const wxString& text ) void WinEDA_MainFrame::PrintMsg( const wxString& text )
/*******************************************************/ /*******************************************************/
/* /*
* Put text in the dialog frame * Put text in the dialog frame
*/ */
...@@ -394,6 +397,7 @@ void WinEDA_MainFrame::OnRefresh( wxCommandEvent& event ) ...@@ -394,6 +397,7 @@ void WinEDA_MainFrame::OnRefresh( wxCommandEvent& event )
} }
/*********************************/ /*********************************/
void WinEDA_MainFrame::ClearMsg() void WinEDA_MainFrame::ClearMsg()
/*********************************/ /*********************************/
...@@ -401,11 +405,13 @@ void WinEDA_MainFrame::ClearMsg() ...@@ -401,11 +405,13 @@ void WinEDA_MainFrame::ClearMsg()
m_DialogWin->Clear(); m_DialogWin->Clear();
} }
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
/*****************************************************************************/
void WinEDA_MainFrame::OnRefreshPy() void WinEDA_MainFrame::OnRefreshPy()
/*****************************************************************************/
{ {
m_LeftWin->ReCreateTreePrj(); m_LeftWin->ReCreateTreePrj();
} }
#endif #endif
/*********************/ /**
/* treeprj_frame.cpp */ * @file treeprj_frame.cpp
/*********************/ * @brief TODO
*/
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
#include <pyhandler.h> #include <pyhandler.h>
#endif #endif
#include "fctsys.h" #include "fctsys.h"
...@@ -45,30 +47,43 @@ const wxChar * s_AllowedExtensionsToList[] = ...@@ -45,30 +47,43 @@ const wxChar * s_AllowedExtensionsToList[] =
NULL // end of list NULL // end of list
}; };
/**
* @brief TODO
*/
/******************************************************************/ /******************************************************************/
WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent, WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size ) : const wxSize& size ) :
wxSashLayoutWindow( parent, ID_LEFT_FRAME, pos, size, wxSashLayoutWindow( parent,
ID_LEFT_FRAME,
pos,
size,
wxNO_BORDER | wxSW_3D ) wxNO_BORDER | wxSW_3D )
/******************************************************************/ /******************************************************************/
{ {
m_Parent = parent; m_Parent = parent;
m_TreeProject = NULL; m_TreeProject = NULL;
wxMenu* menu = m_ContextMenus[TREE_PY];
wxMenuItem* item; wxMenuItem* item;
m_PopupMenu = NULL; m_PopupMenu = NULL;
/* Filtering is now inverted: the filters are actually used to _enable_ support /*
* Filtering is now inverted: the filters are actually used to _enable_ support
* for a given file type. * for a given file type.
*/ */
m_Filters.push_back( wxT( "^.*\\.sch$" ) ); // note: sch filter must be first because of a test in AddFile() below
// NOTE: sch filter must be first because of a test in AddFile() below
m_Filters.push_back( wxT( "^.*\\.sch$" ) );
for ( int ii = 0; s_AllowedExtensionsToList[ii] != NULL; ii++ ) for ( int ii = 0; s_AllowedExtensionsToList[ii] != NULL; ii++ )
{ {
m_Filters.push_back( s_AllowedExtensionsToList[ii] ); m_Filters.push_back( s_AllowedExtensionsToList[ii] );
} }
m_Filters.push_back( wxT( "^no kicad files found" ) ); m_Filters.push_back( wxT( "^no kicad files found" ) );
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
m_Filters.push_back( wxT( "^.*\\.py$" ) ); m_Filters.push_back( wxT( "^.*\\.py$" ) );
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RunScript" ) ); PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RunScript" ) );
...@@ -80,31 +95,32 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent, ...@@ -80,31 +95,32 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::DeleteFile" ) ); PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::DeleteFile" ) );
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RenameFile" ) ); PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RenameFile" ) );
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::MoveFile" ) ); PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::MoveFile" ) );
#endif #endif /* KICAD_PYTHON */
for( int i = 0; i < TREE_MAX; i++ ) for( int i = 0; i < TREE_MAX; i++ )
m_ContextMenus.push_back( new wxMenu() ); m_ContextMenus.push_back( new wxMenu() );
// Python script context menu:
wxMenu* menu = m_ContextMenus[TREE_PY];
#ifdef KICAD_PYTHON // Python script context menu
#ifdef KICAD_PYTHON
item = new wxMenuItem( menu, ID_PROJECT_RUNPY, item = new wxMenuItem( menu, ID_PROJECT_RUNPY,
_( "&Run" ), _( "&Run" ),
_( "Run the Python Script" ) ); _( "Run the Python Script" ) );
item->SetBitmap( icon_python_small_xpm ); item->SetBitmap( icon_python_small_xpm );
menu->Append( item ); menu->Append( item );
#endif #endif /* KICAD_PYTHON */
item = new wxMenuItem( menu, ID_PROJECT_TXTEDIT, // ID_PROJECT_TXTEDIT
item = new wxMenuItem( menu,
ID_PROJECT_TXTEDIT,
_( "&Edit in a text editor" ), _( "&Edit in a text editor" ),
_( "&Open the file in a Text Editor" ) ); _( "&Open the file in a Text Editor" ) );
item->SetBitmap( icon_txt_xpm ); item->SetBitmap( icon_txt_xpm );
menu->Append( item ); menu->Append( item );
// New files context menu: // New files context menu:
wxMenu* menus[2]; wxMenu* menus[2];
menus[0] = m_ContextMenus[TREE_DIRECTORY]; menus[0] = m_ContextMenus[TREE_DIRECTORY];
...@@ -114,56 +130,80 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent, ...@@ -114,56 +130,80 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
{ {
menu = menus[i]; menu = menus[i];
item = new wxMenuItem( menu, ID_PROJECT_NEWDIR, _( "New D&irectory" ), _( // ID_PROJECT_NEWDIR
"Create a New Directory" ) ); item = new wxMenuItem( menu,
ID_PROJECT_NEWDIR,
_( "New D&irectory" ),
_( "Create a New Directory" ) );
item->SetBitmap( directory_xpm ); item->SetBitmap( directory_xpm );
menu->Append( item ); menu->Append( item );
#ifdef KICAD_PYTHON
item = new wxMenuItem( menu, ID_PROJECT_NEWPY, _( "New P&ython Script" ), _(
"Create a New Python Script" ) );
// ID_PROJECT_NEWPY
#ifdef KICAD_PYTHON
item = new wxMenuItem( menu,
ID_PROJECT_NEWPY,
_( "New P&ython Script" ),
_( "Create a New Python Script" ) );
item->SetBitmap( new_python_xpm ); item->SetBitmap( new_python_xpm );
menu->Append( item ); menu->Append( item );
#endif #endif /* KICAD_PYTHON */
item = new wxMenuItem( menu, ID_PROJECT_NEWTXT, _( "New &Text File" ), _(
"Create a New Txt File" ) );
// ID_PROJECT_NEWTXT
item = new wxMenuItem( menu,
ID_PROJECT_NEWTXT,
_( "New &Text File" ),
_( "Create a New Txt File" ) );
item->SetBitmap( new_txt_xpm ); item->SetBitmap( new_txt_xpm );
menu->Append( item ); menu->Append( item );
item = new wxMenuItem( menu, ID_PROJECT_NEWFILE, _( "New &File" ), _( "Create a New File" ) );
// ID_PROJECT_NEWFILE
item = new wxMenuItem( menu,
ID_PROJECT_NEWFILE,
_( "New &File" ),
_( "Create a New File" ) );
item->SetBitmap( new_xpm ); item->SetBitmap( new_xpm );
menu->Append( item ); menu->Append( item );
} }
// Put the Rename and Delete file menu commands: // Put the Rename and Delete file menu commands:
for( int i = TREE_PROJECT + 1; i < TREE_MAX; i++ ) for( int i = TREE_PROJECT + 1; i < TREE_MAX; i++ )
{ {
menu = m_ContextMenus[i]; menu = m_ContextMenus[i];
item = new wxMenuItem( menu, ID_PROJECT_RENAME,
TREE_DIRECTORY != i ? _ ("&Rename file") : _( "&Rename directory" ),
TREE_DIRECTORY != i ? _ ("Rename file") : _( "&Rename directory" ) );
// ID_PROJECT_RENAME
item = new wxMenuItem( menu,
ID_PROJECT_RENAME,
TREE_DIRECTORY != i ? _ ("&Rename file") :
_( "&Rename directory" ),
TREE_DIRECTORY != i ? _ ("Rename file") :
_( "&Rename directory" ) );
item->SetBitmap( right_xpm ); item->SetBitmap( right_xpm );
menu->Append( item ); menu->Append( item );
if( TREE_DIRECTORY != i ) if( TREE_DIRECTORY != i )
{ {
item = new wxMenuItem( menu, ID_PROJECT_TXTEDIT, // ID_PROJECT_TXTEDIT
item = new wxMenuItem( menu,
ID_PROJECT_TXTEDIT,
_( "&Edit in a text editor" ), _( "&Edit in a text editor" ),
_( "Open the file in a Text Editor" ) ); _( "Open the file in a Text Editor" ) );
item->SetBitmap( icon_txt_xpm ); item->SetBitmap( icon_txt_xpm );
menu->Append( item ); menu->Append( item );
} }
item = new wxMenuItem( menu, ID_PROJECT_DELETE,
TREE_DIRECTORY != i ? _ ("&Delete File") : _( "&Delete Directory" ),
TREE_DIRECTORY != i ? _ ("Delete the File") : _(
"&Delete the Directory and its content" ) );
// ID_PROJECT_DELETE
item = new wxMenuItem( menu,
ID_PROJECT_DELETE,
TREE_DIRECTORY != i ? _( "&Delete File" ) :
_( "&Delete Directory" ),
TREE_DIRECTORY != i ? _( "Delete the File" ) :
_( "&Delete the Directory and its content" ) );
item->SetBitmap( delete_xpm ); item->SetBitmap( delete_xpm );
menu->Append( item ); menu->Append( item );
} }
...@@ -172,7 +212,10 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent, ...@@ -172,7 +212,10 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
} }
/*****************************************************************************/
BEGIN_EVENT_TABLE( WinEDA_PrjFrame, wxSashLayoutWindow ) BEGIN_EVENT_TABLE( WinEDA_PrjFrame, wxSashLayoutWindow )
/*****************************************************************************/
EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRenameAsk ) EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRenameAsk )
EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRename ) EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRename )
...@@ -188,25 +231,35 @@ EVT_MENU( ID_PROJECT_NEWTXT, WinEDA_PrjFrame::OnNewTxtFile ) ...@@ -188,25 +231,35 @@ EVT_MENU( ID_PROJECT_NEWTXT, WinEDA_PrjFrame::OnNewTxtFile )
EVT_MENU( ID_PROJECT_DELETE, WinEDA_PrjFrame::OnDeleteFile ) EVT_MENU( ID_PROJECT_DELETE, WinEDA_PrjFrame::OnDeleteFile )
EVT_MENU( ID_PROJECT_RENAME, WinEDA_PrjFrame::OnRenameFile ) EVT_MENU( ID_PROJECT_RENAME, WinEDA_PrjFrame::OnRenameFile )
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
EVT_MENU( ID_PROJECT_RUNPY, WinEDA_PrjFrame::OnRunPy ) EVT_MENU( ID_PROJECT_RUNPY, WinEDA_PrjFrame::OnRunPy )
#endif #endif /* KICAD_PYTHON */
/*****************************************************************************/
END_EVENT_TABLE() END_EVENT_TABLE()
/*****************************************************************************/
/********************************/
/*****************************************************************************/
WinEDA_TreePrj::~WinEDA_TreePrj() WinEDA_TreePrj::~WinEDA_TreePrj()
/********************************/ /*****************************************************************************/
{ {
} }
/*******************************************************/
void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
/*******************************************************/
// Allowing drag&drop of file other than the currently opened project /**
* @brief Allowing drag & drop of file other than the currently opened project
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
/*****************************************************************************/
{ {
/* Ensure item is selected (Under Windows start drag does not activate the item) */ /* Ensure item is selected
(Under Windows start drag does not activate the item) */
wxTreeItemId curr_item = event.GetItem(); wxTreeItemId curr_item = event.GetItem();
m_TreeProject->SelectItem( curr_item ); m_TreeProject->SelectItem( curr_item );
...@@ -224,9 +277,10 @@ void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event ) ...@@ -224,9 +277,10 @@ void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
} }
/*******************************************************/
/*****************************************************************************/
void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event ) void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
/*******************************************************/ /*****************************************************************************/
{ {
m_Parent->SetCursor( wxNullCursor ); m_Parent->SetCursor( wxNullCursor );
...@@ -261,17 +315,18 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event ) ...@@ -261,17 +315,18 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
} }
/************************************/
/*****************************************************************************/
void WinEDA_PrjFrame::ClearFilters() void WinEDA_PrjFrame::ClearFilters()
/************************************/ /*****************************************************************************/
{ {
m_Filters.clear(); m_Filters.clear();
} }
/*************************************************************/ /*****************************************************************************/
void WinEDA_PrjFrame::RemoveFilter( const wxString& filter ) void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
/*************************************************************/ /*****************************************************************************/
{ {
for( unsigned int i = 0; i < m_Filters.size(); i++ ) for( unsigned int i = 0; i < m_Filters.size(); i++ )
{ {
...@@ -284,13 +339,17 @@ void WinEDA_PrjFrame::RemoveFilter( const wxString& filter ) ...@@ -284,13 +339,17 @@ void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
} }
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
/********************************************************************************/
TreePrjItemData* WinEDA_PrjFrame::FindItemData( const boost::python::str& name )
/********************************************************************************/
// Return the data corresponding to the file, or NULL
/**
* @brief Return the data corresponding to the file, or NULL
*/
/*****************************************************************************/
TreePrjItemData* WinEDA_PrjFrame::FindItemData(const boost::python::str& name)
/*****************************************************************************/
{ {
// (Interative tree parsing) // (Interative tree parsing)
std::vector< wxTreeItemId > roots1, roots2; std::vector< wxTreeItemId > roots1, roots2;
...@@ -349,17 +408,25 @@ TreePrjItemData* WinEDA_PrjFrame::FindItemData( const boost::python::str& name ) ...@@ -349,17 +408,25 @@ TreePrjItemData* WinEDA_PrjFrame::FindItemData( const boost::python::str& name )
} }
/******************************************************************/
void WinEDA_PrjFrame::RemoveFilterPy( const boost::python::str& filter ) /**
/******************************************************************/ * @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::RemoveFilterPy(const boost::python::str& filter)
/*****************************************************************************/
{ {
RemoveFilter( PyHandler::MakeStr( filter ) ); RemoveFilter( PyHandler::MakeStr( filter ) );
} }
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter ) void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter )
/******************************************************************/ /*****************************************************************************/
{ {
wxRegEx reg; wxRegEx reg;
wxString text = PyHandler::MakeStr( filter ); wxString text = PyHandler::MakeStr( filter );
...@@ -369,44 +436,88 @@ void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter ) ...@@ -369,44 +436,88 @@ void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter )
m_Filters.push_back( text ); m_Filters.push_back( text );
} }
#endif #endif /* KICAD_PYTHON */
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
const std::vector<wxString>& WinEDA_PrjFrame::GetFilters() const std::vector<wxString>& WinEDA_PrjFrame::GetFilters()
/******************************************************************/ /*****************************************************************************/
{ {
return m_Filters; return m_Filters;
} }
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
wxMenu* WinEDA_PrjFrame::GetContextMenu( int type ) wxMenu* WinEDA_PrjFrame::GetContextMenu( int type )
/******************************************************************/ /*****************************************************************************/
{ {
return m_ContextMenus[type]; return m_ContextMenus[type];
} }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnNewDirectory( wxCommandEvent& event ) void WinEDA_PrjFrame::OnNewDirectory( wxCommandEvent& event )
/*****************************************************************************/
{ {
NewFile( TREE_DIRECTORY ); NewFile( TREE_DIRECTORY );
} }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnNewFile( wxCommandEvent& event ) void WinEDA_PrjFrame::OnNewFile( wxCommandEvent& event )
/*****************************************************************************/
{ {
NewFile( TREE_UNKNOWN ); NewFile( TREE_UNKNOWN );
} }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnNewPyFile( wxCommandEvent& event ) void WinEDA_PrjFrame::OnNewPyFile( wxCommandEvent& event )
/*****************************************************************************/
{ {
NewFile( TREE_PY ); NewFile( TREE_PY );
} }
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnNewTxtFile( wxCommandEvent& event ) void WinEDA_PrjFrame::OnNewTxtFile( wxCommandEvent& event )
/*****************************************************************************/
{ {
NewFile( TREE_TXT ); NewFile( TREE_TXT );
} }
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::NewFile( TreeFileType type ) void WinEDA_PrjFrame::NewFile( TreeFileType type )
/******************************************************************/ /*****************************************************************************/
{ {
wxString filename; wxString filename;
wxString mask = GetFileExt( type ); wxString mask = GetFileExt( type );
...@@ -418,6 +529,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type ) ...@@ -418,6 +529,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
TreePrjItemData* treeData; TreePrjItemData* treeData;
wxString FullFileName; wxString FullFileName;
treeData = GetSelectedData(); treeData = GetSelectedData();
if( !treeData ) if( !treeData )
return; return;
...@@ -425,7 +537,6 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type ) ...@@ -425,7 +537,6 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
dir = treeData->GetDir(); dir = treeData->GetDir();
// Ask for the new file name // Ask for the new file name
filename = EDA_FileSelector( TREE_DIRECTORY != filename = EDA_FileSelector( TREE_DIRECTORY !=
type ? _( "Create New File:" ) : _( "Create New Directory" ), type ? _( "Create New File:" ) : _( "Create New Directory" ),
wxGetCwd() + sep + dir, /* Chemin par defaut */ wxGetCwd() + sep + dir, /* Chemin par defaut */
...@@ -449,6 +560,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type ) ...@@ -449,6 +560,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
else else
{ {
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() ); root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
if( !root.IsOk() ) if( !root.IsOk() )
root = m_TreeProject->GetSelection(); root = m_TreeProject->GetSelection();
} }
...@@ -457,42 +569,53 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type ) ...@@ -457,42 +569,53 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
} }
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::NewFile( const wxString& name, void WinEDA_PrjFrame::NewFile( const wxString& name,
TreeFileType type, wxTreeItemId& root ) TreeFileType type,
/******************************************************************/ wxTreeItemId& root )
/*****************************************************************************/
{ {
if( TREE_DIRECTORY != type ) if( TREE_DIRECTORY != type )
{ {
wxFile( name, wxFile::write ); wxFile( name, wxFile::write );
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( #ifdef KICAD_PYTHON
wxT( "kicad::NewFile" ), PyHandler::Convert( name ) ); PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewFile" ),
#endif PyHandler::Convert( name ) );
#endif /* KICAD_PYTHON */
} }
else else
{ {
wxMkdir( name ); wxMkdir( name );
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( #ifdef KICAD_PYTHON
wxT( "kicad::NewDirectory" ), PyHandler::Convert( name ) ); PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewDirectory" ),
#endif PyHandler::Convert( name ) );
#endif /* KICAD_PYTHON */
} }
AddFile( name, root ); AddFile( name, root );
} }
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type ) wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
/******************************************************************/ /*****************************************************************************/
{ {
wxString ext; wxString ext;
switch( type ) switch( type )
{ {
case 0: case 0: // 0 is not used
break; // 0 is not used break;
case TREE_PROJECT: case TREE_PROJECT:
ext = wxT( ".pro" ); ext = wxT( ".pro" );
...@@ -534,13 +657,15 @@ wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type ) ...@@ -534,13 +657,15 @@ wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
} }
/**************************************************************************/
bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
/**************************************************************************/
/* add filename "name" to the tree /**
* @brief Add filename "name" to the tree \n
* if name is a directory, add the sub directory file names * if name is a directory, add the sub directory file names
* @return TODO
*/ */
/*****************************************************************************/
bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
/*****************************************************************************/
{ {
wxTreeItemId cellule; wxTreeItemId cellule;
...@@ -586,8 +711,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root ) ...@@ -586,8 +711,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
fp = wxFopen( FullFileName, wxT( "rt" ) ); fp = wxFopen( FullFileName, wxT( "rt" ) );
if( fp == NULL ) if( fp == NULL )
{ {
//printf("Unable to open \"%s\"\n", (const char*) FullFileName.mb_str() ); return false;
return false; // why show a file we cannot open?
} }
addFile = false; addFile = false;
...@@ -640,8 +764,8 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root ) ...@@ -640,8 +764,8 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
} }
kid = m_TreeProject->GetNextChild(root, cookie); kid = m_TreeProject->GetNextChild(root, 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( name ); wxString file = wxFileNameFromPath( name );
cellule = m_TreeProject->AppendItem( root, file ); cellule = m_TreeProject->AppendItem( root, file );
TreePrjItemData* data = new TreePrjItemData( type, name, m_TreeProject ); TreePrjItemData* data = new TreePrjItemData( type, name, m_TreeProject );
...@@ -659,41 +783,49 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root ) ...@@ -659,41 +783,49 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
else else
data->m_IsRootFile = false; data->m_IsRootFile = false;
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ), PyHandler::Convert( name ) );
#endif
#ifdef ADD_FILES_IN_SUBDIRS #ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ),
PyHandler::Convert( name ) );
#endif /* KICAD_YTHON */
// When enabled This section adds dirs and files found in the subdirs // When enabled This section adds dirs and files found in the subdirs
// in this case AddFile is recursive. // in this case AddFile is recursive.
#ifdef ADD_FILES_IN_SUBDIRS
if( TREE_DIRECTORY == type ) if( TREE_DIRECTORY == type )
{ {
const wxString sep = wxFileName().GetPathSeparator(); const wxString sep = wxFileName().GetPathSeparator();
wxDir dir( name ); wxDir dir( name );
wxString dir_filename; wxString dir_filename;
if( dir.GetFirst( &dir_filename ) ) if( dir.GetFirst( &dir_filename ) )
{ {
do do
{ {
AddFile( name + sep + dir_filename, cellule ); AddFile( name + sep + dir_filename, cellule );
} while( dir.GetNext( &dir_filename ) ); }
while( dir.GetNext( &dir_filename ) );
} }
/* Sort filenames by alphabetic order */ /* Sort filenames by alphabetic order */
m_TreeProject->SortChildren( cellule ); m_TreeProject->SortChildren( cellule );
} }
#endif #endif /* ADD_FILES_IN_SUBDIRS */
return true; return true;
} }
/******************************************/
void WinEDA_PrjFrame::ReCreateTreePrj()
/******************************************/
/* Create or modify the tree showing project file names /**
* @brief Create or modify the tree showing project file names
* @return TODO
*/ */
/*****************************************************************************/
void WinEDA_PrjFrame::ReCreateTreePrj()
/*****************************************************************************/
{ {
wxTreeItemId rootcellule; wxTreeItemId rootcellule;
wxString Text; wxString Text;
...@@ -760,11 +892,13 @@ void WinEDA_PrjFrame::ReCreateTreePrj() ...@@ -760,11 +892,13 @@ void WinEDA_PrjFrame::ReCreateTreePrj()
} }
/**************************************************/
void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
/**************************************************/
// Opens (popup) the context menu /**
* @brief Opens *popup* the context menu
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
/*****************************************************************************/
{ {
int tree_id; int tree_id;
TreePrjItemData* tree_data; TreePrjItemData* tree_data;
...@@ -819,19 +953,25 @@ void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event ) ...@@ -819,19 +953,25 @@ void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
// At last, call python to let python add menu items "on the fly" // At last, call python to let python add menu items "on the fly"
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeContextMenu" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeContextMenu" ),
PyHandler::Convert( FullFileName ) ); PyHandler::Convert( FullFileName ) );
#endif #endif /* KICAD_PYTHON */
if( m_PopupMenu ) if( m_PopupMenu )
PopupMenu( m_PopupMenu ); PopupMenu( m_PopupMenu );
} }
/*******************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event ) void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
/*******************************************************/ /*****************************************************************************/
{ {
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -841,20 +981,27 @@ void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event ) ...@@ -841,20 +981,27 @@ void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
wxString FullFileName = tree_data->GetFileName(); wxString FullFileName = tree_data->GetFileName();
AddDelimiterString( FullFileName ); AddDelimiterString( FullFileName );
wxString editorname = GetEditorName(); wxString editorname = GetEditorName();
if( !editorname.IsEmpty() ) if( !editorname.IsEmpty() )
{ {
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ),
PyHandler::Convert( FullFileName ) ); PyHandler::Convert( FullFileName ) );
#endif #endif
ExecuteFile( this, editorname, FullFileName ); ExecuteFile( this, editorname, FullFileName );
} }
} }
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& ) void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& )
/***************************************************/ /*****************************************************************************/
{ {
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -864,9 +1011,13 @@ void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& ) ...@@ -864,9 +1011,13 @@ void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& )
} }
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& ) void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& )
/***************************************************/ /*****************************************************************************/
{ {
wxTreeItemId curr_item = m_TreeProject->GetSelection(); wxTreeItemId curr_item = m_TreeProject->GetSelection();
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -876,20 +1027,24 @@ void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& ) ...@@ -876,20 +1027,24 @@ void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& )
wxString buffer = m_TreeProject->GetItemText( curr_item ); wxString buffer = m_TreeProject->GetItemText( curr_item );
wxString msg = _( "Change filename: " ) + tree_data->m_FileName; wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
if( Get_Message(msg, _("Change filename"), buffer, this ) != 0 ) if( Get_Message(msg, _("Change filename"), buffer, this ) != 0 )
return; //Abort command return; //Abort command
if( tree_data->Rename( buffer, true ) ) if( tree_data->Rename( buffer, true ) )
{
m_TreeProject->SetItemText( curr_item, buffer ); m_TreeProject->SetItemText( curr_item, buffer );
}
} }
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event ) void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
/***************************************************/ /*****************************************************************************/
{ {
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -903,14 +1058,17 @@ void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event ) ...@@ -903,14 +1058,17 @@ void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
} }
/****************************************************************/
int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
/****************************************************************/
// Add a state to the image list ... /**
* @brief Add a state to the image list
*/
/*****************************************************************************/
int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
/*****************************************************************************/
{ {
wxBitmap* image; wxBitmap* image;
bool success = wxPyConvertSwigPtr( bitmap.ptr(), (void**) &image, _T( "wxBitmap" ) ); bool success = wxPyConvertSwigPtr( bitmap.ptr(),
(void**) &image, _T( "wxBitmap" ) );
if( !success ) if( !success )
return -1; return -1;
...@@ -931,13 +1089,16 @@ int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap ) ...@@ -931,13 +1089,16 @@ int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
return ret; return ret;
} }
#endif /* KICAD_PYTHON */
#endif
/***************************************************/
/**
* @brief Prevent the main project to be renamed
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event ) void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event )
/***************************************************/ /*****************************************************************************/
/* Prevent the main project to be renamed */
{ {
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -948,10 +1109,13 @@ void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event ) ...@@ -948,10 +1109,13 @@ void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event )
} }
/***************************************************/
/**
* @brief Rename a tree item on demand of the context menu
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnRename( wxTreeEvent& event ) void WinEDA_PrjFrame::OnRename( wxTreeEvent& event )
/***************************************************/ /*****************************************************************************/
/* rename a tree item on demand of the context menu */
{ {
TreePrjItemData* tree_data = GetSelectedData(); TreePrjItemData* tree_data = GetSelectedData();
...@@ -962,9 +1126,13 @@ void WinEDA_PrjFrame::OnRename( wxTreeEvent& event ) ...@@ -962,9 +1126,13 @@ void WinEDA_PrjFrame::OnRename( wxTreeEvent& event )
} }
/**************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void WinEDA_PrjFrame::OnSelect( wxTreeEvent& Event ) void WinEDA_PrjFrame::OnSelect( wxTreeEvent& Event )
/**************************************************/ /*****************************************************************************/
{ {
wxString FullFileName; wxString FullFileName;
......
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