Beautify code for kicad.cpp, kicad/mainframe.cpp, treeprj_frame.cpp
This commit is contained in:
parent
365dbe15b8
commit
e7cd29ece6
238
kicad/kicad.cpp
238
kicad/kicad.cpp
|
@ -1,6 +1,11 @@
|
|||
/********************************/
|
||||
/* kicad.cpp - module principal */
|
||||
/********************************/
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @file kicad.cpp
|
||||
* @brief Main kicad library manager file
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
|
@ -13,13 +18,9 @@
|
|||
|
||||
#include <wx/image.h>
|
||||
|
||||
//#define SPLASH_OK
|
||||
|
||||
#ifdef SPLASH_OK
|
||||
|
||||
/* Define Splash Image */
|
||||
#ifdef USE_SPLASH_IMAGE
|
||||
#define SPLASH_IMAGE logo_kicad.png
|
||||
|
||||
#include "wx/splash.h"
|
||||
#include "wx/mediactrl.h"
|
||||
#endif
|
||||
|
@ -35,95 +36,174 @@
|
|||
#include <pyhandler.h>
|
||||
#endif
|
||||
|
||||
/* Routines exportees */
|
||||
/* Export functions */
|
||||
|
||||
/* fonctions importees */
|
||||
/* Import functions */
|
||||
char *GetFileName(char *FullPathName);
|
||||
void ShowLogo(char * FonteFileName);
|
||||
|
||||
/* Routines locales */
|
||||
|
||||
/************************************/
|
||||
/* Called to initialize the program */
|
||||
/************************************/
|
||||
/* Local functions */
|
||||
|
||||
/************************************/
|
||||
/* Called to initialize the program */
|
||||
/************************************/
|
||||
// Create a new application object
|
||||
IMPLEMENT_APP(WinEDA_App)
|
||||
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
using namespace boost::python;
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
// Global functions:
|
||||
/*****************************************************************************/
|
||||
static WinEDA_MainFrame& GetMainFrame() { return *( wxGetApp().m_MainFrame ); }
|
||||
static void WinEDAPrint( str msg ) { GetMainFrame().PrintMsg( PyHandler::MakeStr( msg ) + wxT("\n") ); }
|
||||
static void WinEDAClear() { GetMainFrame().ClearMsg(); }
|
||||
static object GetTypeExt( enum TreeFileType type ) { return PyHandler::Convert( WinEDA_PrjFrame::GetFileExt( type ) ); }
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
// WinEDA_MainFrame Special binding functions:
|
||||
// (one line functions are simple wrappers)
|
||||
|
||||
/*****************************************************************************/
|
||||
object WinEDA_MainFrame::GetPrjName() const { return PyHandler::Convert( m_PrjFileName ); }
|
||||
object WinEDA_MainFrame::ToWx() { return object( handle<>( borrowed( wxPyMake_wxObject( this, false ) ) ) ); }
|
||||
WinEDA_PrjFrame* WinEDA_MainFrame::GetTree() const { return m_LeftWin; }
|
||||
|
||||
void WinEDA_MainFrame::AddFastLaunchPy( object & button )
|
||||
{
|
||||
wxBitmapButton * btn;
|
||||
bool success = wxPyConvertSwigPtr( button.ptr(), (void**)&btn, _T("wxBitmapButton"));
|
||||
if ( !success ) return;
|
||||
|
||||
Py_INCREF( button.ptr() );
|
||||
btn->Reparent( m_CommandWin );
|
||||
m_CommandWin->AddFastLaunch( btn );
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_MainFrame::AddFastLaunchPy( object & button )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxBitmapButton * btn;
|
||||
|
||||
bool success = wxPyConvertSwigPtr( button.ptr(), (void**)&btn, _T("wxBitmapButton"));
|
||||
if(!success)
|
||||
return;
|
||||
|
||||
Py_INCREF( button.ptr() );
|
||||
btn->Reparent( m_CommandWin );
|
||||
m_CommandWin->AddFastLaunch( btn );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
// WinEDA_PrjFrame Special binding functions:
|
||||
// (one line functions are simple wrappers)
|
||||
/*****************************************************************************/
|
||||
// TODO To WxWidgets ?
|
||||
object WinEDA_PrjFrame::ToWx()
|
||||
{ return object( handle<>( borrowed( wxPyMake_wxObject( this, 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 ) ) ) ); }
|
||||
// TODO Get ?
|
||||
object WinEDA_PrjFrame::GetFtExPy( enum TreeFileType type ) const
|
||||
{ return PyHandler::Convert( GetFileExt( type ) ); }
|
||||
|
||||
void WinEDA_PrjFrame::NewFilePy( const str & name, enum TreeFileType type, object & id )
|
||||
// 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 ) ) ) ); }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::NewFilePy( const str & name,
|
||||
enum TreeFileType type,
|
||||
object & id )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxTreeItemId root;
|
||||
if (! wxPyConvertSwigPtr( id.ptr(), (void**)&root, _T("wxTreeItemId") ) ) return;
|
||||
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 )
|
||||
/* Add a file to the tree under root, or m_root if conversion is wrong */
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxTreeItemId * theroot = &m_root;
|
||||
if ( !wxPyConvertSwigPtr( root.ptr(), (void**)&root, _T("wxTreeItemId") ) )
|
||||
{
|
||||
theroot = &m_root;
|
||||
}
|
||||
AddFile( PyHandler::MakeStr( file ), *theroot );
|
||||
wxTreeItemId * theroot = &m_root;
|
||||
|
||||
if ( !wxPyConvertSwigPtr( root.ptr(), (void**)&root, _T("wxTreeItemId") ) )
|
||||
{
|
||||
theroot = &m_root;
|
||||
}
|
||||
|
||||
AddFile( PyHandler::MakeStr( file ), *theroot );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief convert wxTreeItem into TreePrjItemData
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
TreePrjItemData * WinEDA_PrjFrame::GetItemData( const object & item )
|
||||
/* convert wxTreeItem into TreePrjItemData */
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxTreeItemId *id = NULL;
|
||||
if ( !wxPyConvertSwigPtr( item.ptr(), (void**)&id, _T("wxTreeItemId") ) ) return NULL;
|
||||
return dynamic_cast<TreePrjItemData *>( m_TreeProject->GetItemData( *id ) );
|
||||
wxTreeItemId *id = NULL;
|
||||
|
||||
if (!wxPyConvertSwigPtr( item.ptr(), (void**)&id, _T("wxTreeItemId")))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dynamic_cast<TreePrjItemData *>( m_TreeProject->GetItemData( *id ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
// TreePrjItemData Special binding functions
|
||||
// (one line functions are simple wrappers)
|
||||
/*****************************************************************************/
|
||||
// Python rename
|
||||
bool TreePrjItemData::RenamePy( const str & newname, bool check )
|
||||
{ return Rename( PyHandler::MakeStr(newname), check ); }
|
||||
|
||||
bool TreePrjItemData::RenamePy( const str & newname, bool check ) { return Rename( PyHandler::MakeStr(newname), check ); }
|
||||
object TreePrjItemData::GetDirPy() const { return PyHandler::Convert( GetDir() ); }
|
||||
object TreePrjItemData::GetFileNamePy() const { return PyHandler::Convert( GetFileName() ); }
|
||||
object TreePrjItemData::GetMenuPy() { return object( handle<>( borrowed( wxPyMake_wxObject( &m_fileMenu, false ) ) ) ); }
|
||||
// Get python directory
|
||||
object TreePrjItemData::GetDirPy() const
|
||||
{ return PyHandler::Convert( GetDir() ); }
|
||||
|
||||
// kicad module init function
|
||||
// ( this function is called from PyHandler to init the kicad module )
|
||||
// Get python filename
|
||||
object TreePrjItemData::GetFileNamePy() const
|
||||
{ return PyHandler::Convert( GetFileName() ); }
|
||||
|
||||
// Get python menu
|
||||
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()
|
||||
/*****************************************************************************/
|
||||
{
|
||||
def( "GetMainFrame", &GetMainFrame, return_value_policy< reference_existing_object >() );
|
||||
def( "GetTypeExtension", &GetTypeExt );
|
||||
|
@ -156,6 +236,7 @@ static void py_kicad_init()
|
|||
.value( "DIRECTORY", TREE_DIRECTORY )
|
||||
.value( "MAX", TREE_MAX );
|
||||
|
||||
|
||||
class_<WinEDA_PrjFrame>( "TreeWindow" )
|
||||
// wx Interface
|
||||
.def( "ToWx", &WinEDA_PrjFrame::ToWx )
|
||||
|
@ -168,14 +249,38 @@ static void py_kicad_init()
|
|||
.def( "RemoveFilter", &WinEDA_PrjFrame::RemoveFilterPy )
|
||||
.def( "GetFilters", &WinEDA_PrjFrame::GetFilters, return_value_policy < copy_const_reference >() )
|
||||
.def( "GetCurrentMenu", &WinEDA_PrjFrame::GetCurrentMenu )
|
||||
// Project tree control
|
||||
.def( "AddState", &WinEDA_PrjFrame::AddStatePy )
|
||||
.def( "GetTreeCtrl", &WinEDA_PrjFrame::GetTreeCtrl )
|
||||
.def( "GetItemData", &WinEDA_PrjFrame::GetItemData, return_value_policy < reference_existing_object >() )
|
||||
.def( "FindItemData", &WinEDA_PrjFrame::FindItemData, return_value_policy < reference_existing_object >() )
|
||||
.def( "NewFile", &WinEDA_PrjFrame::NewFilePy )
|
||||
.def( "AddFile", &WinEDA_PrjFrame::AddFilePy )
|
||||
;
|
||||
|
||||
|
||||
/** Project tree control **/
|
||||
|
||||
// AddState
|
||||
.def( "AddState",
|
||||
&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" )
|
||||
// Wx interface
|
||||
|
@ -188,18 +293,25 @@ static void py_kicad_init()
|
|||
|
||||
}
|
||||
|
||||
// common module init function
|
||||
|
||||
|
||||
/**
|
||||
* @brief Common python module init
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
static void py_common_init()
|
||||
/*****************************************************************************/
|
||||
{
|
||||
def( "Print", &WinEDAPrint );
|
||||
def( "Clear", &WinEDAClear );
|
||||
def( "Print", &WinEDAPrint );
|
||||
def( "Clear", &WinEDAClear );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
bool WinEDA_App::OnInit()
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxImage::AddHandler(new wxPNGHandler);
|
||||
|
||||
|
@ -236,8 +348,8 @@ bool WinEDA_App::OnInit()
|
|||
m_MainFrame->m_LeftWin->ReCreateTreePrj();
|
||||
SetTopWindow(m_MainFrame);
|
||||
|
||||
/* Splash Screen Logo */
|
||||
#ifdef SPLASH_OK
|
||||
/* Splash screen logo */
|
||||
#ifdef USE_SPLASH_IMAGE
|
||||
wxString logoname( wxString(m_BinDir) + _T("logokicad.png") );
|
||||
wxBitmap splash_screen;
|
||||
if ( splash_screen.LoadFile( logoname, wxBITMAP_TYPE_PNG ) )
|
||||
|
@ -247,7 +359,7 @@ bool WinEDA_App::OnInit()
|
|||
3000, m_MainFrame, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxSIMPLE_BORDER|wxSTAY_ON_TOP);
|
||||
}
|
||||
#endif
|
||||
#endif /* USE_SPLASH_IMAGE */
|
||||
|
||||
m_MainFrame->Show(TRUE);
|
||||
m_MainFrame->Raise();
|
||||
|
@ -265,5 +377,3 @@ bool WinEDA_App::OnInit()
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// vim: tabstop=4 : noexpandtab :
|
||||
|
|
|
@ -21,16 +21,19 @@
|
|||
|
||||
#include "kicad.h"
|
||||
|
||||
/****************/
|
||||
/* Constructor */
|
||||
/****************/
|
||||
|
||||
// Constructor
|
||||
/*****************************************************************************/
|
||||
WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
|
||||
wxWindow* parent, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size ) :
|
||||
WinEDA_BasicFrame( parent, KICAD_MAIN_FRAME, eda_app, title, pos, size )
|
||||
wxWindow* parent,
|
||||
const wxString& title,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size ) :
|
||||
WinEDA_BasicFrame( parent, KICAD_MAIN_FRAME, eda_app, title, pos, size )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxString msg;
|
||||
wxString line;
|
||||
wxSize clientsize;
|
||||
|
||||
m_FrameName = wxT( "KicadFrame" );
|
||||
|
@ -44,8 +47,10 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
|
|||
GetSettings();
|
||||
if( m_Parent->m_EDA_Config )
|
||||
{
|
||||
m_Parent->m_EDA_Config->Read( wxT( "LeftWinWidth" ), &m_LeftWin_Width );
|
||||
m_Parent->m_EDA_Config->Read( wxT( "CommandWinWidth" ), &m_CommandWin_Height );
|
||||
m_Parent->m_EDA_Config->Read( wxT( "LeftWinWidth" ),
|
||||
&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 );
|
||||
|
@ -57,9 +62,9 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
|
|||
|
||||
// Give an icon
|
||||
#ifdef __WINDOWS__
|
||||
SetIcon( wxICON( a_kicad_icon ) );
|
||||
SetIcon( wxICON( a_kicad_icon ) );
|
||||
#else
|
||||
SetIcon( wxICON( kicad_icon ) );
|
||||
SetIcon( wxICON( kicad_icon ) );
|
||||
#endif
|
||||
|
||||
clientsize = GetClientSize();
|
||||
|
@ -78,7 +83,7 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
|
|||
wxNO_BORDER | wxSW_3D );
|
||||
m_BottomWin->SetDefaultSize( wxSize( clientsize.x, 150 ) );
|
||||
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_LEFT, TRUE );
|
||||
m_BottomWin->SetExtraBorderSize( 2 );
|
||||
|
@ -91,43 +96,41 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
|
|||
m_DialogWin->SetFont( *g_StdFont );
|
||||
|
||||
// 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,
|
||||
0 ),
|
||||
wxSize( clientsize.x, m_CommandWin_Height ),
|
||||
0 ),
|
||||
wxSize( clientsize.x,
|
||||
m_CommandWin_Height ),
|
||||
wxNO_BORDER | wxSW_3D );
|
||||
|
||||
wxString line;
|
||||
msg = wxGetCwd();
|
||||
line.Printf( _( "Ready\nWorking dir: %s\n" ), msg.GetData() );
|
||||
PrintMsg( line );
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::LoadProject" ) );
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/***************/
|
||||
/* Destructor */
|
||||
/***************/
|
||||
|
||||
/*****************************************************************************/
|
||||
WinEDA_MainFrame::~WinEDA_MainFrame()
|
||||
/*****************************************************************************/
|
||||
{
|
||||
if( m_Parent->m_EDA_Config )
|
||||
{
|
||||
m_LeftWin_Width = m_LeftWin->GetSize().x;
|
||||
m_CommandWin_Height = m_CommandWin->GetSize().y;
|
||||
m_Parent->m_EDA_Config->Write( wxT( "LeftWinWidth" ), m_LeftWin_Width );
|
||||
m_Parent->m_EDA_Config->Write( wxT( "CommandWinWidth" ), m_CommandWin_Height );
|
||||
}
|
||||
if( m_Parent->m_EDA_Config )
|
||||
{
|
||||
m_LeftWin_Width = m_LeftWin->GetSize().x;
|
||||
m_CommandWin_Height = m_CommandWin->GetSize().y;
|
||||
m_Parent->m_EDA_Config->Write( wxT( "LeftWinWidth" ), m_LeftWin_Width );
|
||||
m_Parent->m_EDA_Config->Write( wxT( "CommandWinWidth" ), m_CommandWin_Height );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************/
|
||||
void WinEDA_MainFrame::PrintMsg( const wxString& text )
|
||||
/*******************************************************/
|
||||
|
||||
/*
|
||||
* Put text in the dialog frame
|
||||
*/
|
||||
|
@ -135,7 +138,7 @@ void WinEDA_MainFrame::PrintMsg( const wxString& text )
|
|||
m_DialogWin->SetFont( *g_StdFont );
|
||||
m_DialogWin->AppendText( text );
|
||||
#ifdef DEBUG
|
||||
printf("%s\n", (const char*)text.mb_str() );
|
||||
printf("%s\n", (const char*)text.mb_str() );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -275,18 +278,18 @@ void WinEDA_MainFrame::ReDraw( wxDC* DC )
|
|||
void WinEDA_MainFrame::Process_Special_Functions( wxCommandEvent& event )
|
||||
/**********************************************************************/
|
||||
{
|
||||
int id = event.GetId();
|
||||
int id = event.GetId();
|
||||
|
||||
switch( id )
|
||||
{
|
||||
switch( id )
|
||||
{
|
||||
case ID_EXIT:
|
||||
Close( TRUE );
|
||||
break;
|
||||
Close( TRUE );
|
||||
break;
|
||||
|
||||
default:
|
||||
DisplayError( this, wxT( "WinEDA_MainFrame::Process_Special_Functions error" ) );
|
||||
break;
|
||||
}
|
||||
DisplayError( this, wxT( "WinEDA_MainFrame::Process_Special_Functions error" ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -394,18 +397,21 @@ void WinEDA_MainFrame::OnRefresh( wxCommandEvent& event )
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*********************************/
|
||||
void WinEDA_MainFrame::ClearMsg()
|
||||
/*********************************/
|
||||
{
|
||||
m_DialogWin->Clear();
|
||||
m_DialogWin->Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
/*****************************************************************************/
|
||||
void WinEDA_MainFrame::OnRefreshPy()
|
||||
/*****************************************************************************/
|
||||
{
|
||||
m_LeftWin->ReCreateTreePrj();
|
||||
m_LeftWin->ReCreateTreePrj();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/*********************/
|
||||
/* treeprj_frame.cpp */
|
||||
/*********************/
|
||||
/**
|
||||
* @file treeprj_frame.cpp
|
||||
* @brief TODO
|
||||
*/
|
||||
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
#include <pyhandler.h>
|
||||
#include <pyhandler.h>
|
||||
#endif
|
||||
|
||||
#include "fctsys.h"
|
||||
|
@ -45,32 +47,45 @@ const wxChar * s_AllowedExtensionsToList[] =
|
|||
NULL // end of list
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/******************************************************************/
|
||||
WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size ) :
|
||||
wxSashLayoutWindow( parent, ID_LEFT_FRAME, pos, size,
|
||||
wxNO_BORDER | wxSW_3D )
|
||||
wxSashLayoutWindow( parent,
|
||||
ID_LEFT_FRAME,
|
||||
pos,
|
||||
size,
|
||||
wxNO_BORDER | wxSW_3D )
|
||||
/******************************************************************/
|
||||
{
|
||||
m_Parent = parent;
|
||||
m_TreeProject = NULL;
|
||||
wxMenuItem* item;
|
||||
m_PopupMenu = NULL;
|
||||
m_Parent = parent;
|
||||
m_TreeProject = NULL;
|
||||
wxMenu* menu = m_ContextMenus[TREE_PY];
|
||||
wxMenuItem* item;
|
||||
m_PopupMenu = NULL;
|
||||
|
||||
/* Filtering is now inverted: the filters are actually used to _enable_ support
|
||||
* for a given file type.
|
||||
*/
|
||||
m_Filters.push_back( wxT( "^.*\\.sch$" ) ); // note: sch filter must be first because of a test in AddFile() below
|
||||
for ( int ii = 0; s_AllowedExtensionsToList[ii] != NULL; ii++ )
|
||||
{
|
||||
m_Filters.push_back( s_AllowedExtensionsToList[ii] );
|
||||
}
|
||||
m_Filters.push_back( wxT( "^no kicad files found" ) );
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
/*
|
||||
* Filtering is now inverted: the filters are actually used to _enable_ support
|
||||
* for a given file type.
|
||||
*/
|
||||
|
||||
// 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++ )
|
||||
{
|
||||
m_Filters.push_back( s_AllowedExtensionsToList[ii] );
|
||||
}
|
||||
m_Filters.push_back( wxT( "^no kicad files found" ) );
|
||||
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
m_Filters.push_back( wxT( "^.*\\.py$" ) );
|
||||
|
||||
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RunScript" ) );
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::EditScript" ) );
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::TreeContextMenu" ) );
|
||||
|
@ -80,99 +95,127 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
|
|||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::DeleteFile" ) );
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RenameFile" ) );
|
||||
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::MoveFile" ) );
|
||||
#endif
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
for( int i = 0; i < TREE_MAX; i++ )
|
||||
m_ContextMenus.push_back( new wxMenu() );
|
||||
|
||||
// Python script context menu:
|
||||
for( int i = 0; i < TREE_MAX; i++ )
|
||||
m_ContextMenus.push_back( new wxMenu() );
|
||||
|
||||
wxMenu* menu = m_ContextMenus[TREE_PY];
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
// Python script context menu
|
||||
#ifdef KICAD_PYTHON
|
||||
item = new wxMenuItem( menu, ID_PROJECT_RUNPY,
|
||||
_( "&Run" ),
|
||||
_( "Run the Python Script" ) );
|
||||
|
||||
_( "&Run" ),
|
||||
_( "Run the Python Script" ) );
|
||||
item->SetBitmap( icon_python_small_xpm );
|
||||
menu->Append( item );
|
||||
#endif
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
item = new wxMenuItem( menu, ID_PROJECT_TXTEDIT,
|
||||
_( "&Edit in a text editor" ),
|
||||
_( "&Open the file in a Text Editor" ) );
|
||||
|
||||
item->SetBitmap( icon_txt_xpm );
|
||||
menu->Append( item );
|
||||
// ID_PROJECT_TXTEDIT
|
||||
item = new wxMenuItem( menu,
|
||||
ID_PROJECT_TXTEDIT,
|
||||
_( "&Edit in a text editor" ),
|
||||
_( "&Open the file in a Text Editor" ) );
|
||||
item->SetBitmap( icon_txt_xpm );
|
||||
menu->Append( item );
|
||||
|
||||
// New files context menu:
|
||||
wxMenu* menus[2];
|
||||
menus[0] = m_ContextMenus[TREE_DIRECTORY];
|
||||
menus[1] = m_ContextMenus[TREE_PROJECT];
|
||||
|
||||
// New files context menu:
|
||||
wxMenu* menus[2];
|
||||
menus[0] = m_ContextMenus[TREE_DIRECTORY];
|
||||
menus[1] = m_ContextMenus[TREE_PROJECT];
|
||||
|
||||
for( int i = 0; i < 2; i++ )
|
||||
{
|
||||
menu = menus[i];
|
||||
menu = menus[i];
|
||||
|
||||
item = new wxMenuItem( menu, ID_PROJECT_NEWDIR, _( "New D&irectory" ), _(
|
||||
"Create a New Directory" ) );
|
||||
// ID_PROJECT_NEWDIR
|
||||
item = new wxMenuItem( menu,
|
||||
ID_PROJECT_NEWDIR,
|
||||
_( "New D&irectory" ),
|
||||
_( "Create a New Directory" ) );
|
||||
item->SetBitmap( directory_xpm );
|
||||
menu->Append( item );
|
||||
|
||||
item->SetBitmap( directory_xpm );
|
||||
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 );
|
||||
menu->Append( item );
|
||||
#endif
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
item = new wxMenuItem( menu, ID_PROJECT_NEWTXT, _( "New &Text File" ), _(
|
||||
"Create a New Txt File" ) );
|
||||
|
||||
item->SetBitmap( new_txt_xpm );
|
||||
menu->Append( item );
|
||||
// ID_PROJECT_NEWTXT
|
||||
item = new wxMenuItem( menu,
|
||||
ID_PROJECT_NEWTXT,
|
||||
_( "New &Text File" ),
|
||||
_( "Create a New Txt File" ) );
|
||||
item->SetBitmap( new_txt_xpm );
|
||||
menu->Append( item );
|
||||
|
||||
item = new wxMenuItem( menu, ID_PROJECT_NEWFILE, _( "New &File" ), _( "Create a New File" ) );
|
||||
|
||||
item->SetBitmap( new_xpm );
|
||||
menu->Append( item );
|
||||
// ID_PROJECT_NEWFILE
|
||||
item = new wxMenuItem( menu,
|
||||
ID_PROJECT_NEWFILE,
|
||||
_( "New &File" ),
|
||||
_( "Create a New File" ) );
|
||||
item->SetBitmap( new_xpm );
|
||||
menu->Append( item );
|
||||
}
|
||||
|
||||
|
||||
// Put the Rename and Delete file menu commands:
|
||||
for( int i = TREE_PROJECT + 1; i < TREE_MAX; 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" ) );
|
||||
menu = m_ContextMenus[i];
|
||||
|
||||
|
||||
// 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 );
|
||||
menu->Append( item );
|
||||
|
||||
|
||||
if( TREE_DIRECTORY != i )
|
||||
{
|
||||
item = new wxMenuItem( menu, ID_PROJECT_TXTEDIT,
|
||||
_( "&Edit in a text editor" ),
|
||||
_( "Open the file in a Text Editor" ) );
|
||||
|
||||
// ID_PROJECT_TXTEDIT
|
||||
item = new wxMenuItem( menu,
|
||||
ID_PROJECT_TXTEDIT,
|
||||
_( "&Edit in a text editor" ),
|
||||
_( "Open the file in a Text Editor" ) );
|
||||
item->SetBitmap( icon_txt_xpm );
|
||||
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 );
|
||||
menu->Append( item );
|
||||
}
|
||||
|
||||
ReCreateTreePrj();
|
||||
ReCreateTreePrj();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
BEGIN_EVENT_TABLE( WinEDA_PrjFrame, wxSashLayoutWindow )
|
||||
/*****************************************************************************/
|
||||
|
||||
EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRenameAsk )
|
||||
EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRename )
|
||||
|
@ -188,25 +231,35 @@ EVT_MENU( ID_PROJECT_NEWTXT, WinEDA_PrjFrame::OnNewTxtFile )
|
|||
EVT_MENU( ID_PROJECT_DELETE, WinEDA_PrjFrame::OnDeleteFile )
|
||||
EVT_MENU( ID_PROJECT_RENAME, WinEDA_PrjFrame::OnRenameFile )
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
EVT_MENU( ID_PROJECT_RUNPY, WinEDA_PrjFrame::OnRunPy )
|
||||
#endif
|
||||
END_EVENT_TABLE()
|
||||
|
||||
/********************************/
|
||||
#ifdef KICAD_PYTHON
|
||||
EVT_MENU( ID_PROJECT_RUNPY, WinEDA_PrjFrame::OnRunPy )
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
END_EVENT_TABLE()
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
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();
|
||||
|
||||
m_TreeProject->SelectItem( curr_item );
|
||||
|
@ -224,9 +277,10 @@ void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
|
|||
}
|
||||
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
|
||||
/*******************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
m_Parent->SetCursor( wxNullCursor );
|
||||
|
||||
|
@ -261,17 +315,18 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
|
|||
}
|
||||
|
||||
|
||||
/************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::ClearFilters()
|
||||
/************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
m_Filters.clear();
|
||||
m_Filters.clear();
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
|
||||
/*************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
for( unsigned int i = 0; i < m_Filters.size(); i++ )
|
||||
{
|
||||
|
@ -284,13 +339,17 @@ void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
|
|||
}
|
||||
|
||||
|
||||
|
||||
#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)
|
||||
std::vector< wxTreeItemId > roots1, roots2;
|
||||
|
@ -345,88 +404,140 @@ TreePrjItemData* WinEDA_PrjFrame::FindItemData( const boost::python::str& name )
|
|||
reserve = tmp;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
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 )
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxRegEx reg;
|
||||
wxString text = PyHandler::MakeStr( filter );
|
||||
wxRegEx reg;
|
||||
wxString text = PyHandler::MakeStr( filter );
|
||||
|
||||
if( !reg.Compile( text ) )
|
||||
return;
|
||||
m_Filters.push_back( text );
|
||||
if( !reg.Compile( text ) )
|
||||
return;
|
||||
m_Filters.push_back( text );
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
const std::vector<wxString>& WinEDA_PrjFrame::GetFilters()
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
return m_Filters;
|
||||
return m_Filters;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
wxMenu* WinEDA_PrjFrame::GetContextMenu( int type )
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
return m_ContextMenus[type];
|
||||
return m_ContextMenus[type];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnNewDirectory( wxCommandEvent& event )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
NewFile( TREE_DIRECTORY );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnNewFile( wxCommandEvent& event )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
NewFile( TREE_UNKNOWN );
|
||||
NewFile( TREE_UNKNOWN );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnNewPyFile( wxCommandEvent& event )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
NewFile( TREE_PY );
|
||||
NewFile( TREE_PY );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnNewTxtFile( wxCommandEvent& event )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
NewFile( TREE_TXT );
|
||||
NewFile( TREE_TXT );
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::NewFile( TreeFileType type )
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxString filename;
|
||||
wxString mask = GetFileExt( type );
|
||||
const wxString sep = wxFileName().GetPathSeparator();
|
||||
wxString filename;
|
||||
wxString mask = GetFileExt( type );
|
||||
const wxString sep = wxFileName().GetPathSeparator();
|
||||
|
||||
// Get the directory:
|
||||
wxString dir;
|
||||
// Get the directory:
|
||||
wxString dir;
|
||||
|
||||
TreePrjItemData* treeData;
|
||||
wxString FullFileName;
|
||||
TreePrjItemData* treeData;
|
||||
wxString FullFileName;
|
||||
|
||||
treeData = GetSelectedData();
|
||||
if( !treeData )
|
||||
return;
|
||||
|
||||
dir = treeData->GetDir();
|
||||
treeData = GetSelectedData();
|
||||
if( !treeData )
|
||||
return;
|
||||
|
||||
// Ask for the new file name
|
||||
dir = treeData->GetDir();
|
||||
|
||||
filename = EDA_FileSelector( TREE_DIRECTORY !=
|
||||
// Ask for the new file name
|
||||
filename = EDA_FileSelector( TREE_DIRECTORY !=
|
||||
type ? _( "Create New File:" ) : _( "Create New Directory" ),
|
||||
wxGetCwd() + sep + dir, /* Chemin par defaut */
|
||||
_( "noname" ) + mask, /* nom fichier par defaut */
|
||||
|
@ -436,63 +547,75 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
|
|||
wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
|
||||
TRUE
|
||||
);
|
||||
if( filename.IsEmpty() )
|
||||
return;
|
||||
if( filename.IsEmpty() )
|
||||
return;
|
||||
|
||||
TreeFileType rootType = treeData->GetType();
|
||||
wxTreeItemId root;
|
||||
TreeFileType rootType = treeData->GetType();
|
||||
wxTreeItemId root;
|
||||
|
||||
if( TREE_DIRECTORY == rootType )
|
||||
{
|
||||
root = m_TreeProject->GetSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
||||
if( !root.IsOk() )
|
||||
root = m_TreeProject->GetSelection();
|
||||
}
|
||||
if( TREE_DIRECTORY == rootType )
|
||||
{
|
||||
root = m_TreeProject->GetSelection();
|
||||
}
|
||||
else
|
||||
{
|
||||
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
||||
|
||||
NewFile( filename, type, root );
|
||||
if( !root.IsOk() )
|
||||
root = m_TreeProject->GetSelection();
|
||||
}
|
||||
|
||||
NewFile( filename, type, root );
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::NewFile( const wxString& name,
|
||||
TreeFileType type, wxTreeItemId& root )
|
||||
/******************************************************************/
|
||||
TreeFileType type,
|
||||
wxTreeItemId& root )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
if( TREE_DIRECTORY != type )
|
||||
{
|
||||
wxFile( name, wxFile::write );
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->TriggerEvent(
|
||||
wxT( "kicad::NewFile" ), PyHandler::Convert( name ) );
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMkdir( name );
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->TriggerEvent(
|
||||
wxT( "kicad::NewDirectory" ), PyHandler::Convert( name ) );
|
||||
#endif
|
||||
}
|
||||
if( TREE_DIRECTORY != type )
|
||||
{
|
||||
wxFile( name, wxFile::write );
|
||||
|
||||
AddFile( name, root );
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewFile" ),
|
||||
PyHandler::Convert( name ) );
|
||||
#endif /* KICAD_PYTHON */
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMkdir( name );
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewDirectory" ),
|
||||
PyHandler::Convert( name ) );
|
||||
#endif /* KICAD_PYTHON */
|
||||
}
|
||||
|
||||
AddFile( name, root );
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
|
||||
/******************************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxString ext;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case 0:
|
||||
break; // 0 is not used
|
||||
case 0: // 0 is not used
|
||||
break;
|
||||
|
||||
case TREE_PROJECT:
|
||||
ext = wxT( ".pro" );
|
||||
|
@ -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
|
||||
* if name is a directory, add the sub directory file names
|
||||
/**
|
||||
* @brief Add filename "name" to the tree \n
|
||||
* if name is a directory, add the sub directory file names
|
||||
* @return TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxTreeItemId cellule;
|
||||
|
||||
|
@ -549,7 +674,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
|||
|
||||
if( wxDirExists( name ) )
|
||||
{
|
||||
type = TREE_DIRECTORY;
|
||||
type = TREE_DIRECTORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -586,8 +711,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
|||
fp = wxFopen( FullFileName, wxT( "rt" ) );
|
||||
if( fp == NULL )
|
||||
{
|
||||
//printf("Unable to open \"%s\"\n", (const char*) FullFileName.mb_str() );
|
||||
return false; // why show a file we cannot open?
|
||||
return false;
|
||||
}
|
||||
|
||||
addFile = false;
|
||||
|
@ -640,8 +764,8 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
|||
}
|
||||
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 );
|
||||
cellule = m_TreeProject->AppendItem( root, file );
|
||||
TreePrjItemData* data = new TreePrjItemData( type, name, m_TreeProject );
|
||||
|
@ -659,41 +783,49 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
|||
else
|
||||
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
|
||||
// in this case AddFile is recursive.
|
||||
if( TREE_DIRECTORY == type )
|
||||
{
|
||||
#ifdef ADD_FILES_IN_SUBDIRS
|
||||
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 ) );
|
||||
do
|
||||
{
|
||||
AddFile( name + sep + dir_filename, cellule );
|
||||
}
|
||||
while( dir.GetNext( &dir_filename ) );
|
||||
}
|
||||
|
||||
/* Sort filenames by alphabetic order */
|
||||
m_TreeProject->SortChildren( cellule );
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#endif /* ADD_FILES_IN_SUBDIRS */
|
||||
|
||||
|
||||
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;
|
||||
wxString Text;
|
||||
|
@ -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;
|
||||
TreePrjItemData* tree_data;
|
||||
|
@ -819,19 +953,25 @@ void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
|
|||
|
||||
// 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::Convert( FullFileName ) );
|
||||
#endif
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
if( m_PopupMenu )
|
||||
PopupMenu( m_PopupMenu );
|
||||
|
||||
if( m_PopupMenu )
|
||||
PopupMenu( m_PopupMenu );
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
|
||||
/*******************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
|
@ -841,55 +981,70 @@ void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
|
|||
wxString FullFileName = tree_data->GetFileName();
|
||||
AddDelimiterString( FullFileName );
|
||||
wxString editorname = GetEditorName();
|
||||
|
||||
if( !editorname.IsEmpty() )
|
||||
{
|
||||
#ifdef KICAD_PYTHON
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ),
|
||||
PyHandler::Convert( FullFileName ) );
|
||||
#endif
|
||||
ExecuteFile( this, editorname, FullFileName );
|
||||
PyHandler::Convert( FullFileName ) );
|
||||
#endif
|
||||
|
||||
ExecuteFile( this, editorname, FullFileName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& )
|
||||
/***************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
if( !tree_data )
|
||||
return;
|
||||
tree_data->Delete();
|
||||
if( !tree_data )
|
||||
return;
|
||||
tree_data->Delete();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& )
|
||||
/***************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
if( !tree_data )
|
||||
return;
|
||||
if( !tree_data )
|
||||
return;
|
||||
|
||||
wxString buffer = m_TreeProject->GetItemText( curr_item );
|
||||
wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
|
||||
if( Get_Message(msg, _("Change filename"), buffer, this ) != 0 )
|
||||
return; //Abort command
|
||||
wxString buffer = m_TreeProject->GetItemText( curr_item );
|
||||
wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
|
||||
|
||||
if( tree_data->Rename( buffer, true ) )
|
||||
{
|
||||
m_TreeProject->SetItemText( curr_item, buffer );
|
||||
}
|
||||
if( Get_Message(msg, _("Change filename"), buffer, this ) != 0 )
|
||||
return; //Abort command
|
||||
|
||||
if( tree_data->Rename( buffer, true ) )
|
||||
m_TreeProject->SetItemText( curr_item, buffer );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef KICAD_PYTHON
|
||||
/***************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
|
||||
/***************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
|
@ -898,19 +1053,22 @@ void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
|
|||
|
||||
wxString FullFileName = tree_data->GetFileName();
|
||||
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::RunScript" ),
|
||||
PyHandler::Convert( FullFileName ) );
|
||||
PyHandler::Convert( FullFileName ) );
|
||||
PyHandler::GetInstance()->RunScript( FullFileName );
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
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;
|
||||
bool success = wxPyConvertSwigPtr( bitmap.ptr(), (void**) &image, _T( "wxBitmap" ) );
|
||||
bool success = wxPyConvertSwigPtr( bitmap.ptr(),
|
||||
(void**) &image, _T( "wxBitmap" ) );
|
||||
|
||||
if( !success )
|
||||
return -1;
|
||||
|
@ -931,13 +1089,16 @@ int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
|
|||
return ret;
|
||||
}
|
||||
|
||||
#endif /* KICAD_PYTHON */
|
||||
|
||||
#endif
|
||||
|
||||
/***************************************************/
|
||||
|
||||
/**
|
||||
* @brief Prevent the main project to be renamed
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event )
|
||||
/***************************************************/
|
||||
/* Prevent the main project to be renamed */
|
||||
/*****************************************************************************/
|
||||
{
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
|
@ -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 )
|
||||
/***************************************************/
|
||||
/* rename a tree item on demand of the context menu */
|
||||
/*****************************************************************************/
|
||||
{
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
|
@ -962,15 +1126,19 @@ void WinEDA_PrjFrame::OnRename( wxTreeEvent& event )
|
|||
}
|
||||
|
||||
|
||||
/**************************************************/
|
||||
|
||||
/**
|
||||
* @brief TODO
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
void WinEDA_PrjFrame::OnSelect( wxTreeEvent& Event )
|
||||
/**************************************************/
|
||||
/*****************************************************************************/
|
||||
{
|
||||
wxString FullFileName;
|
||||
wxString FullFileName;
|
||||
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
TreePrjItemData* tree_data = GetSelectedData();
|
||||
|
||||
if( !tree_data )
|
||||
return;
|
||||
tree_data->Activate(this);
|
||||
if( !tree_data )
|
||||
return;
|
||||
tree_data->Activate(this);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue