KiCad PCB EDA Suite
PROJECT_TREE_ITEM Class Reference

PROJECT_TREE_ITEM handles one item (a file or a directory name) for the tree file. More...

#include <project_tree_item.h>

Inheritance diagram for PROJECT_TREE_ITEM:

Public Member Functions

 PROJECT_TREE_ITEM (TREE_FILE_TYPE type, const wxString &data, wxTreeCtrl *parent)
 Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and store info about a file or directory shown in the KiCad tree project files. More...
 
 PROJECT_TREE_ITEM ()
 
 PROJECT_TREE_ITEM (const PROJECT_TREE_ITEM &src)
 
TREE_FILE_TYPE GetType () const
 
void SetType (TREE_FILE_TYPE aType)
 
const wxString & GetFileName () const
 
void SetFileName (const wxString &name)
 
bool IsRootFile () const
 
void SetRootFile (bool aValue)
 
bool IsPopulated () const
 
void SetPopulated (bool aValue)
 
const wxString GetDir () const
 
bool Rename (const wxString &name, bool check=true)
 
void Delete ()
 
void Print ()
 
void Activate (PROJECT_TREE_PANE *aTreePrjFrame)
 
void SetState (int state)
 

Private Attributes

TREE_FILE_TYPE m_type
 
wxString m_file_name
 
bool m_isRootFile
 
bool m_isPopulated
 
wxTreeCtrl * m_parent
 
int m_state
 

Detailed Description

PROJECT_TREE_ITEM handles one item (a file or a directory name) for the tree file.

Definition at line 40 of file project_tree_item.h.

Constructor & Destructor Documentation

◆ PROJECT_TREE_ITEM() [1/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( TREE_FILE_TYPE  type,
const wxString &  data,
wxTreeCtrl *  parent 
)

Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and store info about a file or directory shown in the KiCad tree project files.

Definition at line 47 of file project_tree_item.cpp.

48  :
49  wxTreeItemData()
50 {
51  m_parent = parent;
52  SetType( type );
53  SetFileName( data );
54  SetRootFile( false ); // true only for the root item of the tree (the project name)
55  SetPopulated( false );
56  m_state = 0;
57 }
void SetFileName(const wxString &name)
void SetPopulated(bool aValue)
wxTreeCtrl * m_parent
void SetType(TREE_FILE_TYPE aType)
void SetRootFile(bool aValue)

References m_parent, m_state, SetFileName(), SetPopulated(), SetRootFile(), and SetType().

◆ PROJECT_TREE_ITEM() [2/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( )
inline

Definition at line 46 of file project_tree_item.h.

46  :
47  m_parent( NULL )
48  { }
#define NULL
wxTreeCtrl * m_parent

◆ PROJECT_TREE_ITEM() [3/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( const PROJECT_TREE_ITEM src)
inline

Definition at line 50 of file project_tree_item.h.

50  :
51  m_type( src.m_type ),
52  m_file_name( src.m_file_name ),
53  m_parent( src.m_parent )
54  {
55  SetState( src.m_state );
56  m_isPopulated = false;
57  }
void SetState(int state)
TREE_FILE_TYPE m_type
wxTreeCtrl * m_parent

References m_isPopulated, m_state, and SetState().

Member Function Documentation

◆ Activate()

void PROJECT_TREE_ITEM::Activate ( PROJECT_TREE_PANE aTreePrjFrame)

Definition at line 150 of file project_tree_item.cpp.

151 {
152  wxString sep = wxFileName::GetPathSeparator();
153  wxString fullFileName = GetFileName();
154  wxTreeItemId id = GetId();
155  std::string packet;
156 
157  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
158  TOOL_MANAGER* toolMgr = frame->GetToolManager();
159  KIWAY& kiway = frame->Kiway();
160 
161  switch( GetType() )
162  {
165  // Select a new project if this is not the current project:
166  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
167  frame->LoadProject( fullFileName );
168 
169  break;
170 
172  m_parent->Toggle( id );
173  break;
174 
177  // Schematics not part of the project are opened in a separate process.
178  if( fullFileName == frame->SchFileName() || fullFileName == frame->SchLegacyFileName() )
180  else
181  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
182 
183  break;
184 
187  // Boards not part of the project are opened in a separate process.
188  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
189  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
190  else
191  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
192 
193  break;
194 
200  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
201  break;
202 
204  wxLaunchDefaultBrowser( fullFileName );
205  break;
206 
207  case TREE_FILE_TYPE::PDF:
208  OpenPDF( fullFileName );
209  break;
210 
211  case TREE_FILE_TYPE::NET:
212  case TREE_FILE_TYPE::TXT:
214  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
215  break;
216 
218  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editDrawingSheet, true, &fullFileName );
219  break;
220 
223  packet = fullFileName.ToStdString();
225  break;
226 
230  packet = fullFileName.ToStdString();
232  break;
233 
234  default:
235  OpenFile( fullFileName );
236  break;
237  }
238 }
const wxString & GetFileName() const
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:56
TREE_FILE_TYPE GetType() const
const wxString SchLegacyFileName()
static TOOL_ACTION viewGerbers
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:451
static TOOL_ACTION editOtherPCB
Master controller class:
Definition: tool_manager.h:52
const wxString SchFileName()
static TOOL_ACTION editSchematic
PROJECT_TREE * m_TreeProject
static TOOL_ACTION editFootprints
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
wxTreeCtrl * m_parent
static TOOL_ACTION editOtherSch
static TOOL_ACTION editPCB
const wxString PcbLegacyFileName()
const wxString PcbFileName()
void OpenFile(const wxString &file)
Definition: gestfich.cpp:257
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void LoadProject(const wxFileName &aProjectFileName)
KICAD_MANAGER_FRAME * m_Parent
static TOOL_ACTION editSymbols
The main KiCad project manager frame.
static TOOL_ACTION openTextEditor
static TOOL_ACTION editDrawingSheet
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
Definition: gestfich.cpp:196

References DIRECTORY, DRILL, DRILL_NC, DRILL_XNC, KICAD_MANAGER_ACTIONS::editDrawingSheet, KICAD_MANAGER_ACTIONS::editFootprints, KICAD_MANAGER_ACTIONS::editOtherPCB, KICAD_MANAGER_ACTIONS::editOtherSch, KICAD_MANAGER_ACTIONS::editPCB, KICAD_MANAGER_ACTIONS::editSchematic, KICAD_MANAGER_ACTIONS::editSymbols, KIWAY::ExpressMail(), FOOTPRINT_FILE, FRAME_FOOTPRINT_EDITOR, FRAME_SCH_SYMBOL_EDITOR, GERBER, GERBER_JOB_FILE, GetFileName(), TOOLS_HOLDER::GetToolManager(), GetType(), HTML, JSON_PROJECT, KIWAY_HOLDER::Kiway(), LEGACY_PCB, LEGACY_PROJECT, LEGACY_SCHEMATIC, KICAD_MANAGER_FRAME::LoadProject(), m_parent, PROJECT_TREE_PANE::m_Parent, PROJECT_TREE_PANE::m_TreeProject, MAIL_FP_EDIT, MAIL_LIB_EDIT, NET, OpenFile(), OpenPDF(), KICAD_MANAGER_ACTIONS::openTextEditor, PAGE_LAYOUT_DESCR, KICAD_MANAGER_FRAME::PcbFileName(), KICAD_MANAGER_FRAME::PcbLegacyFileName(), PDF, REPORT, TOOL_MANAGER::RunAction(), SCHEMATIC_LIBFILE, KICAD_MANAGER_FRAME::SchFileName(), KICAD_MANAGER_FRAME::SchLegacyFileName(), SEXPR_PCB, SEXPR_SCHEMATIC, SEXPR_SYMBOL_LIB_FILE, TXT, and KICAD_MANAGER_ACTIONS::viewGerbers.

Referenced by PROJECT_TREE_PANE::onIdle().

◆ Delete()

void PROJECT_TREE_ITEM::Delete ( )

Definition at line 129 of file project_tree_item.cpp.

130 {
131  wxString errMsg;
132 
133  if( !KIPLATFORM::ENV::MoveToTrash( GetFileName(), errMsg ) )
134  {
135  wxString dialogMsg = wxString::Format( _( "Failed to delete '%s'"), GetFileName() );
136  DisplayErrorMessage( m_parent, dialogMsg, errMsg );
137  return;
138  }
139 
140  m_parent->Delete( GetId() );
141 }
const wxString & GetFileName() const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxTreeCtrl * m_parent
#define _(s)
Definition: 3d_actions.cpp:33
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.

References _, DisplayErrorMessage(), Format(), GetFileName(), m_parent, and KIPLATFORM::ENV::MoveToTrash().

◆ GetDir()

const wxString PROJECT_TREE_ITEM::GetDir ( ) const
Returns
the path of an item. if this item is a directory, returns the stored filename if this is a file, returns its path

Definition at line 75 of file project_tree_item.cpp.

76 {
78  return GetFileName();
79 
80  return wxFileName( GetFileName() ).GetPath();
81 }
const wxString & GetFileName() const
TREE_FILE_TYPE m_type

References DIRECTORY, GetFileName(), and m_type.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and Rename().

◆ GetFileName()

◆ GetType()

◆ IsPopulated()

bool PROJECT_TREE_ITEM::IsPopulated ( ) const
inline

◆ IsRootFile()

bool PROJECT_TREE_ITEM::IsRootFile ( ) const
inline

Definition at line 65 of file project_tree_item.h.

65 { return m_isRootFile; }

References m_isRootFile.

Referenced by PROJECT_TREE::OnCompareItems().

◆ Print()

void PROJECT_TREE_ITEM::Print ( )

Definition at line 144 of file project_tree_item.cpp.

145 {
146  PrintFile( GetFileName() );
147 }
const wxString & GetFileName() const
void PrintFile(const wxString &file)
Definition: gestfich.cpp:351

References GetFileName(), and PrintFile().

◆ Rename()

bool PROJECT_TREE_ITEM::Rename ( const wxString &  name,
bool  check = true 
)

Definition at line 84 of file project_tree_item.cpp.

85 {
86  // this is broken & unsafe to use on linux.
88  return false;
89 
90  if( name.IsEmpty() )
91  return false;
92 
93  const wxString sep = wxFileName().GetPathSeparator();
94  wxString newFile;
95  wxString dirs = GetDir();
96 
97  if( !dirs.IsEmpty() && GetType() != TREE_FILE_TYPE::DIRECTORY )
98  newFile = dirs + sep + name;
99  else
100  newFile = name;
101 
102  if( newFile == GetFileName() )
103  return false;
104 
105  wxString ext = PROJECT_TREE_PANE::GetFileExt( GetType() );
106  wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
107 
108  if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
109  {
110  wxMessageDialog dialog( m_parent, _( "Changing file extension will change file type.\n"
111  "Do you want to continue ?" ),
112  _( "Rename File" ), wxYES_NO | wxICON_QUESTION );
113 
114  if( wxID_YES != dialog.ShowModal() )
115  return false;
116  }
117 
118  if( !wxRenameFile( GetFileName(), newFile, false ) )
119  {
120  wxMessageDialog( m_parent, _( "Unable to rename file ... " ), _( "Permission error?" ),
121  wxICON_ERROR | wxOK );
122  return false;
123  }
124 
125  return true;
126 }
const wxString & GetFileName() const
TREE_FILE_TYPE GetType() const
TREE_FILE_TYPE m_type
const wxString GetDir() const
wxTreeCtrl * m_parent
const char * name
Definition: DXF_plotter.cpp:59
#define _(s)
Definition: 3d_actions.cpp:33
static wxString GetFileExt(TREE_FILE_TYPE type)

References _, DIRECTORY, GetDir(), PROJECT_TREE_PANE::GetFileExt(), GetFileName(), GetType(), m_parent, m_type, and name.

◆ SetFileName()

void PROJECT_TREE_ITEM::SetFileName ( const wxString &  name)
inline

Definition at line 63 of file project_tree_item.h.

63 { m_file_name = name; }
const char * name
Definition: DXF_plotter.cpp:59

References m_file_name, and name.

Referenced by PROJECT_TREE_ITEM().

◆ SetPopulated()

void PROJECT_TREE_ITEM::SetPopulated ( bool  aValue)
inline

◆ SetRootFile()

void PROJECT_TREE_ITEM::SetRootFile ( bool  aValue)
inline

Definition at line 66 of file project_tree_item.h.

66 { m_isRootFile = aValue; }

References m_isRootFile.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and PROJECT_TREE_ITEM().

◆ SetState()

void PROJECT_TREE_ITEM::SetState ( int  state)

Definition at line 60 of file project_tree_item.cpp.

61 {
62  wxImageList* imglist = m_parent->GetImageList();
63  int treeEnumMax = static_cast<int>( TREE_FILE_TYPE::MAX );
64 
65  if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( treeEnumMax - 2 ) )
66  return;
67 
68  m_state = state;
69  int imgid = static_cast<int>( m_type ) - 1 + state * ( treeEnumMax - 1 );
70  m_parent->SetItemImage( GetId(), imgid );
71  m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
72 }
TREE_FILE_TYPE m_type
wxTreeCtrl * m_parent

References m_parent, m_state, m_type, and MAX.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and PROJECT_TREE_ITEM().

◆ SetType()

void PROJECT_TREE_ITEM::SetType ( TREE_FILE_TYPE  aType)
inline

Definition at line 60 of file project_tree_item.h.

60 { m_type = aType; }
TREE_FILE_TYPE m_type

References m_type.

Referenced by PROJECT_TREE_ITEM().

Member Data Documentation

◆ m_file_name

wxString PROJECT_TREE_ITEM::m_file_name
private

Definition at line 87 of file project_tree_item.h.

Referenced by GetFileName(), and SetFileName().

◆ m_isPopulated

bool PROJECT_TREE_ITEM::m_isPopulated
private

Definition at line 89 of file project_tree_item.h.

Referenced by IsPopulated(), PROJECT_TREE_ITEM(), and SetPopulated().

◆ m_isRootFile

bool PROJECT_TREE_ITEM::m_isRootFile
private

Definition at line 88 of file project_tree_item.h.

Referenced by IsRootFile(), and SetRootFile().

◆ m_parent

wxTreeCtrl* PROJECT_TREE_ITEM::m_parent
private

Definition at line 90 of file project_tree_item.h.

Referenced by Activate(), Delete(), PROJECT_TREE_ITEM(), Rename(), and SetState().

◆ m_state

int PROJECT_TREE_ITEM::m_state
private

Definition at line 91 of file project_tree_item.h.

Referenced by PROJECT_TREE_ITEM(), and SetState().

◆ m_type

TREE_FILE_TYPE PROJECT_TREE_ITEM::m_type
private

Definition at line 86 of file project_tree_item.h.

Referenced by GetDir(), GetType(), Rename(), SetState(), and SetType().


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