KiCad PCB EDA Suite
PROJECT_TREE_ITEM Class Reference

Handle one item (a file or a directory name) for the tree file. More...

#include <project_tree_item.h>

Inheritance diagram for PROJECT_TREE_ITEM:

Public Member Functions

 PROJECT_TREE_ITEM (TREE_FILE_TYPE type, const wxString &data, wxTreeCtrl *parent)
 Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and store info about a file or directory shown in the KiCad tree project files. More...
 
 PROJECT_TREE_ITEM ()
 
 PROJECT_TREE_ITEM (const PROJECT_TREE_ITEM &src)
 
TREE_FILE_TYPE GetType () const
 
void SetType (TREE_FILE_TYPE 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 (PROJECT_TREE_PANE *aTreePrjFrame)
 
void SetState (int state)
 
bool CanDelete () const
 Determine if a file can be deleted via the project tree pane. More...
 
bool CanRename () const
 

Private Attributes

TREE_FILE_TYPE m_type
 
wxString m_file_name
 
bool m_isRootFile
 
bool m_isPopulated
 
wxTreeCtrl * m_parent
 
int m_state
 

Detailed Description

Handle one item (a file or a directory name) for the tree file.

Definition at line 39 of file project_tree_item.h.

Constructor & Destructor Documentation

◆ PROJECT_TREE_ITEM() [1/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( TREE_FILE_TYPE  type,
const wxString &  data,
wxTreeCtrl *  parent 
)

Class PROJECT_TREE_ITEM is a derived class from wxTreeItemData and store info about a file or directory shown in the KiCad tree project files.

Definition at line 47 of file project_tree_item.cpp.

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

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

◆ PROJECT_TREE_ITEM() [2/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( )
inline

Definition at line 45 of file project_tree_item.h.

45  :
46  m_parent( nullptr )
47  { }
wxTreeCtrl * m_parent

◆ PROJECT_TREE_ITEM() [3/3]

PROJECT_TREE_ITEM::PROJECT_TREE_ITEM ( const PROJECT_TREE_ITEM src)
inline

Definition at line 49 of file project_tree_item.h.

49  :
50  m_type( src.m_type ),
51  m_file_name( src.m_file_name ),
52  m_parent( src.m_parent )
53  {
54  SetState( src.m_state );
55  m_isPopulated = false;
56  }
void SetState(int state)
TREE_FILE_TYPE m_type
wxTreeCtrl * m_parent

References m_isPopulated, m_state, and SetState().

Member Function Documentation

◆ Activate()

void PROJECT_TREE_ITEM::Activate ( PROJECT_TREE_PANE aTreePrjFrame)

Definition at line 174 of file project_tree_item.cpp.

175 {
176  wxString sep = wxFileName::GetPathSeparator();
177  wxString fullFileName = GetFileName();
178  wxTreeItemId id = GetId();
179  std::string packet;
180 
181  KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
182  TOOL_MANAGER* toolMgr = frame->GetToolManager();
183  KIWAY& kiway = frame->Kiway();
184 
185  switch( GetType() )
186  {
189  // Select a new project if this is not the current project:
190  if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
191  frame->LoadProject( fullFileName );
192 
193  break;
194 
196  m_parent->Toggle( id );
197  break;
198 
201  // Schematics not part of the project are opened in a separate process.
202  if( fullFileName == frame->SchFileName() || fullFileName == frame->SchLegacyFileName() )
204  else
205  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
206 
207  break;
208 
211  // Boards not part of the project are opened in a separate process.
212  if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
213  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );
214  else
215  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
216 
217  break;
218 
224  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
225  break;
226 
228  wxLaunchDefaultBrowser( fullFileName );
229  break;
230 
231  case TREE_FILE_TYPE::PDF:
232  OpenPDF( fullFileName );
233  break;
234 
235  case TREE_FILE_TYPE::NET:
236  case TREE_FILE_TYPE::TXT:
238  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::openTextEditor, true, &fullFileName );
239  break;
240 
242  toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editDrawingSheet, true, &fullFileName );
243  break;
244 
247  packet = fullFileName.ToStdString();
249  break;
250 
254  packet = fullFileName.ToStdString();
256  break;
257 
258  default:
259  OpenFile( fullFileName );
260  break;
261  }
262 }
const wxString & GetFileName() const
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
TREE_FILE_TYPE GetType() const
const wxString SchLegacyFileName()
static TOOL_ACTION viewGerbers
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:477
static TOOL_ACTION editOtherPCB
Master controller class:
Definition: tool_manager.h:54
const wxString SchFileName()
static TOOL_ACTION editSchematic
PROJECT_TREE * m_TreeProject
static TOOL_ACTION editFootprints
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
wxTreeCtrl * m_parent
static TOOL_ACTION editOtherSch
static TOOL_ACTION editPCB
const wxString PcbLegacyFileName()
const wxString PcbFileName()
void OpenFile(const wxString &file)
Definition: gestfich.cpp:195
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void LoadProject(const wxFileName &aProjectFileName)
KICAD_MANAGER_FRAME * m_Parent
static TOOL_ACTION editSymbols
The main KiCad project manager frame.
static TOOL_ACTION openTextEditor
static TOOL_ACTION editDrawingSheet
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
Definition: gestfich.cpp:159

References DIRECTORY, DRAWING_SHEET, DRILL, DRILL_NC, DRILL_XNC, KICAD_MANAGER_ACTIONS::editDrawingSheet, KICAD_MANAGER_ACTIONS::editFootprints, KICAD_MANAGER_ACTIONS::editOtherPCB, KICAD_MANAGER_ACTIONS::editOtherSch, KICAD_MANAGER_ACTIONS::editPCB, KICAD_MANAGER_ACTIONS::editSchematic, KICAD_MANAGER_ACTIONS::editSymbols, KIWAY::ExpressMail(), FOOTPRINT_FILE, FRAME_FOOTPRINT_EDITOR, FRAME_SCH_SYMBOL_EDITOR, GERBER, GERBER_JOB_FILE, GetFileName(), TOOLS_HOLDER::GetToolManager(), GetType(), HTML, JSON_PROJECT, KIWAY_HOLDER::Kiway(), LEGACY_PCB, LEGACY_PROJECT, LEGACY_SCHEMATIC, KICAD_MANAGER_FRAME::LoadProject(), m_parent, PROJECT_TREE_PANE::m_Parent, PROJECT_TREE_PANE::m_TreeProject, MAIL_FP_EDIT, MAIL_LIB_EDIT, NET, OpenFile(), OpenPDF(), KICAD_MANAGER_ACTIONS::openTextEditor, KICAD_MANAGER_FRAME::PcbFileName(), KICAD_MANAGER_FRAME::PcbLegacyFileName(), PDF, REPORT, TOOL_MANAGER::RunAction(), SCHEMATIC_LIBFILE, KICAD_MANAGER_FRAME::SchFileName(), KICAD_MANAGER_FRAME::SchLegacyFileName(), SEXPR_PCB, SEXPR_SCHEMATIC, SEXPR_SYMBOL_LIB_FILE, TXT, and KICAD_MANAGER_ACTIONS::viewGerbers.

Referenced by PROJECT_TREE_PANE::onIdle().

◆ CanDelete()

bool PROJECT_TREE_ITEM::CanDelete ( ) const

Determine if a file can be deleted via the project tree pane.

Note
Any of the files that could potentially break a project are flagged as cannot delete or rename.
Returns
false if the file managed by this item cannot be deleted or true if it can.

Definition at line 75 of file project_tree_item.cpp.

References DESIGN_RULES, DIRECTORY, DRAWING_SHEET, FOOTPRINT_FILE, JSON_PROJECT, LEGACY_PCB, LEGACY_PROJECT, LEGACY_SCHEMATIC, m_type, SCHEMATIC_LIBFILE, SEXPR_PCB, SEXPR_SCHEMATIC, and SEXPR_SYMBOL_LIB_FILE.

Referenced by CanRename(), and Delete().

◆ CanRename()

bool PROJECT_TREE_ITEM::CanRename ( ) const
inline

Definition at line 92 of file project_tree_item.h.

92 { return CanDelete(); }
bool CanDelete() const
Determine if a file can be deleted via the project tree pane.

References CanDelete().

Referenced by Rename().

◆ Delete()

void PROJECT_TREE_ITEM::Delete ( )

Definition at line 149 of file project_tree_item.cpp.

150 {
151  if( !CanDelete() )
152  return;
153 
154  wxString errMsg;
155 
156  if( !KIPLATFORM::ENV::MoveToTrash( GetFileName(), errMsg ) )
157  {
158 #ifdef __WINDOWS__
159  wxString dialogMsg = wxString::Format( _( "Can not move '%s' to recycle bin."),
160  GetFileName() );
161 #else
162  wxString dialogMsg = wxString::Format( _( "Can not move '%s' to trash."),
163  GetFileName() );
164 #endif
165 
166  DisplayErrorMessage( m_parent, dialogMsg, errMsg );
167  return;
168  }
169 
170  m_parent->Delete( GetId() );
171 }
const wxString & GetFileName() const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
bool CanDelete() const
Determine if a file can be deleted via the project tree pane.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxTreeCtrl * m_parent
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.

References _, CanDelete(), DisplayErrorMessage(), Format(), GetFileName(), m_parent, and KIPLATFORM::ENV::MoveToTrash().

◆ GetDir()

const wxString PROJECT_TREE_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 95 of file project_tree_item.cpp.

96 {
98  return GetFileName();
99 
100  return wxFileName( GetFileName() ).GetPath();
101 }
const wxString & GetFileName() const
TREE_FILE_TYPE m_type

References DIRECTORY, GetFileName(), and m_type.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and Rename().

◆ GetFileName()

◆ GetType()

◆ IsPopulated()

bool PROJECT_TREE_ITEM::IsPopulated ( ) const
inline

◆ IsRootFile()

bool PROJECT_TREE_ITEM::IsRootFile ( ) const
inline

Definition at line 64 of file project_tree_item.h.

64 { return m_isRootFile; }

References m_isRootFile.

Referenced by PROJECT_TREE::OnCompareItems().

◆ Print()

void PROJECT_TREE_ITEM::Print ( )

◆ Rename()

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

Definition at line 104 of file project_tree_item.cpp.

105 {
106  // this is broken & unsafe to use on linux.
107  if( !CanRename() )
108  return false;
109 
110  if( name.IsEmpty() )
111  return false;
112 
113  const wxString sep = wxFileName().GetPathSeparator();
114  wxString newFile;
115  wxString dirs = GetDir();
116 
117  if( !dirs.IsEmpty() && GetType() != TREE_FILE_TYPE::DIRECTORY )
118  newFile = dirs + sep + name;
119  else
120  newFile = name;
121 
122  if( newFile == GetFileName() )
123  return false;
124 
125  wxString ext = PROJECT_TREE_PANE::GetFileExt( GetType() );
126  wxRegEx reg( wxT( "^.*\\" ) + ext + wxT( "$" ), wxRE_ICASE );
127 
128  if( check && !ext.IsEmpty() && !reg.Matches( newFile ) )
129  {
130  wxMessageDialog dialog( m_parent, _( "Changing file extension will change file type.\n"
131  "Do you want to continue ?" ),
132  _( "Rename File" ), wxYES_NO | wxICON_QUESTION );
133 
134  if( wxID_YES != dialog.ShowModal() )
135  return false;
136  }
137 
138  if( !wxRenameFile( GetFileName(), newFile, false ) )
139  {
140  wxMessageDialog( m_parent, _( "Unable to rename file ... " ), _( "Permission error?" ),
141  wxICON_ERROR | wxOK );
142  return false;
143  }
144 
145  return true;
146 }
const wxString & GetFileName() const
TREE_FILE_TYPE GetType() const
bool CanRename() const
#define _(s)
const wxString GetDir() const
wxTreeCtrl * m_parent
const char * name
Definition: DXF_plotter.cpp:56
static wxString GetFileExt(TREE_FILE_TYPE type)

References _, CanRename(), DIRECTORY, GetDir(), PROJECT_TREE_PANE::GetFileExt(), GetFileName(), GetType(), m_parent, and name.

◆ SetFileName()

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

Definition at line 62 of file project_tree_item.h.

62 { m_file_name = name; }
const char * name
Definition: DXF_plotter.cpp:56

References m_file_name, and name.

Referenced by PROJECT_TREE_ITEM().

◆ SetPopulated()

void PROJECT_TREE_ITEM::SetPopulated ( bool  aValue)
inline

◆ SetRootFile()

void PROJECT_TREE_ITEM::SetRootFile ( bool  aValue)
inline

Definition at line 65 of file project_tree_item.h.

65 { m_isRootFile = aValue; }

References m_isRootFile.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and PROJECT_TREE_ITEM().

◆ SetState()

void PROJECT_TREE_ITEM::SetState ( int  state)

Definition at line 60 of file project_tree_item.cpp.

61 {
62  wxImageList* imglist = m_parent->GetImageList();
63  int treeEnumMax = static_cast<int>( TREE_FILE_TYPE::MAX );
64 
65  if( !imglist || state < 0 || state >= imglist->GetImageCount() / ( treeEnumMax - 2 ) )
66  return;
67 
68  m_state = state;
69  int imgid = static_cast<int>( m_type ) - 1 + state * ( treeEnumMax - 1 );
70  m_parent->SetItemImage( GetId(), imgid );
71  m_parent->SetItemImage( GetId(), imgid, wxTreeItemIcon_Selected );
72 }
TREE_FILE_TYPE m_type
wxTreeCtrl * m_parent

References m_parent, m_state, m_type, and MAX.

Referenced by PROJECT_TREE_PANE::addItemToProjectTree(), and PROJECT_TREE_ITEM().

◆ SetType()

void PROJECT_TREE_ITEM::SetType ( TREE_FILE_TYPE  aType)
inline

Definition at line 59 of file project_tree_item.h.

59 { m_type = aType; }
TREE_FILE_TYPE m_type

References m_type.

Referenced by PROJECT_TREE_ITEM().

Member Data Documentation

◆ m_file_name

wxString PROJECT_TREE_ITEM::m_file_name
private

Definition at line 96 of file project_tree_item.h.

Referenced by GetFileName(), and SetFileName().

◆ m_isPopulated

bool PROJECT_TREE_ITEM::m_isPopulated
private

Definition at line 98 of file project_tree_item.h.

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

◆ m_isRootFile

bool PROJECT_TREE_ITEM::m_isRootFile
private

Definition at line 97 of file project_tree_item.h.

Referenced by IsRootFile(), and SetRootFile().

◆ m_parent

wxTreeCtrl* PROJECT_TREE_ITEM::m_parent
private

Definition at line 99 of file project_tree_item.h.

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

◆ m_state

int PROJECT_TREE_ITEM::m_state
private

Definition at line 100 of file project_tree_item.h.

Referenced by PROJECT_TREE_ITEM(), and SetState().

◆ m_type

TREE_FILE_TYPE PROJECT_TREE_ITEM::m_type
private

Definition at line 95 of file project_tree_item.h.

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


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