KiCad PCB EDA Suite
TREE_PROJECT_FRAME Class Reference

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

std::vector< TREEPROJECT_ITEM * > GetSelectedData ()
 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 aCanResetFileWatcher=true, 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

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

134  :
135  wxSashLayoutWindow( parent, ID_LEFT_FRAME, wxDefaultPosition, wxDefaultSize,
136  wxNO_BORDER | wxTAB_TRAVERSAL )
137 {
138  m_Parent = parent;
140  m_isRenaming = false;
141 
142  m_watcher = NULL;
143  Connect( wxEVT_FSWATCHER,
144  wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
145 
146  /*
147  * Filtering is now inverted: the filters are actually used to _enable_ support
148  * for a given file type.
149  */
150  for( int ii = 0; s_allowedExtensionsToList[ii] != NULL; ii++ )
151  m_filters.emplace_back( s_allowedExtensionsToList[ii] );
152 
153  m_filters.emplace_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 ...
#define NULL
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 NULL, 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 }
#define NULL
wxFileSystemWatcher * m_watcher

References m_watcher, and NULL.

Member Function Documentation

◆ AddItemToTreeProject()

wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject ( const wxString &  aName,
wxTreeItemId &  aRoot,
bool  aCanResetFileWatcher = true,
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
aCanResetFileWatcher= true to reset file watcher if additional conditions are met
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  bool addFile = false;
314 
315  for( const wxString& m_filter : m_filters )
316  {
317  wxCHECK2_MSG( reg.Compile( m_filter, wxRE_ICASE ), continue,
318  wxString::Format( "Regex %s failed to compile.", m_filter ) );
319 
320  if( reg.Matches( aName ) )
321  {
322  addFile = true;
323  break;
324  }
325  }
326 
327  if( !addFile )
328  return newItemId;
329 
330  // only show the schematic if it is a top level schematic. Eeschema
331  // cannot open a schematic and display it properly unless it starts
332  // at the top of the hierarchy. The schematic is top level only if
333  // there is a line in the header saying:
334  // "Sheet 1 "
335  // However if the file has the same name as the project, it is always
336  // shown, because it is expected the root sheet.
337  // (and to fix an issue (under XP but could exist under other OS),
338  // when a .sch file is created, the file
339  // create is sent to the wxFileSystemWatcher, but the file still has 0 byte
340  // so it cannot detected as root sheet
341  // This is an ugly fix.
342  if( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" )
343  {
344  wxString fullFileName = aName.BeforeLast( '.' );
345  wxString rootName;
346  TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
347 
348  if( itemData )
349  rootName = itemData->GetFileName().BeforeLast( '.' );
350 
351  if( fullFileName != rootName )
352  {
353  char line[128]; // small because we just need a few bytes from the start of a line
354  FILE* fp;
355 
356  fullFileName = aName;
357  fp = wxFopen( fullFileName, wxT( "rt" ) );
358 
359  if( fp == NULL )
360  return newItemId;
361 
362  addFile = false;
363 
364  // check the first 100 lines for the "Sheet 1" or "(page 1" string
365  for( int i = 0; i<100; ++i )
366  {
367  if( !fgets( line, sizeof(line), fp ) )
368  break;
369 
370  if( fn.GetExt() == "sch" )
371  {
372  if( strncmp( line, "Sheet 1 ", 8 ) == 0 )
373  {
374  addFile = true;
375  break;
376  }
377  } else if( fn.GetExt() == "kicad_sch" )
378  {
379  char* start = line;
380 
381  while( *start == ' ' )
382  start++;
383 
384  if( strncmp( start, "(page 1 ", 8 ) == 0 )
385  {
386  addFile = true;
387  break;
388  }
389  }
390  }
391 
392  fclose( fp );
393 
394  if( !addFile )
395  return newItemId; // it is a non-top-level schematic
396  }
397  }
398 
399  for( int i = TREE_PROJECT; i < TREE_MAX; i++ )
400  {
401  wxString ext = GetFileExt( (TreeFileType) i );
402 
403  if( ext == wxT( "" ) )
404  continue;
405 
406  reg.Compile( wxString::FromAscii( "^.*\\" ) + ext +
407  wxString::FromAscii( "$" ), wxRE_ICASE );
408 
409  if( reg.Matches( aName ) )
410  {
411  type = (TreeFileType) i;
412  break;
413  }
414  }
415  }
416 
417  // also check to see if it is already there.
418  wxTreeItemIdValue cookie;
419  wxTreeItemId kid = m_TreeProject->GetFirstChild( aRoot, cookie );
420 
421  while( kid.IsOk() )
422  {
423  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
424 
425  if( itemData )
426  {
427  if( itemData->GetFileName() == aName )
428  return itemData->GetId(); // well, we would have added it, but it is already here!
429  }
430 
431  kid = m_TreeProject->GetNextChild( aRoot, cookie );
432  }
433 
434  // Append the item (only appending the filename not the full path):
435  wxString file = wxFileNameFromPath( aName );
436  newItemId = m_TreeProject->AppendItem( aRoot, file );
437  TREEPROJECT_ITEM* data = new TREEPROJECT_ITEM( type, aName, m_TreeProject );
438 
439  m_TreeProject->SetItemData( newItemId, data );
440  data->SetState( 0 );
441 
442  // Mark root files (files which have the same aName as the project)
443  wxFileName project( m_Parent->GetProjectFileName() );
444  wxFileName currfile( file );
445 
446  if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
447  data->SetRootFile( true );
448  else
449  data->SetRootFile( false );
450 
451 #ifndef __WINDOWS__
452  bool subdir_populated = false;
453 #endif
454 
455  // This section adds dirs and files found in the subdirs
456  // in this case AddFile is recursive, but for the first level only.
457  if( TREE_DIRECTORY == type && aRecurse )
458  {
459  wxDir dir( aName );
460 
461  if( dir.IsOpened() ) // protected dirs will not open properly.
462  {
463  wxString dir_filename;
464 
465  data->SetPopulated( true );
466 #ifndef __WINDOWS__
467  subdir_populated = aCanResetFileWatcher;
468 #endif
469 
470  if( dir.GetFirst( &dir_filename ) )
471  {
472  do // Add name in tree, but do not recurse
473  {
474  wxString path = aName + wxFileName::GetPathSeparator() + dir_filename;
475  AddItemToTreeProject( path, newItemId, false, false );
476  } while( dir.GetNext( &dir_filename ) );
477  }
478  }
479 
480  // Sort filenames by alphabetic order
481  m_TreeProject->SortChildren( newItemId );
482  }
483 
484 #ifndef __WINDOWS__
485  if( subdir_populated )
487 #endif
488 
489  return newItemId;
490 }
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetProjectFileName() const
void SetRootFile(bool aValue)
TREEPROJECTFILES * m_TreeProject
#define NULL
TreeFileType
friend class TREEPROJECT_ITEM
KICAD_MANAGER_FRAME * m_Parent
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.
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)
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aCanResetFileWatcher=true, bool aRecurse=true)
Function AddItemToTreeProject.
const wxString & GetFileName() const
std::vector< wxString > m_filters
static wxString GetFileExt(TreeFileType type)
void SetPopulated(bool aValue)

References FileWatcherReset(), Format(), GetFileExt(), TREEPROJECT_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), m_filters, m_Parent, m_root, m_TreeProject, NULL, 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 1074 of file tree_project_frame.cpp.

1075 {
1076  // Prepare file watcher:
1077  if( m_watcher )
1078  {
1079  m_watcher->RemoveAll();
1080  }
1081  else
1082  {
1083  m_watcher = new wxFileSystemWatcher();
1084  m_watcher->SetOwner( this );
1085  }
1086 
1087  // We can see wxString under a debugger, not a wxFileName
1088  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
1089  wxFileName fn;
1090  fn.AssignDir( prj_dir );
1091  fn.DontFollowLink();
1092 
1093  // Add directories which should be monitored.
1094  // under windows, we add the curr dir and all subdirs
1095  // under unix, we add only the curr dir and the populated subdirs
1096  // see http://docs.wxwidgets.org/trunk/classwx_file_system_watcher.htm
1097  // under unix, the file watcher needs more work to be efficient
1098  // moreover, under wxWidgets 2.9.4, AddTree does not work properly.
1099 #ifdef __WINDOWS__
1100  m_watcher->AddTree( fn );
1101 #else
1102  m_watcher->Add( fn );
1103 
1104  // Add subdirs
1105  wxTreeItemIdValue cookie;
1106  wxTreeItemId root_id = m_root;
1107 
1108  std::stack < wxTreeItemId > subdirs_id;
1109 
1110  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
1111 
1112  while( true )
1113  {
1114  if( !kid.IsOk() )
1115  {
1116  if( subdirs_id.empty() ) // all items were explored
1117  break;
1118  else
1119  {
1120  root_id = subdirs_id.top();
1121  subdirs_id.pop();
1122  kid = m_TreeProject->GetFirstChild( root_id, cookie );
1123 
1124  if( !kid.IsOk() )
1125  continue;
1126  }
1127  }
1128 
1129  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1130 
1131  if( itemData && itemData->GetType() == TREE_DIRECTORY )
1132  {
1133  // we can see wxString under a debugger, not a wxFileName
1134  const wxString& path = itemData->GetFileName();
1135 
1136  wxLogTrace( tracePathsAndFiles, "%s: add '%s'\n", __func__, TO_UTF8( path ) );
1137 
1138  if( wxFileName::IsDirReadable( path ) ) // linux whines about watching protected dir
1139  {
1140  fn.AssignDir( path );
1141  m_watcher->Add( fn );
1142 
1143  // if kid is a subdir, push in list to explore it later
1144  if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
1145  subdirs_id.push( kid );
1146  }
1147  }
1148 
1149  kid = m_TreeProject->GetNextChild( root_id, cookie );
1150  }
1151 #endif
1152 
1153 #if defined(DEBUG) && 1
1154  wxArrayString paths;
1155  m_watcher->GetWatchedPaths( &paths );
1156  wxLogTrace( tracePathsAndFiles, "%s: watched paths:", __func__ );
1157 
1158  for( unsigned ii = 0; ii < paths.GetCount(); ii++ )
1159  wxLogTrace( tracePathsAndFiles, " %s\n", TO_UTF8( paths[ii] ) );
1160 #endif
1161 }
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetProjectFileName() const
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
bool IsPopulated() const
KICAD_MANAGER_FRAME * m_Parent
TREEPROJECT_ITEM * GetItemIdData(wxTreeItemId aId)
Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
wxFileSystemWatcher * m_watcher
#define TO_UTF8(wxstring)
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 AddItemToTreeProject(), 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 913 of file tree_project_frame.cpp.

914 {
915  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
916 
917  // If the subdir is the current working directory, return m_root
918  // in main list:
919  if( prj_dir == aSubDir )
920  return m_root;
921 
922  // The subdir is in the main tree or in a subdir: Locate it
923  wxTreeItemIdValue cookie;
924  wxTreeItemId root_id = m_root;
925  std::stack < wxTreeItemId > subdirs_id;
926 
927  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
928 
929  while( true )
930  {
931  if( ! kid.IsOk() )
932  {
933  if( subdirs_id.empty() ) // all items were explored
934  {
935  root_id = kid; // Not found: return an invalid wxTreeItemId
936  break;
937  }
938  else
939  {
940  root_id = subdirs_id.top();
941  subdirs_id.pop();
942  kid = m_TreeProject->GetFirstChild( root_id, cookie );
943 
944  if( ! kid.IsOk() )
945  continue;
946  }
947  }
948 
949  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
950 
951  if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
952  {
953  if( itemData->GetFileName() == aSubDir ) // Found!
954  {
955  root_id = kid;
956  break;
957  }
958 
959  // kid is a subdir, push in list to explore it later
960  if( itemData->IsPopulated() )
961  subdirs_id.push( kid );
962  }
963 
964  kid = m_TreeProject->GetNextChild( root_id, cookie );
965  }
966 
967  return root_id;
968 }
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetProjectFileName() const
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
bool IsPopulated() const
KICAD_MANAGER_FRAME * m_Parent
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 263 of file tree_project_frame.cpp.

264 {
265  switch( type )
266  {
267  case TREE_PROJECT: return ProjectFileExtension;
273  case TREE_HTML: return HtmlFileExtension;
274  case TREE_PDF: return PdfFileExtension;
275  case TREE_TXT: return TextFileExtension;
276  case TREE_NET: return NetlistFileExtension;
278  case TREE_REPORT: return ReportFileExtension;
280  case TREE_DRILL: return DrillFileExtension;
281  case TREE_DRILL_NC: return "nc";
282  case TREE_DRILL_XNC: return "xnc";
283  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 LegacySymbolLibFileExtension
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 PdfFileExtension
const std::string LegacySchematicFileExtension
const std::string PageLayoutDescrFileExtension
const std::string ReportFileExtension
const std::string KiCadSchematicFileExtension
const std::string SVGFileExtension
const std::string FootprintPlaceFileExtension
const std::string DrillFileExtension
const std::string KiCadSymbolLibFileExtension

References ComponentFileExtension, DrillFileExtension, FootprintPlaceFileExtension, GerberFileExtensionWildCard(), HtmlFileExtension, KiCadFootprintFileExtension, KiCadPcbFileExtension, KiCadSchematicFileExtension, KiCadSymbolLibFileExtension, LegacyPcbFileExtension, LegacySchematicFileExtension, LegacySymbolLibFileExtension, NetlistFileExtension, PageLayoutDescrFileExtension, PdfFileExtension, ProjectFileExtension, ReportFileExtension, 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_LEGACY_SCHEMATIC, TREE_NET, TREE_PAGE_LAYOUT_DESCR, TREE_PDF, TREE_PROJECT, TREE_REPORT, TREE_SCHEMATIC_LIBFILE, TREE_SEXPR_PCB, TREE_SEXPR_SCHEMATIC, TREE_SEXPR_SYMBOL_LIB_FILE, 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 corresponding to item id aId

Definition at line 907 of file tree_project_frame.cpp.

908 {
909  return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
910 }
TREEPROJECTFILES * m_TreeProject

References m_TreeProject.

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

◆ GetSelectedData()

std::vector< 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 893 of file tree_project_frame.cpp.

894 {
895  wxArrayTreeItemIds selection;
896  std::vector<TREEPROJECT_ITEM*> data;
897 
898  m_TreeProject->GetSelections( selection );
899 
900  for( auto it = selection.begin(); it != selection.end(); it++ )
901  data.push_back( GetItemIdData( *it ) );
902 
903  return data;
904 }
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 223 of file tree_project_frame.cpp.

224 {
225  // Get the root directory name:
226  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
227 
228  for( TREEPROJECT_ITEM* item_data : tree_data )
229  {
230  wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
231 
232  // Ask for the new sub directory name
233  wxString curr_dir = item_data->GetDir();
234 
235  if( !curr_dir.IsEmpty() ) // A subdir is selected
236  {
237  // Make this subdir name relative to the current path.
238  // It will be more easy to read by the user, in the next dialog
239  wxFileName fn;
240  fn.AssignDir( curr_dir );
241  fn.MakeRelativeTo( prj_dir );
242  curr_dir = fn.GetPath();
243 
244  if( !curr_dir.IsEmpty() )
245  curr_dir += wxFileName::GetPathSeparator();
246  }
247 
248  wxString msg =
249  wxString::Format( _( "Current project directory:\n%s" ), GetChars( prj_dir ) );
250  wxString subdir = wxGetTextFromUser( msg, _( "Create New Directory" ), curr_dir );
251 
252  if( subdir.IsEmpty() )
253  return;
254 
255  wxString full_dirname = prj_dir + wxFileName::GetPathSeparator() + subdir;
256 
257  // Make the new item and let the file watcher add it to the tree
258  wxMkdir( full_dirname );
259  }
260 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetProjectFileName() const
KICAD_MANAGER_FRAME * m_Parent
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:153
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
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), GetChars(), 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 753 of file tree_project_frame.cpp.

754 {
755  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
756  wxString msg, caption;
757 
758  if( tree_data.size() == 1 )
759  {
760  bool is_directory = wxDirExists( tree_data[0]->GetFileName() );
761  msg = wxString::Format(
762  _( "Are you sure you want to delete '%s'?" ), tree_data[0]->GetFileName() );
763  caption = is_directory ? _( "Delete Directory" ) : _( "Delete File" );
764  }
765  else
766  {
767  msg = wxString::Format(
768  _( "Are you sure you want to delete %lu items?" ), tree_data.size() );
769  caption = _( "Delete Multiple Items" );
770  }
771 
772  wxMessageDialog dialog( m_parent, msg, caption, wxYES_NO | wxICON_QUESTION );
773 
774  if( dialog.ShowModal() == wxID_YES )
775  {
776  for( TREEPROJECT_ITEM* item_data : tree_data )
777  item_data->Delete();
778  }
779 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
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
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), 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 831 of file tree_project_frame.cpp.

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

972 {
973  const wxFileName& pathModified = event.GetPath();
974  wxString subdir = pathModified.GetPath();
975  wxString fn = pathModified.GetFullPath();
976 
977  switch( event.GetChangeType() )
978  {
979  case wxFSW_EVENT_DELETE:
980  case wxFSW_EVENT_CREATE:
981  case wxFSW_EVENT_RENAME:
982  break;
983 
984  case wxFSW_EVENT_MODIFY:
985  case wxFSW_EVENT_ACCESS:
986  default:
987  return;
988  }
989 
990  wxTreeItemId root_id = findSubdirTreeItem( subdir );
991 
992  if( !root_id.IsOk() )
993  return;
994 
995  wxTreeItemIdValue cookie; // dummy variable needed by GetFirstChild()
996  wxTreeItemId kid = m_TreeProject->GetFirstChild( root_id, cookie );
997 
998  switch( event.GetChangeType() )
999  {
1000  case wxFSW_EVENT_CREATE:
1001  {
1002  wxTreeItemId newitem = AddItemToTreeProject( pathModified.GetFullPath(), root_id );
1003 
1004  // If we are in the process of renaming a file, select the new one
1005  // This is needed for MSW and OSX, since we don't get RENAME events from them, just a
1006  // pair of DELETE and CREATE events.
1007  if( m_isRenaming && newitem.IsOk() )
1008  {
1009  m_TreeProject->SelectItem( newitem );
1010  m_isRenaming = false;
1011  }
1012  }
1013  break;
1014 
1015  case wxFSW_EVENT_DELETE:
1016  while( kid.IsOk() )
1017  {
1018  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1019 
1020  if( itemData && itemData->GetFileName() == fn )
1021  {
1022  m_TreeProject->Delete( kid );
1023  return;
1024  }
1025  kid = m_TreeProject->GetNextChild( root_id, cookie );
1026  }
1027  break;
1028 
1029  case wxFSW_EVENT_RENAME :
1030  {
1031  const wxFileName& newpath = event.GetNewPath();
1032  wxString newdir = newpath.GetPath();
1033  wxString newfn = newpath.GetFullPath();
1034 
1035  while( kid.IsOk() )
1036  {
1037  TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
1038 
1039  if( itemData && itemData->GetFileName() == fn )
1040  {
1041  m_TreeProject->Delete( kid );
1042  break;
1043  }
1044 
1045  kid = m_TreeProject->GetNextChild( root_id, cookie );
1046  }
1047 
1048  // Add the new item only if it is not the current project file (root item).
1049  // Remember: this code is called by a wxFileSystemWatcherEvent event, and not always
1050  // called after an actual file rename, and the cleanup code does not explore the
1051  // root item, because it cannot be renamed by the user.
1052  TREEPROJECT_ITEM* rootData = GetItemIdData( root_id );
1053 
1054  if( newfn != rootData->GetFileName() )
1055  {
1056  wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
1057  wxTreeItemId newitem = AddItemToTreeProject( newfn, newroot_id );
1058 
1059  // If the item exists, select it
1060  if( newitem.IsOk() )
1061  m_TreeProject->SelectItem( newitem );
1062  }
1063 
1064  m_isRenaming = false;
1065  }
1066  break;
1067  }
1068 
1069  // Sort filenames by alphabetic order
1070  m_TreeProject->SortChildren( root_id );
1071 }
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 aCanResetFileWatcher=true, 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 183 of file tree_project_frame.cpp.

184 {
185  // Get the root directory name:
186  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
187 
188  for( TREEPROJECT_ITEM* item_data : tree_data )
189  {
190  // Ask for the new sub directory name
191  wxString curr_dir = item_data->GetDir();
192 
193  if( curr_dir.IsEmpty() )
194  {
195  // Use project path if the tree view path was empty.
196  curr_dir = wxPathOnly( m_Parent->GetProjectFileName() );
197 
198  // As a last resort use the user's documents folder.
199  if( curr_dir.IsEmpty() || !wxFileName::DirExists( curr_dir ) )
200  curr_dir = wxStandardPaths::Get().GetDocumentsDir();
201 
202  if( !curr_dir.IsEmpty() )
203  curr_dir += wxFileName::GetPathSeparator();
204  }
205 
206 #ifdef __WXMAC__
207  wxString msg;
208 
209  // Quote in case there are spaces in the path.
210  msg.Printf( "open \"%s\"", curr_dir );
211 
212  system( msg.c_str() );
213 #else
214  // Quote in case there are spaces in the path.
215  AddDelimiterString( curr_dir );
216 
217  wxLaunchDefaultApplication( curr_dir );
218 #endif
219  }
220 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const wxString GetProjectFileName() 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

References AddDelimiterString(), 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 727 of file tree_project_frame.cpp.

728 {
729  wxString editorname = Pgm().GetEditorName();
730 
731  if( editorname.IsEmpty() )
732  return;
733 
734  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
735 
736  wxString files;
737 
738  for( TREEPROJECT_ITEM* item_data : tree_data )
739  {
740  wxString fullFileName = item_data->GetFileName();
741  AddDelimiterString( fullFileName );
742 
743  if( !files.IsEmpty() )
744  files += " ";
745 
746  files += fullFileName;
747  }
748 
749  ExecuteFile( this, editorname, files );
750 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:42
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:174

References AddDelimiterString(), ExecuteFile(), GetSelectedData(), and Pgm().

◆ OnPrintFile()

void TREE_PROJECT_FRAME::OnPrintFile ( wxCommandEvent &  event)
private

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

Definition at line 782 of file tree_project_frame.cpp.

783 {
784  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
785 
786  for( TREEPROJECT_ITEM* item_data : tree_data )
787  item_data->Print();
788 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.

References GetSelectedData().

◆ OnRenameFile()

void TREE_PROJECT_FRAME::OnRenameFile ( wxCommandEvent &  event)
private

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

Definition at line 791 of file tree_project_frame.cpp.

792 {
793  wxTreeItemId curr_item = m_TreeProject->GetFocusedItem();
794  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
795 
796  // XXX: Unnecessary?
797  if( tree_data.size() != 1 )
798  return;
799 
800  wxString buffer = m_TreeProject->GetItemText( curr_item );
801  wxString msg = wxString::Format( _( "Change filename: \"%s\"" ),
802  tree_data[0]->GetFileName() );
803  wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
804 
805  if( dlg.ShowModal() != wxID_OK )
806  return; // canceled by user
807 
808  buffer = dlg.GetValue();
809  buffer.Trim( true );
810  buffer.Trim( false );
811 
812  if( buffer.IsEmpty() )
813  return; // empty file name not allowed
814 
815  tree_data[0]->Rename( buffer, true );
816  m_isRenaming = true;
817 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECTFILES * m_TreeProject
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
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), GetSelectedData(), m_isRenaming, and m_TreeProject.

◆ OnRight()

void TREE_PROJECT_FRAME::OnRight ( wxTreeEvent &  Event)
private

Called on a right click on an item.

Definition at line 558 of file tree_project_frame.cpp.

559 {
560  wxTreeItemId curr_item = Event.GetItem();
561 
562  // Ensure item is selected (Under Windows right click does not select the item)
563  m_TreeProject->SelectItem( curr_item );
564 
565  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
566 
567  bool can_switch_to_project = true;
568  bool can_create_new_directory = true;
569  bool can_open_this_directory = true;
570  bool can_edit = true;
571  bool can_rename = true;
572  bool can_delete = true;
573  bool can_print = true;
574 
575  if( tree_data.size() == 0 )
576  return;
577 
578  if( tree_data.size() != 1 )
579  {
580  can_switch_to_project = false;
581  can_create_new_directory = false;
582  can_rename = false;
583  can_print = false;
584  }
585 
586  if( curr_item == m_TreeProject->GetRootItem() )
587  can_switch_to_project = false;
588 
589  for( TREEPROJECT_ITEM* item_data : tree_data )
590  {
591  int tree_id = item_data->GetType();
592  wxString full_file_name = item_data->GetFileName();
593 
594  switch( tree_id )
595  {
596  case TREE_PROJECT:
597  can_edit = false;
598  can_rename = false;
599  can_delete = false;
600  can_print = false;
601  break;
602 
603  case TREE_DIRECTORY:
604  can_switch_to_project = false;
605  can_edit = false;
606  can_rename = false;
607  can_print = false;
608  break;
609 
610  default:
611  can_switch_to_project = false;
612  can_create_new_directory = false;
613  can_open_this_directory = false;
614 
615  if( !CanPrintFile( full_file_name ) )
616  can_print = false;
617 
618  break;
619  }
620  }
621 
622  wxMenu popup_menu;
623  wxString text;
624  wxString help_text;
625 
626  if( can_switch_to_project )
627  {
629  _( "Switch to this Project" ),
630  _( "Close all editors, and switch to the selected project" ),
632  popup_menu.AppendSeparator();
633  }
634 
635  if( can_create_new_directory )
636  {
637  AddMenuItem( &popup_menu, ID_PROJECT_NEWDIR, _( "New Directory..." ),
638  _( "Create a New Directory" ), KiBitmap( directory_xpm ) );
639  }
640 
641  if( can_open_this_directory )
642  {
643  if( tree_data.size() == 1 )
644  {
645 #ifdef __APPLE__
646  text = _( "Reveal in Finder" );
647  help_text = _( "Reveals the directory in a Finder window" );
648 #else
649  text = _( "Open Directory in File Explorer" );
650  help_text = _( "Opens the directory in the default system file manager" );
651 #endif
652  }
653  else
654  {
655 #ifdef __APPLE__
656  text = _( "Reveal in Finder" );
657  help_text = _( "Reveals the directories in a Finder window" );
658 #else
659  text = _( "Open Directories in File Explorer" );
660  help_text = _( "Opens the directories in the default system file manager" );
661 #endif
662  }
663 
664  AddMenuItem( &popup_menu, ID_PROJECT_OPEN_DIR, text, help_text,
666  }
667 
668  if( can_edit )
669  {
670  if( tree_data.size() == 1 )
671  help_text = _( "Open the file in a Text Editor" );
672  else
673  help_text = _( "Open files in a Text Editor" );
674 
675  AddMenuItem( &popup_menu, ID_PROJECT_TXTEDIT, _( "Edit in a Text Editor" ),
676  help_text, KiBitmap( editor_xpm ) );
677  }
678 
679  if( can_rename )
680  {
681  if( tree_data.size() == 1 )
682  {
683  text = _( "Rename File..." );
684  help_text = _( "Rename file" );
685  }
686  else
687  {
688  text = _( "Rename Files..." );
689  help_text = _( "Rename files" );
690  }
691 
692  AddMenuItem( &popup_menu, ID_PROJECT_RENAME, text, help_text, KiBitmap( right_xpm ) );
693  }
694 
695  if( can_delete )
696  {
697  if( tree_data.size() == 1 )
698  help_text = _( "Delete the file and its content" );
699  else
700  help_text = _( "Delete the files and their contents" );
701 
702  if( can_switch_to_project || can_create_new_directory || can_open_this_directory || can_edit
703  || can_rename )
704  popup_menu.AppendSeparator();
705 
706  AddMenuItem(
707  &popup_menu, ID_PROJECT_DELETE, _( "Delete" ), help_text, KiBitmap( delete_xpm ) );
708  }
709 
710  if( can_print )
711  {
712  popup_menu.AppendSeparator();
713  AddMenuItem( &popup_menu, ID_PROJECT_PRINT,
714 #ifdef __APPLE__
715  _( "Print..." ),
716 #else
717  _( "Print" ),
718 #endif
719  _( "Print the contents of the file" ), KiBitmap( print_button_xpm ) );
720  }
721 
722  if( popup_menu.GetMenuItemCount() > 0 )
723  PopupMenu( &popup_menu );
724 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
TREEPROJECT_ITEM handles one item (a file or a directory name) for the tree file.
const BITMAP_OPAQUE right_xpm[1]
Definition: right.cpp:49
const BITMAP_OPAQUE editor_xpm[1]
Definition: editor.cpp:83
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:232
const BITMAP_OPAQUE directory_browser_xpm[1]
TREEPROJECTFILES * m_TreeProject
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
const BITMAP_OPAQUE open_project_xpm[1]
const BITMAP_OPAQUE directory_xpm[1]
Definition: directory.cpp:30
#define _(s)
Definition: 3d_actions.cpp:33
bool CanPrintFile(const wxString &file)
Definition: gestfich.cpp:357
const BITMAP_OPAQUE delete_xpm[1]
Definition: delete.cpp:62

References _, AddMenuItem(), CanPrintFile(), delete_xpm, directory_browser_xpm, directory_xpm, editor_xpm, GetSelectedData(), 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, open_project_xpm, print_button_xpm, right_xpm, 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 820 of file tree_project_frame.cpp.

821 {
822  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
823 
824  if( tree_data.size() != 1 )
825  return;
826 
827  tree_data[0]->Activate( this );
828 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...

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

171 {
172  std::vector<TREEPROJECT_ITEM*> tree_data = GetSelectedData();
173 
174  if( tree_data.size() != 1 )
175  return;
176 
177  wxString prj_filename = tree_data[0]->GetFileName();
178 
179  m_Parent->LoadProject( prj_filename );
180 }
std::vector< TREEPROJECT_ITEM * > GetSelectedData()
Function GetSelectedData return the item data from item currently selected (highlighted) Note this is...
KICAD_MANAGER_FRAME * m_Parent
void LoadProject(const wxFileName &aProjectFileName)

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

494 {
495  wxString pro_dir = m_Parent->GetProjectFileName();
496 
497  if( !m_TreeProject )
498  m_TreeProject = new TREEPROJECTFILES( this );
499  else
500  m_TreeProject->DeleteAllItems();
501 
502  if( !pro_dir ) // This is empty from TREE_PROJECT_FRAME constructor
503  return;
504 
505  wxFileName fn = pro_dir;
506 
507  if( !fn.IsOk() )
508  {
509  fn.Clear();
510  fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
511  fn.SetName( NAMELESS_PROJECT );
512  fn.SetExt( ProjectFileExtension );
513  }
514 
515  bool prjOpened = fn.FileExists();
516 
517  // root tree:
518  m_root = m_TreeProject->AddRoot( fn.GetFullName(), TREE_ROOT, TREE_ROOT );
519  m_TreeProject->SetItemBold( m_root, true );
520  m_TreeProject->SetItemData( m_root, new TREEPROJECT_ITEM( TREE_PROJECT, fn.GetFullPath(),
521  m_TreeProject ) );
522 
523  // Now adding all current files if available
524  if( prjOpened )
525  {
526  pro_dir = wxPathOnly( m_Parent->GetProjectFileName() );
527  wxDir dir( pro_dir );
528 
529  if( dir.IsOpened() ) // protected dirs will not open, see "man opendir()"
530  {
531  wxString filename;
532  bool cont = dir.GetFirst( &filename );
533 
534  while( cont )
535  {
536  if( filename != fn.GetFullName() )
537  {
538  wxString name = dir.GetName() + wxFileName::GetPathSeparator() + filename;
539  AddItemToTreeProject( name, m_root, false );
540  }
541 
542  cont = dir.GetNext( &filename );
543  }
544  }
545  }
546  else
547  {
548  m_TreeProject->AppendItem( m_root, wxT( "Empty project" ) );
549  }
550 
551  m_TreeProject->Expand( m_root );
552 
553  // Sort filenames by alphabetic order
554  m_TreeProject->SortChildren( m_root );
555 }
const wxString GetProjectFileName() const
const std::string ProjectFileExtension
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 char * name
Definition: DXF_plotter.cpp:60
wxTreeItemId AddItemToTreeProject(const wxString &aName, wxTreeItemId &aRoot, bool aCanResetFileWatcher=true, 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: