2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2010-12-14 15:56:30 +00:00
|
|
|
* @file tree_project_frame.cpp
|
2008-11-02 14:54:53 +00:00
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <appl_wxstruct.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <kicad.h>
|
|
|
|
#include <tree_project_frame.h>
|
|
|
|
#include <class_treeprojectfiles.h>
|
|
|
|
#include <class_treeproject_item.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/regex.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/imaglist.h>
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/* Note about the tree project build process:
|
2010-02-17 17:47:12 +00:00
|
|
|
* Building the tree project can be *very* long if there are a lot of subdirectories
|
|
|
|
* in the working directory.
|
2010-05-29 18:34:18 +00:00
|
|
|
* Unfortunately, this happens easily if the project file *.pro is in the home directory
|
2010-02-20 13:20:55 +00:00
|
|
|
* So the tree project is built "on demand":
|
|
|
|
* First the tree is built from the current directory and shows files and subdirs.
|
|
|
|
* > First level subdirs trees are built (i.e subdirs contents are not read)
|
|
|
|
* > When expanding a subdir, each subdir contains is read,
|
|
|
|
* and the corresponding sub tree is populated on the fly.
|
2010-02-17 17:47:12 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-30 18:06:21 +00:00
|
|
|
// list of files extensions listed in the tree project window
|
2009-02-04 15:25:03 +00:00
|
|
|
// *.sch files are always allowed, do not add here
|
2008-05-30 18:06:21 +00:00
|
|
|
// Add extensions in a compatible regex format to see others files types
|
2009-02-04 15:25:03 +00:00
|
|
|
const wxChar* s_AllowedExtensionsToList[] =
|
2008-05-30 18:06:21 +00:00
|
|
|
{
|
|
|
|
wxT( "^.*\\.pro$" ),
|
|
|
|
wxT( "^.*\\.pdf$" ),
|
2012-02-16 20:03:33 +00:00
|
|
|
wxT( "^[^$].*\\.brd$" ), // Pcbnew files
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.net$" ),
|
|
|
|
wxT( "^.*\\.txt$" ),
|
2012-02-16 20:03:33 +00:00
|
|
|
wxT( "^.*\\.pho$" ), // Gerber file (Kicad extension)
|
2011-08-19 13:08:24 +00:00
|
|
|
wxT( "^.*\\.gbr$" ), // Gerber file
|
|
|
|
wxT( "^.*\\.gb[alops]$" ), // Gerber back (or bottom) layer file
|
|
|
|
wxT( "^.*\\.gt[alops]$" ), // Gerber front (or top) layer file
|
|
|
|
wxT( "^.*\\.g[0-9]{1,2}$" ), // Gerber inner layer file
|
2008-05-30 18:06:21 +00:00
|
|
|
wxT( "^.*\\.odt$" ),
|
|
|
|
wxT( "^.*\\.sxw$" ),
|
|
|
|
wxT( "^.*\\.htm$" ),
|
|
|
|
wxT( "^.*\\.html$" ),
|
2012-02-16 20:03:33 +00:00
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separateed format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
|
|
|
wxT( "^.*\\.cmp$" ), // Cvpcb cmp/footprint link files
|
2011-08-19 13:08:24 +00:00
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
|
|
|
NULL // end of list
|
2008-05-30 18:06:21 +00:00
|
|
|
};
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* TODO: Check if these file extension and wildcard definitions are used
|
2011-09-30 18:15:37 +00:00
|
|
|
* in any of the other KiCad programs and move them into the common
|
2009-04-05 20:49:15 +00:00
|
|
|
* library as required. */
|
|
|
|
|
|
|
|
/* File extension definitions. */
|
|
|
|
const wxString TextFileExtension( wxT( "txt" ) );
|
|
|
|
|
|
|
|
/* File wildcard definitions. */
|
|
|
|
const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) );
|
|
|
|
|
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
2010-02-20 13:20:55 +00:00
|
|
|
* @brief class TREE_PROJECT_FRAME is the frame that shows the tree list
|
|
|
|
* of files and subdirs inside the working directory
|
|
|
|
* Files are filtered (see s_AllowedExtensionsToList) so
|
|
|
|
* only useful files are shown.
|
2008-11-02 14:54:53 +00:00
|
|
|
*/
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BEGIN_EVENT_TABLE( TREE_PROJECT_FRAME, wxSashLayoutWindow )
|
|
|
|
EVT_TREE_BEGIN_LABEL_EDIT( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRenameAsk )
|
|
|
|
EVT_TREE_END_LABEL_EDIT( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRename )
|
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnSelect )
|
|
|
|
EVT_TREE_ITEM_EXPANDED( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnExpand )
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnRight )
|
|
|
|
EVT_TREE_BEGIN_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragStart )
|
|
|
|
EVT_TREE_END_DRAG( ID_PROJECT_TREE, TREE_PROJECT_FRAME::OnDragEnd )
|
|
|
|
EVT_MENU( ID_PROJECT_TXTEDIT, TREE_PROJECT_FRAME::OnTxtEdit )
|
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnNewDirectory )
|
|
|
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile )
|
|
|
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
2011-04-17 13:54:17 +00:00
|
|
|
TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
|
2009-02-04 15:25:03 +00:00
|
|
|
wxSashLayoutWindow( parent,
|
|
|
|
ID_LEFT_FRAME,
|
2009-11-18 20:12:11 +00:00
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
2009-02-04 15:25:03 +00:00
|
|
|
wxNO_BORDER | wxSW_3D )
|
2007-05-28 18:09:49 +00:00
|
|
|
/******************************************************************/
|
|
|
|
{
|
2009-02-04 15:25:03 +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] );
|
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
m_Filters.push_back( wxT( "^no KiCad files found" ) );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
for( int i = 0; i < TREE_MAX; i++ )
|
|
|
|
m_ContextMenus.push_back( new wxMenu() );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2010-02-28 13:44:29 +00:00
|
|
|
wxMenu *menu;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +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
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
menu = menus[i];
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
// ID_PROJECT_NEWDIR
|
|
|
|
item = new wxMenuItem( menu,
|
|
|
|
ID_PROJECT_NEWDIR,
|
|
|
|
_( "New D&irectory" ),
|
|
|
|
_( "Create a New Directory" ) );
|
2011-09-08 05:58:45 +00:00
|
|
|
item->SetBitmap( KiBitmap( directory_xpm ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
menu->Append( item );
|
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-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++ )
|
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
menu = m_ContextMenus[i];
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
// ID_PROJECT_RENAME
|
|
|
|
item = new wxMenuItem( menu,
|
2008-11-02 14:54:53 +00:00
|
|
|
ID_PROJECT_RENAME,
|
2009-02-04 15:25:03 +00:00
|
|
|
TREE_DIRECTORY != i ? _( "&Rename file" ) :
|
|
|
|
_( "&Rename directory" ),
|
|
|
|
TREE_DIRECTORY != i ? _( "Rename file" ) :
|
|
|
|
_( "&Rename directory" ) );
|
2011-09-08 05:58:45 +00:00
|
|
|
item->SetBitmap( KiBitmap( right_xpm ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
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" ) );
|
2011-09-08 05:58:45 +00:00
|
|
|
item->SetBitmap( KiBitmap( icon_txt_xpm ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
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" ) :
|
2009-02-04 15:25:03 +00:00
|
|
|
_( "&Delete Directory" ),
|
2008-11-02 14:54:53 +00:00
|
|
|
TREE_DIRECTORY != i ? _( "Delete the File" ) :
|
2009-02-04 15:25:03 +00:00
|
|
|
_( "&Delete the Directory and its content" ) );
|
2011-09-08 05:58:45 +00:00
|
|
|
item->SetBitmap( KiBitmap( delete_xpm ) );
|
2007-09-13 11:55:46 +00:00
|
|
|
menu->Append( item );
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
ReCreateTreePrj();
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 05:58:45 +00:00
|
|
|
|
2010-02-19 15:01:32 +00:00
|
|
|
TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
|
2009-05-21 17:42:42 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
wxMenu* menu;
|
|
|
|
|
|
|
|
for( i = 0; i < m_ContextMenus.size(); i++ )
|
|
|
|
{
|
|
|
|
menu = m_ContextMenus[i];
|
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_PopupMenu )
|
|
|
|
delete m_PopupMenu;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-11-02 14:54:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Allowing drag & drop of file other than the currently opened project
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnDragStart( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +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 );
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* data = GetSelectedData();
|
2011-05-13 13:15:28 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( data->GetFileName() == m_Parent->m_ProjectFileName.GetFullPath() )
|
2007-09-13 11:55:46 +00:00
|
|
|
return;
|
|
|
|
|
2011-05-13 13:15:28 +00:00
|
|
|
wxImage img = m_TreeProject->GetImageList()->GetBitmap( data->GetType() - 1 ).ConvertToImage();
|
2007-09-13 11:55:46 +00:00
|
|
|
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
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::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 );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* source_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId dest = event.GetItem();
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !dest.IsOk() )
|
|
|
|
return; // Cancelled ...
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* destData =
|
|
|
|
dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( dest ) );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !destData )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// the item can be a member of the selected directory; get the directory itself
|
2009-02-04 15:25:03 +00:00
|
|
|
if( TREE_DIRECTORY != destData->GetType()
|
|
|
|
&& !m_TreeProject->ItemHasChildren( dest ) )
|
|
|
|
{
|
|
|
|
// the item is a member of the selected directory; get the directory itself
|
2007-09-13 11:55:46 +00:00
|
|
|
dest = m_TreeProject->GetItemParent( dest );
|
|
|
|
if( !dest.IsOk() )
|
|
|
|
return; // no parent ?
|
|
|
|
|
|
|
|
// Select the right destData:
|
2009-02-04 15:25:03 +00:00
|
|
|
destData =
|
2010-02-20 13:20:55 +00:00
|
|
|
dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( dest ) );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
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
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::ClearFilters()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +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
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::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
|
|
|
/**
|
|
|
|
* @brief TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
const std::vector<wxString>& TREE_PROJECT_FRAME::GetFilters()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
wxMenu* TREE_PROJECT_FRAME::GetContextMenu( int type )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::NewFile( TreeFileType type )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxString mask = GetFileExt( type );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString wildcard = GetFileWildcard( type );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
// Get the directory:
|
|
|
|
wxString dir;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString title;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* treeData;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
title = ( TREE_DIRECTORY != type ) ? _( "Create New File" ) :
|
|
|
|
_( "Create New Directory" );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
treeData = GetSelectedData();
|
|
|
|
if( !treeData )
|
|
|
|
return;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
dir = wxGetCwd() + wxFileName().GetPathSeparator() + treeData->GetDir();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
// Ask for the new file name
|
2010-02-24 15:33:03 +00:00
|
|
|
wxString nameless_prj = NAMELESS_PROJECT;
|
|
|
|
nameless_prj += wxT(".") + mask;
|
|
|
|
wxFileDialog dlg( this, title, dir, nameless_prj,
|
2009-04-05 20:49:15 +00:00
|
|
|
wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
TreeFileType rootType = treeData->GetType();
|
|
|
|
wxTreeItemId root;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( TREE_DIRECTORY == rootType )
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !root.IsOk() )
|
|
|
|
root = m_TreeProject->GetSelection();
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
NewFile( dlg.GetPath(), 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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::NewFile( const wxString& name,
|
2009-02-04 15:25:03 +00:00
|
|
|
TreeFileType type,
|
|
|
|
wxTreeItemId& root )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
if( TREE_DIRECTORY != type )
|
|
|
|
{
|
|
|
|
wxFile( name, wxFile::write );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMkdir( name );
|
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString TREE_PROJECT_FRAME::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 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
case TREE_PROJECT:
|
|
|
|
ext = ProjectFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_SCHEMA:
|
|
|
|
ext = SchematicFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PCB:
|
2010-05-17 20:35:46 +00:00
|
|
|
ext = PcbFileExtension;
|
2009-04-05 20:49:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_GERBER:
|
|
|
|
ext = GerberFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
|
|
|
ext = PdfFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
|
|
|
ext = TextFileExtension;
|
2008-11-02 14:54:53 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
case TREE_NET:
|
|
|
|
ext = NetlistFileExtension;
|
|
|
|
break;
|
2012-02-16 20:03:33 +00:00
|
|
|
|
|
|
|
case TREE_CMP_LINK:
|
|
|
|
ext = ComponentFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_REPORT:
|
|
|
|
ext = ReportFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FP_PLACE:
|
|
|
|
ext = FootprintPlaceFileExtension;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DRILL:
|
|
|
|
ext = DrillFileExtension;
|
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
default: /* Eliminates unnecessary GCC warning. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the wxFileDialog wildcard string for the selected file type.
|
|
|
|
*/
|
2010-02-19 15:01:32 +00:00
|
|
|
wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
wxString ext;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
case TREE_PROJECT:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = ProjectFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_SCHEMA:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = SchematicFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PCB:
|
2010-05-17 20:35:46 +00:00
|
|
|
ext = PcbFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_GERBER:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = GerberFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_PDF:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = PdfFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_TXT:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = TextFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_NET:
|
2009-04-05 20:49:15 +00:00
|
|
|
ext = NetlistFileWildcard;
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
2012-02-16 20:03:33 +00:00
|
|
|
|
|
|
|
case TREE_CMP_LINK:
|
|
|
|
ext = ComponentFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_REPORT:
|
|
|
|
ext = ReportFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_FP_PLACE:
|
|
|
|
ext = FootprintPlaceFileWildcard;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TREE_DRILL:
|
|
|
|
ext = DrillFileWildcard;
|
|
|
|
break;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
default: /* Eliminates unnecessary GCC warning. */
|
2007-09-13 11:55:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function AddFile
|
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
|
2010-02-20 13:20:55 +00:00
|
|
|
* @param aName = the filename or the dirctory name to add
|
|
|
|
* @param aRoot = the wxTreeItemId item where to add sub tree items
|
|
|
|
* @param aRecurse = true to filenames or sub dir names to the current tree item
|
|
|
|
* false to stop file add.
|
|
|
|
* @return true if the file (or directory) is added.
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2010-02-20 13:20:55 +00:00
|
|
|
bool TREE_PROJECT_FRAME::AddFile( const wxString& aName,
|
|
|
|
wxTreeItemId& aRoot, bool aRecurse )
|
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
|
2009-02-04 15:25:03 +00:00
|
|
|
TreeFileType type = TREE_UNKNOWN;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2010-02-17 17:47:12 +00:00
|
|
|
// Skip not visible files and dirs
|
2010-02-20 13:20:55 +00:00
|
|
|
wxFileName fn(aName);
|
2010-02-17 17:47:12 +00:00
|
|
|
// Files/dirs names starting by "." are not visible files under unices.
|
|
|
|
// Skip them also under Windows
|
|
|
|
if( fn.GetName().StartsWith(wxT(".") ) )
|
|
|
|
return false;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( wxDirExists( aName ) )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
type = TREE_DIRECTORY;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
// Filter
|
2009-02-04 15:25:03 +00:00
|
|
|
wxRegEx reg;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
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 );
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
addFile = true;
|
2007-09-13 11:55:46 +00:00
|
|
|
if( i==0 )
|
|
|
|
isSchematic = true;
|
2009-10-26 21:25:23 +00:00
|
|
|
break;
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
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;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// only show the schematic if it is a top level schematic. Eeschema
|
2007-09-13 11:55:46 +00:00
|
|
|
// 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 )
|
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
wxString FullFileName = aName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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;
|
2009-10-26 21:25:23 +00:00
|
|
|
|
|
|
|
// check the first 100 lines for the "Sheet 1" string
|
|
|
|
for( int i = 0; i<100; ++i )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
|
|
|
if( !fgets( line, sizeof(line), fp ) )
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !strncmp( line, "Sheet 1 ", 8 ) )
|
|
|
|
{
|
|
|
|
addFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
fclose( fp );
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
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
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
|
|
|
|
wxString::FromAscii( "$" ), wxRE_ICASE );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
if( reg.Matches( aName ) )
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
//also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie;
|
2010-02-20 13:20:55 +00:00
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
|
2009-02-04 15:25:03 +00:00
|
|
|
while( kid.IsOk() )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( itemData )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
if( itemData->m_FileName == aName )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
return true; //well, we would have added it, but it is already here!
|
|
|
|
}
|
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
kid = m_TreeProject->GetNextChild( aRoot, cookie );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
// Append the item (only appending the filename not the full path):
|
2010-02-20 13:20:55 +00:00
|
|
|
wxString file = wxFileNameFromPath( aName );
|
|
|
|
cellule = m_TreeProject->AppendItem( aRoot, file );
|
|
|
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
m_TreeProject->SetItemData( cellule, data );
|
|
|
|
data->SetState( 0 );
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
/* Mark root files (files which have the same aName as the project) */
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName project( m_Parent->m_ProjectFileName );
|
2009-02-04 15:25:03 +00:00
|
|
|
wxFileName currfile( file );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
|
|
|
|
data->m_IsRootFile = true;
|
|
|
|
else
|
|
|
|
data->m_IsRootFile = false;
|
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
// This section adds dirs and files found in the subdirs
|
|
|
|
// in this case AddFile is recursive, but for the first level only.
|
|
|
|
if( TREE_DIRECTORY == type && aRecurse )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2008-05-16 11:38:35 +00:00
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
2010-02-20 13:20:55 +00:00
|
|
|
wxDir dir( aName );
|
2008-05-16 11:38:35 +00:00
|
|
|
wxString dir_filename;
|
2010-02-20 13:20:55 +00:00
|
|
|
data->m_WasPopulated = true; // set state to populated
|
2008-05-16 11:38:35 +00:00
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
do // Add name in tree, but do not recurse
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
AddFile( aName + sep + dir_filename, cellule, false );
|
2009-02-04 15:25:03 +00:00
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
2008-05-16 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( cellule );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
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
|
2007-09-13 11:55:46 +00:00
|
|
|
*/
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-09-13 11:55:46 +00:00
|
|
|
wxTreeItemId rootcellule;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2007-09-13 11:55:46 +00:00
|
|
|
bool prjOpened = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !m_TreeProject )
|
2010-02-19 15:01:32 +00:00
|
|
|
m_TreeProject = new TREEPROJECTFILES( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
|
|
|
m_TreeProject->DeleteAllItems();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !m_Parent->m_ProjectFileName.IsOk() )
|
|
|
|
{
|
|
|
|
fn.Clear();
|
|
|
|
fn.SetPath( ::wxGetCwd() );
|
2010-02-24 15:33:03 +00:00
|
|
|
fn.SetName( NAMELESS_PROJECT );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
}
|
2007-09-13 11:55:46 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_Parent->m_ProjectFileName;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
prjOpened = fn.FileExists();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// root tree:
|
2009-04-05 20:49:15 +00:00
|
|
|
m_root = rootcellule = m_TreeProject->AddRoot( fn.GetFullName(),
|
2009-02-04 15:25:03 +00:00
|
|
|
TREE_PROJECT - 1,
|
|
|
|
TREE_PROJECT - 1 );
|
|
|
|
|
2012-01-22 17:20:22 +00:00
|
|
|
m_TreeProject->SetItemBold( rootcellule, true );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
m_TreeProject->SetItemData( rootcellule,
|
2010-02-20 13:20:55 +00:00
|
|
|
new TREEPROJECT_ITEM( TREE_PROJECT,
|
2009-02-04 15:25:03 +00:00
|
|
|
wxEmptyString,
|
|
|
|
m_TreeProject ) );
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
// Now adding all current files if available
|
|
|
|
if( prjOpened )
|
|
|
|
{
|
2007-05-28 18:09:49 +00:00
|
|
|
wxString filename;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxDir dir( wxGetCwd() );
|
|
|
|
bool cont = dir.GetFirst( &filename );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
while( cont )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( filename != fn.GetFullName() )
|
|
|
|
AddFile( dir.GetName() + wxFileName::GetPathSeparator() +
|
|
|
|
filename, m_root );
|
2009-10-26 21:25:23 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
cont = dir.GetNext( &filename );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2011-05-12 18:47:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-12 20:11:45 +00:00
|
|
|
m_TreeProject->AppendItem( m_root, wxT("Empty project") );
|
2011-05-12 18:47:56 +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 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
m_Parent->m_ProjectFileName = fn;
|
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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
int tree_id;
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data;
|
2007-09-13 11:55:46 +00:00
|
|
|
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
|
2009-02-04 15:25:03 +00:00
|
|
|
delete ( m_PopupMenu );
|
2007-09-13 11:55:46 +00:00
|
|
|
m_PopupMenu = new wxMenu();
|
|
|
|
|
|
|
|
// Get the current filename:
|
|
|
|
tree_data = GetSelectedData();
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
tree_id = tree_data->GetType();
|
2007-09-13 11:55:46 +00:00
|
|
|
FullFileName = tree_data->GetFileName();
|
|
|
|
|
|
|
|
// copy menu contents in order of the next array:
|
|
|
|
wxMenu* menus[] =
|
|
|
|
{
|
|
|
|
GetContextMenu( tree_id ),
|
|
|
|
const_cast<wxMenu*>( tree_data->GetMenu() )
|
|
|
|
};
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
for( unsigned int j = 0; j < sizeof(menus) / sizeof(wxMenu*); j++ )
|
2007-09-13 11:55:46 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxMenu* menu = menus[j];
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !menu )
|
|
|
|
continue;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
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];
|
2009-05-16 05:38:38 +00:00
|
|
|
wxString label = src->GetItemLabelText();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
// for obscure reasons, the & is translated into _ ... so replace it
|
|
|
|
label.Replace( wxT( "_" ), wxT( "&" ), true );
|
|
|
|
wxMenuItem* item = new wxMenuItem( m_PopupMenu, src->GetId(),
|
2009-02-04 15:25:03 +00:00
|
|
|
label,
|
|
|
|
src->GetHelp(), src->GetKind() );
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
item->SetBitmap( src->GetBitmap() );
|
|
|
|
m_PopupMenu->Append( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString FullFileName = tree_data->GetFileName();
|
|
|
|
AddDelimiterString( FullFileName );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString editorname = wxGetApp().GetEditorName();
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
if( !editorname.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
ExecuteFile( this, editorname, 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 TODO
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection();
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2007-09-13 11:55:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +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
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return; // cancelled by user
|
|
|
|
|
|
|
|
buffer = dlg.GetValue( );
|
2010-07-21 08:15:54 +00:00
|
|
|
buffer.Trim( true );
|
|
|
|
buffer.Trim( false );
|
2010-07-20 10:30:40 +00:00
|
|
|
if( buffer.IsEmpty() )
|
|
|
|
return; // empty file name not allowed
|
2008-11-02 14:54:53 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
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
|
|
|
/**
|
|
|
|
* @brief Prevent the main project to be renamed
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRenameAsk( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
if( m_Parent->m_ProjectFileName.GetFullPath() == tree_data->GetFileName() )
|
2007-09-13 11:55:46 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnRename( wxTreeEvent& event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-09-13 11:55:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
2010-02-19 15:01:32 +00:00
|
|
|
void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
|
2008-11-02 14:54:53 +00:00
|
|
|
/*****************************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-02-04 15:25:03 +00:00
|
|
|
wxString FullFileName;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2010-02-20 13:20:55 +00:00
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData();
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
tree_data->Activate( this );
|
2007-09-13 11:55:46 +00:00
|
|
|
}
|
2010-02-20 13:20:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Called when expanding an item of the tree
|
|
|
|
* populate tree items corresponding to subdirectories not already populated
|
|
|
|
*/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
wxString FullFileName;
|
|
|
|
|
|
|
|
wxTreeItemId itemId = Event.GetItem();
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );
|
|
|
|
|
|
|
|
if( !tree_data )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( tree_data->GetType() != TREE_DIRECTORY )
|
|
|
|
return;
|
|
|
|
|
|
|
|
//explore list of non populated subdirs, and populate them
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
|
|
|
|
for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
|
|
|
|
{
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
|
|
|
|
if( !itemData || itemData->GetType() != TREE_DIRECTORY )
|
|
|
|
continue;
|
|
|
|
if ( itemData->m_WasPopulated )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString fileName = itemData->GetFileName();
|
|
|
|
const wxString sep = wxFileName().GetPathSeparator();
|
|
|
|
wxDir dir( fileName );
|
|
|
|
wxString dir_filename;
|
|
|
|
if( dir.GetFirst( &dir_filename ) )
|
|
|
|
{
|
|
|
|
do // Add name to tree item, but do not recurse in subdirs:
|
|
|
|
{
|
|
|
|
AddFile( fileName + sep + dir_filename, kid, false );
|
|
|
|
} while( dir.GetNext( &dir_filename ) );
|
|
|
|
}
|
|
|
|
itemData->m_WasPopulated = true; // set state to populated
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */
|
|
|
|
m_TreeProject->SortChildren( kid );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetSelectedData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data from item currently selected (highlighted)
|
|
|
|
* Note this is not necessary the "clicked" item,
|
|
|
|
* because when expanding, collapsing an item this item is not selected
|
|
|
|
*/
|
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
|
|
|
|
{
|
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( m_TreeProject->GetSelection() ) );
|
|
|
|
}
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function GetItemIdData
|
2010-02-20 13:20:55 +00:00
|
|
|
* return the item data corresponding to a wxTreeItemId identifier
|
|
|
|
* @param aId = the wxTreeItemId identifier.
|
|
|
|
* @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId
|
|
|
|
*/
|
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData(wxTreeItemId aId)
|
|
|
|
{
|
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|