KiCad PCB EDA Suite
TREE_PROJECT_FRAME Class Reference

class TREE_PROJECT_FRAME Window to display the tree files More...

#include <tree_project_frame.h>

Inheritance diagram for TREE_PROJECT_FRAME:

Public Member Functions

 TREE_PROJECT_FRAME (KICAD_MANAGER_FRAME *parent)
 class TREE_PROJECT_FRAME is the frame that shows the tree list of files and subdirs inside the working directory. More...
 
 ~TREE_PROJECT_FRAME ()
 
void ReCreateTreePrj ()
 Create or modify the tree showing project file names. More...
 
void FileWatcherReset ()
 Reinit the watched paths Should be called after opening a new project to rebuild the list of watched paths. More...
 

Public Attributes

KICAD_MANAGER_FRAMEm_Parent
 
TREEPROJECTFILESm_TreeProject
 

Protected Member Functions

TREEPROJECT_ITEMGetSelectedData ()
 Function GetSelectedData 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. More...
 
TREEPROJECT_ITEMGetItemIdData (wxTreeItemId aId)
 Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier. More...
 

Static Protected Member Functions

static wxString GetFileExt (TreeFileType type)
 

Private Member Functions

void OnSelect (wxTreeEvent &Event)
 Called on a double click on an item. More...
 
void OnExpand (wxTreeEvent &Event)
 Called on a click on the + or - button of an item with children. More...
 
void OnRight (wxTreeEvent &Event)
 Called on a right click on an item. More...
 
void OnOpenSelectedFileWithTextEditor (wxCommandEvent &event)
 Function OnOpenSelectedFileWithTextEditor Call the text editor to open the selected file in the tree project. More...
 
void OnDeleteFile (wxCommandEvent &event)
 Function OnDeleteFile Delete the selected file or directory in the tree project. More...
 
void OnPrintFile (wxCommandEvent &event)
 Function OnDeleteFile Print the selected file or directory in the tree project. More...
 
void OnRenameFile (wxCommandEvent &event)
 Function OnRenameFile Rename the selected file or directory in the tree project. More...
 
void OnOpenDirectory (wxCommandEvent &event)
 Function OnOpenDirectory Handles the right-click menu for opening a directory in the current system file browser. More...
 
void OnCreateNewDirectory (wxCommandEvent &event)
 Function OnCreateNewDirectory Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a directory name. More...
 
void OnSwitchToSelectedProject (wxCommandEvent &event)
 Switch to a other project selected from the tree project (by selecting an other .pro file inside the current project folder) More...
 
wxTreeItemId AddItemToTreeProject (const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
 Function AddItemToTreeProject. More...
 
wxTreeItemId findSubdirTreeItem (const wxString &aSubDir)
 Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirectory aSubDir. More...
 
void OnFileSystemEvent (wxFileSystemWatcherEvent &event)
 called when a file or directory is modified/created/deleted The tree project is modified when a file or directory is created/deleted/renamed to reflect the file change More...
 

Private Attributes

bool m_isRenaming
 
wxTreeItemId m_root
 
std::vector< wxString > m_filters
 
wxFileSystemWatcher * m_watcher
 

Friends

class TREEPROJECT_ITEM
 

Detailed Description

class TREE_PROJECT_FRAME Window to display the tree files

Definition at line 47 of file tree_project_frame.h.

Constructor & Destructor Documentation

◆ TREE_PROJECT_FRAME()

TREE_PROJECT_FRAME::TREE_PROJECT_FRAME ( KICAD_MANAGER_FRAME parent)

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.

Definition at line 133 of file tree_project_frame.cpp.

133  :
134  wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize,
135  wxNO_BORDER | wxTAB_TRAVERSAL )
136 {
137  m_Parent = parent;
138  m_TreeProject = NULL;
139  m_isRenaming = false;
140 
141  m_watcher = NULL;
142  Connect( wxEVT_FSWATCHER,
143  wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
144 
145  /*
146  * Filtering is now inverted: the filters are actually used to _enable_ support
147  * for a given file type.
148  */
149 
150  // NOTE: sch filter must be first because of a test in AddFile() below
151  m_filters.emplace_back( wxT( "^.*\\.sch$" ) );
152 
153  for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
154  m_filters.emplace_back( s_allowedExtensionsToList[ii] );
155 
156  m_filters.emplace_back( wxT( "^no KiCad files found" ) );
157 
158  ReCreateTreePrj();
159 }
TREEPROJECTFILES * m_TreeProject
void OnFileSystemEvent(wxFileSystemWatcherEvent &event)
called when a file or directory is modified/created/deleted The tree project is modified when a file ...
KICAD_MANAGER_FRAME * m_Parent
void ReCreateTreePrj()
Create or modify the tree showing project file names.
wxFileSystemWatcher * m_watcher
std::vector< wxString > m_filters
static const wxChar * s_allowedExtensionsToList[]

References OnFileSystemEvent(), and s_allowedExtensionsToList.

◆ ~TREE_PROJECT_FRAME()

TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME ( )

Definition at line 162 of file tree_project_frame.cpp.

163 {
164  if( m_watcher )
165  {
166  m_watcher->RemoveAll();
167  m_watcher->SetOwner( NULL );
168  delete m_watcher;
169  }
170 }
wxFileSystemWatcher * m_watcher

References m_watcher.

Member Function Documentation

◆ AddItemToTreeProject()

wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject ( const wxString &  aName,
wxTreeItemId &  aRoot,
bool  aRecurse = true 
)
private

Function AddItemToTreeProject.

Add the file or directory aName to the project tree

Parameters
aName= the filename or the directory name to add in tree
aRoot= the wxTreeItemId item where to add sub tree items
aRecurse= true to add file or subdir names to the current tree item false to stop file add.
Returns
the Id for the new tree item

Definition at line 293 of file tree_project_frame.cpp.

295 {
296  wxTreeItemId newItemId;
297  TreeFileType type = TREE_UNKNOWN;
298  wxFileName fn( aName );
299 
300  // Files/dirs names starting by "." are not visible files under unices.
301  // Skip them also under Windows
302  if( fn.GetName().StartsWith( wxT( "." ) ) )
303  return newItemId;
304 
305  if( wxDirExists( aName ) )
306  {
307  type = TREE_DIRECTORY;
308  }
309  else
310  {
311  // Filter
312  wxRegEx reg;
313 
314  bool isSchematic = false;
315  bool addFile = false;
316 
317  for( unsigned i = 0; i < m_filters.size(); i++ )
318  {
319  wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
320  wxString::Format( "Regex %s failed to compile.", m_filters[i] ) );
321 
322  if( reg.Matches( aName ) )
323  {
324  addFile = true;
325 
326  if( i == 0 )
327  isSchematic = true;
328 
329  break;
330  }
331  }
332 
333  if( !addFile )
334  return newItemId;
335 
336  // only show the schematic if it is a top level schematic. Eeschema
337  // cannot open a schematic and display it properly unless it starts
338  // at the top of the hierarchy. The schematic is top level only if
339  // there is a line in the header saying:
340  // "Sheet 1 "
341  // However if the file has the same name as the project, it is always
342  // shown, because it is expected the root sheet.
343  // (and to fix an issue (under XP but could exist under other OS),
344  // when a .sch file is created, the file
345  // create is sent to the wxFileSystemWatcher, but the file still has 0 byte
346  // so it cannot detected as root sheet
347  // This is an ugly fix.
348  if( isSchematic )
349  {
350  wxString fullFileName = aName.BeforeLast( '.' );
351  wxString rootName;
352  TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
353 
354  if( itemData )
355  rootName = itemData->GetFileName().BeforeLast( '.' );
356 
357  if( fullFileName != rootName )
358  {
359  char line[128]; // small because we just need a few bytes from the start of a line
360  FILE* fp;
361 
362  fullFileName = aName;
363  fp = wxFopen( fullFileName, wxT( "rt" ) );
364 
365  if( fp == NULL )
366  return newItemId;
367 
368  addFile = false;
369 
370  // check the first 100 lines for the "Sheet 1" string
371  for( int i = 0; i<100; ++i )
372  {
373  if( !fgets( line, sizeof(line), fp ) )
374  break;
375 
376  if( !strncmp( line, "Sheet 1 ", 8 ) )
377  {
378  addFile = true;
379  break;
380  }
381  }
382 
383  fclose( fp );
384 
385  if( !addFile )
386  return newItemId; // it is a non-top-level schematic
387  }
388  }
389 
390  for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
391  {
392  wxString ext = GetFileExt( (TreeFileType) i );
393 
394  if( ext == wxT( "" ) )
395  continue;
396 
397  reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
398  wxString::FromAscii( "$" ), wxRE_ICASE );
399 
400  if( reg.Matches( aName ) )
401  {
402  type = (TreeFileType) i;
403  break;
404  }
405  }
406  }
407 
408  // also check to see if it is already there.
409  wxTreeItemIdValue cookie;
410  wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
411 
412  while( kid.IsOk() )
413  {
414  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
415 
416  if( itemData )
417  {
418  if( itemData->GetFileName() == aName )
419  return itemData->GetId(); // well, we would have added it, but it is already here!
420  }
421 
422  kid = m_TreeProject->GetNextChild( aRoot, cookie );
423  }
424 
425  // Append the item (only appending the filename not the full path):
426  wxString file = wxFileNameFromPath( aName );
427  newItemId = m_TreeProject->AppendItem( aRoot, file );
428  TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
429 
430  m_TreeProject->SetItemData( newItemId, data );
431  data->SetState( 0 );
432 
433  // Mark root files (files which have the same aName as the project)
434  wxFileName project( m_Parent->GetProjectFileName() );
435  wxFileName currfile( file );
436 
437  if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
438  data->SetRootFile( true );
439  else
440  data->SetRootFile( false );
441 
442  // This section adds dirs and files found in the subdirs
443  // in this case AddFile is recursive, but for the first level only.
444  if( TREE_DIRECTORY == type && aRecurse )
445  {
446  wxDir dir( aName );
447 
448  if( dir.IsOpened() ) // protected dirs will not open properly.
449  {
450  wxString dir_filename;
451 
452  data->SetPopulated( true );
453 
454  if( dir.GetFirst( &dir_filename ) )
455  {
456  do // Add name in tree, but do not recurse
457  {
458  wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
459  AddItemToTreeProject( path, newItemId, false );
460  } while( dir.GetNext( &dir_filename ) );
461  }
462  }
463 
464  // Sort filenames by alphabetic order
465  m_TreeProject->SortChildren( newItemId );
466  }
467 
468  return newItemId;
469 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
void SetRootFile(bool aValue)
TREEPROJECTFILES * m_TreeProject
TreeFileType
friend class TREEPROJECT_ITEM
KICAD_MANAGER_FRAME * m_Parent
const wxString GetProjectFileName()
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetState(int state)
size_t i
Definition: json11.cpp:649
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
Function AddItemToTreeProject.
const wxString & GetFileName() const
std::vector< wxString > m_filters
static wxString GetFileExt(TreeFileType type)
void SetPopulated(bool aValue)

References Format(), GetFileExt(), TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), i, m_filters, m_Parent, m_root, m_TreeProject, TREEPROJECT_ITEM::SetPopulated(), TREEPROJECT_ITEM::SetRootFile(), TREEPROJECT_ITEM::SetState(), TREE_DIRECTORY, TREE_MAX, TREE_PROJECT, TREE_UNKNOWN, and TREEPROJECT_ITEM.

Referenced by OnExpand(), OnFileSystemEvent(), and ReCreateTreePrj().

◆ FileWatcherReset()

void TREE_PROJECT_FRAME::FileWatcherReset ( )

Reinit the watched paths Should be called after opening a new project to rebuild the list of watched paths.

Should be called atfer the main loop event handler is started

Definition at line 942 of file tree_project_frame.cpp.

943 {
944  // Prepare file watcher:
945  if( m_watcher )
946  {
947  m_watcher->RemoveAll();
948  }
949  else
950  {
951  m_watcher = new wxFileSystemWatcher();
952  m_watcher->SetOwner( this );
953  }
954 
955  // We can see wxString under a debugger, not a wxFileName
956  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
957  wxFileName fn;
958  fn.AssignDir( prj_dir );
959  fn.DontFollowLink();
960 
961  // Add directories which should be monitored.
962  // under windows, we add the curr dir and all subdirs
963  // under unix, we add only the curr dir and the populated subdirs
964  // see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
965  // under unix, the file watcher needs more work to be efficient
966  // moreover, under wxWidgets 2.9.4, AddTree does not work properly.
967 #ifdef __WINDOWS__
968  m_watcher->AddTree( fn );
969 #else
970  m_watcher->Add( fn );
971 
972  // Add subdirs
973  wxTreeItemIdValue cookie;
974  wxTreeItemId root_id = m_root;
975 
976  std::stack < wxTreeItemId > subdirs_id;
977 
978  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
979 
980  while( true )
981  {
982  if( !kid.IsOk() )
983  {
984  if( subdirs_id.empty() ) // all items were explored
985  break;
986  else
987  {
988  root_id = subdirs_id.top();
989  subdirs_id.pop();
990  kid = m_TreeProject->GetFirstChild( root_id, cookie );
991 
992  if( !kid.IsOk() )
993  continue;
994  }
995  }
996 
997  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
998 
999  if( itemData && itemData->GetType() == TREE_DIRECTORY )
1000  {
1001  // we can see wxString under a debugger, not a wxFileName
1002  const wxString& path = itemData->GetFileName();
1003 
1004  wxLogTrace( tracePathsAndFiles, "%s: add '%s'\n", __func__, TO_UTF8( path ) );
1005 
1006  if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
1007  {
1008  fn.AssignDir( path );
1009  m_watcher->Add( fn );
1010 
1011  // if kid is a subdir, push in list to explore it later
1012  if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
1013  subdirs_id.push( kid );
1014  }
1015  }
1016 
1017  kid = m_TreeProject->GetNextChild( root_id, cookie );
1018  }
1019 #endif
1020 
1021 #if defined(DEBUG) && 1
1022  wxArrayString paths;
1023  m_watcher->GetWatchedPaths( &paths );
1024  wxLogTrace( tracePathsAndFiles, "%s: watched paths:", __func__ );
1025 
1026  for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
1027  wxLogTrace( tracePathsAndFiles, " %s\n", TO_UTF8( paths[ii] ) );
1028 #endif
1029 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
bool IsPopulated() const
KICAD_MANAGER_FRAME * m_Parent
const wxString GetProjectFileName()
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
wxFileSystemWatcher * m_watcher
const wxString & GetFileName() const

References TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), TREEPROJECT_ITEM::GetType(), TREEPROJECT_ITEM::IsPopulated(), m_Parent, m_root, m_TreeProject, m_watcher, TO_UTF8, tracePathsAndFiles, and TREE_DIRECTORY.

Referenced by KICAD_MANAGER_FRAME::OnChangeWatchedPaths(), and OnExpand().

◆ findSubdirTreeItem()

wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem ( const wxString &  aSubDir)
private

Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirectory aSubDir.

Parameters
aSubDir= the directory to find in tree
Returns
the opaque reference to the tree item; if not found, return an invalid tree item so that wxTreeItemId::IsOk() can be used to test the returned value

Definition at line 790 of file tree_project_frame.cpp.

791 {
792  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
793 
794  // If the subdir is the current working directory, return m_root
795  // in main list:
796  if( prj_dir == aSubDir )
797  return m_root;
798 
799  // The subdir is in the main tree or in a subdir: Locate it
800  wxTreeItemIdValue cookie;
801  wxTreeItemId root_id = m_root;
802  std::stack < wxTreeItemId > subdirs_id;
803 
804  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
805 
806  while( true )
807  {
808  if( ! kid.IsOk() )
809  {
810  if( subdirs_id.empty() ) // all items were explored
811  {
812  root_id = kid; // Not found: return an invalid wxTreeItemId
813  break;
814  }
815  else
816  {
817  root_id = subdirs_id.top();
818  subdirs_id.pop();
819  kid = m_TreeProject->GetFirstChild( root_id, cookie );
820 
821  if( !kid.IsOk() )
822  continue;
823  }
824  }
825 
826  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
827 
828  if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
829  {
830  if( itemData->GetFileName() == aSubDir ) // Found!
831  {
832  root_id = kid;
833  break;
834  }
835 
836  // kid is a subdir, push in list to explore it later
837  if( itemData->IsPopulated() )
838  subdirs_id.push( kid );
839  }
840 
841  kid = m_TreeProject->GetNextChild( root_id, cookie );
842  }
843 
844  return root_id;
845 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
bool IsPopulated() const
KICAD_MANAGER_FRAME * m_Parent
const wxString GetProjectFileName()
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
const wxString & GetFileName() const

References TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), TREEPROJECT_ITEM::GetType(), TREEPROJECT_ITEM::IsPopulated(), m_Parent, m_root, m_TreeProject, and TREE_DIRECTORY.

Referenced by OnFileSystemEvent().

◆ GetFileExt()

wxString TREE_PROJECT_FRAME::GetFileExt ( TreeFileType  type)
staticprotected

Definition at line 265 of file tree_project_frame.cpp.

266 {
267  switch( type )
268  {
269  case TREE_PROJECT: return ProjectFileExtension;
270  case TREE_SCHEMA: return SchematicFileExtension;
274  case TREE_HTML: return HtmlFileExtension;
275  case TREE_PDF: return PdfFileExtension;
276  case TREE_TXT: return TextFileExtension;
277  case TREE_NET: return NetlistFileExtension;
279  case TREE_REPORT: return ReportFileExtension;
281  case TREE_DRILL: return DrillFileExtension;
282  case TREE_DRILL_NC: return "nc";
283  case TREE_DRILL_XNC: return "xnc";
284  case TREE_SVG: return SVGFileExtension;
288  default: return wxEmptyString;
289  }
290 }
const std::string NetlistFileExtension
const std::string KiCadFootprintFileExtension
const std::string ProjectFileExtension
const std::string LegacyPcbFileExtension
const std::string ComponentFileExtension
const std::string KiCadPcbFileExtension
const wxChar TextFileExtension[]
const std::string HtmlFileExtension
const wxString GerberFileExtensionWildCard(".((gbr|gbrjob|(gb|gt)[alops])|pho)")
const std::string SchematicLibraryFileExtension
const std::string SchematicFileExtension
const std::string PdfFileExtension
const std::string PageLayoutDescrFileExtension
const std::string ReportFileExtension
const std::string SVGFileExtension
const std::string FootprintPlaceFileExtension
const std::string DrillFileExtension

References ComponentFileExtension, DrillFileExtension, FootprintPlaceFileExtension, GerberFileExtensionWildCard(), HtmlFileExtension, KiCadFootprintFileExtension, KiCadPcbFileExtension, LegacyPcbFileExtension, NetlistFileExtension, PageLayoutDescrFileExtension, PdfFileExtension, ProjectFileExtension, ReportFileExtension, SchematicFileExtension, SchematicLibraryFileExtension, SVGFileExtension, TextFileExtension, TREE_CMP_LINK, TREE_DRILL, TREE_DRILL_NC, TREE_DRILL_XNC, TREE_FOOTPRINT_FILE, TREE_FP_PLACE, TREE_GERBER, TREE_HTML, TREE_LEGACY_PCB, TREE_NET, TREE_PAGE_LAYOUT_DESCR, TREE_PDF, TREE_PROJECT, TREE_REPORT, TREE_SCHEMA, TREE_SCHEMATIC_LIBFILE, TREE_SEXP_PCB, TREE_SVG, and TREE_TXT.

Referenced by AddItemToTreeProject(), and TREEPROJECT_ITEM::Rename().

◆ GetItemIdData()

TREEPROJECT_ITEM * TREE_PROJECT_FRAME::GetItemIdData ( wxTreeItemId  aId)
protected

Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.

Parameters
aId= the wxTreeItemId identifier.
Returns
a TREEPROJECT_ITEM pointer correspondinfg to item id aId

Definition at line 784 of file tree_project_frame.cpp.

785 {
786  return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
787 }
TREEPROJECTFILES * m_TreeProject

References m_TreeProject.

Referenced by AddItemToTreeProject(), FileWatcherReset(), findSubdirTreeItem(), GetSelectedData(), OnExpand(), and OnFileSystemEvent().

◆ GetSelectedData()

TREEPROJECT_ITEM * TREE_PROJECT_FRAME::GetSelectedData ( )
protected

Function GetSelectedData 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.

Definition at line 778 of file tree_project_frame.cpp.

779 {
780  return GetItemIdData( m_TreeProject->GetSelection() );
781 }
TREEPROJECTFILES * m_TreeProject
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.

References GetItemIdData(), and m_TreeProject.

Referenced by OnCreateNewDirectory(), OnDeleteFile(), OnOpenDirectory(), OnOpenSelectedFileWithTextEditor(), OnPrintFile(), OnRenameFile(), OnRight(), OnSelect(), and OnSwitchToSelectedProject().

◆ OnCreateNewDirectory()

void TREE_PROJECT_FRAME::OnCreateNewDirectory ( wxCommandEvent &  event)
private

Function OnCreateNewDirectory Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a directory name.

Definition at line 226 of file tree_project_frame.cpp.

227 {
228  // Get the root directory name:
229  TREEPROJECT_ITEM* treeData = GetSelectedData();
230 
231  if( !treeData )
232  return;
233 
234  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
235 
236  // Ask for the new sub directory name
237  wxString curr_dir = treeData->GetDir();
238 
239  if( !curr_dir.IsEmpty() ) // A subdir is selected
240  {
241  // Make this subdir name relative to the current path.
242  // It will be more easy to read by the user, in the next dialog
243  wxFileName fn;
244  fn.AssignDir( curr_dir );
245  fn.MakeRelativeTo( prj_dir );
246  curr_dir = fn.GetPath();
247 
248  if( !curr_dir.IsEmpty() )
249  curr_dir += wxFileName::GetPathSeparator();
250  }
251 
252  wxString msg = wxString::Format( _( "Current project directory:\n%s" ), GetChars( prj_dir ) );
253  wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
254 
255  if( subdir.IsEmpty() )
256  return;
257 
258  wxString full_dirname = prj_dir + wxFileName::GetPathSeparator() + subdir;
259 
260  // Make the new item and let the file watcher add it to the tree
261  wxMkdir( full_dirname );
262 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetDir() const
KICAD_MANAGER_FRAME * m_Parent
#define _(s)
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
const wxString GetProjectFileName()
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References _, Format(), GetChars(), TREEPROJECT_ITEM::GetDir(), KICAD_MANAGER_FRAME::GetProjectFileName(), GetSelectedData(), and m_Parent.

◆ OnDeleteFile()

void TREE_PROJECT_FRAME::OnDeleteFile ( wxCommandEvent &  event)
private

Function OnDeleteFile Delete the selected file or directory in the tree project.

Definition at line 660 of file tree_project_frame.cpp.

661 {
662  TREEPROJECT_ITEM* tree_data = GetSelectedData();
663 
664  if( tree_data )
665  tree_data->Delete();
666 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...

References TREEPROJECT_ITEM::Delete(), and GetSelectedData().

◆ OnExpand()

void TREE_PROJECT_FRAME::OnExpand ( wxTreeEvent &  Event)
private

Called on a click on the + or - button of an item with children.

Definition at line 716 of file tree_project_frame.cpp.

717 {
718  wxTreeItemId itemId = Event.GetItem();
719  TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );
720 
721  if( !tree_data )
722  return;
723 
724  if( tree_data->GetType() != TREE_DIRECTORY )
725  return;
726 
727  // explore list of non populated subdirs, and populate them
728  wxTreeItemIdValue cookie;
729  wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
730 
731 #ifndef __WINDOWS__
732  bool subdir_populated = false;
733 #endif
734 
735  for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
736  {
737  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
738 
739  if( !itemData || itemData->GetType() != TREE_DIRECTORY )
740  continue;
741 
742  if( itemData->IsPopulated() )
743  continue;
744 
745  wxString fileName = itemData->GetFileName();
746  wxDir dir( fileName );
747 
748  if( dir.IsOpened() )
749  {
750  wxString dir_filename;
751 
752  if( dir.GetFirst( &dir_filename ) )
753  {
754  do // Add name to tree item, but do not recurse in subdirs:
755  {
756  wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
757  AddItemToTreeProject( name, kid, false );
758  } while( dir.GetNext( &dir_filename ) );
759  }
760 
761  itemData->SetPopulated( true ); // set state to populated
762 #ifndef __WINDOWS__
763  subdir_populated = true;
764 #endif
765  }
766 
767  // Sort filenames by alphabetic order
768  m_TreeProject->SortChildren( kid );
769  }
770 
771 #ifndef __WINDOWS__
772  if( subdir_populated )
774 #endif
775 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
bool IsPopulated() const
void FileWatcherReset()
Reinit the watched paths Should be called after opening a new project to rebuild the list of watched ...
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
const char * name
Definition: DXF_plotter.cpp:61
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
Function AddItemToTreeProject.
const wxString & GetFileName() const
void SetPopulated(bool aValue)

References AddItemToTreeProject(), FileWatcherReset(), TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), TREEPROJECT_ITEM::GetType(), TREEPROJECT_ITEM::IsPopulated(), m_TreeProject, name, TREEPROJECT_ITEM::SetPopulated(), and TREE_DIRECTORY.

◆ OnFileSystemEvent()

void TREE_PROJECT_FRAME::OnFileSystemEvent ( wxFileSystemWatcherEvent &  event)
private

called when a file or directory is modified/created/deleted The tree project is modified when a file or directory is created/deleted/renamed to reflect the file change

Definition at line 848 of file tree_project_frame.cpp.

849 {
850  const wxFileName& pathModified = event.GetPath();
851  wxString subdir = pathModified.GetPath();
852  wxString fn = pathModified.GetFullPath();
853 
854  switch( event.GetChangeType() )
855  {
856  case wxFSW_EVENT_DELETE:
857  case wxFSW_EVENT_CREATE:
858  case wxFSW_EVENT_RENAME:
859  break;
860 
861  case wxFSW_EVENT_MODIFY:
862  case wxFSW_EVENT_ACCESS:
863  default:
864  return;
865  }
866 
867  wxTreeItemId root_id = findSubdirTreeItem( subdir );
868 
869  if( !root_id.IsOk() )
870  return;
871 
872  wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
873  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
874 
875  switch( event.GetChangeType() )
876  {
877  case wxFSW_EVENT_CREATE:
878  {
879  wxTreeItemId newitem = AddItemToTreeProject( pathModified.GetFullPath(), root_id, false );
880 
881  // If we are in the process of renaming a file, select the new one
882  // This is needed for MSW and OSX, since we don't get RENAME events from them, just a
883  // pair of DELETE and CREATE events.
884  if( m_isRenaming && newitem.IsOk() )
885  {
886  m_TreeProject->SelectItem( newitem );
887  m_isRenaming = false;
888  }
889  }
890  break;
891 
892  case wxFSW_EVENT_DELETE:
893  while( kid.IsOk() )
894  {
895  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
896 
897  if( itemData && itemData->GetFileName() == fn )
898  {
899  m_TreeProject->Delete( kid );
900  return;
901  }
902  kid = m_TreeProject->GetNextChild( root_id, cookie );
903  }
904  break;
905 
906  case wxFSW_EVENT_RENAME :
907  {
908  const wxFileName& newpath = event.GetNewPath();
909  wxString newdir = newpath.GetPath();
910  wxString newfn = newpath.GetFullPath();
911 
912  while( kid.IsOk() )
913  {
914  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
915 
916  if( itemData && itemData->GetFileName() == fn )
917  {
918  m_TreeProject->Delete( kid );
919  break;
920  }
921 
922  kid = m_TreeProject->GetNextChild( root_id, cookie );
923  }
924 
925  wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
926  wxTreeItemId newitem = AddItemToTreeProject( newfn, newroot_id, false );
927 
928  // If the item exists, select it
929  if( newitem.IsOk() )
930  m_TreeProject->SelectItem( newitem );
931 
932  m_isRenaming = false;
933  }
934  break;
935  }
936 
937  // Sort filenames by alphabetic order
938  m_TreeProject->SortChildren( root_id );
939 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TREEPROJECTFILES * m_TreeProject
wxTreeItemId findSubdirTreeItem(const wxString &aSubDir)
Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirecto...
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
Function AddItemToTreeProject.
const wxString & GetFileName() const

References AddItemToTreeProject(), findSubdirTreeItem(), TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), m_isRenaming, and m_TreeProject.

Referenced by TREE_PROJECT_FRAME().

◆ OnOpenDirectory()

void TREE_PROJECT_FRAME::OnOpenDirectory ( wxCommandEvent &  event)
private

Function OnOpenDirectory Handles the right-click menu for opening a directory in the current system file browser.

Definition at line 186 of file tree_project_frame.cpp.

187 {
188  // Get the root directory name:
189  TREEPROJECT_ITEM* treeData = GetSelectedData();
190 
191  if( !treeData )
192  return;
193 
194  // Ask for the new sub directory name
195  wxString curr_dir = treeData->GetDir();
196 
197  if( curr_dir.IsEmpty() )
198  {
199  // Use project path if the tree view path was empty.
200  curr_dir = wxPathOnly( m_Parent->GetProjectFileName() );
201 
202  // As a last resort use the user's documents folder.
203  if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
204  curr_dir = wxStandardPaths::Get().GetDocumentsDir();
205 
206  if( !curr_dir.IsEmpty() )
207  curr_dir += wxFileName::GetPathSeparator();
208  }
209 
210 #ifdef __WXMAC__
211  wxString msg;
212 
213  // Quote in case there are spaces in the path.
214  msg.Printf( "open \"%s\"", curr_dir );
215 
216  system( msg.c_str() );
217 #else
218  // Quote in case there are spaces in the path.
219  AddDelimiterString( curr_dir );
220 
221  wxLaunchDefaultApplication( curr_dir );
222 #endif
223 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetDir() const
KICAD_MANAGER_FRAME * m_Parent
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:42
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
const wxString GetProjectFileName()

References AddDelimiterString(), TREEPROJECT_ITEM::GetDir(), KICAD_MANAGER_FRAME::GetProjectFileName(), GetSelectedData(), and m_Parent.

◆ OnOpenSelectedFileWithTextEditor()

void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor ( wxCommandEvent &  event)
private

Function OnOpenSelectedFileWithTextEditor Call the text editor to open the selected file in the tree project.

Definition at line 644 of file tree_project_frame.cpp.

645 {
646  TREEPROJECT_ITEM* tree_data = GetSelectedData();
647 
648  if( !tree_data || tree_data->GetType() == TREE_DIRECTORY )
649  return;
650 
651  wxString fullFileName = tree_data->GetFileName();
652  AddDelimiterString( fullFileName );
653  wxString editorname = Pgm().GetEditorName();
654 
655  if( !editorname.IsEmpty() )
656  ExecuteFile( this, editorname, fullFileName );
657 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TreeFileType GetType() const
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:42
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:179
const wxString & GetFileName() const
int ExecuteFile(wxWindow *frame, const wxString &ExecFile, const wxString &param, wxProcess *callback)
Function ExecuteFile calls the executable file ExecFile with the command line parameters param.
Definition: gestfich.cpp:178

References AddDelimiterString(), ExecuteFile(), PGM_BASE::GetEditorName(), TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), TREEPROJECT_ITEM::GetType(), Pgm(), and TREE_DIRECTORY.

◆ OnPrintFile()

void TREE_PROJECT_FRAME::OnPrintFile ( wxCommandEvent &  event)
private

Function OnDeleteFile Print the selected file or directory in the tree project.

Definition at line 669 of file tree_project_frame.cpp.

670 {
671  TREEPROJECT_ITEM* tree_data = GetSelectedData();
672 
673  if( tree_data )
674  tree_data->Print();
675 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...

References GetSelectedData(), and TREEPROJECT_ITEM::Print().

◆ OnRenameFile()

void TREE_PROJECT_FRAME::OnRenameFile ( wxCommandEvent &  event)
private

Function OnRenameFile Rename the selected file or directory in the tree project.

Definition at line 678 of file tree_project_frame.cpp.

679 {
680  wxTreeItemId curr_item = m_TreeProject->GetSelection();
681  TREEPROJECT_ITEM* tree_data = GetSelectedData();
682 
683  if( !tree_data )
684  return;
685 
686  wxString buffer = m_TreeProject->GetItemText( curr_item );
687  wxString msg = wxString::Format( _( "Change filename: \"%s\"" ), tree_data->GetFileName() );
688  wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
689 
690  if( dlg.ShowModal() != wxID_OK )
691  return; // canceled by user
692 
693  buffer = dlg.GetValue();
694  buffer.Trim( true );
695  buffer.Trim( false );
696 
697  if( buffer.IsEmpty() )
698  return; // empty file name not allowed
699 
700  tree_data->Rename( buffer, true );
701  m_isRenaming = true;
702 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TREEPROJECTFILES * m_TreeProject
#define _(s)
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
bool Rename(const wxString &name, bool check=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const wxString & GetFileName() const

References _, Format(), TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), m_isRenaming, m_TreeProject, and TREEPROJECT_ITEM::Rename().

◆ OnRight()

void TREE_PROJECT_FRAME::OnRight ( wxTreeEvent &  Event)
private

Called on a right click on an item.

Definition at line 537 of file tree_project_frame.cpp.

538 {
539  int tree_id;
540  TREEPROJECT_ITEM* tree_data;
541  wxString fullFileName;
542  wxTreeItemId curr_item = Event.GetItem();
543 
544  // Ensure item is selected (Under Windows right click does not select the item)
545  m_TreeProject->SelectItem( curr_item );
546 
547  tree_data = GetSelectedData();
548 
549  if( !tree_data )
550  return;
551 
552  tree_id = tree_data->GetType();
553  fullFileName = tree_data->GetFileName();
554 
555  wxMenu popupMenu;
556 
557  switch( tree_id )
558  {
559  case TREE_PROJECT:
560  // Add a swith to an other project option only if the selected item
561  // is not the root item (current project)
562  if( curr_item != m_TreeProject->GetRootItem() )
563  {
565  _( "&Switch to this Project" ),
566  _( "Close all editors, and switch to the selected project" ),
567  KiBitmap( open_project_xpm ) );
568  popupMenu.AppendSeparator();
569  }
570 
571  AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
572  _( "New D&irectory..." ),
573  _( "Create a New Directory" ),
574  KiBitmap( directory_xpm ) );
575 
576  AddMenuItem( &popupMenu, ID_PROJECT_OPEN_DIR,
577 #ifdef __APPLE__
578  _( "Reveal in Finder" ),
579  _( "Reveals the directory in a Finder window" ),
580 #else
581  _( "&Open Directory in File Explorer" ),
582  _( "Opens the directory in the default system file manager" ),
583 #endif
584  KiBitmap( directory_browser_xpm ) );
585  break;
586 
587  case TREE_DIRECTORY:
588  AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
589  _( "New D&irectory..." ),
590  _( "Create a New Directory" ),
591  KiBitmap( directory_xpm ) );
592  AddMenuItem( &popupMenu, ID_PROJECT_OPEN_DIR,
593 #ifdef __APPLE__
594  _( "Reveal in Finder" ),
595  _( "Reveals the directory in a Finder window" ),
596 #else
597  _( "&Open Directory in File Explorer" ),
598  _( "Opens the directory in the default system file manager" ),
599 #endif
600  KiBitmap( directory_browser_xpm ) );
601 
602  popupMenu.AppendSeparator();
603  AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
604  _( "&Delete Directory" ),
605  _( "Delete the Directory and its content" ),
606  KiBitmap( delete_xpm ) );
607  break;
608 
609  default:
610  AddMenuItem( &popupMenu, ID_PROJECT_TXTEDIT,
611  _( "&Edit in a Text Editor" ),
612  _( "Open the file in a Text Editor" ),
613  KiBitmap( editor_xpm ) );
614  AddMenuItem( &popupMenu, ID_PROJECT_RENAME,
615  _( "&Rename File..." ),
616  _( "Rename file" ),
617  KiBitmap( right_xpm ) );
618 
619  popupMenu.AppendSeparator();
620  AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
621  _( "&Delete File" ),
622  _( "Delete the file and its content" ),
623  KiBitmap( delete_xpm ) );
624 
625  if( CanPrintFile( fullFileName ) )
626  {
627  popupMenu.AppendSeparator();
628  AddMenuItem( &popupMenu, ID_PROJECT_PRINT,
629 #ifdef __APPLE__
630  _( "Print..." ),
631 #else
632  _( "&Print" ),
633 #endif
634  _( "Print the contents of the file" ),
635  KiBitmap( print_button_xpm ) );
636  }
637  break;
638  }
639 
640  PopupMenu( &popupMenu );
641 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:251
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
#define _(s)
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
const wxString & GetFileName() const
bool CanPrintFile(const wxString &file)
Definition: gestfich.cpp:356

References _, AddMenuItem(), CanPrintFile(), TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), TREEPROJECT_ITEM::GetType(), ID_PROJECT_DELETE, ID_PROJECT_NEWDIR, ID_PROJECT_OPEN_DIR, ID_PROJECT_PRINT, ID_PROJECT_RENAME, ID_PROJECT_SWITCH_TO_OTHER, ID_PROJECT_TXTEDIT, KiBitmap(), m_TreeProject, TREE_DIRECTORY, and TREE_PROJECT.

◆ OnSelect()

void TREE_PROJECT_FRAME::OnSelect ( wxTreeEvent &  Event)
private

Called on a double click on an item.

Definition at line 705 of file tree_project_frame.cpp.

706 {
707  TREEPROJECT_ITEM* selected_item = GetSelectedData();
708 
709  if( !selected_item )
710  return;
711 
712  selected_item->Activate( this );
713 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
void Activate(TREE_PROJECT_FRAME *aTreePrjFrame)
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...

References TREEPROJECT_ITEM::Activate(), and GetSelectedData().

◆ OnSwitchToSelectedProject()

void TREE_PROJECT_FRAME::OnSwitchToSelectedProject ( wxCommandEvent &  event)
private

Switch to a other project selected from the tree project (by selecting an other .pro file inside the current project folder)

Definition at line 173 of file tree_project_frame.cpp.

174 {
175  TREEPROJECT_ITEM* tree_data = GetSelectedData();
176 
177  if( !tree_data )
178  return;
179 
180  wxString prj_filename = tree_data->GetFileName();
181 
182  m_Parent->LoadProject( prj_filename );
183 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
KICAD_MANAGER_FRAME * m_Parent
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
void LoadProject(const wxFileName &aProjectFileName)
const wxString & GetFileName() const

References TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), KICAD_MANAGER_FRAME::LoadProject(), and m_Parent.

◆ ReCreateTreePrj()

void TREE_PROJECT_FRAME::ReCreateTreePrj ( )

Create or modify the tree showing project file names.

Definition at line 472 of file tree_project_frame.cpp.

473 {
474  wxString pro_dir = m_Parent->GetProjectFileName();
475 
476  if( !m_TreeProject )
477  m_TreeProject = new TREEPROJECTFILES( this );
478  else
479  m_TreeProject->DeleteAllItems();
480 
481  if( !pro_dir ) // This is empty from TREE_PROJECT_FRAME constructor
482  return;
483 
484  wxFileName fn = pro_dir;
485 
486  if( !fn.IsOk() )
487  {
488  fn.Clear();
489  fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
490  fn.SetName( NAMELESS_PROJECT );
491  fn.SetExt( ProjectFileExtension );
492  }
493 
494  bool prjOpened = fn.FileExists();
495 
496  // root tree:
497  m_root = m_TreeProject->AddRoot( fn.GetFullName(), TREE_ROOT, TREE_ROOT );
498  m_TreeProject->SetItemBold( m_root, true );
499  m_TreeProject->SetItemData( m_root, new TREEPROJECT_ITEM( TREE_PROJECT, fn.GetFullPath(),
500  m_TreeProject ) );
501 
502  // Now adding all current files if available
503  if( prjOpened )
504  {
505  pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
506  wxDir dir( pro_dir );
507 
508  if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
509  {
510  wxString filename;
511  bool cont = dir.GetFirst( &filename );
512 
513  while( cont )
514  {
515  if( filename != fn.GetFullName() )
516  {
517  wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
519  }
520 
521  cont = dir.GetNext( &filename );
522  }
523  }
524  }
525  else
526  {
527  m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
528  }
529 
530  m_TreeProject->Expand( m_root );
531 
532  // Sort filenames by alphabetic order
533  m_TreeProject->SortChildren( m_root );
534 }
const std::string ProjectFileExtension
Class TREEPROJECTFILES This is the class to show (as a tree) the files in the project directory.
TREEPROJECTFILES * m_TreeProject
#define NAMELESS_PROJECT
friend class TREEPROJECT_ITEM
KICAD_MANAGER_FRAME * m_Parent
const wxString GetProjectFileName()
const char * name
Definition: DXF_plotter.cpp:61
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
Function AddItemToTreeProject.

References AddItemToTreeProject(), KICAD_MANAGER_FRAME::GetProjectFileName(), m_Parent, m_root, m_TreeProject, name, NAMELESS_PROJECT, ProjectFileExtension, TREE_PROJECT, TREE_ROOT, and TREEPROJECT_ITEM.

Referenced by KICAD_MANAGER_FRAME::LoadProject(), KICAD_MANAGER_FRAME::ReCreateTreePrj(), and KICAD_MANAGER_FRAME::RefreshProjectTree().

Friends And Related Function Documentation

◆ TREEPROJECT_ITEM

friend class TREEPROJECT_ITEM
friend

Definition at line 49 of file tree_project_frame.h.

Referenced by AddItemToTreeProject(), and ReCreateTreePrj().

Member Data Documentation

◆ m_filters

std::vector<wxString> TREE_PROJECT_FRAME::m_filters
private

Definition at line 57 of file tree_project_frame.h.

Referenced by AddItemToTreeProject().

◆ m_isRenaming

bool TREE_PROJECT_FRAME::m_isRenaming
private

Definition at line 55 of file tree_project_frame.h.

Referenced by OnFileSystemEvent(), and OnRenameFile().

◆ m_Parent

◆ m_root

wxTreeItemId TREE_PROJECT_FRAME::m_root
private

◆ m_TreeProject

◆ m_watcher

wxFileSystemWatcher* TREE_PROJECT_FRAME::m_watcher
private

Definition at line 58 of file tree_project_frame.h.

Referenced by FileWatcherReset(), and ~TREE_PROJECT_FRAME().


The documentation for this class was generated from the following files: