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 Files are filtered (see s_allowedExtensionsToList) so only useful files are shown. 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)
 
static wxString GetFileWildcard (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 Called via the popup menu, when right clicking on a file name Call the text editor to open the selected file in the tree project. More...
 
void OnDeleteFile (wxCommandEvent &event)
 Function OnDeleteFile 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. More...
 
void OnRenameFile (wxCommandEvent &event)
 Function OnRenameFile 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. 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...
 
void ClearFilters ()
 
const std::vector< wxString > & GetFilters ()
 
void RemoveFilter (const wxString &filter)
 
bool 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

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 130 of file tree_project_frame.cpp.

130  :
131  wxSashLayoutWindow( parent, ID_LEFT_FRAME,
132  wxDefaultPosition, wxDefaultSize,
133  wxNO_BORDER | wxTAB_TRAVERSAL )
134 {
135  m_Parent = parent;
136  m_TreeProject = NULL;
137 
138  m_watcher = NULL;
139  Connect( wxEVT_FSWATCHER,
140  wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
141 
142  /*
143  * Filtering is now inverted: the filters are actually used to _enable_ support
144  * for a given file type.
145  */
146 
147  // NOTE: sch filter must be first because of a test in AddFile() below
148  m_filters.push_back( wxT( "^.*\\.sch$" ) );
149 
150  for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
151  m_filters.push_back( s_allowedExtensionsToList[ii] );
152 
153  m_filters.push_back( wxT( "^no KiCad files found" ) );
154 
155  ReCreateTreePrj();
156 }
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 159 of file tree_project_frame.cpp.

160 {
161  if( m_watcher )
162  {
163  m_watcher->RemoveAll();
164  m_watcher->SetOwner( NULL );
165  delete m_watcher;
166  }
167 }
wxFileSystemWatcher * m_watcher

References m_watcher.

Member Function Documentation

◆ AddItemToTreeProject()

bool 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
true if the file (or directory) is added.

Definition at line 427 of file tree_project_frame.cpp.

429 {
430  wxTreeItemId cellule;
431 
432  // Check the file type
433  TreeFileType type = TREE_UNKNOWN;
434 
435  // Skip not visible files and dirs
436  wxFileName fn( aName );
437 
438  // Files/dirs names starting by "." are not visible files under unices.
439  // Skip them also under Windows
440  if( fn.GetName().StartsWith( wxT( "." ) ) )
441  return false;
442 
443  if( wxDirExists( aName ) )
444  {
445  type = TREE_DIRECTORY;
446  }
447  else
448  {
449  // Filter
450  wxRegEx reg;
451 
452  bool isSchematic = false;
453  bool addFile = false;
454 
455  for( unsigned i = 0; i < m_filters.size(); i++ )
456  {
457  wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
458  wxT( "Regular expression " ) + m_filters[i] +
459  wxT( " failed to compile." ) );
460 
461  if( reg.Matches( aName ) )
462  {
463  addFile = true;
464 
465  if( i==0 )
466  isSchematic = true;
467 
468  break;
469  }
470  }
471 
472  if( !addFile )
473  return false;
474 
475  // only show the schematic if it is a top level schematic. Eeschema
476  // cannot open a schematic and display it properly unless it starts
477  // at the top of the hierarchy. The schematic is top level only if
478  // there is a line in the header saying:
479  // "Sheet 1 "
480  // However if the file has the same name as the project, it is always
481  // shown, because it is expected the root sheet.
482  // (and to fix an issue (under XP but could exist under other OS),
483  // when a .sch file is created, the file
484  // create is sent to the wxFileSystemWatcher, but the file still has 0 byte
485  // so it cannot detected as root sheet
486  // This is an ugly fix.
487  if( isSchematic )
488  {
489  wxString fullFileName = aName.BeforeLast( '.' );
490  wxString rootName;
491  TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
492 
493  if( itemData )
494  rootName = itemData->GetFileName().BeforeLast( '.' );
495 
496  if( fullFileName != rootName )
497  {
498  char line[128]; // small because we just need a few bytes from the start of a line
499  FILE* fp;
500 
501  fullFileName = aName;
502  fp = wxFopen( fullFileName, wxT( "rt" ) );
503 
504  if( fp == NULL )
505  return false;
506 
507  addFile = false;
508 
509  // check the first 100 lines for the "Sheet 1" string
510  for( int i = 0; i<100; ++i )
511  {
512  if( !fgets( line, sizeof(line), fp ) )
513  break;
514 
515  if( !strncmp( line, "Sheet 1 ", 8 ) )
516  {
517  addFile = true;
518  break;
519  }
520  }
521 
522  fclose( fp );
523 
524  if( !addFile )
525  return false; // it is a non-top-level schematic
526  }
527  }
528 
529  for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
530  {
531  wxString ext = GetFileExt( (TreeFileType) i );
532 
533  if( ext == wxT( "" ) )
534  continue;
535 
536  reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
537  wxString::FromAscii( "$" ), wxRE_ICASE );
538 
539  if( reg.Matches( aName ) )
540  {
541  type = (TreeFileType) i;
542  break;
543  }
544  }
545  }
546 
547  // also check to see if it is already there.
548  wxTreeItemIdValue cookie;
549  wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
550 
551  while( kid.IsOk() )
552  {
553  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
554 
555  if( itemData )
556  {
557  if( itemData->GetFileName() == aName )
558  {
559  return true; // well, we would have added it, but it is already here!
560  }
561  }
562 
563  kid = m_TreeProject->GetNextChild( aRoot, cookie );
564  }
565 
566  // Append the item (only appending the filename not the full path):
567  wxString file = wxFileNameFromPath( aName );
568  cellule = m_TreeProject->AppendItem( aRoot, file );
569  TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
570 
571  m_TreeProject->SetItemData( cellule, data );
572  data->SetState( 0 );
573 
574  // Mark root files (files which have the same aName as the project)
575  wxFileName project( m_Parent->GetProjectFileName() );
576  wxFileName currfile( file );
577 
578  if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
579  data->SetRootFile( true );
580  else
581  data->SetRootFile( false );
582 
583  // This section adds dirs and files found in the subdirs
584  // in this case AddFile is recursive, but for the first level only.
585  if( TREE_DIRECTORY == type && aRecurse )
586  {
587  wxDir dir( aName );
588 
589  if( dir.IsOpened() ) // protected dirs will not open properly.
590  {
591  wxString dir_filename;
592 
593  data->SetPopulated( true );
594 
595  if( dir.GetFirst( &dir_filename ) )
596  {
597  do // Add name in tree, but do not recurse
598  {
599  wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
600  AddItemToTreeProject( path, cellule, false );
601  } while( dir.GetNext( &dir_filename ) );
602  }
603  }
604 
605  // Sort filenames by alphabetic order
606  m_TreeProject->SortChildren( cellule );
607  }
608 
609  return true;
610 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TreeFileType
Definition: kicad.h:52
void SetRootFile(bool aValue)
TREEPROJECTFILES * m_TreeProject
friend class TREEPROJECT_ITEM
KICAD_MANAGER_FRAME * m_Parent
Definition: kicad.h:74
const wxString GetProjectFileName()
Definition: mainframe.cpp:142
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
void SetState(int state)
size_t i
Definition: json11.cpp:597
bool 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 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().

◆ ClearFilters()

void TREE_PROJECT_FRAME::ClearFilters ( )
inlineprivate

Definition at line 149 of file tree_project_frame.h.

150  {
151  m_filters.clear();
152  }
std::vector< wxString > m_filters

References m_filters.

◆ 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 1038 of file tree_project_frame.cpp.

1039 {
1040  // Prepare file watcher:
1041  if( m_watcher )
1042  {
1043  m_watcher->RemoveAll();
1044  }
1045  else
1046  {
1047  m_watcher = new wxFileSystemWatcher();
1048  m_watcher->SetOwner( this );
1049  }
1050 
1051  // Add directories which should be monitored.
1052  // under windows, we add the curr dir and all subdirs
1053  // under unix, we add only the curr dir and the populated subdirs
1054  // see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
1055  // under unix, the file watcher needs more work to be efficient
1056  // moreover, under wxWidgets 2.9.4, AddTree does not work properly.
1057 
1058  // We can see wxString under a debugger, not a wxFileName
1059  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
1060  wxFileName fn;
1061  fn.AssignDir( prj_dir );
1062  fn.DontFollowLink();
1063 
1064 #ifdef __WINDOWS__
1065  m_watcher->AddTree( fn );
1066 #else
1067  m_watcher->Add( fn );
1068 
1069  // Add subdirs
1070  wxTreeItemIdValue cookie;
1071  wxTreeItemId root_id = m_root;
1072 
1073  std::stack < wxTreeItemId > subdirs_id;
1074 
1075  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
1076 
1077  while( 1 )
1078  {
1079  if( !kid.IsOk() )
1080  {
1081  if( subdirs_id.empty() ) // all items were explored
1082  break;
1083  else
1084  {
1085  root_id = subdirs_id.top();
1086  subdirs_id.pop();
1087  kid = m_TreeProject->GetFirstChild( root_id, cookie );
1088 
1089  if( !kid.IsOk() )
1090  continue;
1091  }
1092  }
1093 
1094  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1095 
1096  if( itemData && itemData->GetType() == TREE_DIRECTORY )
1097  {
1098  // we can see wxString under a debugger, not a wxFileName
1099  const wxString& path = itemData->GetFileName();
1100 
1101  wxLogTrace( tracePathsAndFiles, "%s: add '%s'\n", __func__, TO_UTF8( path ) );
1102 
1103  if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
1104  {
1105  fn.AssignDir( path );
1106  m_watcher->Add( fn );
1107 
1108  // if kid is a subdir, push in list to explore it later
1109  if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
1110  subdirs_id.push( kid );
1111  }
1112  }
1113 
1114  kid = m_TreeProject->GetNextChild( root_id, cookie );
1115  }
1116 #endif
1117 
1118 #if defined(DEBUG) && 1
1119  wxArrayString paths;
1120  m_watcher->GetWatchedPaths( &paths );
1121  wxLogTrace( tracePathsAndFiles, "%s: watched paths:", __func__ );
1122 
1123  for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
1124  wxLogTrace( tracePathsAndFiles, " %s\n", TO_UTF8( paths[ii] ) );
1125 #endif
1126 }
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:47
bool IsPopulated() const
KICAD_MANAGER_FRAME * m_Parent
const wxString GetProjectFileName()
Definition: mainframe.cpp:142
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. therefore wxTreeItemId::IsOk should be used to test the returned value

Definition at line 901 of file tree_project_frame.cpp.

902 {
903  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
904 
905  // If the subdir is the current working directory, return m_root
906  // in main list:
907  if( prj_dir == aSubDir )
908  return m_root;
909 
910  // The subdir is in the main tree or in a subdir: Locate it
911  wxTreeItemIdValue cookie;
912  wxTreeItemId root_id = m_root;
913  std::stack < wxTreeItemId > subdirs_id;
914 
915  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
916 
917  while( 1 )
918  {
919  if( ! kid.IsOk() )
920  {
921  if( subdirs_id.empty() ) // all items were explored
922  {
923  root_id = kid; // Not found: return an invalid wxTreeItemId
924  break;
925  }
926  else
927  {
928  root_id = subdirs_id.top();
929  subdirs_id.pop();
930  kid = m_TreeProject->GetFirstChild( root_id, cookie );
931 
932  if( ! kid.IsOk() )
933  continue;
934  }
935  }
936 
937  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
938 
939  if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
940  {
941  if( itemData->GetFileName() == aSubDir ) // Found!
942  {
943  root_id = kid;
944  break;
945  }
946 
947  // kid is a subdir, push in list to explore it later
948  if( itemData->IsPopulated() )
949  subdirs_id.push( kid );
950  }
951 
952  kid = m_TreeProject->GetNextChild( root_id, cookie );
953  }
954 
955  return root_id;
956 }
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()
Definition: mainframe.cpp:142
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 253 of file tree_project_frame.cpp.

254 {
255  wxString ext;
256 
257  switch( type )
258  {
259  case TREE_PROJECT:
260  ext = ProjectFileExtension;
261  break;
262 
263  case TREE_SCHEMA:
265  break;
266 
267  case TREE_LEGACY_PCB:
269  break;
270 
271  case TREE_SEXP_PCB:
272  ext = KiCadPcbFileExtension;
273  break;
274 
275  case TREE_GERBER:
277  break;
278 
279  case TREE_HTML:
280  ext = HtmlFileExtension;
281  break;
282 
283  case TREE_PDF:
284  ext = PdfFileExtension;
285  break;
286 
287  case TREE_TXT:
288  ext = TextFileExtension;
289  break;
290 
291  case TREE_NET:
292  ext = NetlistFileExtension;
293  break;
294 
295  case TREE_CMP_LINK:
297  break;
298 
299  case TREE_REPORT:
300  ext = ReportFileExtension;
301  break;
302 
303  case TREE_FP_PLACE:
305  break;
306 
307  case TREE_DRILL:
308  ext = DrillFileExtension;
309  break;
310 
311  case TREE_DRILL_NC:
312  ext = "nc";
313  break;
314 
315  case TREE_DRILL_XNC:
316  ext = "xnc";
317  break;
318 
319  case TREE_SVG:
320  ext = SVGFileExtension;
321  break;
322 
325  break;
326 
327  case TREE_FOOTPRINT_FILE:
329  break;
330 
333  break;
334 
335  default: // Eliminates unnecessary GCC warning.
336  break;
337  }
338 
339  return ext;
340 }
const std::string NetlistFileExtension
Definition: kicad.h:59
const std::string KiCadFootprintFileExtension
const std::string ProjectFileExtension
const std::string LegacyPcbFileExtension
const std::string ComponentFileExtension
const std::string KiCadPcbFileExtension
Definition: kicad.h:61
const wxChar TextFileExtension[]
const std::string HtmlFileExtension
Definition: kicad.h:70
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
Definition: kicad.h:60
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().

◆ GetFileWildcard()

wxString TREE_PROJECT_FRAME::GetFileWildcard ( TreeFileType  type)
staticprotected

Definition at line 346 of file tree_project_frame.cpp.

347 {
348  wxString ext;
349 
350  switch( type )
351  {
352  case TREE_PROJECT:
353  ext = ProjectFileWildcard();
354  break;
355 
356  case TREE_SCHEMA:
357  ext = SchematicFileWildcard();
358  break;
359 
360  case TREE_LEGACY_PCB:
361  case TREE_SEXP_PCB:
362  ext = PcbFileWildcard();
363  break;
364 
365  case TREE_GERBER:
366  ext = GerberFileWildcard();
367  break;
368 
369  case TREE_HTML:
370  ext = HtmlFileWildcard();
371  break;
372 
373  case TREE_PDF:
374  ext = PdfFileWildcard();
375  break;
376 
377  case TREE_TXT:
378  ext = TextFileWildcard();
379  break;
380 
381  case TREE_NET:
382  ext = NetlistFileWildcard();
383  break;
384 
385  case TREE_CMP_LINK:
386  ext = ComponentFileWildcard();
387  break;
388 
389  case TREE_REPORT:
390  ext = ReportFileWildcard();
391  break;
392 
393  case TREE_FP_PLACE:
395  break;
396 
397  case TREE_DRILL:
398  case TREE_DRILL_NC:
399  case TREE_DRILL_XNC:
400  ext = DrillFileWildcard();
401  break;
402 
403  case TREE_SVG:
404  ext = SVGFileWildcard();
405  break;
406 
409  break;
410 
411  case TREE_FOOTPRINT_FILE:
413  break;
414 
417  break;
418 
419  default: // Eliminates unnecessary GCC warning.
420  break;
421  }
422 
423  return ext;
424 }
wxString GerberFileWildcard()
Definition: kicad.h:59
wxString PageLayoutDescrFileWildcard()
wxString SchematicFileWildcard()
wxString SVGFileWildcard()
wxString ComponentFileWildcard()
wxString PdfFileWildcard()
wxString SchematicLibraryFileWildcard()
Definition: kicad.h:61
Definition: kicad.h:70
wxString ReportFileWildcard()
wxString NetlistFileWildcard()
wxString HtmlFileWildcard()
wxString DrillFileWildcard()
wxString ProjectFileWildcard()
wxString FootprintPlaceFileWildcard()
wxString PcbFileWildcard()
wxString TextFileWildcard()
Definition: kicad.h:60
wxString KiCadFootprintLibFileWildcard()

References ComponentFileWildcard(), DrillFileWildcard(), FootprintPlaceFileWildcard(), GerberFileWildcard(), HtmlFileWildcard(), KiCadFootprintLibFileWildcard(), NetlistFileWildcard(), PageLayoutDescrFileWildcard(), PcbFileWildcard(), PdfFileWildcard(), ProjectFileWildcard(), ReportFileWildcard(), SchematicFileWildcard(), SchematicLibraryFileWildcard(), SVGFileWildcard(), TextFileWildcard(), 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.

◆ GetFilters()

const std::vector<wxString>& TREE_PROJECT_FRAME::GetFilters ( )
inlineprivate

Definition at line 154 of file tree_project_frame.h.

155  {
156  return m_filters;
157  }
std::vector< wxString > m_filters

References m_filters.

◆ 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 895 of file tree_project_frame.cpp.

896 {
897  return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
898 }
TREEPROJECTFILES * m_TreeProject

References m_TreeProject.

Referenced by AddItemToTreeProject(), FileWatcherReset(), findSubdirTreeItem(), 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 888 of file tree_project_frame.cpp.

889 {
890  return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData
891  ( m_TreeProject->GetSelection() ) );
892 }
TREEPROJECTFILES * m_TreeProject

References m_TreeProject.

Referenced by OnCreateNewDirectory(), OnDeleteFile(), OnOpenSelectedFileWithTextEditor(), 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 196 of file tree_project_frame.cpp.

197 {
198  // Get the root directory name:
199  TREEPROJECT_ITEM* treeData = GetSelectedData();
200 
201  if( !treeData )
202  return;
203 
204  TreeFileType rootType = treeData->GetType();
205  wxTreeItemId root;
206 
207  if( TREE_DIRECTORY == rootType )
208  {
209  root = m_TreeProject->GetSelection();
210  }
211  else
212  {
213  root = m_TreeProject->GetItemParent( m_TreeProject->GetSelection() );
214 
215  if( !root.IsOk() )
216  root = m_TreeProject->GetSelection();
217  }
218 
219  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
220 
221  // Ask for the new sub directory name
222  wxString curr_dir = treeData->GetDir();
223 
224  if( !curr_dir.IsEmpty() ) // A subdir is selected
225  {
226  // Make this subdir name relative to the current path.
227  // It will be more easy to read by the user, in the next dialog
228  wxFileName fn;
229  fn.AssignDir( curr_dir );
230  fn.MakeRelativeTo( prj_dir );
231  curr_dir = fn.GetPath();
232 
233  if( !curr_dir.IsEmpty() )
234  curr_dir += wxFileName::GetPathSeparator();
235  }
236 
237  wxString msg = wxString::Format( _( "Current project directory:\n%s" ), GetChars( prj_dir ) );
238  wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
239 
240  if( subdir.IsEmpty() )
241  return;
242 
243  wxString full_dirname = prj_dir + wxFileName::GetPathSeparator() + subdir;
244 
245  if( wxMkdir( full_dirname ) )
246  {
247  // the new itel will be added by the file watcher
248  // AddItemToTreeProject( subdir, root );
249  }
250 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TreeFileType
Definition: kicad.h:52
TreeFileType GetType() const
const wxString GetDir() const
TREEPROJECTFILES * m_TreeProject
KICAD_MANAGER_FRAME * m_Parent
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
const wxString GetProjectFileName()
Definition: mainframe.cpp:142
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:100
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(), TREEPROJECT_ITEM::GetType(), m_Parent, m_TreeProject, and TREE_DIRECTORY.

◆ OnDeleteFile()

void TREE_PROJECT_FRAME::OnDeleteFile ( wxCommandEvent &  event)
private

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

Definition at line 776 of file tree_project_frame.cpp.

777 {
778  TREEPROJECT_ITEM* tree_data = GetSelectedData();
779 
780  if( !tree_data )
781  return;
782 
783  tree_data->Delete();
784 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
bool Delete(bool check=true)
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 828 of file tree_project_frame.cpp.

829 {
830  wxTreeItemId itemId = Event.GetItem();
831  TREEPROJECT_ITEM* tree_data = GetItemIdData( itemId );
832 
833  if( !tree_data )
834  return;
835 
836  if( tree_data->GetType() != TREE_DIRECTORY )
837  return;
838 
839  // explore list of non populated subdirs, and populate them
840  wxTreeItemIdValue cookie;
841  wxTreeItemId kid = m_TreeProject->GetFirstChild( itemId, cookie );
842 
843  bool subdir_populated = false;
844 
845  for( ; kid.IsOk(); kid = m_TreeProject->GetNextChild( itemId, cookie ) )
846  {
847  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
848 
849  if( !itemData || itemData->GetType() != TREE_DIRECTORY )
850  continue;
851 
852  if( itemData->IsPopulated() )
853  continue;
854 
855  wxString fileName = itemData->GetFileName();
856  wxDir dir( fileName );
857 
858  if( dir.IsOpened() )
859  {
860  wxString dir_filename;
861 
862  if( dir.GetFirst( &dir_filename ) )
863  {
864  do // Add name to tree item, but do not recurse in subdirs:
865  {
866  wxString name = fileName + wxFileName::GetPathSeparator() + dir_filename;
867  AddItemToTreeProject( name, kid, false );
868  } while( dir.GetNext( &dir_filename ) );
869  }
870 
871  itemData->SetPopulated( true ); // set state to populated
872  subdir_populated = true;
873  }
874 
875  // Sort filenames by alphabetic order
876  m_TreeProject->SortChildren( kid );
877  }
878 
879  if( subdir_populated )
880  {
881  #ifndef __WINDOWS__
883  #endif
884  }
885 }
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
bool 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 959 of file tree_project_frame.cpp.

960 {
961  const wxFileName& pathModified = event.GetPath();
962  wxString subdir = pathModified.GetPath();
963  wxString fn = pathModified.GetFullPath();
964 
965  switch( event.GetChangeType() )
966  {
967  case wxFSW_EVENT_DELETE:
968  break;
969 
970  case wxFSW_EVENT_CREATE:
971  break;
972 
973  case wxFSW_EVENT_RENAME:
974  break;
975 
976  case wxFSW_EVENT_MODIFY:
977  case wxFSW_EVENT_ACCESS:
978  default:
979  return;
980  }
981 
982  wxTreeItemId root_id = findSubdirTreeItem( subdir );
983 
984  if( !root_id.IsOk() )
985  return;
986 
987  wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
988  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
989 
990  switch( event.GetChangeType() )
991  {
992  case wxFSW_EVENT_CREATE:
993  AddItemToTreeProject( pathModified.GetFullPath(), root_id, false );
994  break;
995 
996  case wxFSW_EVENT_DELETE:
997  while( kid.IsOk() )
998  {
999  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1000 
1001  if( itemData && itemData->GetFileName() == fn )
1002  {
1003  m_TreeProject->Delete( kid );
1004  return;
1005  }
1006  kid = m_TreeProject->GetNextChild( root_id, cookie );
1007  }
1008  break;
1009 
1010  case wxFSW_EVENT_RENAME :
1011  {
1012  const wxFileName& newpath = event.GetNewPath();
1013  wxString newfn = newpath.GetFullPath();
1014 
1015  while( kid.IsOk() )
1016  {
1017  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1018 
1019  if( itemData && itemData->GetFileName() == fn )
1020  {
1021  m_TreeProject->Delete( kid );
1022  break;
1023  }
1024 
1025  kid = m_TreeProject->GetNextChild( root_id, cookie );
1026  }
1027 
1028  AddItemToTreeProject( newfn, root_id, false );
1029  }
1030  break;
1031  }
1032 
1033  // Sort filenames by alphabetic order
1034  m_TreeProject->SortChildren( root_id );
1035 }
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.
bool AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aRecurse=true)
Function AddItemToTreeProject.
const wxString & GetFileName() const

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

Referenced by TREE_PROJECT_FRAME().

◆ OnOpenSelectedFileWithTextEditor()

void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor ( wxCommandEvent &  event)
private

Function OnOpenSelectedFileWithTextEditor Called via the popup menu, when right clicking on a file name Call the text editor to open the selected file in the tree project.

Definition at line 757 of file tree_project_frame.cpp.

758 {
759  TREEPROJECT_ITEM* tree_data = GetSelectedData();
760 
761  if( !tree_data )
762  return;
763 
764  if( tree_data->GetType() == TREE_DIRECTORY )
765  return;
766 
767  wxString fullFileName = tree_data->GetFileName();
768  AddDelimiterString( fullFileName );
769  wxString editorname = Pgm().GetEditorName();
770 
771  if( !editorname.IsEmpty() )
772  ExecuteFile( this, editorname, fullFileName );
773 }
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:66
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:44
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:200
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:208

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

◆ OnRenameFile()

void TREE_PROJECT_FRAME::OnRenameFile ( wxCommandEvent &  event)
private

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

Definition at line 787 of file tree_project_frame.cpp.

788 {
789  wxTreeItemId curr_item = m_TreeProject->GetSelection();
790  TREEPROJECT_ITEM* tree_data = GetSelectedData();
791 
792  if( !tree_data )
793  return;
794 
795  wxString buffer = m_TreeProject->GetItemText( curr_item );
796  wxString msg = wxString::Format(
797  _( "Change filename: \"%s\"" ),
798  GetChars( tree_data->GetFileName() ) );
799 
800  wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
801 
802  if( dlg.ShowModal() != wxID_OK )
803  return; // canceled by user
804 
805  buffer = dlg.GetValue();
806  buffer.Trim( true );
807  buffer.Trim( false );
808 
809  if( buffer.IsEmpty() )
810  return; // empty file name not allowed
811 
812  if( tree_data->Rename( buffer, true ) )
813  m_TreeProject->SetItemText( curr_item, buffer );
814 }
Class TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
TREEPROJECTFILES * m_TreeProject
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)
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:100
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(), GetChars(), TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), 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 686 of file tree_project_frame.cpp.

687 {
688  int tree_id;
689  TREEPROJECT_ITEM* tree_data;
690  wxString fullFileName;
691  wxTreeItemId curr_item = Event.GetItem();
692 
693  // Ensure item is selected (Under Windows right click does not select the item)
694  m_TreeProject->SelectItem( curr_item );
695 
696  tree_data = GetSelectedData();
697 
698  if( !tree_data )
699  return;
700 
701  tree_id = tree_data->GetType();
702  fullFileName = tree_data->GetFileName();
703 
704  wxMenu popupMenu;
705 
706  switch( tree_id )
707  {
708  case TREE_PROJECT:
709  // Add a swith to an other project option only if the selected item
710  // is not the root item (current project)
711  if( curr_item != m_TreeProject->GetRootItem() )
712  {
714  _( "&Switch to this Project" ),
715  _( "Close all editors, and switch to the selected project" ),
716  KiBitmap( open_project_xpm ) );
717  popupMenu.AppendSeparator();
718  }
719 
720  AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
721  _( "New D&irectory..." ),
722  _( "Create a New Directory" ),
723  KiBitmap( directory_xpm ) );
724  break;
725 
726  case TREE_DIRECTORY:
727  AddMenuItem( &popupMenu, ID_PROJECT_NEWDIR,
728  _( "New D&irectory..." ),
729  _( "Create a New Directory" ),
730  KiBitmap( directory_xpm ) );
731  AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
732  _( "&Delete Directory" ),
733  _( "Delete the Directory and its content" ),
734  KiBitmap( delete_xpm ) );
735  break;
736 
737  default:
738  AddMenuItem( &popupMenu, ID_PROJECT_TXTEDIT,
739  _( "&Edit in a Text Editor" ),
740  _( "Open the file in a Text Editor" ),
741  KiBitmap( editor_xpm ) );
742  AddMenuItem( &popupMenu, ID_PROJECT_RENAME,
743  _( "&Rename File..." ),
744  _( "Rename file" ),
745  KiBitmap( right_xpm ) );
746  AddMenuItem( &popupMenu, ID_PROJECT_DELETE,
747  _( "&Delete File" ),
748  _( "Delete the Directory and its content" ),
749  KiBitmap( delete_xpm ) );
750  break;
751  }
752 
753  PopupMenu( &popupMenu );
754 }
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
TREEPROJECT_ITEM * GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
const wxString & GetFileName() const

References AddMenuItem(), TREEPROJECT_ITEM::GetFileName(), GetSelectedData(), TREEPROJECT_ITEM::GetType(), ID_PROJECT_DELETE, ID_PROJECT_NEWDIR, 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 817 of file tree_project_frame.cpp.

818 {
819  TREEPROJECT_ITEM* selected_item = GetSelectedData();
820 
821  if( !selected_item )
822  return;
823 
824  selected_item->Activate( this );
825 }
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 183 of file tree_project_frame.cpp.

184 {
185  TREEPROJECT_ITEM* tree_data = GetSelectedData();
186 
187  if( !tree_data )
188  return;
189 
190  wxString prj_filename = tree_data->GetFileName();
191 
192  m_Parent->LoadProject( prj_filename );
193 }
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)
Definition: prjconfig.cpp:61
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 613 of file tree_project_frame.cpp.

614 {
615  wxTreeItemId rootcellule;
616  bool prjOpened = false;
617  wxString pro_dir = m_Parent->GetProjectFileName();
618 
619  if( !m_TreeProject )
620  m_TreeProject = new TREEPROJECTFILES( this );
621  else
622  m_TreeProject->DeleteAllItems();
623 
624  if( !pro_dir ) // This is empty from TREE_PROJECT_FRAME constructor
625  return;
626 
627  wxFileName fn = pro_dir;
628 
629  if( !fn.IsOk() )
630  {
631  fn.Clear();
632  fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
633  fn.SetName( NAMELESS_PROJECT );
634  fn.SetExt( ProjectFileExtension );
635  }
636 
637  prjOpened = fn.FileExists();
638 
639  // root tree:
640  m_root = rootcellule = m_TreeProject->AddRoot( fn.GetFullName(),
641  TREE_PROJECT - 1,
642  TREE_PROJECT - 1 );
643 
644  m_TreeProject->SetItemBold( rootcellule, true );
645 
646  m_TreeProject->SetItemData( rootcellule,
648  fn.GetFullPath(),
649  m_TreeProject ) );
650 
651  // Now adding all current files if available
652  if( prjOpened )
653  {
654  pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
655  wxDir dir( pro_dir );
656 
657  if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
658  {
659  wxString filename;
660  bool cont = dir.GetFirst( &filename );
661 
662  while( cont )
663  {
664  if( filename != fn.GetFullName() )
665  {
666  wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
668  }
669 
670  cont = dir.GetNext( &filename );
671  }
672  }
673  }
674  else
675  {
676  m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
677  }
678 
679  m_TreeProject->Expand( rootcellule );
680 
681  // Sort filenames by alphabetic order
682  m_TreeProject->SortChildren( m_root );
683 }
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()
Definition: mainframe.cpp:142
const char * name
Definition: DXF_plotter.cpp:61
bool 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, and TREEPROJECT_ITEM.

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

◆ RemoveFilter()

void TREE_PROJECT_FRAME::RemoveFilter ( const wxString &  filter)
private

Definition at line 170 of file tree_project_frame.cpp.

171 {
172  for( unsigned int i = 0; i < m_filters.size(); i++ )
173  {
174  if( filter == m_filters[i] )
175  {
176  m_filters.erase( m_filters.begin() + i );
177  return;
178  }
179  }
180 }
size_t i
Definition: json11.cpp:597
std::vector< wxString > m_filters

References i, and m_filters.

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 56 of file tree_project_frame.h.

Referenced by AddItemToTreeProject(), ClearFilters(), GetFilters(), and RemoveFilter().

◆ 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 57 of file tree_project_frame.h.

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


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