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 <class_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 *prjframe)
 
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 class_treeproject_item.h.

Constructor & Destructor Documentation

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

Definition at line 44 of file class_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)
void SetType(TreeFileType aType)
void SetPopulated(bool aValue)
TREEPROJECT_ITEM::TREEPROJECT_ITEM ( )
inline

Definition at line 47 of file class_treeproject_item.h.

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

Definition at line 49 of file class_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  }

Member Function Documentation

void TREEPROJECT_ITEM::Activate ( TREE_PROJECT_FRAME prjframe)

Definition at line 167 of file class_treeproject_item.cpp.

References AddDelimiterString(), EESCHEMA_EXE, KICAD_MANAGER_FRAME::Execute(), GERBVIEW_EXE, PGM_BASE::GetEditorName(), GetFileName(), GetType(), ID_TO_PCB, ID_TO_SCH, TREE_PROJECT_FRAME::m_Parent, m_parent, OpenFile(), OpenPDF(), KICAD_MANAGER_FRAME::PcbFileName(), KICAD_MANAGER_FRAME::PcbLegacyFileName(), PCBNEW_EXE, Pgm(), PL_EDITOR_EXE, KICAD_MANAGER_FRAME::SchFileName(), TREE_DIRECTORY, TREE_GERBER, TREE_HTML, TREE_LEGACY_PCB, TREE_NET, TREE_PAGE_LAYOUT_DESCR, TREE_PDF, TREE_PROJECT, TREE_SCHEMA, TREE_SEXP_PCB, and TREE_TXT.

Referenced by TREE_PROJECT_FRAME::OnSelect().

168 {
169  wxString sep = wxFileName().GetPathSeparator();
170  wxString fullFileName = GetFileName();
171  wxTreeItemId id = GetId();
172 
173  KICAD_MANAGER_FRAME* frame = prjframe->m_Parent;
174  wxASSERT( frame );
175 
176  switch( GetType() )
177  {
178  case TREE_PROJECT:
179  break;
180 
181  case TREE_DIRECTORY:
182  m_parent->Toggle( id );
183  break;
184 
185  case TREE_SCHEMA:
186  if( fullFileName == frame->SchFileName() )
187  {
188  // the project's schematic is opened using the *.kiface as part of this process.
189  // We do not call frame->RunEeschema( fullFileName ),
190  // because after the double click, for some reason,
191  // the tree project frame is brought to the foreground after Eeschema is called from here.
192  // Instead, we post an event, equivalent to click on the eeschema tool in command frame
193  wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_TO_SCH );
194  wxPostEvent( frame, evt );
195  }
196  else
197  {
198  // schematics not part of the project are opened in a separate process.
199  frame->Execute( m_parent, EESCHEMA_EXE, fullFileName );
200  }
201  break;
202 
203  case TREE_LEGACY_PCB:
204  case TREE_SEXP_PCB:
205  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
206  {
207  // the project's BOARD is opened using the *.kiface as part of this process.
208  // We do not call frame->RunPcbNew( fullFileName ),
209  // because after the double click, for some reason,
210  // the tree project frame is brought to the foreground after PcbNew is called from here.
211  // Instead, we post an event, equivalent to simple click on the pcb editor tool in command frame
212  wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_TO_PCB );
213  wxPostEvent( frame, evt );
214  }
215  else
216  {
217  // boards not part of the project are opened in a separate process.
218  frame->Execute( m_parent, PCBNEW_EXE, fullFileName );
219  }
220  break;
221 
222  case TREE_GERBER:
223  frame->Execute( m_parent, GERBVIEW_EXE, fullFileName );
224  break;
225 
226  case TREE_HTML:
227  wxLaunchDefaultBrowser( fullFileName );
228  break;
229 
230  case TREE_PDF:
231  OpenPDF( fullFileName );
232  break;
233 
234  case TREE_NET:
235  // Nothing to do ( can be read only by Pcbnew, or by a text editor)
236  break;
237 
238  case TREE_TXT:
239  {
240  wxString editorname = Pgm().GetEditorName();
241 
242  if( !editorname.IsEmpty() )
243  frame->Execute( m_parent, editorname, fullFileName );
244  }
245  break;
246 
248  frame->Execute( m_parent, PL_EDITOR_EXE, fullFileName );
249  break;
250 
251  default:
252  AddDelimiterString( fullFileName );
253  OpenFile( fullFileName );
254  break;
255  }
256 }
Definition: kicad.h:59
const wxString PL_EDITOR_EXE
const wxString PCBNEW_EXE
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
Definition: kicad.h:61
const wxString GERBVIEW_EXE
const wxString SchFileName()
Definition: mainframe.cpp:153
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:272
TreeFileType GetType() const
KICAD_MANAGER_FRAME * m_Parent
void AddDelimiterString(wxString &string)
Function AddDelimiterString Add un " to the start and the end of string (if not already done)...
Definition: gestfich.cpp:44
const wxString PcbLegacyFileName()
Definition: mainframe.cpp:173
const wxString PcbFileName()
Definition: mainframe.cpp:163
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:338
Definition: kicad.h:60
The main KiCad project manager frame.
Definition: kicad.h:136
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 class_treeproject_item.cpp.

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

Referenced by TREE_PROJECT_FRAME::OnDeleteFile().

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
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
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 class_treeproject_item.cpp.

References GetFileName(), m_Type, and TREE_DIRECTORY.

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

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

Definition at line 62 of file class_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 class_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().

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
TreeFileType GetType() const
const char * name
const wxString & GetFileName() const
static wxString GetFileExt(TreeFileType type)
void TREEPROJECT_ITEM::SetFileName ( const wxString &  name)
inline

Definition at line 60 of file class_treeproject_item.h.

References m_file_name, and name.

Referenced by Rename(), and TREEPROJECT_ITEM().

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

Definition at line 63 of file class_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 class_treeproject_item.cpp.

References m_parent, m_state, m_Type, and TREE_MAX.

Referenced by TREE_PROJECT_FRAME::AddItemToTreeProject(), 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 }
Definition: kicad.h:72
void TREEPROJECT_ITEM::SetType ( TreeFileType  aType)
inline

Definition at line 57 of file class_treeproject_item.h.

References m_Type.

Referenced by TREEPROJECT_ITEM().

57 { m_Type = aType; }

Member Data Documentation

wxString TREEPROJECT_ITEM::m_file_name
private

Definition at line 83 of file class_treeproject_item.h.

Referenced by GetFileName(), and SetFileName().

bool TREEPROJECT_ITEM::m_IsPopulated
private

Definition at line 85 of file class_treeproject_item.h.

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

bool TREEPROJECT_ITEM::m_IsRootFile
private

Definition at line 84 of file class_treeproject_item.h.

Referenced by IsRootFile(), and SetRootFile().

wxTreeCtrl* TREEPROJECT_ITEM::m_parent
private

Definition at line 86 of file class_treeproject_item.h.

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

int TREEPROJECT_ITEM::m_state
private

Definition at line 87 of file class_treeproject_item.h.

Referenced by SetState(), and TREEPROJECT_ITEM().

TreeFileType TREEPROJECT_ITEM::m_Type
private

Definition at line 82 of file class_treeproject_item.h.

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


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