KiCad PCB EDA Suite
TREEPROJECT_ITEM Class Reference

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

#include <treeproject_item.h>

Inheritance diagram for TREEPROJECT_ITEM:

Public Member Functions

 TREEPROJECT_ITEM (TreeFileType type, const wxString &data, wxTreeCtrl *parent)
 
 TREEPROJECT_ITEM ()
 
 TREEPROJECT_ITEM (const TREEPROJECT_ITEM &src)
 
TreeFileType GetType () const
 
void SetType (TreeFileType 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 (TREE_PROJECT_FRAME *aTreePrjFrame)
 
void SetState (int state)
 

Private Attributes

TreeFileType m_Type
 
wxString m_file_name
 
bool m_IsRootFile
 
bool m_IsPopulated
 
wxTreeCtrl * m_parent
 
int m_state
 

Detailed Description

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

Definition at line 38 of file treeproject_item.h.

Constructor & Destructor Documentation

◆ TREEPROJECT_ITEM() [1/3]

TREEPROJECT_ITEM::TREEPROJECT_ITEM ( TreeFileType  type,
const wxString &  data,
wxTreeCtrl *  parent 
)

Definition at line 45 of file treeproject_item.cpp.

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

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

◆ TREEPROJECT_ITEM() [2/3]

TREEPROJECT_ITEM::TREEPROJECT_ITEM ( )
inline

Definition at line 45 of file treeproject_item.h.

45 : m_parent( NULL ) { }
#define NULL
wxTreeCtrl * m_parent

◆ TREEPROJECT_ITEM() [3/3]

TREEPROJECT_ITEM::TREEPROJECT_ITEM ( const TREEPROJECT_ITEM src)
inline

Definition at line 47 of file treeproject_item.h.

47  :
48  m_Type( src.m_Type ), m_file_name( src.m_file_name ), m_parent( src.m_parent )
49  {
50  SetState( src.m_state );
51  m_IsPopulated = false;
52  }
wxTreeCtrl * m_parent
void SetState(int state)
TreeFileType m_Type

References m_IsPopulated, m_state, and SetState().

Member Function Documentation

◆ Activate()

void TREEPROJECT_ITEM::Activate ( TREE_PROJECT_FRAME aTreePrjFrame)

Definition at line 156 of file treeproject_item.cpp.

157 {
158  wxString sep = wxFileName::GetPathSeparator();
159  wxString fullFileName = GetFileName();
160  wxTreeItemId id = GetId();
161  std::string packet;
162 
163  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
164  TOOL_MANAGER* toolMgr = frame->GetToolManager();
165  KIWAY& kiway = frame->Kiway();
166 
167  switch( GetType() )
168  {
169  case TREE_PROJECT:
170  // Select a new project if this is not the current project:
171  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
172  frame->LoadProject( fullFileName );
173  break;
174 
175  case TREE_DIRECTORY:
176  m_parent->Toggle( id );
177  break;
178 
179  case TREE_SCHEMA:
180  if( fullFileName == frame->SchFileName() )
181  {
183  }
184  else
185  {
186  // schematics not part of the project are opened in a separate process.
187  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
188  }
189  break;
190 
191  case TREE_LEGACY_PCB:
192  case TREE_SEXP_PCB:
193  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
194  {
195  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
196  }
197  else
198  {
199  // boards not part of the project are opened in a separate process.
200  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
201  }
202  break;
203 
204  case TREE_GERBER:
205  case TREE_DRILL:
206  case TREE_DRILL_NC:
207  case TREE_DRILL_XNC:
208  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
209  break;
210 
211  case TREE_HTML:
212  wxLaunchDefaultBrowser( fullFileName );
213  break;
214 
215  case TREE_PDF:
216  OpenPDF( fullFileName );
217  break;
218 
219  case TREE_NET:
220  case TREE_TXT:
221  case TREE_REPORT:
222  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
223  break;
224 
226  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editWorksheet, true, &fullFileName );
227  break;
228 
229  case TREE_FOOTPRINT_FILE:
231  packet = fullFileName.ToStdString();
233  break;
234 
237  packet = fullFileName.ToStdString();
239  break;
240 
241  default:
242  OpenFile( fullFileName );
243  break;
244  }
245 }
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
static TOOL_ACTION viewGerbers
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
static TOOL_ACTION editOtherPCB
TOOL_MANAGER.
Definition: tool_manager.h:50
const wxString SchFileName()
static TOOL_ACTION editSchematic
wxTreeCtrl * m_parent
KICAD_MANAGER_FRAME * m_Parent
static TOOL_ACTION editFootprints
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
static TOOL_ACTION editWorksheet
VTBL_ENTRY void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=NULL)
Function ExpressMail send aPayload to aDestination from aSource.
Definition: kiway.cpp:427
static TOOL_ACTION editOtherSch
static TOOL_ACTION editPCB
const wxString PcbLegacyFileName()
const wxString PcbFileName()
void OpenFile(const wxString &file)
Definition: gestfich.cpp:257
void LoadProject(const wxFileName &aProjectFileName)
const wxString & GetFileName() const
static TOOL_ACTION editSymbols
The main KiCad project manager frame.
static TOOL_ACTION openTextEditor
bool OpenPDF(const wxString &file)
Function OpenPDF run the PDF viewer and display a PDF file.
Definition: gestfich.cpp:205

References KICAD_MANAGER_ACTIONS::editFootprints, KICAD_MANAGER_ACTIONS::editOtherPCB, KICAD_MANAGER_ACTIONS::editOtherSch, KICAD_MANAGER_ACTIONS::editPCB, KICAD_MANAGER_ACTIONS::editSchematic, KICAD_MANAGER_ACTIONS::editSymbols, KICAD_MANAGER_ACTIONS::editWorksheet, KIWAY::ExpressMail(), FRAME_FOOTPRINT_EDITOR, FRAME_SCH_LIB_EDITOR, GetFileName(), EDA_BASE_FRAME::GetToolManager(), GetType(), KIWAY_HOLDER::Kiway(), KICAD_MANAGER_FRAME::LoadProject(), TREE_PROJECT_FRAME::m_Parent, m_parent, TREE_PROJECT_FRAME::m_TreeProject, MAIL_FP_EDIT, MAIL_LIB_EDIT, OpenFile(), OpenPDF(), KICAD_MANAGER_ACTIONS::openTextEditor, KICAD_MANAGER_FRAME::PcbFileName(), KICAD_MANAGER_FRAME::PcbLegacyFileName(), TOOL_MANAGER::RunAction(), KICAD_MANAGER_FRAME::SchFileName(), TREE_DIRECTORY, TREE_DRILL, TREE_DRILL_NC, TREE_DRILL_XNC, TREE_FOOTPRINT_FILE, 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_TXT, and KICAD_MANAGER_ACTIONS::viewGerbers.

◆ Delete()

void TREEPROJECT_ITEM::Delete ( )

Definition at line 127 of file treeproject_item.cpp.

128 {
129  bool isDirectory = wxDirExists( GetFileName() );
130 
131  wxString msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ), GetFileName() );
132  wxMessageDialog dialog( m_parent, msg, isDirectory ? _( "Delete Directory" ) : _( "Delete File" ),
133  wxYES_NO | wxICON_QUESTION );
134 
135  if( dialog.ShowModal() == wxID_YES )
136  {
137  bool success;
138 
139  if( !isDirectory )
140  success = wxRemoveFile( GetFileName() );
141  else
142  success = DeleteDirectory( GetFileName() );
143 
144  if( success )
145  m_parent->Delete( GetId() );
146  }
147 }
bool DeleteDirectory(const wxString &aDirName, bool aRecurse, bool aIncludeHidden)
Delete a directory and all of its contents recursively.
Definition: gestfich.cpp:384
wxTreeCtrl * m_parent
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
const wxString & GetFileName() const

References _, DeleteDirectory(), Format(), GetFileName(), and m_parent.

◆ GetDir()

const wxString TREEPROJECT_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 72 of file treeproject_item.cpp.

73 {
74  if( TREE_DIRECTORY == m_Type )
75  return GetFileName();
76 
77  return wxFileName( GetFileName() ).GetPath();
78 }
const wxString & GetFileName() const
TreeFileType m_Type

References GetFileName(), m_Type, and TREE_DIRECTORY.

Referenced by Rename().

◆ GetFileName()

◆ GetType()

TreeFileType TREEPROJECT_ITEM::GetType ( ) const
inline

◆ IsPopulated()

bool TREEPROJECT_ITEM::IsPopulated ( ) const
inline

◆ IsRootFile()

bool TREEPROJECT_ITEM::IsRootFile ( ) const
inline

Definition at line 60 of file treeproject_item.h.

60 { return m_IsRootFile; }

References m_IsRootFile.

Referenced by TREEPROJECTFILES::OnCompareItems().

◆ Print()

void TREEPROJECT_ITEM::Print ( )

Definition at line 150 of file treeproject_item.cpp.

151 {
152  PrintFile( GetFileName() );
153 }
void PrintFile(const wxString &file)
Definition: gestfich.cpp:351
const wxString & GetFileName() const

References GetFileName(), and PrintFile().

◆ Rename()

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

Definition at line 81 of file treeproject_item.cpp.

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

References _, GetDir(), TREE_PROJECT_FRAME::GetFileExt(), GetFileName(), GetType(), m_parent, m_Type, name, and TREE_DIRECTORY.

◆ SetFileName()

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

Definition at line 58 of file treeproject_item.h.

58 { m_file_name = name; }
const char * name
Definition: DXF_plotter.cpp:60

References m_file_name, and name.

Referenced by TREEPROJECT_ITEM().

◆ SetPopulated()

void TREEPROJECT_ITEM::SetPopulated ( bool  aValue)
inline

◆ SetRootFile()

void TREEPROJECT_ITEM::SetRootFile ( bool  aValue)
inline

Definition at line 61 of file treeproject_item.h.

61 { m_IsRootFile = aValue; }

References m_IsRootFile.

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

◆ SetState()

void TREEPROJECT_ITEM::SetState ( int  state)

Definition at line 58 of file treeproject_item.cpp.

59 {
60  wxImageList* imglist = m_parent->GetImageList();
61 
62  if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
63  return;
64 
65  m_state = state;
66  int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
67  m_parent->SetItemImage( GetId(), imgid );
68  m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
69 }
wxTreeCtrl * m_parent
TreeFileType m_Type

References m_parent, m_state, m_Type, and TREE_MAX.

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

◆ SetType()

void TREEPROJECT_ITEM::SetType ( TreeFileType  aType)
inline

Definition at line 55 of file treeproject_item.h.

55 { m_Type = aType; }
TreeFileType m_Type

References m_Type.

Referenced by TREEPROJECT_ITEM().

Member Data Documentation

◆ m_file_name

wxString TREEPROJECT_ITEM::m_file_name
private

Definition at line 82 of file treeproject_item.h.

Referenced by GetFileName(), and SetFileName().

◆ m_IsPopulated

bool TREEPROJECT_ITEM::m_IsPopulated
private

Definition at line 84 of file treeproject_item.h.

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

◆ m_IsRootFile

bool TREEPROJECT_ITEM::m_IsRootFile
private

Definition at line 83 of file treeproject_item.h.

Referenced by IsRootFile(), and SetRootFile().

◆ m_parent

wxTreeCtrl* TREEPROJECT_ITEM::m_parent
private

Definition at line 85 of file treeproject_item.h.

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

◆ m_state

int TREEPROJECT_ITEM::m_state
private

Definition at line 86 of file treeproject_item.h.

Referenced by SetState(), and TREEPROJECT_ITEM().

◆ m_Type

TreeFileType TREEPROJECT_ITEM::m_Type
private

Definition at line 81 of file treeproject_item.h.

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


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