|
|
@ -44,6 +44,7 @@ |
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/imaglist.h>
|
|
|
|
#include <menus_helpers.h>
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
|
|
|
|
/* Note about the tree project build process:
|
|
|
@ -77,13 +78,13 @@ static const wxChar* s_allowedExtensionsToList[] = |
|
|
|
wxT( "^.*\\.sxw$" ), |
|
|
|
wxT( "^.*\\.htm$" ), |
|
|
|
wxT( "^.*\\.html$" ), |
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separateed format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
|
|
|
wxT( "^.*\\.cmp$" ), // Cvpcb cmp/footprint link files
|
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
|
|
|
wxT( "^.*\\.svg$" ), // SVG print/plot files
|
|
|
|
NULL // end of list
|
|
|
|
wxT( "^.*\\.rpt$" ), // Report files
|
|
|
|
wxT( "^.*\\.csv$" ), // Report files in comma separateed format
|
|
|
|
wxT( "^.*\\.pos$" ), // Footprint position files
|
|
|
|
wxT( "^.*\\.cmp$" ), // Cvpcb cmp/footprint link files
|
|
|
|
wxT( "^.*\\.drl$" ), // Excellon drill files
|
|
|
|
wxT( "^.*\\.svg$" ), // SVG print/plot files
|
|
|
|
NULL // end of list
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -93,10 +94,10 @@ static const wxChar* s_allowedExtensionsToList[] = |
|
|
|
*/ |
|
|
|
|
|
|
|
/* File extension definitions. */ |
|
|
|
const wxString TextFileExtension( wxT( "txt" ) ); |
|
|
|
const wxString TextFileExtension( wxT( "txt" ) ); |
|
|
|
|
|
|
|
/* File wildcard definitions. */ |
|
|
|
const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) ); |
|
|
|
const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) ); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
@ -109,17 +110,16 @@ const wxString TextFileWildcard( wxT( "Text files (*.txt)|*.txt" ) ); |
|
|
|
|
|
|
|
/*****************************************************************************/ |
|
|
|
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::OnCreateNewDirectory ) |
|
|
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile ) |
|
|
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile ) |
|
|
|
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::OnOpenSelectedFileWithTextEditor ) |
|
|
|
EVT_MENU( ID_PROJECT_NEWDIR, TREE_PROJECT_FRAME::OnCreateNewDirectory ) |
|
|
|
EVT_MENU( ID_PROJECT_DELETE, TREE_PROJECT_FRAME::OnDeleteFile ) |
|
|
|
EVT_MENU( ID_PROJECT_RENAME, TREE_PROJECT_FRAME::OnRenameFile ) |
|
|
|
|
|
|
|
END_EVENT_TABLE() |
|
|
|
/*****************************************************************************/ |
|
|
|
|
|
|
@ -137,30 +137,34 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : |
|
|
|
m_TreeProject = NULL; |
|
|
|
wxMenuItem* item; |
|
|
|
m_PopupMenu = NULL; |
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
|
|
|
m_watcher = new wxFileSystemWatcher(); |
|
|
|
m_watcher->SetOwner( this ); |
|
|
|
Connect( wxEVT_FSWATCHER, |
|
|
|
wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) ); |
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* 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$" ) ); |
|
|
|
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( s_allowedExtensionsToList[ii] ); |
|
|
|
|
|
|
|
m_Filters.push_back( wxT( "^no KiCad files found" ) ); |
|
|
|
m_filters.push_back( wxT( "^no KiCad files found" ) ); |
|
|
|
|
|
|
|
for( int i = 0; i < TREE_MAX; i++ ) |
|
|
|
m_ContextMenus.push_back( new wxMenu() ); |
|
|
|
|
|
|
|
wxMenu *menu; |
|
|
|
wxMenu* menu; |
|
|
|
|
|
|
|
// New files context menu:
|
|
|
|
wxMenu* menus[2]; |
|
|
|
menus[0] = m_ContextMenus[TREE_DIRECTORY]; |
|
|
|
menus[1] = m_ContextMenus[TREE_PROJECT]; |
|
|
|
menus[0] = m_ContextMenus[TREE_DIRECTORY]; |
|
|
|
menus[1] = m_ContextMenus[TREE_PROJECT]; |
|
|
|
|
|
|
|
for( int i = 0; i < 2; i++ ) |
|
|
|
{ |
|
|
@ -173,7 +177,6 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) : |
|
|
|
_( "Create a New Directory" ) ); |
|
|
|
item->SetBitmap( KiBitmap( directory_xpm ) ); |
|
|
|
menu->Append( item ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -231,6 +234,10 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME() |
|
|
|
|
|
|
|
if( m_PopupMenu ) |
|
|
|
delete m_PopupMenu; |
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
|
|
|
delete m_watcher; |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -242,18 +249,19 @@ void TREE_PROJECT_FRAME::OnDragStart( wxTreeEvent& event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
/* Ensure item is selected
|
|
|
|
* (Under Windows start drag does not activate the item) */ |
|
|
|
wxTreeItemId curr_item = event.GetItem(); |
|
|
|
* (Under Windows start drag does not activate the item) |
|
|
|
*/ |
|
|
|
wxTreeItemId curr_item = event.GetItem(); |
|
|
|
|
|
|
|
m_TreeProject->SelectItem( curr_item ); |
|
|
|
TREEPROJECT_ITEM* data = GetSelectedData(); |
|
|
|
TREEPROJECT_ITEM* data = GetSelectedData(); |
|
|
|
|
|
|
|
if( data->GetFileName() == m_Parent->m_ProjectFileName.GetFullPath() ) |
|
|
|
return; |
|
|
|
|
|
|
|
wxImage img = m_TreeProject->GetImageList()->GetBitmap( data->GetType() - 1 ).ConvertToImage(); |
|
|
|
m_DragCursor = wxCursor( img ); |
|
|
|
m_Parent->wxWindow::SetCursor( (wxCursor &)m_DragCursor ); |
|
|
|
m_Parent->wxWindow::SetCursor( (wxCursor&) m_DragCursor ); |
|
|
|
event.Allow(); |
|
|
|
} |
|
|
|
|
|
|
@ -264,11 +272,11 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event ) |
|
|
|
{ |
|
|
|
m_Parent->SetCursor( wxNullCursor ); |
|
|
|
|
|
|
|
TREEPROJECT_ITEM* source_data = GetSelectedData(); |
|
|
|
wxTreeItemId dest = event.GetItem(); |
|
|
|
TREEPROJECT_ITEM* source_data = GetSelectedData(); |
|
|
|
wxTreeItemId dest = event.GetItem(); |
|
|
|
|
|
|
|
if( !dest.IsOk() ) |
|
|
|
return; // Cancelled ...
|
|
|
|
return; // Cancelled ...
|
|
|
|
|
|
|
|
TREEPROJECT_ITEM* destData = |
|
|
|
dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( dest ) ); |
|
|
@ -278,12 +286,13 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event ) |
|
|
|
|
|
|
|
// the item can be a member of the selected directory; get the directory itself
|
|
|
|
if( TREE_DIRECTORY != destData->GetType() |
|
|
|
&& !m_TreeProject->ItemHasChildren( dest ) ) |
|
|
|
&& !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 ?
|
|
|
|
return; // no parent ?
|
|
|
|
|
|
|
|
// Select the right destData:
|
|
|
|
destData = |
|
|
@ -294,19 +303,6 @@ void TREE_PROJECT_FRAME::OnDragEnd( wxTreeEvent& event ) |
|
|
|
} |
|
|
|
|
|
|
|
source_data->Move( destData ); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Sort filenames by alphabetic order */ |
|
|
|
m_TreeProject->SortChildren( dest ); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::ClearFilters() |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
m_Filters.clear(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -314,28 +310,17 @@ void TREE_PROJECT_FRAME::ClearFilters() |
|
|
|
void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
for( unsigned int i = 0; i < m_Filters.size(); i++ ) |
|
|
|
for( unsigned int i = 0; i < m_filters.size(); i++ ) |
|
|
|
{ |
|
|
|
if( filter == m_Filters[i] ) |
|
|
|
if( filter == m_filters[i] ) |
|
|
|
{ |
|
|
|
m_Filters.erase( m_Filters.begin() + i ); |
|
|
|
m_filters.erase( m_filters.begin() + i ); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
const std::vector<wxString>& TREE_PROJECT_FRAME::GetFilters() |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
return m_Filters; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
*/ |
|
|
@ -349,18 +334,19 @@ wxMenu* TREE_PROJECT_FRAME::GetContextMenu( int type ) |
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the popup menu in the tree frame |
|
|
|
* Creates a new subdirectory inside the current kicad project directory |
|
|
|
* Creates a new subdirectory inside the current kicad project directory |
|
|
|
* the user is prompted to enter a directory name |
|
|
|
*/ |
|
|
|
void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) |
|
|
|
{ |
|
|
|
// Get the root directory name:
|
|
|
|
TREEPROJECT_ITEM* treeData = GetSelectedData(); |
|
|
|
|
|
|
|
if( !treeData ) |
|
|
|
return; |
|
|
|
|
|
|
|
TreeFileType rootType = treeData->GetType(); |
|
|
|
wxTreeItemId root; |
|
|
|
TreeFileType rootType = treeData->GetType(); |
|
|
|
wxTreeItemId root; |
|
|
|
|
|
|
|
if( TREE_DIRECTORY == rootType ) |
|
|
|
{ |
|
|
@ -369,6 +355,7 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) |
|
|
|
else |
|
|
|
{ |
|
|
|
root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() ); |
|
|
|
|
|
|
|
if( !root.IsOk() ) |
|
|
|
root = m_TreeProject->GetSelection(); |
|
|
|
} |
|
|
@ -377,32 +364,28 @@ void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) |
|
|
|
wxString curr_dir = treeData->GetDir(); |
|
|
|
|
|
|
|
// Make the current subdir relative to the current path:
|
|
|
|
if( !curr_dir.IsEmpty() ) // A subdir is selected
|
|
|
|
if( !curr_dir.IsEmpty() ) // A subdir is selected
|
|
|
|
{ |
|
|
|
curr_dir += wxFileName::GetPathSeparator(); |
|
|
|
curr_dir += wxT("dummy"); |
|
|
|
wxFileName fn(curr_dir); |
|
|
|
curr_dir += wxFileName::GetPathSeparator(); |
|
|
|
curr_dir += wxT( "dummy" ); |
|
|
|
wxFileName fn( curr_dir ); |
|
|
|
fn.MakeRelativeTo(); |
|
|
|
curr_dir = fn.GetPath() + wxFileName::GetPathSeparator(); |
|
|
|
} |
|
|
|
wxString msg; |
|
|
|
msg.Printf( wxT("Current working directory:\n%s"), GetChars( wxGetCwd() ) ); |
|
|
|
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir ); |
|
|
|
|
|
|
|
wxString msg; |
|
|
|
msg.Printf( wxT( "Current working directory:\n%s" ), GetChars( wxGetCwd() ) ); |
|
|
|
wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir ); |
|
|
|
|
|
|
|
if( subdir.IsEmpty() ) |
|
|
|
return; |
|
|
|
|
|
|
|
if( wxMkdir( subdir ) ) |
|
|
|
AddFileToTree( subdir, root ); |
|
|
|
AddItemToTreeProject( subdir, root ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
wxString ext; |
|
|
|
|
|
|
@ -467,6 +450,7 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type ) |
|
|
|
return ext; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the wxFileDialog wildcard string for the selected file type. |
|
|
|
*/ |
|
|
@ -534,28 +518,29 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type ) |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function AddFileToTree |
|
|
|
* Function AddItemToTreeProject |
|
|
|
* @brief Add filename "name" to the tree \n |
|
|
|
* if name is a directory, add the sub directory file names |
|
|
|
* @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 |
|
|
|
* @param aRecurse = true to add file or subdir names to the current tree item |
|
|
|
* false to stop file add. |
|
|
|
* @return true if the file (or directory) is added. |
|
|
|
*/ |
|
|
|
bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
wxTreeItemId& aRoot, bool aRecurse ) |
|
|
|
bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, |
|
|
|
wxTreeItemId& aRoot, bool aRecurse ) |
|
|
|
{ |
|
|
|
wxTreeItemId cellule; |
|
|
|
wxTreeItemId cellule; |
|
|
|
|
|
|
|
// Check the file type
|
|
|
|
TreeFileType type = TREE_UNKNOWN; |
|
|
|
TreeFileType type = TREE_UNKNOWN; |
|
|
|
|
|
|
|
// Skip not visible files and dirs
|
|
|
|
wxFileName fn(aName); |
|
|
|
wxFileName fn( aName ); |
|
|
|
|
|
|
|
// Files/dirs names starting by "." are not visible files under unices.
|
|
|
|
// Skip them also under Windows
|
|
|
|
if( fn.GetName().StartsWith(wxT(".") ) ) |
|
|
|
if( fn.GetName().StartsWith( wxT( "." ) ) ) |
|
|
|
return false; |
|
|
|
|
|
|
|
if( wxDirExists( aName ) ) |
|
|
@ -569,17 +554,20 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
|
|
|
|
bool isSchematic = false; |
|
|
|
bool addFile = false; |
|
|
|
for( unsigned i = 0; i < m_Filters.size(); i++ ) |
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_filters.size(); i++ ) |
|
|
|
{ |
|
|
|
wxCHECK2_MSG( reg.Compile( m_Filters[i], wxRE_ICASE ), continue, |
|
|
|
wxT( "Regular expression " ) + m_Filters[i] + |
|
|
|
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue, |
|
|
|
wxT( "Regular expression " ) + m_filters[i] + |
|
|
|
wxT( " failed to compile." ) ); |
|
|
|
|
|
|
|
if( reg.Matches( aName ) ) |
|
|
|
{ |
|
|
|
addFile = true; |
|
|
|
|
|
|
|
if( i==0 ) |
|
|
|
isSchematic = true; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -594,12 +582,13 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
// "Sheet 1 "
|
|
|
|
if( isSchematic ) |
|
|
|
{ |
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp; |
|
|
|
char line[128]; // small because we just need a few bytes from the start of a line
|
|
|
|
FILE* fp; |
|
|
|
|
|
|
|
wxString FullFileName = aName; |
|
|
|
wxString FullFileName = aName; |
|
|
|
|
|
|
|
fp = wxFopen( FullFileName, wxT( "rt" ) ); |
|
|
|
|
|
|
|
if( fp == NULL ) |
|
|
|
{ |
|
|
|
return false; |
|
|
@ -608,7 +597,7 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
addFile = false; |
|
|
|
|
|
|
|
// check the first 100 lines for the "Sheet 1" string
|
|
|
|
for( int i = 0; i<100; ++i ) |
|
|
|
for( int i = 0; i<100; ++i ) |
|
|
|
{ |
|
|
|
if( !fgets( line, sizeof(line), fp ) ) |
|
|
|
break; |
|
|
@ -623,7 +612,7 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
fclose( fp ); |
|
|
|
|
|
|
|
if( !addFile ) |
|
|
|
return false; // it is a non-top-level schematic
|
|
|
|
return false; // it is a non-top-level schematic
|
|
|
|
} |
|
|
|
|
|
|
|
for( int i = TREE_PROJECT; i < TREE_MAX; i++ ) |
|
|
@ -644,32 +633,36 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie; |
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie ); |
|
|
|
// also check to see if it is already there.
|
|
|
|
wxTreeItemIdValue cookie; |
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie ); |
|
|
|
|
|
|
|
while( kid.IsOk() ) |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); |
|
|
|
|
|
|
|
if( itemData ) |
|
|
|
{ |
|
|
|
if( itemData->m_FileName == aName ) |
|
|
|
{ |
|
|
|
return true; //well, we would have added it, but it is already here!
|
|
|
|
return true; // well, we would have added it, but it is already here!
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
kid = m_TreeProject->GetNextChild( aRoot, cookie ); |
|
|
|
} |
|
|
|
|
|
|
|
// Append the item (only appending the filename not the full path):
|
|
|
|
wxString file = wxFileNameFromPath( aName ); |
|
|
|
wxString file = wxFileNameFromPath( aName ); |
|
|
|
cellule = m_TreeProject->AppendItem( aRoot, file ); |
|
|
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject ); |
|
|
|
TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject ); |
|
|
|
|
|
|
|
m_TreeProject->SetItemData( cellule, data ); |
|
|
|
data->SetState( 0 ); |
|
|
|
|
|
|
|
/* Mark root files (files which have the same aName as the project) */ |
|
|
|
wxFileName project( m_Parent->m_ProjectFileName ); |
|
|
|
wxFileName currfile( file ); |
|
|
|
wxFileName project( m_Parent->m_ProjectFileName ); |
|
|
|
wxFileName currfile( file ); |
|
|
|
|
|
|
|
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) |
|
|
|
data->m_IsRootFile = true; |
|
|
@ -680,15 +673,16 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
// in this case AddFile is recursive, but for the first level only.
|
|
|
|
if( TREE_DIRECTORY == type && aRecurse ) |
|
|
|
{ |
|
|
|
const wxString sep = wxFileName().GetPathSeparator(); |
|
|
|
wxDir dir( aName ); |
|
|
|
wxString dir_filename; |
|
|
|
const wxString sep = wxFileName().GetPathSeparator(); |
|
|
|
wxDir dir( aName ); |
|
|
|
wxString dir_filename; |
|
|
|
data->m_WasPopulated = true; // set state to populated
|
|
|
|
|
|
|
|
if( dir.GetFirst( &dir_filename ) ) |
|
|
|
{ |
|
|
|
do // Add name in tree, but do not recurse
|
|
|
|
do // Add name in tree, but do not recurse
|
|
|
|
{ |
|
|
|
AddFileToTree( aName + sep + dir_filename, cellule, false ); |
|
|
|
AddItemToTreeProject( aName + sep + dir_filename, cellule, false ); |
|
|
|
} while( dir.GetNext( &dir_filename ) ); |
|
|
|
} |
|
|
|
|
|
|
@ -703,13 +697,11 @@ bool TREE_PROJECT_FRAME::AddFileToTree( const wxString& aName, |
|
|
|
/**
|
|
|
|
* @brief Create or modify the tree showing project file names |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::ReCreateTreePrj() |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
wxTreeItemId rootcellule; |
|
|
|
wxFileName fn; |
|
|
|
bool prjOpened = false; |
|
|
|
wxTreeItemId rootcellule; |
|
|
|
wxFileName fn; |
|
|
|
bool prjOpened = false; |
|
|
|
|
|
|
|
if( !m_TreeProject ) |
|
|
|
m_TreeProject = new TREEPROJECTFILES( this ); |
|
|
@ -737,29 +729,29 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj() |
|
|
|
|
|
|
|
m_TreeProject->SetItemData( rootcellule, |
|
|
|
new TREEPROJECT_ITEM( TREE_PROJECT, |
|
|
|
wxEmptyString, |
|
|
|
m_TreeProject ) ); |
|
|
|
wxEmptyString, |
|
|
|
m_TreeProject ) ); |
|
|
|
|
|
|
|
// Now adding all current files if available
|
|
|
|
if( prjOpened ) |
|
|
|
{ |
|
|
|
wxString filename; |
|
|
|
wxDir dir( wxGetCwd() ); |
|
|
|
bool cont = dir.GetFirst( &filename ); |
|
|
|
wxString filename; |
|
|
|
wxDir dir( wxGetCwd() ); |
|
|
|
bool cont = dir.GetFirst( &filename ); |
|
|
|
|
|
|
|
while( cont ) |
|
|
|
{ |
|
|
|
if( filename != fn.GetFullName() ) |
|
|
|
AddFileToTree( dir.GetName() + wxFileName::GetPathSeparator() + |
|
|
|
filename, m_root ); |
|
|
|
AddItemToTreeProject( dir.GetName() + wxFileName::GetPathSeparator() + |
|
|
|
filename, m_root ); |
|
|
|
|
|
|
|
cont = dir.GetNext( &filename ); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_TreeProject->AppendItem( m_root, wxT("Empty project") ); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) ); |
|
|
|
} |
|
|
|
|
|
|
|
m_TreeProject->Expand( rootcellule ); |
|
|
|
|
|
|
@ -777,10 +769,10 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj() |
|
|
|
void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
int tree_id; |
|
|
|
TREEPROJECT_ITEM* tree_data; |
|
|
|
wxString FullFileName; |
|
|
|
wxTreeItemId curr_item = Event.GetItem(); |
|
|
|
int tree_id; |
|
|
|
TREEPROJECT_ITEM* 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 ); |
|
|
@ -791,6 +783,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) |
|
|
|
|
|
|
|
// Get the current filename:
|
|
|
|
tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
@ -804,9 +797,10 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) |
|
|
|
const_cast<wxMenu*>( tree_data->GetMenu() ) |
|
|
|
}; |
|
|
|
|
|
|
|
for( unsigned int j = 0; j < sizeof(menus) / sizeof(wxMenu*); j++ ) |
|
|
|
for( unsigned int j = 0; j < sizeof(menus) / sizeof(wxMenu*); j++ ) |
|
|
|
{ |
|
|
|
wxMenu* menu = menus[j]; |
|
|
|
|
|
|
|
if( !menu ) |
|
|
|
continue; |
|
|
|
|
|
|
@ -815,8 +809,8 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) |
|
|
|
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->GetItemLabelText(); |
|
|
|
wxMenuItem* src = list[i]; |
|
|
|
wxString label = src->GetItemLabelText(); |
|
|
|
|
|
|
|
// for obscure reasons, the & is translated into _ ... so replace it
|
|
|
|
label.Replace( wxT( "_" ), wxT( "&" ), true ); |
|
|
@ -833,106 +827,73 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) |
|
|
|
PopupMenu( m_PopupMenu ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
/*
|
|
|
|
* Called by the popup menu, when right clicking on a file name |
|
|
|
* Launch the text editor to open the selected file |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnTxtEdit( wxCommandEvent& event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event ) |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
|
wxString FullFileName = tree_data->GetFileName(); |
|
|
|
wxString FullFileName = tree_data->GetFileName(); |
|
|
|
AddDelimiterString( FullFileName ); |
|
|
|
wxString editorname = wxGetApp().GetEditorName(); |
|
|
|
wxString editorname = wxGetApp().GetEditorName(); |
|
|
|
|
|
|
|
if( !editorname.IsEmpty() ) |
|
|
|
ExecuteFile( this, editorname, FullFileName ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
/* Called via the popup menu, when right clicking on a file name
|
|
|
|
* or a directory name to delete the selected file or directory |
|
|
|
* in the tree project |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
|
tree_data->Delete(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
/* Called via the popup menu, when right clicking on a file name
|
|
|
|
* or a directory name to rename the selected file or directory |
|
|
|
* in the tree project |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection(); |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
wxTreeItemId curr_item = m_TreeProject->GetSelection(); |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
|
wxString buffer = m_TreeProject->GetItemText( curr_item ); |
|
|
|
wxString msg = _( "Change filename: " ) + tree_data->m_FileName; |
|
|
|
wxString buffer = m_TreeProject->GetItemText( curr_item ); |
|
|
|
wxString msg = _( "Change filename: " ) + tree_data->m_FileName; |
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer ); |
|
|
|
|
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer ); |
|
|
|
if( dlg.ShowModal() != wxID_OK ) |
|
|
|
return; // cancelled by user
|
|
|
|
|
|
|
|
buffer = dlg.GetValue( ); |
|
|
|
buffer = dlg.GetValue(); |
|
|
|
buffer.Trim( true ); |
|
|
|
buffer.Trim( false ); |
|
|
|
|
|
|
|
if( buffer.IsEmpty() ) |
|
|
|
return; // empty file name not allowed
|
|
|
|
return; // empty file name not allowed
|
|
|
|
|
|
|
|
if( tree_data->Rename( buffer, true ) ) |
|
|
|
m_TreeProject->SetItemText( curr_item, buffer ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Prevent the main project to be renamed |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnRenameAsk( wxTreeEvent& event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
if( m_Parent->m_ProjectFileName.GetFullPath() == tree_data->GetFileName() ) |
|
|
|
event.Veto(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Rename a tree item on demand of the context menu |
|
|
|
*/ |
|
|
|
/*****************************************************************************/ |
|
|
|
void TREE_PROJECT_FRAME::OnRename( wxTreeEvent& event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
|
tree_data->OnRename( event ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief TODO |
|
|
|
*/ |
|
|
@ -940,15 +901,17 @@ void TREE_PROJECT_FRAME::OnRename( wxTreeEvent& event ) |
|
|
|
void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
wxString FullFileName; |
|
|
|
wxString FullFileName; |
|
|
|
|
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
TREEPROJECT_ITEM* tree_data = GetSelectedData(); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
|
|
|
|
|
tree_data->Activate( this ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Called when expanding an item of the tree |
|
|
|
* populate tree items corresponding to subdirectories not already populated |
|
|
@ -957,10 +920,10 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) |
|
|
|
void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) |
|
|
|
/*****************************************************************************/ |
|
|
|
{ |
|
|
|
wxString FullFileName; |
|
|
|
wxString FullFileName; |
|
|
|
|
|
|
|
wxTreeItemId itemId = Event.GetItem(); |
|
|
|
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId ); |
|
|
|
wxTreeItemId itemId = Event.GetItem(); |
|
|
|
TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId ); |
|
|
|
|
|
|
|
if( !tree_data ) |
|
|
|
return; |
|
|
@ -968,28 +931,33 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) |
|
|
|
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 ); |
|
|
|
// 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 ) |
|
|
|
|
|
|
|
if( itemData->m_WasPopulated ) |
|
|
|
continue; |
|
|
|
|
|
|
|
wxString fileName = itemData->GetFileName(); |
|
|
|
const wxString sep = wxFileName().GetPathSeparator(); |
|
|
|
wxDir dir( fileName ); |
|
|
|
wxString dir_filename; |
|
|
|
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:
|
|
|
|
do // Add name to tree item, but do not recurse in subdirs:
|
|
|
|
{ |
|
|
|
AddFileToTree( fileName + sep + dir_filename, kid, false ); |
|
|
|
AddItemToTreeProject( fileName + sep + dir_filename, kid, false ); |
|
|
|
} while( dir.GetNext( &dir_filename ) ); |
|
|
|
} |
|
|
|
|
|
|
|
itemData->m_WasPopulated = true; // set state to populated
|
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */ |
|
|
@ -997,6 +965,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSelectedData |
|
|
|
* return the item data from item currently selected (highlighted) |
|
|
@ -1005,18 +974,183 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) |
|
|
|
*/ |
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData() |
|
|
|
{ |
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( m_TreeProject->GetSelection() ) ); |
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData |
|
|
|
( m_TreeProject->GetSelection() ) ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetItemIdData |
|
|
|
* 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) |
|
|
|
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId ) |
|
|
|
{ |
|
|
|
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) ); |
|
|
|
} |
|
|
|
|
|
|
|
/* Search for the item in tree project which is the
|
|
|
|
* node of the subdirectory aSubDir |
|
|
|
* param aSubDir = the directory to find in tree |
|
|
|
* return the opaque reference to the tree item. |
|
|
|
* if not found, return an invalid tree item. |
|
|
|
* therefore wxTreeItemId::IsOk should be used to test |
|
|
|
* the returned value |
|
|
|
*/ |
|
|
|
wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir ) |
|
|
|
{ |
|
|
|
// If the subdir is the current working directory, return m_root
|
|
|
|
// in main list:
|
|
|
|
if( wxGetCwd() == aSubDir ) |
|
|
|
return m_root; |
|
|
|
|
|
|
|
// The subdir is in the main tree or in a subdir: Locate it
|
|
|
|
wxTreeItemIdValue cookie; |
|
|
|
wxTreeItemId root_id = m_root; |
|
|
|
std::stack < wxTreeItemId > subdirs_id; |
|
|
|
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie ); |
|
|
|
while( 1 ) |
|
|
|
{ |
|
|
|
if( ! kid.IsOk() ) |
|
|
|
{ |
|
|
|
if( subdirs_id.empty() ) // all items were explored
|
|
|
|
{ |
|
|
|
root_id = kid; // Not found: return an invalid wxTreeItemId
|
|
|
|
break; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
root_id = subdirs_id.top(); |
|
|
|
subdirs_id.pop(); |
|
|
|
kid = m_TreeProject->GetFirstChild( root_id, cookie ); |
|
|
|
if( ! kid.IsOk() ) |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); |
|
|
|
|
|
|
|
if( itemData ) |
|
|
|
{ |
|
|
|
if( itemData->GetType() != TREE_DIRECTORY ) |
|
|
|
continue; |
|
|
|
|
|
|
|
if( itemData->m_FileName == aSubDir ) // Found!
|
|
|
|
{ |
|
|
|
root_id = kid; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// if kid is a subdir, push in list to explore it later
|
|
|
|
if( itemData->GetType() == TREE_DIRECTORY && |
|
|
|
itemData->m_WasPopulated ) |
|
|
|
subdirs_id.push( kid ); |
|
|
|
} |
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie ); |
|
|
|
} |
|
|
|
|
|
|
|
return root_id; |
|
|
|
} |
|
|
|
|
|
|
|
#if wxCHECK_VERSION( 2, 9, 2 )
|
|
|
|
/* called when a file or directory is modified/created/deleted
|
|
|
|
* The tree project should be rebuilt when a file or directory |
|
|
|
* is created or deleted |
|
|
|
*/ |
|
|
|
void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event ) |
|
|
|
{ |
|
|
|
|
|
|
|
switch( event.GetChangeType() ) |
|
|
|
{ |
|
|
|
case wxFSW_EVENT_DELETE: |
|
|
|
break; |
|
|
|
|
|
|
|
case wxFSW_EVENT_CREATE: |
|
|
|
break; |
|
|
|
|
|
|
|
case wxFSW_EVENT_RENAME: |
|
|
|
break; |
|
|
|
|
|
|
|
case wxFSW_EVENT_MODIFY: |
|
|
|
case wxFSW_EVENT_ACCESS: |
|
|
|
default: |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
wxFileName pathModified = event.GetPath(); |
|
|
|
wxString subdir = pathModified.GetPath(); |
|
|
|
wxString fn = pathModified.GetFullPath(); |
|
|
|
|
|
|
|
wxTreeItemId root_id = findSubdirTreeItem( subdir ); |
|
|
|
if( !root_id.IsOk() ) |
|
|
|
return; |
|
|
|
|
|
|
|
// Add item if it is created
|
|
|
|
if( event.GetChangeType() == wxFSW_EVENT_CREATE ) |
|
|
|
AddItemToTreeProject( pathModified.GetFullPath(), root_id, false ); |
|
|
|
|
|
|
|
// search for item to delete/rename.
|
|
|
|
if( event.GetChangeType() == wxFSW_EVENT_DELETE || |
|
|
|
event.GetChangeType() == wxFSW_EVENT_RENAME ) |
|
|
|
{ |
|
|
|
wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
|
|
|
|
wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie ); |
|
|
|
|
|
|
|
while( kid.IsOk() ) |
|
|
|
{ |
|
|
|
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); |
|
|
|
|
|
|
|
if( itemData ) |
|
|
|
{ |
|
|
|
if( itemData->m_FileName == fn ) |
|
|
|
{ |
|
|
|
if( event.GetChangeType() == wxFSW_EVENT_DELETE ) |
|
|
|
{ |
|
|
|
m_TreeProject->Delete( kid ); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
wxFileName newpath = event.GetNewPath(); |
|
|
|
wxString newfn = newpath.GetFullPath(); |
|
|
|
// Change item label and item data
|
|
|
|
// Extension could be modified and be not an usually selected file type
|
|
|
|
// However, here we do not filter files.
|
|
|
|
// This is simple, and I am not sure filtering renamed files here is better,
|
|
|
|
// becuse they could disappear, like deleted files
|
|
|
|
itemData->SetFileName( newpath.GetFullPath() ); |
|
|
|
m_TreeProject->SetItemText( kid, newpath.GetFullName() ); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
kid = m_TreeProject->GetNextChild( root_id, cookie ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* Sort filenames by alphabetic order */ |
|
|
|
m_TreeProject->SortChildren( root_id ); |
|
|
|
} |
|
|
|
|
|
|
|
void TREE_PROJECT_FRAME::FileWatcherReset() |
|
|
|
{ |
|
|
|
// Prepare file watcher:
|
|
|
|
delete m_watcher; |
|
|
|
m_watcher = new wxFileSystemWatcher(); |
|
|
|
m_watcher->SetOwner( this ); |
|
|
|
|
|
|
|
// Add directories which should be monitored.
|
|
|
|
// under windows, we add the curr dir and subdirs
|
|
|
|
// under unix, we add only the curr dir
|
|
|
|
// see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
|
|
|
|
// under unix, the file watcher needs more work to be efficient
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
m_watcher->AddTree( wxFileName::DirName( wxT( "./" ) ) ); |
|
|
|
#else
|
|
|
|
m_watcher->Add( wxFileName::DirName( wxT( "./" ) ) ); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
#endif
|