2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @file treeprj_frame.cpp
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#ifdef KICAD_PYTHON
|
2008-11-02 14:54:53 +00:00
|
|
|
#include <pyhandler.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "kicad.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#include "wx/treectrl.h"
|
|
|
|
#include "wx/regex.h"
|
|
|
|
#include "wx/dir.h"
|
|
|
|
|
|
|
|
#include "bitmaps.h"
|
|
|
|
|
|
|
|
#include "id.h"
|
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
// Comment this if you do no want to load subdirs files in the tree project
|
|
|
|
// UnComment this to load subdirs files in the tree project
|
|
|
|
#define ADD_FILES_IN_SUBDIRS
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
// list of files extensions listed in the tree project window
|
|
|
|
// *.sch files are always allowed, do not add here
|
|
|
|
// Add extensions in a compatible regex format to see others files types
|
|
|
|
const wxChar * s_AllowedExtensionsToList[] =
|
|
|
|
{
|
|
|
|
wxT( "^.*\\.pro$" ),
|
|
|
|
wxT( "^.*\\.pdf$" ),
|
|
|
|
wxT( "^[^$].*\\.brd$" ),
|
|
|
|
wxT( "^.*\\.net$" ),
|
|
|
|
wxT( "^.*\\.txt$" ),
|
|
|
|
wxT( "^.*\\.pho$" ),
|
|
|
|
wxT( "^.*\\.odt$" ),
|
|
|
|
wxT( "^.*\\.sxw$" ),
|
|
|
|
wxT( "^.*\\.htm$" ),
|
|
|
|
wxT( "^.*\\.html$" ),
|
|
|
|
NULL // end of list
|
|
|
|
};
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size ) :
|
2008-11-02 14:54:53 +00:00
|
|
|
wxSashLayoutWindow( parent,
|
|
|
|
ID_LEFT_FRAME,
|
|
|
|
pos,
|
|
|
|
size,
|
|
|
|
wxNO_BORDER | wxSW_3D )
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_TreeProject = NULL;
|
|
|
|
wxMenuItem* item;
|
|
|
|
m_PopupMenu = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2007-09-13 11:55:46 +00:00
|
|
|
m_Filters.push_back( wxT( "^.*\\.py$" ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RunScript" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::EditScript" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::TreeContextMenu" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::TreeAddFile" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::NewFile" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::NewDirectory" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::DeleteFile" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::RenameFile" ) );
|
|
|
|
PyHandler::GetInstance()->DeclareEvent( wxT( "kicad::MoveFile" ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
for( int i = 0; i < TREE_MAX; i++ )
|
|
|
|
m_ContextMenus.push_back( new wxMenu() );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 22:53:38 +00:00
|
|
|
wxMenu* menu = m_ContextMenus[TREE_PY];
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Python script context menu
|
|
|
|
#ifdef KICAD_PYTHON
|
2007-09-13 11:55:46 +00:00
|
|
|
item = new wxMenuItem( menu, ID_PROJECT_RUNPY,
|
2008-11-02 14:54:53 +00:00
|
|
|
_( "&Run" ),
|
|
|
|
_( "Run the Python Script" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
item->SetBitmap( icon_python_small_xpm );
|
|
|
|
menu->Append( item );
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// 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 );
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// New files context menu:
|
|
|
|
wxMenu* menus[2];
|
|
|
|
menus[0] = m_ContextMenus[TREE_DIRECTORY];
|
|
|
|
menus[1] = m_ContextMenus[TREE_PROJECT];
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
menu = menus[i];
|
|
|
|
|
|
|
|
// ID_PROJECT_NEWDIR
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory" ),
|
|
|
|
_( "Create a New Directory" ) );
|
|
|
|
item->SetBitmap( directory_xpm );
|
|
|
|
menu->Append( item );
|
|
|
|
|
|
|
|
|
|
|
|
// ID_PROJECT_NEWPY
|
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_NEWPY,
|
|
|
|
_( "New P&ython Script" ),
|
|
|
|
_( "Create a New Python Script" ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
item->SetBitmap( new_python_xpm );
|
|
|
|
menu->Append( item );
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// 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 );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// ID_PROJECT_NEWFILE
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_NEWFILE,
|
|
|
|
_( "New &File" ),
|
|
|
|
_( "Create a New File" ) );
|
|
|
|
item->SetBitmap( new_xpm );
|
|
|
|
menu->Append( item );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// Put the Rename and Delete file menu commands:
|
|
|
|
for( int i = TREE_PROJECT + 1; i < TREE_MAX; i++ )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
menu = m_ContextMenus[i];
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// ID_PROJECT_RENAME
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_RENAME,
|
|
|
|
TREE_DIRECTORY != i ? _ ("&Rename file") :
|
|
|
|
_( "&Rename directory" ),
|
|
|
|
TREE_DIRECTORY != i ? _ ("Rename file") :
|
|
|
|
_( "&Rename directory" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
item->SetBitmap( right_xpm );
|
|
|
|
menu->Append( item );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( TREE_DIRECTORY != i )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
// ID_PROJECT_TXTEDIT
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_TXTEDIT,
|
|
|
|
_( "&Edit in a text editor" ),
|
|
|
|
_( "Open the file in a Text Editor" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
item->SetBitmap( icon_txt_xpm );
|
|
|
|
menu->Append( item );
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// 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" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
item->SetBitmap( delete_xpm );
|
|
|
|
menu->Append( item );
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
ReCreateTreePrj();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_PrjFrame, wxSashLayoutWindow )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRenameAsk )
|
|
|
|
EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRename )
|
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, WinEDA_PrjFrame::OnSelect )
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, WinEDA_PrjFrame::OnRight )
|
|
|
|
EVT_TREE_BEGIN_DRAG( ID_PROJECT_TREE, WinEDA_PrjFrame::OnDragStart )
|
|
|
|
EVT_TREE_END_DRAG( ID_PROJECT_TREE, WinEDA_PrjFrame::OnDragEnd )
|
|
|
|
EVT_MENU( ID_PROJECT_TXTEDIT, WinEDA_PrjFrame::OnTxtEdit )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWFILE, WinEDA_PrjFrame::OnNewFile )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, WinEDA_PrjFrame::OnNewDirectory )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWPY, WinEDA_PrjFrame::OnNewPyFile )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWTXT, WinEDA_PrjFrame::OnNewTxtFile )
|
|
|
|
EVT_MENU( ID_PROJECT_DELETE, WinEDA_PrjFrame::OnDeleteFile )
|
|
|
|
EVT_MENU( ID_PROJECT_RENAME, WinEDA_PrjFrame::OnRenameFile )
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2008-11-02 14:54:53 +00:00
|
|
|
EVT_MENU( ID_PROJECT_RUNPY, WinEDA_PrjFrame::OnRunPy )
|
|
|
|
#endif /* KICAD_PYTHON */
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
END_EVENT_TABLE()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
WinEDA_TreePrj::~WinEDA_TreePrj()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Allowing drag & drop of file other than the currently opened project
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
/* Ensure item is selected
|
|
|
|
(Under Windows start drag does not activate the item) */
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId curr_item = event.GetItem();
|
|
|
|
|
|
|
|
m_TreeProject->SelectItem( curr_item );
|
|
|
|
TreePrjItemData* data = GetSelectedData();
|
|
|
|
if( data->GetFileName() == m_Parent->m_PrjFileName )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxTreeItemId id = m_TreeProject->GetSelection();
|
|
|
|
|
|
|
|
wxImage img = m_TreeProject->GetImageList()->GetBitmap( data->GetType() -
|
|
|
|
1 ).ConvertToImage();
|
|
|
|
m_DragCursor = wxCursor( img );
|
|
|
|
m_Parent->wxWindow::SetCursor( (wxCursor &)m_DragCursor );
|
|
|
|
event.Allow();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
m_Parent->SetCursor( wxNullCursor );
|
|
|
|
|
|
|
|
wxTreeItemId moved = m_TreeProject->GetSelection();
|
|
|
|
TreePrjItemData* source_data = GetSelectedData();
|
|
|
|
wxTreeItemId dest = event.GetItem();
|
|
|
|
if( !dest.IsOk() )
|
|
|
|
return; // Cancelled ...
|
|
|
|
TreePrjItemData* destData = dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) );
|
|
|
|
if( !destData )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// the item can be a member of the selected directory; get the directory itself
|
|
|
|
if( TREE_DIRECTORY != destData->GetType() && !m_TreeProject->ItemHasChildren( dest ) )
|
|
|
|
{ // the item is a member of the selected directory; get the directory itself
|
|
|
|
dest = m_TreeProject->GetItemParent( dest );
|
|
|
|
if( !dest.IsOk() )
|
|
|
|
return; // no parent ?
|
|
|
|
|
|
|
|
// Select the right destData:
|
|
|
|
destData = dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) );
|
|
|
|
if( !destData )
|
|
|
|
return;
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
source_data->Move( destData );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#if 0
|
2007-09-13 11:55:46 +00:00
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( dest );
|
2007-05-28 18:09:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
void WinEDA_PrjFrame::ClearFilters()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
m_Filters.clear();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
for( unsigned int i = 0; i < m_Filters.size(); i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
if( filter == m_Filters[i] )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
m_Filters.erase( m_Filters.begin() + i );
|
2007-05-28 18:09:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return the data corresponding to the file, or NULL
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
TreePrjItemData* WinEDA_PrjFrame::FindItemData(const boost::python::str& name)
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
// (Interative tree parsing)
|
|
|
|
std::vector< wxTreeItemId > roots1, roots2;
|
|
|
|
std::vector< wxTreeItemId > * root, * reserve;
|
|
|
|
wxString filename = PyHandler::MakeStr( name );
|
|
|
|
|
|
|
|
root = &roots1;
|
|
|
|
reserve = &roots2;
|
|
|
|
|
|
|
|
root->push_back( m_TreeProject->GetRootItem() );
|
|
|
|
|
|
|
|
// if we look for the root, return it ...
|
|
|
|
TreePrjItemData* data = dynamic_cast< TreePrjItemData*>(
|
|
|
|
m_TreeProject->GetItemData( root->at( 0 ) ) );
|
|
|
|
|
|
|
|
if( data->GetFileName() == filename )
|
|
|
|
return data;
|
|
|
|
|
|
|
|
// Then find in its child
|
|
|
|
while( root->size() )
|
|
|
|
{
|
|
|
|
// look in all roots
|
|
|
|
for( unsigned int i = 0; i < root->size(); i++ )
|
|
|
|
{
|
|
|
|
wxTreeItemId id = root->at( i );
|
|
|
|
|
|
|
|
// for each root check any child:
|
|
|
|
void* cookie = NULL;
|
|
|
|
wxTreeItemId child = m_TreeProject->GetFirstChild( id, cookie );
|
|
|
|
|
|
|
|
while( child.IsOk() )
|
|
|
|
{
|
|
|
|
TreePrjItemData* data = dynamic_cast< TreePrjItemData*>(
|
|
|
|
m_TreeProject->GetItemData( child ) );
|
|
|
|
|
|
|
|
if( data )
|
|
|
|
{
|
|
|
|
if( data->GetFileName() == filename )
|
|
|
|
return data;
|
|
|
|
if( m_TreeProject->ItemHasChildren( child ) )
|
|
|
|
reserve->push_back( child );
|
|
|
|
}
|
|
|
|
child = m_TreeProject->GetNextSibling( child );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap the roots
|
|
|
|
root->clear();
|
|
|
|
std::vector< wxTreeItemId > * tmp;
|
|
|
|
tmp = root;
|
|
|
|
root = reserve;
|
|
|
|
reserve = tmp;
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
return NULL;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void WinEDA_PrjFrame::RemoveFilterPy(const boost::python::str& filter)
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
RemoveFilter( PyHandler::MakeStr( filter ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
wxRegEx reg;
|
|
|
|
wxString text = PyHandler::MakeStr( filter );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( !reg.Compile( text ) )
|
|
|
|
return;
|
|
|
|
m_Filters.push_back( text );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
const std::vector<wxString>& WinEDA_PrjFrame::GetFilters()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
return m_Filters;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
wxMenu* WinEDA_PrjFrame::GetContextMenu( int type )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
return m_ContextMenus[type];
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnNewDirectory( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
|
|
|
NewFile( TREE_DIRECTORY );
|
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnNewFile( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
NewFile( TREE_UNKNOWN );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnNewPyFile( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
NewFile( TREE_PY );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnNewTxtFile( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
NewFile( TREE_TXT );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::NewFile( TreeFileType type )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
wxString filename;
|
|
|
|
wxString mask = GetFileExt( type );
|
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Get the directory:
|
|
|
|
wxString dir;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
TreePrjItemData* treeData;
|
|
|
|
wxString FullFileName;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
treeData = GetSelectedData();
|
|
|
|
if( !treeData )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
dir = treeData->GetDir();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Ask for the new file name
|
|
|
|
filename = EDA_FileSelector( TREE_DIRECTORY !=
|
2007-09-13 11:55:46 +00:00
|
|
|
type ? _( "Create New File:" ) : _( "Create New Directory" ),
|
|
|
|
wxGetCwd() + sep + dir, /* Chemin par defaut */
|
|
|
|
_( "noname" ) + mask, /* nom fichier par defaut */
|
|
|
|
mask, /* extension par defaut */
|
|
|
|
mask, /* Masque d'affichage */
|
|
|
|
this,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
|
|
|
|
TRUE
|
|
|
|
);
|
2008-11-02 14:54:53 +00:00
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
TreeFileType rootType = treeData->GetType();
|
|
|
|
wxTreeItemId root;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( TREE_DIRECTORY == rootType )
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
|
|
|
|
|
|
|
if( !root.IsOk() )
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
NewFile( filename, type, root );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::NewFile( const wxString& name,
|
2008-11-02 14:54:53 +00:00
|
|
|
TreeFileType type,
|
|
|
|
wxTreeItemId& root )
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
if( TREE_DIRECTORY != type )
|
|
|
|
{
|
|
|
|
wxFile( name, wxFile::write );
|
|
|
|
|
|
|
|
#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 );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString ext;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
case 0: // 0 is not used
|
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
case TREE_PROJECT:
|
|
|
|
ext = wxT( ".pro" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_SCHEMA:
|
|
|
|
ext = g_SchExtBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PCB:
|
|
|
|
ext = g_BoardExtBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PY:
|
|
|
|
ext = wxT( ".py" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_GERBER:
|
|
|
|
ext = g_GerberExtBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
|
|
|
ext = wxT( ".pdf" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
|
|
|
ext = wxT( ".txt" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_NET:
|
|
|
|
ext = wxT( ".net" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Add filename "name" to the tree \n
|
|
|
|
* if name is a directory, add the sub directory file names
|
|
|
|
* @return TODO
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId cellule;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
// Check the file type
|
2007-09-13 11:55:46 +00:00
|
|
|
TreeFileType type = TREE_UNKNOWN;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( wxDirExists( name ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
type = TREE_DIRECTORY;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
// Filter
|
|
|
|
wxRegEx reg;
|
|
|
|
|
|
|
|
bool isSchematic=false;
|
|
|
|
bool addFile=false;
|
|
|
|
for( unsigned i=0; i < m_Filters.size(); i++ )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
reg.Compile( m_Filters[i], wxRE_ICASE );
|
|
|
|
if( reg.Matches( name ) )
|
|
|
|
{
|
|
|
|
addFile=true;
|
|
|
|
if( i==0 )
|
|
|
|
isSchematic = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !addFile )
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
return false;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// only show the schematic if it is a top level schematic. eeschema
|
|
|
|
// cannot open a schematic and display it properly unless it starts
|
|
|
|
// at the top of the hierarchy. The schematic is top level only if
|
|
|
|
// there is a line in the header saying:
|
|
|
|
// "Sheet 1 "
|
|
|
|
if( isSchematic )
|
|
|
|
{
|
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp;
|
|
|
|
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
wxString FullFileName = name;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
fp = wxFopen( FullFileName, wxT( "rt" ) );
|
|
|
|
if( fp == NULL )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
return false;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addFile = false;
|
|
|
|
for( int i=0; i<20; ++i )
|
|
|
|
{
|
|
|
|
if( !fgets( line, sizeof(line), fp ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( !strncmp( line, "Sheet 1 ", 8 ) )
|
|
|
|
{
|
|
|
|
addFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if( !addFile )
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
return false; // it is a non-top-level schematic
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
|
|
|
|
{
|
|
|
|
wxString ext = GetFileExt( (TreeFileType) i );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( ext == wxT( "" ) )
|
|
|
|
continue;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
|
|
|
|
wxString::FromAscii("$" ), wxRE_ICASE );
|
|
|
|
|
|
|
|
if( reg.Matches( name ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
type = (TreeFileType) i;
|
2007-05-28 18:09:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
//also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild(root, cookie);
|
|
|
|
while(kid.IsOk())
|
|
|
|
{
|
|
|
|
TreePrjItemData* itemData = (TreePrjItemData*)
|
|
|
|
m_TreeProject->GetItemData(kid);
|
|
|
|
if( itemData ){
|
|
|
|
if( itemData->m_FileName == name ){
|
|
|
|
return true; //well, we would have added it, but it is already here!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kid = m_TreeProject->GetNextChild(root, cookie);
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
// Append the item (only appending the filename not the full path):
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString file = wxFileNameFromPath( name );
|
|
|
|
cellule = m_TreeProject->AppendItem( root, file );
|
|
|
|
TreePrjItemData* data = new TreePrjItemData( type, name, m_TreeProject );
|
|
|
|
|
|
|
|
m_TreeProject->SetItemFont( cellule, *g_StdFont );
|
|
|
|
m_TreeProject->SetItemData( cellule, data );
|
|
|
|
data->SetState( 0 );
|
|
|
|
|
|
|
|
/* Mark root files (files which have the same name as the project) */
|
|
|
|
wxFileName project( m_Parent->m_PrjFileName );
|
|
|
|
wxFileName currfile( file );
|
|
|
|
|
|
|
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
|
|
|
data->m_IsRootFile = true;
|
|
|
|
else
|
|
|
|
data->m_IsRootFile = false;
|
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ),
|
|
|
|
PyHandler::Convert( name ) );
|
|
|
|
#endif /* KICAD_YTHON */
|
|
|
|
|
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
// When enabled This section adds dirs and files found in the subdirs
|
|
|
|
// in this case AddFile is recursive.
|
2008-11-02 14:54:53 +00:00
|
|
|
#ifdef ADD_FILES_IN_SUBDIRS
|
|
|
|
if( TREE_DIRECTORY == type )
|
|
|
|
{
|
2008-05-16 11:38:35 +00:00
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
|
|
|
wxDir dir( name );
|
|
|
|
wxString dir_filename;
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
AddFile( name + sep + dir_filename, cellule );
|
|
|
|
}
|
|
|
|
while( dir.GetNext( &dir_filename ) );
|
2008-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( cellule );
|
2008-11-02 14:54:53 +00:00
|
|
|
}
|
|
|
|
#endif /* ADD_FILES_IN_SUBDIRS */
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Create or modify the tree showing project file names
|
|
|
|
* @return TODO
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void WinEDA_PrjFrame::ReCreateTreePrj()
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId rootcellule;
|
|
|
|
wxString Text;
|
|
|
|
bool prjOpened = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !m_TreeProject )
|
|
|
|
m_TreeProject = new WinEDA_TreePrj( this );
|
|
|
|
else
|
|
|
|
m_TreeProject->DeleteAllItems();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
m_TreeProject->SetFont( *g_StdFont );
|
|
|
|
|
|
|
|
if( m_Parent->m_PrjFileName.IsEmpty() )
|
|
|
|
Text = wxT( "noname" );
|
|
|
|
else
|
|
|
|
Text = wxFileNameFromPath( m_Parent->m_PrjFileName );
|
|
|
|
|
|
|
|
prjOpened = wxFileExists( Text );
|
|
|
|
|
|
|
|
// root tree:
|
|
|
|
m_root = rootcellule = m_TreeProject->AddRoot( Text, TREE_PROJECT - 1, TREE_PROJECT - 1 );
|
|
|
|
|
|
|
|
m_TreeProject->SetItemBold( rootcellule, TRUE );
|
|
|
|
|
|
|
|
m_TreeProject->SetItemData( rootcellule,
|
|
|
|
new TreePrjItemData( TREE_PROJECT, wxEmptyString, m_TreeProject ) );
|
|
|
|
|
|
|
|
m_TreeProject->SetItemFont( rootcellule, *g_StdFont );
|
|
|
|
|
|
|
|
ChangeFileNameExt( Text, wxEmptyString );
|
|
|
|
|
2008-05-16 11:38:35 +00:00
|
|
|
// Add at least a .sch / .brd if not existing:
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !wxFileExists( Text + g_SchExtBuffer ) )
|
|
|
|
AddFile( Text + g_SchExtBuffer, m_root );
|
|
|
|
|
|
|
|
if( !wxFileExists( Text + g_BoardExtBuffer ) )
|
|
|
|
AddFile( Text + g_BoardExtBuffer, m_root );
|
|
|
|
|
|
|
|
// Now adding all current files if available
|
|
|
|
if( prjOpened )
|
|
|
|
{
|
2007-05-28 18:09:49 +00:00
|
|
|
wxDir dir( wxGetCwd() );
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
wxString dir_str = dir.GetName();
|
|
|
|
wxString sep = wxFileName().GetPathSeparator();
|
2007-05-28 18:09:49 +00:00
|
|
|
wxString filename;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( dir.GetFirst( &filename ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
if( filename == Text + wxT( ".pro" ) )
|
|
|
|
continue;
|
|
|
|
|
modified the treeprj so that, instead of recursively scanning and adding
*all* the nested files and directories within the current working directory, it scans the first
level of files and directories. When a user double-clicks on a folder, *then*
the childeren of that directory are added to the wxTreeCtrl. This means that the little
triangle does not appear until the user opens a directory .. but, i think this is
a worthwile price to pay given below.
This prevents (or at least mitigates) memory overflow in the case that kicad starts in root, or,
in my case, it starts in my home directory, where thanks to wine & other sw,
there are far too many directories.
also modified the TreePrjItemData so that it stores the full pathnames in m_FileName,
not paths relative to the CWD. I'm not sure if this is the correct thing to do,
especially with the python interface, so change it back if it is more complicated.
the move and rename commands threw a segfault on my system
(Debian etch, wxWidgets 2.8.7),
and since there are better ways to rename and move files, this functionality
was disabled until somebody can fix it (alas, I don't have time for this now)
2007-12-16 18:44:12 +00:00
|
|
|
AddFile(dir_str + sep + filename, m_root );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
} while( dir.GetNext( &filename ) );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_TreeProject->Expand( rootcellule );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( m_root );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Opens *popup* the context menu
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
int tree_id;
|
|
|
|
TreePrjItemData* tree_data;
|
|
|
|
wxString FullFileName;
|
|
|
|
wxTreeItemId curr_item = Event.GetItem();
|
|
|
|
|
|
|
|
/* Ensure item is selected (Under Windows right click does not select the item) */
|
|
|
|
m_TreeProject->SelectItem( curr_item );
|
|
|
|
|
|
|
|
// Delete and recreate the context menu
|
|
|
|
delete( m_PopupMenu );
|
|
|
|
m_PopupMenu = new wxMenu();
|
|
|
|
|
|
|
|
// Get the current filename:
|
|
|
|
tree_data = GetSelectedData();
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree_id = tree_data->GetType();
|
|
|
|
FullFileName = tree_data->GetFileName();
|
|
|
|
|
|
|
|
// copy menu contents in order of the next array:
|
|
|
|
wxMenu* menus[] =
|
|
|
|
{
|
|
|
|
GetContextMenu( tree_id ),
|
|
|
|
const_cast<wxMenu*>( tree_data->GetMenu() )
|
|
|
|
};
|
|
|
|
|
|
|
|
for( unsigned int j=0; j < sizeof(menus)/sizeof(wxMenu*); j++ )
|
|
|
|
{
|
|
|
|
wxMenu* menu = menus[j];
|
|
|
|
if( !menu )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxMenuItemList list = menu->GetMenuItems();
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < list.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
// Grrrr! wxMenu does not have any copy constructor !! (do it by hand)
|
|
|
|
wxMenuItem* src = list[i];
|
|
|
|
wxString label = src->GetText();
|
|
|
|
|
|
|
|
// for obscure reasons, the & is translated into _ ... so replace it
|
|
|
|
label.Replace( wxT( "_" ), wxT( "&" ), true );
|
|
|
|
wxMenuItem* item = new wxMenuItem( m_PopupMenu, src->GetId(),
|
|
|
|
label, src->GetHelp(), src->GetKind() );
|
|
|
|
|
|
|
|
item->SetBitmap( src->GetBitmap() );
|
|
|
|
m_PopupMenu->Append( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// At last, call python to let python add menu items "on the fly"
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
#ifdef KICAD_PYTHON
|
2007-09-13 11:55:46 +00:00
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeContextMenu" ),
|
|
|
|
PyHandler::Convert( FullFileName ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( m_PopupMenu )
|
|
|
|
PopupMenu( m_PopupMenu );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString FullFileName = tree_data->GetFileName();
|
|
|
|
AddDelimiterString( FullFileName );
|
|
|
|
wxString editorname = GetEditorName();
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !editorname.IsEmpty() )
|
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
#ifdef KICAD_PYTHON
|
2007-09-13 11:55:46 +00:00
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ),
|
2008-11-02 14:54:53 +00:00
|
|
|
PyHandler::Convert( FullFileName ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ExecuteFile( this, editorname, FullFileName );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
tree_data->Delete();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
wxString buffer = m_TreeProject->GetItemText( curr_item );
|
|
|
|
wxString msg = _( "Change filename: " ) + tree_data->m_FileName;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( Get_Message(msg, _("Change filename"), buffer, this ) != 0 )
|
|
|
|
return; //Abort command
|
|
|
|
|
|
|
|
if( tree_data->Rename( buffer, true ) )
|
|
|
|
m_TreeProject->SetItemText( curr_item, buffer );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
#ifdef KICAD_PYTHON
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
wxString FullFileName = tree_data->GetFileName();
|
|
|
|
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::RunScript" ),
|
2008-11-02 14:54:53 +00:00
|
|
|
PyHandler::Convert( FullFileName ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
PyHandler::GetInstance()->RunScript( FullFileName );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Add a state to the image list
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
|
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxBitmap* image;
|
2008-11-02 14:54:53 +00:00
|
|
|
bool success = wxPyConvertSwigPtr( bitmap.ptr(),
|
|
|
|
(void**) &image, _T( "wxBitmap" ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( !success )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
wxImageList* list = m_TreeProject->GetImageList();
|
|
|
|
int ret = list->GetImageCount() / ( TREE_MAX - 2 );
|
|
|
|
|
|
|
|
for( int i = 0; i < TREE_MAX - 1; i++ )
|
|
|
|
{
|
|
|
|
wxBitmap composed( list->GetBitmap ( i ) );
|
|
|
|
|
|
|
|
wxMemoryDC dc;
|
|
|
|
dc.SelectObject( composed );
|
|
|
|
dc.DrawBitmap( *image, 0, 0, true );
|
|
|
|
list->Add( composed );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
#endif /* KICAD_PYTHON */
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Prevent the main project to be renamed
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
if( m_Parent->m_PrjFileName == tree_data->GetFileName() )
|
|
|
|
event.Veto();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Rename a tree item on demand of the context menu
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnRename( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
tree_data->OnRename( event );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2007-09-13 11:55:46 +00:00
|
|
|
void WinEDA_PrjFrame::OnSelect( wxTreeEvent& Event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-11-02 14:54:53 +00:00
|
|
|
wxString FullFileName;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
TreePrjItemData* tree_data = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
tree_data->Activate(this);
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|