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 SetRootFile(bool aValue)
wxTreeCtrl * m_parent
void SetType(TREE_FILE_TYPE aType)
void SetPopulated(bool aValue)
void SetFileName(const wxString &name)

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 { }

◆ 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 ),
52 m_parent( src.m_parent )
53 {
54 SetState( src.m_state );
55 m_isPopulated = false;
56 }
TREE_FILE_TYPE m_type
void SetState(int state)

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 fullFileName = GetFileName();
177 wxTreeItemId id = GetId();
178 std::string packet;
179
180 KICAD_MANAGER_FRAME* frame = aTreePrjFrame->m_Parent;
181 TOOL_MANAGER* toolMgr = frame->GetToolManager();
182 KIWAY& kiway = frame->Kiway();
183
184 switch( GetType() )
185 {
188 // Select a new project if this is not the current project:
189 if( id != aTreePrjFrame->m_TreeProject->GetRootItem() )
190 frame->LoadProject( fullFileName );
191
192 break;
193
195 m_parent->Toggle( id );
196 break;
197
200 // Schematics not part of the project are opened in a separate process.
201 if( fullFileName == frame->SchFileName() || fullFileName == frame->SchLegacyFileName() )
203 else
204 toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherSch, true, &fullFileName );
205
206 break;
207
210 // Boards not part of the project are opened in a separate process.
211 if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
213 else
214 toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editOtherPCB, true, &fullFileName );
215
216 break;
217
223 toolMgr->RunAction( KICAD_MANAGER_ACTIONS::viewGerbers, true, &fullFileName );
224 break;
225
227 wxLaunchDefaultBrowser( fullFileName );
228 break;
229
231 OpenPDF( fullFileName );
232 break;
233
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}
static TOOL_ACTION editPCB
static TOOL_ACTION editOtherPCB
static TOOL_ACTION editOtherSch
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION editFootprints
static TOOL_ACTION viewGerbers
static TOOL_ACTION editSymbols
The main KiCad project manager frame.
const wxString SchLegacyFileName()
const wxString SchFileName()
void LoadProject(const wxFileName &aProjectFileName)
const wxString PcbLegacyFileName()
const wxString PcbFileName()
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:274
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:491
const wxString & GetFileName() const
TREE_FILE_TYPE GetType() const
PROJECT_TREE * m_TreeProject
KICAD_MANAGER_FRAME * m_Parent
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
Master controller class:
Definition: tool_manager.h:55
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:41
bool OpenPDF(const wxString &file)
Run the PDF viewer and display a PDF file.
Definition: gestfich.cpp:159
void OpenFile(const wxString &file)
Definition: gestfich.cpp:195
@ MAIL_LIB_EDIT
Definition: mail_type.h:53
@ MAIL_FP_EDIT
Definition: mail_type.h:54

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, MD, 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}
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
#define _(s)
bool MoveToTrash(const wxString &aPath, wxString &aError)
Move the specified file/directory to the trash bin/recycle bin.
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

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}

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 char * name
Definition: DXF_plotter.cpp:56
bool CanRename() const
const wxString GetDir() const
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; }

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}

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; }

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: