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::TREEPROJECT_ITEM ( TreeFileType  type,
const wxString &  data,
wxTreeCtrl *  parent 
)

Definition at line 44 of file treeproject_item.cpp.

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

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

Definition at line 47 of file treeproject_item.h.

47 : m_parent( NULL ) { }
wxTreeCtrl * m_parent
TREEPROJECT_ITEM::TREEPROJECT_ITEM ( const TREEPROJECT_ITEM src)
inline

Definition at line 49 of file treeproject_item.h.

References m_IsPopulated, m_state, and SetState().

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

Member Function Documentation

void TREEPROJECT_ITEM::Activate ( TREE_PROJECT_FRAME aTreePrjFrame)

Definition at line 167 of file treeproject_item.cpp.

References AddDelimiterString(), dummy(), EESCHEMA_EXE, KICAD_MANAGER_FRAME::Execute(), KIWAY::ExpressMail(), FRAME_PCB_MODULE_EDITOR, FRAME_SCH_LIB_EDITOR, GERBVIEW_EXE, PGM_BASE::GetEditorName(), GetFileName(), GetType(), ID_TO_PCB, ID_TO_SCH, 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, KICAD_MANAGER_FRAME::OnRunPcbFpEditor(), KICAD_MANAGER_FRAME::OnRunSchLibEditor(), OpenFile(), OpenPDF(), KICAD_MANAGER_FRAME::PcbFileName(), KICAD_MANAGER_FRAME::PcbLegacyFileName(), PCBNEW_EXE, Pgm(), PL_EDITOR_EXE, KICAD_MANAGER_FRAME::SchFileName(), TREE_DIRECTORY, TREE_DRILL, 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, and TREE_TXT.

Referenced by TREE_PROJECT_FRAME::OnSelect(), and SetPopulated().

168 {
169  wxString sep = wxFileName().GetPathSeparator();
170  wxString fullFileName = GetFileName();
171  wxTreeItemId id = GetId();
172 
173  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
174  KIWAY& kiway = frame->Kiway();
175 
176  switch( GetType() )
177  {
178  case TREE_PROJECT:
179  // Select a new project if this is not the current project:
180  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
181  frame->LoadProject( fullFileName );
182  break;
183 
184  case TREE_DIRECTORY:
185  m_parent->Toggle( id );
186  break;
187 
188  case TREE_SCHEMA:
189  if( fullFileName == frame->SchFileName() )
190  {
191  // the project's schematic is opened using the *.kiface as part of this process.
192  // We do not call frame->RunEeschema( fullFileName ),
193  // because after the double click, for some reason,
194  // the tree project frame is brought to the foreground after Eeschema is called from here.
195  // Instead, we post an event, equivalent to click on the eeschema tool in command frame
196  wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_TO_SCH );
197  wxPostEvent( frame, evt );
198  }
199  else
200  {
201  // schematics not part of the project are opened in a separate process.
202  frame->Execute( m_parent, EESCHEMA_EXE, fullFileName );
203  }
204  break;
205 
206  case TREE_LEGACY_PCB:
207  case TREE_SEXP_PCB:
208  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
209  {
210  // the project's BOARD is opened using the *.kiface as part of this process.
211  // We do not call frame->RunPcbNew( fullFileName ),
212  // because after the double click, for some reason,
213  // the tree project frame is brought to the foreground after PcbNew is called from here.
214  // Instead, we post an event, equivalent to simple click on the pcb editor tool in command frame
215  wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_TO_PCB );
216  wxPostEvent( frame, evt );
217  }
218  else
219  {
220  // boards not part of the project are opened in a separate process.
221  frame->Execute( m_parent, PCBNEW_EXE, fullFileName );
222  }
223  break;
224 
225  case TREE_GERBER:
226  frame->Execute( m_parent, GERBVIEW_EXE, fullFileName );
227  break;
228 
229  case TREE_HTML:
230  wxLaunchDefaultBrowser( fullFileName );
231  break;
232 
233  case TREE_PDF:
234  OpenPDF( fullFileName );
235  break;
236 
237  case TREE_NET:
238  case TREE_DRILL:
239  case TREE_TXT:
240  case TREE_REPORT:
241  {
242  wxString editorname = Pgm().GetEditorName();
243 
244  if( !editorname.IsEmpty() )
245  frame->Execute( m_parent, editorname, fullFileName );
246  }
247  break;
248 
250  frame->Execute( m_parent, PL_EDITOR_EXE, fullFileName );
251  break;
252 
253  case TREE_FOOTPRINT_FILE:
254  {
255  wxCommandEvent dummy;
256  frame->OnRunPcbFpEditor( dummy );
257  kiway.ExpressMail( FRAME_PCB_MODULE_EDITOR, MAIL_FP_EDIT, fullFileName.ToStdString() );
258  }
259  break;
260 
262  {
263  wxCommandEvent dummy;
264  frame->OnRunSchLibEditor( dummy );
265  kiway.ExpressMail( FRAME_SCH_LIB_EDITOR, MAIL_LIB_EDIT, fullFileName.ToStdString() );
266  }
267  break;
268 
269  default:
270  AddDelimiterString( fullFileName );
271  OpenFile( fullFileName );
272  break;
273  }
274 }
Definition: kicad.h:59
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
const wxString PL_EDITOR_EXE
void OnRunPcbFpEditor(wxCommandEvent &event)
Definition: mainframe.cpp:404
const wxString PCBNEW_EXE
void OnRunSchLibEditor(wxCommandEvent &event)
Definition: mainframe.cpp:337
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
TREEPROJECTFILES * m_TreeProject
Definition: kicad.h:61
const wxString GERBVIEW_EXE
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:386
const wxString SchFileName()
Definition: mainframe.cpp:146
const wxString EESCHEMA_EXE
void Execute(wxWindow *frame, const wxString &execFile, wxString param=wxEmptyString)
Open another KiCad application and logs a message.
Definition: mainframe.cpp:265
wxTreeCtrl * m_parent
TreeFileType GetType() const
KICAD_MANAGER_FRAME * m_Parent
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
General-puspose messages.
Definition: mail_type.h:52
const wxString PcbLegacyFileName()
Definition: mainframe.cpp:166
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
const wxString PcbFileName()
Definition: mainframe.cpp:156
void OpenFile(const wxString &file)
Definition: gestfich.cpp:392
const wxString & GetFileName() const
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:203
Definition: kicad.h:60
void LoadProject(const wxFileName &aProjectFileName)
Definition: prjconfig.cpp:61
The main KiCad project manager frame.
Definition: kicad.h:135
bool OpenPDF(const wxString &file)
Function OpenPDF run the PDF viewer and display a PDF file.
Definition: gestfich.cpp:345
bool TREEPROJECT_ITEM::Delete ( bool  check = true)

Definition at line 129 of file treeproject_item.cpp.

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

Referenced by TREE_PROJECT_FRAME::OnDeleteFile(), and SetPopulated().

130 {
131  wxString msg = wxString::Format( _(
132  "Do you really want to delete \"%s\"" ),
133  GetChars( GetFileName() )
134  );
135 
136  wxMessageDialog dialog( m_parent, msg,
137  _( "Delete File" ), wxYES_NO | wxICON_QUESTION );
138 
139  if( !check || wxID_YES == dialog.ShowModal() )
140  {
141  bool success;
142 
143  if( !wxDirExists( GetFileName() ) )
144  success = wxRemoveFile( GetFileName() );
145  else
146  {
147  wxArrayString filelist;
148 
149  wxDir::GetAllFiles( GetFileName(), &filelist );
150 
151  for( unsigned int i = 0; i < filelist.Count(); i++ )
152  wxRemoveFile( filelist[i] );
153 
154  success = wxRmdir( GetFileName() );
155  }
156 
157  if( success )
158  m_parent->Delete( GetId() );
159 
160  return success;
161  }
162 
163  return false;
164 }
static list_size_check check
wxTreeCtrl * m_parent
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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
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 71 of file treeproject_item.cpp.

References GetFileName(), m_Type, and TREE_DIRECTORY.

Referenced by TREE_PROJECT_FRAME::OnCreateNewDirectory(), Rename(), and SetPopulated().

72 {
73  if( TREE_DIRECTORY == m_Type )
74  return GetFileName();
75 
76  return wxFileName( GetFileName() ).GetPath();
77 }
const wxString & GetFileName() const
TreeFileType m_Type
bool TREEPROJECT_ITEM::IsPopulated ( ) const
inline
bool TREEPROJECT_ITEM::IsRootFile ( ) const
inline

Definition at line 62 of file treeproject_item.h.

References m_IsRootFile.

Referenced by TREEPROJECTFILES::OnCompareItems().

62 { return m_IsRootFile; }
bool TREEPROJECT_ITEM::Rename ( const wxString &  name,
bool  check = true 
)

Definition at line 80 of file treeproject_item.cpp.

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

Referenced by TREE_PROJECT_FRAME::OnRenameFile(), and SetPopulated().

81 {
82  // this is broken & unsafe to use on linux.
83  if( m_Type == TREE_DIRECTORY )
84  return false;
85 
86  if( name.IsEmpty() )
87  return false;
88 
89  const wxString sep = wxFileName().GetPathSeparator();
90  wxString newFile;
91  wxString dirs = GetDir();
92 
93  if( !dirs.IsEmpty() && GetType() != TREE_DIRECTORY )
94  newFile = dirs + sep + name;
95  else
96  newFile = name;
97 
98  if( newFile == GetFileName() )
99  return false;
100 
101  wxString ext = TREE_PROJECT_FRAME::GetFileExt( GetType() );
102 
103  wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
104 
105  if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
106  {
107  wxMessageDialog dialog( m_parent, _(
108  "Changing file extension will change file type.\n Do you want to continue ?" ),
109  _( "Rename File" ),
110  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 ... " ),
119  _( "Permission error ?" ), wxICON_ERROR | wxOK );
120  return false;
121  }
122 
123  SetFileName( newFile );
124 
125  return true;
126 }
void SetFileName(const wxString &name)
const wxString GetDir() const
static list_size_check check
wxTreeCtrl * m_parent
TreeFileType GetType() const
const char * name
Definition: DXF_plotter.cpp:61
const wxString & GetFileName() const
static wxString GetFileExt(TreeFileType type)
TreeFileType m_Type
void TREEPROJECT_ITEM::SetFileName ( const wxString &  name)
inline

Definition at line 60 of file treeproject_item.h.

References m_file_name, and name.

Referenced by Rename(), and TREEPROJECT_ITEM().

60 { m_file_name = name; }
const char * name
Definition: DXF_plotter.cpp:61
void TREEPROJECT_ITEM::SetPopulated ( bool  aValue)
inline
void TREEPROJECT_ITEM::SetRootFile ( bool  aValue)
inline

Definition at line 63 of file treeproject_item.h.

References m_IsRootFile.

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

63 { m_IsRootFile = aValue; }
void TREEPROJECT_ITEM::SetState ( int  state)

Definition at line 57 of file treeproject_item.cpp.

References m_parent, m_state, m_Type, and TREE_MAX.

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

58 {
59  wxImageList* imglist = m_parent->GetImageList();
60 
61  if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( TREE_MAX - 2 ) )
62  return;
63 
64  m_state = state;
65  int imgid = m_Type - 1 + state * ( TREE_MAX - 1 );
66  m_parent->SetItemImage( GetId(), imgid );
67  m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
68 }
wxTreeCtrl * m_parent
Definition: kicad.h:72
TreeFileType m_Type
void TREEPROJECT_ITEM::SetType ( TreeFileType  aType)
inline

Definition at line 57 of file treeproject_item.h.

References m_Type.

Referenced by TREEPROJECT_ITEM().

57 { m_Type = aType; }
TreeFileType m_Type

Member Data Documentation

wxString TREEPROJECT_ITEM::m_file_name
private

Definition at line 83 of file treeproject_item.h.

Referenced by GetFileName(), and SetFileName().

bool TREEPROJECT_ITEM::m_IsPopulated
private

Definition at line 85 of file treeproject_item.h.

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

bool TREEPROJECT_ITEM::m_IsRootFile
private

Definition at line 84 of file treeproject_item.h.

Referenced by IsRootFile(), and SetRootFile().

wxTreeCtrl* TREEPROJECT_ITEM::m_parent
private

Definition at line 86 of file treeproject_item.h.

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

int TREEPROJECT_ITEM::m_state
private

Definition at line 87 of file treeproject_item.h.

Referenced by SetState(), and TREEPROJECT_ITEM().

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: