KiCad PCB EDA Suite
TREEPROJECT_ITEM Class Reference

Class 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

Class 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 47 of file treeproject_item.h.

47 : m_parent( NULL ) { }
wxTreeCtrl * m_parent

◆ TREEPROJECT_ITEM() [3/3]

TREEPROJECT_ITEM::TREEPROJECT_ITEM ( const TREEPROJECT_ITEM src)
inline

Definition at line 49 of file treeproject_item.h.

49  :
50  m_Type( src.m_Type ), m_file_name( src.m_file_name ), m_parent( src.m_parent )
51  {
52  SetState( src.m_state );
53  m_IsPopulated = false;
54  }
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 164 of file treeproject_item.cpp.

165 {
166  wxString sep = wxFileName::GetPathSeparator();
167  wxString fullFileName = GetFileName();
168  wxTreeItemId id = GetId();
169  std::string packet;
170 
171  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
172  TOOL_MANAGER* toolMgr = frame->GetToolManager();
173  KIWAY& kiway = frame->Kiway();
174 
175  switch( GetType() )
176  {
177  case TREE_PROJECT:
178  // Select a new project if this is not the current project:
179  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
180  frame->LoadProject( fullFileName );
181  break;
182 
183  case TREE_DIRECTORY:
184  m_parent->Toggle( id );
185  break;
186 
187  case TREE_SCHEMA:
188  if( fullFileName == frame->SchFileName() )
189  {
191  }
192  else
193  {
194  // schematics not part of the project are opened in a separate process.
195  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
196  }
197  break;
198 
199  case TREE_LEGACY_PCB:
200  case TREE_SEXP_PCB:
201  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
202  {
203  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
204  }
205  else
206  {
207  // boards not part of the project are opened in a separate process.
208  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
209  }
210  break;
211 
212  case TREE_GERBER:
213  case TREE_DRILL:
214  case TREE_DRILL_NC:
215  case TREE_DRILL_XNC:
216  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
217  break;
218 
219  case TREE_HTML:
220  wxLaunchDefaultBrowser( fullFileName );
221  break;
222 
223  case TREE_PDF:
224  OpenPDF( fullFileName );
225  break;
226 
227  case TREE_NET:
228  case TREE_TXT:
229  case TREE_REPORT:
230  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
231  break;
232 
234  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editWorksheet, true, &fullFileName );
235  break;
236 
237  case TREE_FOOTPRINT_FILE:
239  packet = fullFileName.ToStdString();
241  break;
242 
245  packet = fullFileName.ToStdString();
247  break;
248 
249  default:
250  OpenFile( fullFileName );
251  break;
252  }
253 }
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:109
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
static TOOL_ACTION editOtherPCB
Class 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
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
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:407
static TOOL_ACTION editOtherSch
static TOOL_ACTION editPCB
const wxString PcbLegacyFileName()
const wxString PcbFileName()
void OpenFile(const wxString &file)
Definition: gestfich.cpp:256
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:209

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.

Referenced by TREE_PROJECT_FRAME::OnSelect().

◆ Delete()

void TREEPROJECT_ITEM::Delete ( )

Definition at line 129 of file treeproject_item.cpp.

130 {
131  wxString msg = wxString::Format( _( "Are you sure you want to delete '%s'?" ), GetFileName() );
132  wxMessageDialog dialog( m_parent, msg, _( "Delete File" ), wxYES_NO | wxICON_QUESTION );
133 
134  if( dialog.ShowModal() == wxID_YES )
135  {
136  bool success;
137 
138  if( !wxDirExists( GetFileName() ) )
139  success = wxRemoveFile( GetFileName() );
140  else
141  {
142  wxArrayString filelist;
143 
144  wxDir::GetAllFiles( GetFileName(), &filelist );
145 
146  for( unsigned int i = 0; i < filelist.Count(); i++ )
147  wxRemoveFile( filelist[i] );
148 
149  success = wxRmdir( GetFileName() );
150  }
151 
152  if( success )
153  m_parent->Delete( GetId() );
154  }
155 }
wxTreeCtrl * m_parent
#define _(s)
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
size_t i
Definition: json11.cpp:597
const wxString & GetFileName() const

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

Referenced by TREE_PROJECT_FRAME::OnDeleteFile().

◆ 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 TREE_PROJECT_FRAME::OnCreateNewDirectory(), TREE_PROJECT_FRAME::OnOpenDirectory(), and Rename().

◆ GetFileName()

◆ GetType()

◆ IsPopulated()

bool TREEPROJECT_ITEM::IsPopulated ( ) const
inline

◆ IsRootFile()

bool TREEPROJECT_ITEM::IsRootFile ( ) const
inline

Definition at line 62 of file treeproject_item.h.

62 { return m_IsRootFile; }

References m_IsRootFile.

Referenced by TREEPROJECTFILES::OnCompareItems().

◆ Print()

void TREEPROJECT_ITEM::Print ( )

Definition at line 158 of file treeproject_item.cpp.

159 {
160  PrintFile( GetFileName() );
161 }
void PrintFile(const wxString &file)
Definition: gestfich.cpp:350
const wxString & GetFileName() const

References GetFileName(), and PrintFile().

Referenced by TREE_PROJECT_FRAME::OnPrintFile().

◆ 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  SetFileName( newFile );
124 
125  return true;
126 }
TreeFileType GetType() const
const wxString GetDir() const
void SetFileName(const wxString &name)
wxTreeCtrl * m_parent
#define _(s)
const char * name
Definition: DXF_plotter.cpp:61
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, SetFileName(), and TREE_DIRECTORY.

Referenced by TREE_PROJECT_FRAME::OnRenameFile().

◆ SetFileName()

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

Definition at line 60 of file treeproject_item.h.

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

References m_file_name, and name.

Referenced by Rename(), and TREEPROJECT_ITEM().

◆ SetPopulated()

void TREEPROJECT_ITEM::SetPopulated ( bool  aValue)
inline

◆ SetRootFile()

void TREEPROJECT_ITEM::SetRootFile ( bool  aValue)
inline

Definition at line 63 of file treeproject_item.h.

63 { 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 57 of file treeproject_item.h.

57 { 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 84 of file treeproject_item.h.

Referenced by GetFileName(), and SetFileName().

◆ m_IsPopulated

bool TREEPROJECT_ITEM::m_IsPopulated
private

Definition at line 86 of file treeproject_item.h.

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

◆ m_IsRootFile

bool TREEPROJECT_ITEM::m_IsRootFile
private

Definition at line 85 of file treeproject_item.h.

Referenced by IsRootFile(), and SetRootFile().

◆ m_parent

wxTreeCtrl* TREEPROJECT_ITEM::m_parent
private

Definition at line 87 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 88 of file treeproject_item.h.

Referenced by SetState(), and TREEPROJECT_ITEM().

◆ m_Type

TreeFileType TREEPROJECT_ITEM::m_Type
private

Definition at line 83 of file treeproject_item.h.

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


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