KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PROJECT_TREE_PANE Class Reference

PROJECT_TREE_PANE Window to display the tree files. More...

#include <project_tree_pane.h>

Inheritance diagram for PROJECT_TREE_PANE:

Public Member Functions

 PROJECT_TREE_PANE (KICAD_MANAGER_FRAME *parent)
 The frame that shows the tree list of files and subdirectories inside the working directory.
 
 ~PROJECT_TREE_PANE ()
 
void ReCreateTreePrj ()
 Create or modify the tree showing project file names.
 
void FileWatcherReset ()
 Reinit the watched paths Should be called after opening a new project to rebuild the list of watched paths.
 
void EmptyTreePrj ()
 Delete all m_TreeProject entries.
 

Public Attributes

KICAD_MANAGER_FRAMEm_Parent
 
PROJECT_TREEm_TreeProject
 

Protected Member Functions

std::vector< PROJECT_TREE_ITEM * > GetSelectedData ()
 Function GetSelectedData return the item data from item currently selected (highlighted) Note this is not necessary the "clicked" item, because when expanding, collapsing an item this item is not selected.
 
PROJECT_TREE_ITEMGetItemIdData (wxTreeItemId aId)
 Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.
 

Static Protected Member Functions

static wxString GetFileExt (TREE_FILE_TYPE type)
 

Private Member Functions

void onSelect (wxTreeEvent &Event)
 Called on a double click on an item.
 
void onExpand (wxTreeEvent &Event)
 Called on a click on the + or - button of an item with children.
 
void onRight (wxTreeEvent &Event)
 Called on a right click on an item.
 
void onOpenSelectedFileWithTextEditor (wxCommandEvent &event)
 Function onOpenSelectedFileWithTextEditor Call the text editor to open the selected file in the tree project.
 
void onDeleteFile (wxCommandEvent &event)
 Function onDeleteFile Delete the selected file or directory in the tree project.
 
void onRenameFile (wxCommandEvent &event)
 Function onRenameFile Rename the selected file or directory in the tree project.
 
void onOpenDirectory (wxCommandEvent &event)
 Function onOpenDirectory Handles the right-click menu for opening a directory in the current system file browser.
 
void onCreateNewDirectory (wxCommandEvent &event)
 Function onCreateNewDirectory Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a directory name.
 
void onSwitchToSelectedProject (wxCommandEvent &event)
 Switch to a other project selected from the tree project (by selecting an other .pro file inside the current project folder)
 
void onIdle (wxIdleEvent &aEvent)
 Idle event handler, used process the selected items at a point in time when all other events have been consumed.
 
void onPaint (wxPaintEvent &aEvent)
 We don't have uniform borders so we have to draw them ourselves.
 
void onGitInitializeProject (wxCommandEvent &event)
 Initialize a new git repository in the current project directory.
 
void onGitCommit (wxCommandEvent &event)
 Commit the current project saved changes to the git repository.
 
void onGitPullProject (wxCommandEvent &event)
 Pull the latest changes from the git repository.
 
void onGitPushProject (wxCommandEvent &event)
 Push the current project changes to the git repository.
 
void onGitSwitchBranch (wxCommandEvent &event)
 Switch to a different branch in the git repository.
 
void onGitCompare (wxCommandEvent &event)
 Compare the current project to a different branch in the git repository.
 
void onGitRemoveVCS (wxCommandEvent &event)
 Remove the git repository from the current project directory.
 
void onGitAddToIndex (wxCommandEvent &event)
 Add a file to the git index.
 
void onGitRemoveFromIndex (wxCommandEvent &event)
 Remove a file from the git index.
 
void onGitSyncProject (wxCommandEvent &event)
 Sync the current project with the git repository.
 
void onGitFetch (wxCommandEvent &event)
 Fetch the latest changes from the git repository.
 
void onGitResolveConflict (wxCommandEvent &event)
 Resolve conflicts in the git repository.
 
void onGitRevertLocal (wxCommandEvent &event)
 Revert the local repository to the last commit.
 
void updateGitStatusIcons ()
 Updates the icons shown in the tree project to reflect the current git status.
 
bool hasChangedFiles ()
 Returns true if the current project has any uncommitted changes.
 
bool hasLocalCommits ()
 Returns true if the current project has local commits that have not been pushed to the remote repository.
 
void shutdownFileWatcher ()
 Shutdown the file watcher.
 
wxTreeItemId addItemToProjectTree (const wxString &aName, const wxTreeItemId &aParent, std::vector< wxString > *aProjectNames, bool aRecurse)
 Function addItemToProjectTree.
 
wxTreeItemId findSubdirTreeItem (const wxString &aSubDir)
 Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirectory aSubDir.
 
void onFileSystemEvent (wxFileSystemWatcherEvent &event)
 called when a file or directory is modified/created/deleted The tree project is modified when a file or directory is created/deleted/renamed to reflect the file change
 
void onThemeChanged (wxSysColourChangedEvent &aEvent)
 
bool canFileBeAddedToVCS (const wxString &aFilePath)
 Returns true if the file has already been added to the repository or false if it has not been added yet.
 

Private Attributes

bool m_isRenaming
 
wxTreeItemId m_root
 
std::vector< wxString > m_filters
 
wxFileSystemWatcherm_watcher
 
PROJECT_TREE_ITEMm_selectedItem
 
bool m_watcherNeedReset
 
wxDateTime m_lastGitStatusUpdate
 
int m_gitLastError
 

Friends

class PROJECT_TREE_ITEM
 

Detailed Description

PROJECT_TREE_PANE Window to display the tree files.

Definition at line 49 of file project_tree_pane.h.

Constructor & Destructor Documentation

◆ PROJECT_TREE_PANE()

PROJECT_TREE_PANE::PROJECT_TREE_PANE ( KICAD_MANAGER_FRAME parent)

The frame that shows the tree list of files and subdirectories inside the working directory.

Files are filtered (see s_allowedExtensionsToList) so only useful files are shown.

Definition at line 177 of file project_tree_pane.cpp.

References onFileSystemEvent(), onThemeChanged(), and s_allowedExtensionsToList.

◆ ~PROJECT_TREE_PANE()

PROJECT_TREE_PANE::~PROJECT_TREE_PANE ( )

Definition at line 210 of file project_tree_pane.cpp.

References shutdownFileWatcher().

Member Function Documentation

◆ addItemToProjectTree()

wxTreeItemId PROJECT_TREE_PANE::addItemToProjectTree ( const wxString &  aName,
const wxTreeItemId &  aParent,
std::vector< wxString > *  aProjectNames,
bool  aRecurse 
)
private

Function addItemToProjectTree.

Add the file or directory aName to the project tree

Parameters
aName= the filename or the directory name to add in tree
aParent= the wxTreeItemId item where to add sub tree items
aRecurse= true to add file or subdir names to the current tree item false to stop file add.
Returns
the Id for the new tree item

Definition at line 389 of file project_tree_pane.cpp.

References addItemToProjectTree(), alg::contains(), PROJECT_TREE_ITEM::GetDir(), GetFileExt(), PROJECT_TREE_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), getProjects(), PROJECT_TREE_ITEM::GetType(), KIPLATFORM::IO::IsFileHidden(), m_filters, m_Parent, m_TreeProject, m_watcherNeedReset, path, project, PROJECT_TREE_ITEM, PROJECT_TREE_ITEM::SetPopulated(), PROJECT_TREE_ITEM::SetRootFile(), and PROJECT_TREE_ITEM::SetState().

Referenced by addItemToProjectTree(), onCreateNewDirectory(), onExpand(), onFileSystemEvent(), and ReCreateTreePrj().

◆ canFileBeAddedToVCS()

bool PROJECT_TREE_PANE::canFileBeAddedToVCS ( const wxString &  aFilePath)
private

Returns true if the file has already been added to the repository or false if it has not been added yet.

Definition at line 2298 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), and m_TreeProject.

◆ EmptyTreePrj()

void PROJECT_TREE_PANE::EmptyTreePrj ( )

◆ FileWatcherReset()

void PROJECT_TREE_PANE::FileWatcherReset ( )

Reinit the watched paths Should be called after opening a new project to rebuild the list of watched paths.

Should be called after the main loop event handler is started

Definition at line 1366 of file project_tree_pane.cpp.

References _, KICAD_MANAGER_FRAME::GetProjectFileName(), KIPLATFORM::ENV::IsNetworkPath(), KICAD_MANAGER_FRAME::m_FileWatcherInfo, m_Parent, m_watcher, m_watcherNeedReset, KISTATUSBAR::SetEllipsedTextField(), TO_UTF8, tracePathsAndFiles, and wxFileSystemWatcher.

Referenced by KICAD_MANAGER_FRAME::OnChangeWatchedPaths(), and onIdle().

◆ findSubdirTreeItem()

wxTreeItemId PROJECT_TREE_PANE::findSubdirTreeItem ( const wxString &  aSubDir)
private

Function findSubdirTreeItem searches for the item in tree project which is the node of the subdirectory aSubDir.

Parameters
aSubDir= the directory to find in tree
Returns
the opaque reference to the tree item; if not found, return an invalid tree item so that wxTreeItemId::IsOk() can be used to test the returned value

Definition at line 1194 of file project_tree_pane.cpp.

References PROJECT_TREE_ITEM::GetFileName(), GetItemIdData(), KICAD_MANAGER_FRAME::GetProjectFileName(), PROJECT_TREE_ITEM::GetType(), PROJECT_TREE_ITEM::IsPopulated(), m_Parent, m_root, and m_TreeProject.

Referenced by onFileSystemEvent().

◆ GetFileExt()

◆ GetItemIdData()

PROJECT_TREE_ITEM * PROJECT_TREE_PANE::GetItemIdData ( wxTreeItemId  aId)
protected

Function GetItemIdData return the item data corresponding to a wxTreeItemId identifier.

Parameters
aId= the wxTreeItemId identifier.
Returns
a PROJECT_TREE_ITEM pointer corresponding to item id aId

Definition at line 1188 of file project_tree_pane.cpp.

References m_TreeProject.

Referenced by addItemToProjectTree(), findSubdirTreeItem(), GetSelectedData(), onExpand(), onFileSystemEvent(), onGitInitializeProject(), and updateGitStatusIcons().

◆ GetSelectedData()

std::vector< PROJECT_TREE_ITEM * > PROJECT_TREE_PANE::GetSelectedData ( )
protected

Function GetSelectedData return the item data from item currently selected (highlighted) Note this is not necessary the "clicked" item, because when expanding, collapsing an item this item is not selected.

Definition at line 1163 of file project_tree_pane.cpp.

References GetItemIdData(), m_TreeProject, and traceGit.

Referenced by onCreateNewDirectory(), onDeleteFile(), onGitCommit(), onOpenDirectory(), onOpenSelectedFileWithTextEditor(), onRenameFile(), onRight(), onSelect(), and onSwitchToSelectedProject().

◆ hasChangedFiles()

bool PROJECT_TREE_PANE::hasChangedFiles ( )
private

Returns true if the current project has any uncommitted changes.

Definition at line 709 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), and m_TreeProject.

Referenced by onRight().

◆ hasLocalCommits()

bool PROJECT_TREE_PANE::hasLocalCommits ( )
private

Returns true if the current project has local commits that have not been pushed to the remote repository.

◆ onCreateNewDirectory()

void PROJECT_TREE_PANE::onCreateNewDirectory ( wxCommandEvent &  event)
private

Function onCreateNewDirectory Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a directory name.

Definition at line 269 of file project_tree_pane.cpp.

References _, addItemToProjectTree(), KICAD_MANAGER_FRAME::GetProjectFileName(), GetSelectedData(), and m_Parent.

◆ onDeleteFile()

void PROJECT_TREE_PANE::onDeleteFile ( wxCommandEvent &  event)
private

Function onDeleteFile Delete the selected file or directory in the tree project.

Definition at line 1021 of file project_tree_pane.cpp.

References GetSelectedData().

◆ onExpand()

void PROJECT_TREE_PANE::onExpand ( wxTreeEvent &  Event)
private

◆ onFileSystemEvent()

void PROJECT_TREE_PANE::onFileSystemEvent ( wxFileSystemWatcherEvent &  event)
private

called when a file or directory is modified/created/deleted The tree project is modified when a file or directory is created/deleted/renamed to reflect the file change

Definition at line 1252 of file project_tree_pane.cpp.

References addItemToProjectTree(), findSubdirTreeItem(), PROJECT_TREE_ITEM::GetFileName(), GetItemIdData(), KI_FALLTHROUGH, m_isRenaming, m_TreeProject, m_watcher, and updateGitStatusIcons().

Referenced by PROJECT_TREE_PANE().

◆ onGitAddToIndex()

void PROJECT_TREE_PANE::onGitAddToIndex ( wxCommandEvent &  event)
private

Add a file to the git index.

Definition at line 2292 of file project_tree_pane.cpp.

◆ onGitCommit()

◆ onGitCompare()

void PROJECT_TREE_PANE::onGitCompare ( wxCommandEvent &  event)
private

Compare the current project to a different branch in the git repository.

Definition at line 1689 of file project_tree_pane.cpp.

◆ onGitFetch()

void PROJECT_TREE_PANE::onGitFetch ( wxCommandEvent &  event)
private

Fetch the latest changes from the git repository.

Definition at line 2335 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), m_TreeProject, and GIT_PULL_HANDLER::PerformFetch().

◆ onGitInitializeProject()

◆ onGitPullProject()

◆ onGitPushProject()

◆ onGitRemoveFromIndex()

void PROJECT_TREE_PANE::onGitRemoveFromIndex ( wxCommandEvent &  event)
private

Remove a file from the git index.

Definition at line 2371 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), m_TreeProject, and GIT_REMOVE_FROM_INDEX_HANDLER::PerformRemoveFromIndex().

◆ onGitRemoveVCS()

void PROJECT_TREE_PANE::onGitRemoveVCS ( wxCommandEvent &  event)
private

Remove the git repository from the current project directory.

Definition at line 1849 of file project_tree_pane.cpp.

References _, DisplayErrorMessage(), PROJECT_TREE::GetGitRepo(), KICAD_MANAGER_FRAME::GetProjectFileName(), IsOK(), m_Parent, m_TreeProject, RmDirRecursive(), and PROJECT_TREE::SetGitRepo().

◆ onGitResolveConflict()

void PROJECT_TREE_PANE::onGitResolveConflict ( wxCommandEvent &  event)
private

Resolve conflicts in the git repository.

Definition at line 2347 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), m_TreeProject, and GIT_RESOLVE_CONFLICT_HANDLER::PerformResolveConflict().

◆ onGitRevertLocal()

void PROJECT_TREE_PANE::onGitRevertLocal ( wxCommandEvent &  event)
private

Revert the local repository to the last commit.

Definition at line 2359 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), m_TreeProject, and GIT_REVERT_HANDLER::PerformRevert().

◆ onGitSwitchBranch()

void PROJECT_TREE_PANE::onGitSwitchBranch ( wxCommandEvent &  event)
private

Switch to a different branch in the git repository.

Definition at line 1778 of file project_tree_pane.cpp.

References _, DisplayError(), DIALOG_GIT_SWITCH::GetBranchName(), PROJECT_TREE::GetGitRepo(), git_create_branch(), and m_TreeProject.

◆ onGitSyncProject()

void PROJECT_TREE_PANE::onGitSyncProject ( wxCommandEvent &  event)
private

Sync the current project with the git repository.

Definition at line 2323 of file project_tree_pane.cpp.

References PROJECT_TREE::GetGitRepo(), m_TreeProject, and GIT_SYNC_HANDLER::PerformSync().

◆ onIdle()

void PROJECT_TREE_PANE::onIdle ( wxIdleEvent &  aEvent)
private

Idle event handler, used process the selected items at a point in time when all other events have been consumed.

Definition at line 1073 of file project_tree_pane.cpp.

References PROJECT_TREE_ITEM::Activate(), FileWatcherReset(), m_selectedItem, m_watcherNeedReset, and updateGitStatusIcons().

◆ onOpenDirectory()

void PROJECT_TREE_PANE::onOpenDirectory ( wxCommandEvent &  event)
private

Function onOpenDirectory Handles the right-click menu for opening a directory in the current system file browser.

Definition at line 241 of file project_tree_pane.cpp.

References PATHS::GetDefaultUserProjectsPath(), KICAD_MANAGER_FRAME::GetProjectFileName(), GetSelectedData(), LaunchExternal(), and m_Parent.

◆ onOpenSelectedFileWithTextEditor()

void PROJECT_TREE_PANE::onOpenSelectedFileWithTextEditor ( wxCommandEvent &  event)
private

Function onOpenSelectedFileWithTextEditor Call the text editor to open the selected file in the tree project.

Definition at line 997 of file project_tree_pane.cpp.

References _, ExecuteFile(), GetSelectedData(), PGM_BASE::GetTextEditor(), and Pgm().

◆ onPaint()

void PROJECT_TREE_PANE::onPaint ( wxPaintEvent &  aEvent)
private

We don't have uniform borders so we have to draw them ourselves.

Definition at line 1529 of file project_tree_pane.cpp.

◆ onRenameFile()

void PROJECT_TREE_PANE::onRenameFile ( wxCommandEvent &  event)
private

Function onRenameFile Rename the selected file or directory in the tree project.

Definition at line 1030 of file project_tree_pane.cpp.

References _, GetSelectedData(), m_isRenaming, and m_TreeProject.

◆ onRight()

◆ onSelect()

void PROJECT_TREE_PANE::onSelect ( wxTreeEvent &  Event)
private

Called on a double click on an item.

Definition at line 1059 of file project_tree_pane.cpp.

References GetSelectedData(), and m_selectedItem.

◆ onSwitchToSelectedProject()

void PROJECT_TREE_PANE::onSwitchToSelectedProject ( wxCommandEvent &  event)
private

Switch to a other project selected from the tree project (by selecting an other .pro file inside the current project folder)

Definition at line 228 of file project_tree_pane.cpp.

References GetSelectedData(), KICAD_MANAGER_FRAME::LoadProject(), and m_Parent.

◆ onThemeChanged()

void PROJECT_TREE_PANE::onThemeChanged ( wxSysColourChangedEvent &  aEvent)
private

◆ ReCreateTreePrj()

◆ shutdownFileWatcher()

void PROJECT_TREE_PANE::shutdownFileWatcher ( )
private

Shutdown the file watcher.

Used when closing to prevent post-free access into the project tree. (Using the destructor doesn't work as wxWidgets defers destruction in some cases.)

Definition at line 216 of file project_tree_pane.cpp.

References m_watcher.

Referenced by EmptyTreePrj(), and ~PROJECT_TREE_PANE().

◆ updateGitStatusIcons()

Friends And Related Function Documentation

◆ PROJECT_TREE_ITEM

friend class PROJECT_TREE_ITEM
friend

Definition at line 51 of file project_tree_pane.h.

Referenced by addItemToProjectTree(), and ReCreateTreePrj().

Member Data Documentation

◆ m_filters

std::vector<wxString> PROJECT_TREE_PANE::m_filters
private

Definition at line 288 of file project_tree_pane.h.

Referenced by addItemToProjectTree().

◆ m_gitLastError

int PROJECT_TREE_PANE::m_gitLastError
private

Definition at line 295 of file project_tree_pane.h.

Referenced by onGitInitializeProject(), and updateGitStatusIcons().

◆ m_isRenaming

bool PROJECT_TREE_PANE::m_isRenaming
private

Definition at line 286 of file project_tree_pane.h.

Referenced by onFileSystemEvent(), and onRenameFile().

◆ m_lastGitStatusUpdate

wxDateTime PROJECT_TREE_PANE::m_lastGitStatusUpdate
private

Definition at line 294 of file project_tree_pane.h.

Referenced by updateGitStatusIcons().

◆ m_Parent

◆ m_root

wxTreeItemId PROJECT_TREE_PANE::m_root
private

Definition at line 287 of file project_tree_pane.h.

Referenced by findSubdirTreeItem(), and ReCreateTreePrj().

◆ m_selectedItem

PROJECT_TREE_ITEM* PROJECT_TREE_PANE::m_selectedItem
private

Definition at line 290 of file project_tree_pane.h.

Referenced by onIdle(), and onSelect().

◆ m_TreeProject

◆ m_watcher

wxFileSystemWatcher* PROJECT_TREE_PANE::m_watcher
private

Definition at line 289 of file project_tree_pane.h.

Referenced by FileWatcherReset(), onFileSystemEvent(), and shutdownFileWatcher().

◆ m_watcherNeedReset

bool PROJECT_TREE_PANE::m_watcherNeedReset
private

Definition at line 291 of file project_tree_pane.h.

Referenced by addItemToProjectTree(), FileWatcherReset(), onExpand(), and onIdle().


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