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)
 
bool Delete (bool check=true)
 
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 46 of file treeproject_item.cpp.

47  :
48  wxTreeItemData()
49 {
50  m_parent = parent;
51  SetType( type );
52  SetFileName( data );
53  SetRootFile( false ); // true only for the root item of the tree (the project name)
54  SetPopulated( false );
55  m_state = 0;
56 }
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 163 of file treeproject_item.cpp.

164 {
165  wxString sep = wxFileName::GetPathSeparator();
166  wxString fullFileName = GetFileName();
167  wxTreeItemId id = GetId();
168  std::string packet;
169 
170  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
171  TOOL_MANAGER* toolMgr = frame->GetToolManager();
172  KIWAY& kiway = frame->Kiway();
173 
174  switch( GetType() )
175  {
176  case TREE_PROJECT:
177  // Select a new project if this is not the current project:
178  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
179  frame->LoadProject( fullFileName );
180  break;
181 
182  case TREE_DIRECTORY:
183  m_parent->Toggle( id );
184  break;
185 
186  case TREE_SCHEMA:
187  if( fullFileName == frame->SchFileName() )
188  {
190  }
191  else
192  {
193  // schematics not part of the project are opened in a separate process.
194  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
195  }
196  break;
197 
198  case TREE_LEGACY_PCB:
199  case TREE_SEXP_PCB:
200  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
201  {
202  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
203  }
204  else
205  {
206  // boards not part of the project are opened in a separate process.
207  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
208  }
209  break;
210 
211  case TREE_GERBER:
212  case TREE_DRILL:
213  case TREE_DRILL_NC:
214  case TREE_DRILL_XNC:
215  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
216  break;
217 
218  case TREE_HTML:
219  wxLaunchDefaultBrowser( fullFileName );
220  break;
221 
222  case TREE_PDF:
223  OpenPDF( fullFileName );
224  break;
225 
226  case TREE_NET:
227  case TREE_TXT:
228  case TREE_REPORT:
229  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
230  break;
231 
233  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editWorksheet, true, &fullFileName );
234  break;
235 
236  case TREE_FOOTPRINT_FILE:
238  packet = fullFileName.ToStdString();
240  break;
241 
244  packet = fullFileName.ToStdString();
246  break;
247 
248  default:
249  AddDelimiterString( fullFileName );
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
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:44
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:392
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:345

References AddDelimiterString(), 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_PCB_MODULE_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()

bool TREEPROJECT_ITEM::Delete ( bool  check = true)

Definition at line 130 of file treeproject_item.cpp.

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

74 {
75  if( TREE_DIRECTORY == m_Type )
76  return GetFileName();
77 
78  return wxFileName( GetFileName() ).GetPath();
79 }
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().

◆ Rename()

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

Definition at line 82 of file treeproject_item.cpp.

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

60 {
61  wxImageList* imglist = m_parent->GetImageList();
62 
63  if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
64  return;
65 
66  m_state = state;
67  int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
68  m_parent->SetItemImage( GetId(), imgid );
69  m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
70 }
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 83 of file treeproject_item.h.

Referenced by GetFileName(), and SetFileName().

◆ m_IsPopulated

bool TREEPROJECT_ITEM::m_IsPopulated
private

Definition at line 85 of file treeproject_item.h.

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

◆ m_IsRootFile

bool TREEPROJECT_ITEM::m_IsRootFile
private

Definition at line 84 of file treeproject_item.h.

Referenced by IsRootFile(), and SetRootFile().

◆ m_parent

wxTreeCtrl* TREEPROJECT_ITEM::m_parent
private

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

Referenced by SetState(), and TREEPROJECT_ITEM().

◆ m_Type

TreeFileType TREEPROJECT_ITEM::m_Type
private

Definition at line 82 of file treeproject_item.h.

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


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