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 148 of file treeproject_item.cpp.

149 {
150  wxString sep = wxFileName::GetPathSeparator();
151  wxString fullFileName = GetFileName();
152  wxTreeItemId id = GetId();
153  std::string packet;
154 
155  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
156  TOOL_MANAGER* toolMgr = frame->GetToolManager();
157  KIWAY& kiway = frame->Kiway();
158 
159  switch( GetType() )
160  {
161  case TREE_LEGACY_PROJECT:
162  case TREE_JSON_PROJECT:
163  // Select a new project if this is not the current project:
164  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
165  frame->LoadProject( fullFileName );
166 
167  break;
168 
169  case TREE_DIRECTORY:
170  m_parent->Toggle( id );
171  break;
172 
175  // Schematics not part of the project are opened in a separate process.
176  if( fullFileName == frame->SchFileName() || fullFileName == frame->SchLegacyFileName() )
178  else
179  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
180 
181  break;
182 
183  case TREE_LEGACY_PCB:
184  case TREE_SEXPR_PCB:
185  // Boards not part of the project are opened in a separate process.
186  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
187  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
188  else
189  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
190 
191  break;
192 
193  case TREE_GERBER:
195  case TREE_DRILL:
196  case TREE_DRILL_NC:
197  case TREE_DRILL_XNC:
198  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
199  break;
200 
201  case TREE_HTML:
202  wxLaunchDefaultBrowser( fullFileName );
203  break;
204 
205  case TREE_PDF:
206  OpenPDF( fullFileName );
207  break;
208 
209  case TREE_NET:
210  case TREE_TXT:
211  case TREE_REPORT:
212  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
213  break;
214 
216  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editWorksheet, true, &fullFileName );
217  break;
218 
219  case TREE_FOOTPRINT_FILE:
221  packet = fullFileName.ToStdString();
223  break;
224 
228  packet = fullFileName.ToStdString();
230  break;
231 
232  default:
233  OpenFile( fullFileName );
234  break;
235  }
236 }
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
const wxString SchLegacyFileName()
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:140
TreeFileType GetType() const
TREEPROJECTFILES * m_TreeProject
static TOOL_ACTION editOtherPCB
TOOL_MANAGER.
Definition: tool_manager.h:51
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:432
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:74
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(), TOOLS_HOLDER::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(), KICAD_MANAGER_FRAME::SchLegacyFileName(), TREE_DIRECTORY, TREE_DRILL, TREE_DRILL_NC, TREE_DRILL_XNC, TREE_FOOTPRINT_FILE, TREE_GERBER, TREE_GERBER_JOB_FILE, TREE_HTML, TREE_JSON_PROJECT, TREE_LEGACY_PCB, TREE_LEGACY_PROJECT, TREE_LEGACY_SCHEMATIC, TREE_NET, TREE_PAGE_LAYOUT_DESCR, TREE_PDF, TREE_REPORT, TREE_SCHEMATIC_LIBFILE, TREE_SEXPR_PCB, TREE_SEXPR_SCHEMATIC, TREE_SEXPR_SYMBOL_LIB_FILE, 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  bool success;
131 
132  if( !isDirectory )
133  success = wxRemoveFile( GetFileName() );
134  else
135  success = DeleteDirectory( GetFileName() );
136 
137  if( success )
138  m_parent->Delete( GetId() );
139 }
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
const wxString & GetFileName() const

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

◆ 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 142 of file treeproject_item.cpp.

143 {
144  PrintFile( GetFileName() );
145 }
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: