KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_tree_pane.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
24
25
26#ifndef TREEPRJ_FRAME_H
27#define TREEPRJ_FRAME_H
28
29#include <map>
30#include <mutex>
31#include <unordered_map>
32#include <vector>
33#include <future>
34#include <wx/datetime.h>
35#include <wx/fswatcher.h>
36#include <wx/laywin.h>
37#include <wx/timer.h>
38#include <wx/treebase.h>
39
41#include "tree_file_type.h"
42
43
46class PROJECT_TREE;
47
51class PROJECT_TREE_PANE : public wxSashLayoutWindow
52{
53 friend class PROJECT_TREE_ITEM;
54
55public:
58
62 void ReCreateTreePrj();
63
70 void FileWatcherReset();
71
75 void EmptyTreePrj();
76
77protected:
78 static wxString GetFileExt( TREE_FILE_TYPE type );
79
86 std::vector<PROJECT_TREE_ITEM*> GetSelectedData();
87
93 PROJECT_TREE_ITEM* GetItemIdData( wxTreeItemId aId );
94
95private:
99 void onSelect( wxTreeEvent& Event );
100
104 void onExpand( wxTreeEvent& Event );
105
109 void onRight( wxTreeEvent& Event );
110
114 void onOpenSelectedFileWithTextEditor( wxCommandEvent& event );
115
119 void onDeleteFile( wxCommandEvent& event );
120
124 void onRenameFile( wxCommandEvent& event );
125
129 void onOpenDirectory( wxCommandEvent& event );
130
135 void onCreateNewDirectory( wxCommandEvent& event );
136
141 void onSwitchToSelectedProject( wxCommandEvent& event );
142
147 void onIdle( wxIdleEvent& aEvent );
148
152 void onPaint( wxPaintEvent& aEvent );
153
157 void onGitInitializeProject( wxCommandEvent& event );
158
162 void onGitRemoteSettings( wxCommandEvent& event );
163
167 void onGitCommit( wxCommandEvent& event );
168
172 void onGitAmendCommit( wxCommandEvent& event );
173
177 void onGitPullProject( wxCommandEvent& event );
178
182 void onGitPushProject( wxCommandEvent& event );
183
187 void onGitSwitchBranch( wxCommandEvent& event );
188
192 void onGitCompare( wxCommandEvent& event );
193
197 void onGitRemoveVCS( wxCommandEvent& event );
198
202 void onGitAddToIndex( wxCommandEvent& event );
203
207 void onGitRemoveFromIndex( wxCommandEvent& event );
208
212 void onGitSyncProject( wxCommandEvent& event );
213
217 void onGitFetch( wxCommandEvent& event );
218
222 void onGitResolveConflict( wxCommandEvent& event );
223
227 void onGitRevertLocal( wxCommandEvent& event );
228
232 void onRunSelectedJobsFile( wxCommandEvent& event );
233
238
244
248 void updateTreeCache();
249
254 void releaseGitRepo();
255
259 bool hasChangedFiles();
260
266
271 void shutdownFileWatcher();
272
282 wxTreeItemId addItemToProjectTree( const wxString& aName, const wxTreeItemId& aParent,
283 std::vector<wxString>* aProjectNames, bool aRecurse );
284
291 wxTreeItemId findSubdirTreeItem( const wxString& aSubDir );
292
298 void onFileSystemEvent( wxFileSystemWatcherEvent& event );
299
300 void onThemeChanged( wxSysColourChangedEvent &aEvent );
301
306 bool canFileBeAddedToVCS( const wxString& aFilePath );
307
308 void onGitSyncTimer( wxTimerEvent& event );
309
310 void onGitStatusTimer( wxTimerEvent& event );
311
313
315 void showGitFeedback( const wxString& aText );
316
317 void onGitFeedbackTimer( wxTimerEvent& event );
318
319public:
322
323private:
324 bool m_isRenaming; // Are we in the process of renaming a file
325 wxTreeItemId m_root;
326 std::vector<wxString> m_filters;
327 wxFileSystemWatcher* m_watcher; // file system watcher
329 bool m_watcherNeedReset; // true if FileWatcherReset() must be called
330 // (during an idle time for instance) after
331 // the main loop event handler is started
338 std::future<void> m_gitSyncTask;
339 std::future<void> m_gitStatusIconTask;
340
342 std::unordered_map<wxString, wxTreeItemId> m_gitTreeCache;
344 std::map<wxTreeItemId, KIGIT_COMMON::GIT_STATUS> m_gitStatusIcons;
346
347 DECLARE_EVENT_TABLE()
348};
349
350#endif // TREEPRJ_FRAME_H
The main KiCad project manager frame.
Handle one item (a file or a directory name) for the tree file.
PROJECT_TREE_ITEM * m_selectedItem
std::unordered_map< wxString, wxTreeItemId > m_gitTreeCache
void onGitFetch(wxCommandEvent &event)
Fetch the latest changes from the git repository.
std::map< wxTreeItemId, KIGIT_COMMON::GIT_STATUS > m_gitStatusIcons
void onGitInitializeProject(wxCommandEvent &event)
Initialize a new git repository in the current project directory.
void showGitFeedback(const wxString &aText)
Show a short message in the project status bar after a git operation.
void onGitSyncProject(wxCommandEvent &event)
Sync the current project with the git repository.
void onDeleteFile(wxCommandEvent &event)
Delete the selected file or directory in the tree project.
void onGitRemoveVCS(wxCommandEvent &event)
Remove the git repository from the current project directory.
void EmptyTreePrj()
Delete all m_TreeProject entries.
void FileWatcherReset()
Reinit the watched paths Should be called after opening a new project to rebuild the list of watched ...
std::vector< PROJECT_TREE_ITEM * > GetSelectedData()
Return the item data from item currently selected (highlighted)
void onOpenDirectory(wxCommandEvent &event)
Handles the right-click menu for opening a directory in the current system file browser.
void onGitResolveConflict(wxCommandEvent &event)
Resolve conflicts in the git repository.
void onFileSystemEvent(wxFileSystemWatcherEvent &event)
called when a file or directory is modified/created/deleted The tree project is modified when a file ...
wxFileSystemWatcher * m_watcher
void onRight(wxTreeEvent &Event)
Called on a right click on an item.
void onGitCommit(wxCommandEvent &event)
Commit the current project saved changes to the git repository.
void onSelect(wxTreeEvent &Event)
Called on a double click on an item.
PROJECT_TREE * m_TreeProject
PROJECT_TREE_PANE(KICAD_MANAGER_FRAME *parent)
KICAD_MANAGER_FRAME * m_Parent
std::future< void > m_gitSyncTask
void onExpand(wxTreeEvent &Event)
Called on a click on the + or - button of an item with children.
void onGitSyncTimer(wxTimerEvent &event)
void onIdle(wxIdleEvent &aEvent)
Idle event handler, used process the selected items at a point in time when all other events have bee...
void updateTreeCache()
Updates the map of the wxtreeitemid to the name of each file for use in the thread.
bool hasLocalCommits()
Returns true if the current project has local commits that have not been pushed to the remote reposit...
void onGitRevertLocal(wxCommandEvent &event)
Revert the local repository to the last commit.
void onGitPullProject(wxCommandEvent &event)
Pull the latest changes from the git repository.
void onGitAmendCommit(wxCommandEvent &event)
Amend (rewrite) the last commit on the current branch.
void onGitFeedbackTimer(wxTimerEvent &event)
static wxString GetFileExt(TREE_FILE_TYPE type)
friend class PROJECT_TREE_ITEM
void onGitRemoveFromIndex(wxCommandEvent &event)
Remove a file from the git index.
wxTreeItemId findSubdirTreeItem(const wxString &aSubDir)
Search for the item in tree project which is the node of the subdirectory aSubDir.
void ReCreateTreePrj()
Create or modify the tree showing project file names.
void onThemeChanged(wxSysColourChangedEvent &aEvent)
void onRunSelectedJobsFile(wxCommandEvent &event)
Run a selected jobs file.
void onGitCompare(wxCommandEvent &event)
Compare the current project to a different branch in the git repository.
void onGitStatusTimer(wxTimerEvent &event)
void shutdownFileWatcher()
Shutdown the file watcher.
std::mutex m_gitTreeCacheMutex
wxTreeItemId addItemToProjectTree(const wxString &aName, const wxTreeItemId &aParent, std::vector< wxString > *aProjectNames, bool aRecurse)
Add the file or directory aName to the project tree.
bool hasChangedFiles()
Returns true if the current project has any uncommitted changes.
void onGitRemoteSettings(wxCommandEvent &event)
Configure (or change) the default remote on an already-initialized repository.
void onOpenSelectedFileWithTextEditor(wxCommandEvent &event)
Call the text editor to open the selected file in the tree project.
void onGitAddToIndex(wxCommandEvent &event)
Add a file to the git index.
void updateGitStatusIcons()
Updates the icons shown in the tree project to reflect the current git status.
std::future< void > m_gitStatusIconTask
void updateGitStatusIconMap()
This is a threaded call that will change the map of git status icons for use in the main thread.
PROJECT_TREE_ITEM * GetItemIdData(wxTreeItemId aId)
Return the item data corresponding to a wxTreeItemId identifier.
void onGitSwitchBranch(wxCommandEvent &event)
Switch to a different branch in the git repository.
void onCreateNewDirectory(wxCommandEvent &event)
Creates a new subdirectory inside the current kicad project directory the user is prompted to enter a...
void onSwitchToSelectedProject(wxCommandEvent &event)
Switch to a other project selected from the tree project (by selecting an other .pro file inside the ...
void onPaint(wxPaintEvent &aEvent)
We don't have uniform borders so we have to draw them ourselves.
void onRenameFile(wxCommandEvent &event)
Rename the selected file or directory in the tree project.
void releaseGitRepo()
Releases the git repository handle, deferring the free to the orphan registry while a background git ...
void onGitPushProject(wxCommandEvent &event)
Push the current project changes to the git repository.
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 y...
std::vector< wxString > m_filters
PROJECT_TREE This is the class to show (as a tree) the files in the project directory.
#define wxFileSystemWatcher
TREE_FILE_TYPE