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 <memory>
31#include <mutex>
32#include <unordered_map>
33#include <vector>
34#include <future>
35#include <wx/datetime.h>
36#include <wx/fswatcher.h>
37#include <wx/laywin.h>
38#include <wx/timer.h>
39#include <wx/treebase.h>
40
43#include <git/kigit_failure.h>
44#include "tree_file_type.h"
45
46
48class KIGIT_QUERY;
50class PROJECT_TREE;
51
55class PROJECT_TREE_PANE : public wxSashLayoutWindow
56{
57 friend class PROJECT_TREE_ITEM;
58
59public:
62
66 void ReCreateTreePrj();
67
74 void FileWatcherReset();
75
79 void EmptyTreePrj();
80
86
87protected:
88 static wxString GetFileExt( TREE_FILE_TYPE type );
89
96 std::vector<PROJECT_TREE_ITEM*> GetSelectedData();
97
103 PROJECT_TREE_ITEM* GetItemIdData( wxTreeItemId aId );
104
105private:
109 void onSelect( wxTreeEvent& Event );
110
114 void onExpand( wxTreeEvent& Event );
115
119 void onRight( wxTreeEvent& Event );
120
121 void showContextMenu();
122
126 void onOpenSelectedFileWithTextEditor( wxCommandEvent& event );
127
131 void onDeleteFile( wxCommandEvent& event );
132
136 void onRenameFile( wxCommandEvent& event );
137
141 void onOpenDirectory( wxCommandEvent& event );
142
147 void onCreateNewDirectory( wxCommandEvent& event );
148
153 void onSwitchToSelectedProject( wxCommandEvent& event );
154
159 void onIdle( wxIdleEvent& aEvent );
160
164 void onPaint( wxPaintEvent& aEvent );
165
169 void onGitInitializeProject( wxCommandEvent& event );
170
174 void onGitRemoteSettings( wxCommandEvent& event );
175 void showGitRemoteSettings( const wxString& aExistingURL, const wxString& aUsername, const wxString& aPassword );
176
180 void onGitHistory( wxCommandEvent& event );
181
185 void onGitSwitchBranch( wxCommandEvent& event );
186 void switchGitBranch( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aBranchName, bool aCreate );
187
191 void onGitIgnore( wxCommandEvent& event );
192
196 void onGitEditIgnoreFile( wxCommandEvent& event );
197
203 wxMenu* buildIgnoreSubmenu( const std::vector<PROJECT_TREE_ITEM*>& aSelection, bool& aUsable );
204
208 void openInTextEditor( const std::vector<wxString>& aFileNames );
209
213 void onGitRemoveVCS( wxCommandEvent& event );
214
218 void onRunSelectedJobsFile( wxCommandEvent& event );
219
224
229 void updateGitStatusIconMap( std::shared_ptr<KIGIT_COMMON> aGitCommon, const wxString& aProjectFullName );
230
234 void updateTreeCache();
235
240 void releaseGitRepo();
241
243 std::shared_ptr<KIGIT_COMMON> gitCommon() const;
244
249 void syncGitListener();
250
251 git_repository* gitRepo() const;
252
258
263 void shutdownFileWatcher();
264
274 wxTreeItemId addItemToProjectTree( const wxString& aName, const wxTreeItemId& aParent,
275 std::vector<wxString>* aProjectNames, bool aRecurse );
276
283 wxTreeItemId findSubdirTreeItem( const wxString& aSubDir );
284
290 void onFileSystemEvent( wxFileSystemWatcherEvent& event );
291
292 void onThemeChanged( wxSysColourChangedEvent &aEvent );
293
294 void onGitSyncTimer( wxTimerEvent& event );
295
296 void onGitStatusTimer( wxTimerEvent& event );
297
299
302 void reportGitSyncResult( bool aFetched, std::optional<KIGIT_FAILURE> aKind, const wxString& aSummary );
303
304public:
307
308private:
309 bool m_isRenaming; // Are we in the process of renaming a file
310 wxTreeItemId m_root;
311 std::vector<wxString> m_filters;
312 wxFileSystemWatcher* m_watcher; // file system watcher
314 bool m_watcherNeedReset; // true if FileWatcherReset() must be called
315 // (during an idle time for instance) after
316 // the main loop event handler is started
320 std::future<void> m_gitSyncTask;
321 std::future<void> m_gitStatusIconTask;
322
323 std::weak_ptr<KIGIT_COMMON> m_gitListenerSession;
324
326 std::vector<wxString> m_gitMenuBranches;
327 std::vector<GIT_IGNORE_TARGET> m_gitMenuIgnoreTargets;
328 std::weak_ptr<KIGIT_COMMON> m_gitMenuSession;
329
331 std::unique_ptr<KIGIT_QUERY> m_branchQuery;
332
334 std::unordered_map<wxString, wxTreeItemId> m_gitTreeCache;
336 std::map<wxTreeItemId, KIGIT_COMMON::GIT_STATUS> m_gitStatusIcons;
338
340 std::map<wxString, unsigned int> m_gitLastStatus;
341
342 DECLARE_EVENT_TABLE()
343};
344
345#endif // TREEPRJ_FRAME_H
The main KiCad project manager frame.
Read repository state without blocking the UI.
Handle one item (a file or a directory name) for the tree file.
PROJECT_TREE_ITEM * m_selectedItem
void switchGitBranch(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aBranchName, bool aCreate)
void syncGitListener()
Follow the project's git session with a refresh listener, so operations started from the version cont...
std::unordered_map< wxString, wxTreeItemId > m_gitTreeCache
void onGitIgnore(wxCommandEvent &event)
Add the selected files to, or take them out of, the project's ignored files.
std::map< wxTreeItemId, KIGIT_COMMON::GIT_STATUS > m_gitStatusIcons
void onGitInitializeProject(wxCommandEvent &event)
Initialize a new git repository in the current project directory.
void showGitRemoteSettings(const wxString &aExistingURL, const wxString &aUsername, const wxString &aPassword)
void openInTextEditor(const std::vector< wxString > &aFileNames)
Open files in the user's text editor, or explain that none is chosen.
git_repository * gitRepo() const
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 onFileSystemEvent(wxFileSystemWatcherEvent &event)
called when a file or directory is modified/created/deleted The tree project is modified when a file ...
std::vector< GIT_IGNORE_TARGET > m_gitMenuIgnoreTargets
wxFileSystemWatcher * m_watcher
void WaitForGitOperations()
Give a running background git operation a chance to finish, asking the user to keep waiting or abando...
void onRight(wxTreeEvent &Event)
Called on a right click on an item.
void onSelect(wxTreeEvent &Event)
Called on a double click on an item.
PROJECT_TREE * m_TreeProject
PROJECT_TREE_PANE(KICAD_MANAGER_FRAME *parent)
std::weak_ptr< KIGIT_COMMON > m_gitMenuSession
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.
std::weak_ptr< KIGIT_COMMON > m_gitListenerSession
std::map< wxString, unsigned int > m_gitLastStatus
Raw status of every file in the last pass, so a change with no tree item still reaches the panels.
std::vector< wxString > m_gitMenuBranches
Preserve the shortcut targets while the context menu runs its event loop.
void onGitSyncTimer(wxTimerEvent &event)
void onGitHistory(wxCommandEvent &event)
Open the advanced Git window on its History page.
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...
static wxString GetFileExt(TREE_FILE_TYPE type)
friend class PROJECT_TREE_ITEM
wxTreeItemId findSubdirTreeItem(const wxString &aSubDir)
Search for the item in tree project which is the node of the subdirectory aSubDir.
void onGitEditIgnoreFile(wxCommandEvent &event)
Open the project's ignore file, for rules the menu items cannot reach.
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 onGitStatusTimer(wxTimerEvent &event)
void shutdownFileWatcher()
Shutdown the file watcher.
std::mutex m_gitTreeCacheMutex
std::shared_ptr< KIGIT_COMMON > gitCommon() const
The current project's git session, created empty on first use.
void updateGitStatusIconMap(std::shared_ptr< KIGIT_COMMON > aGitCommon, const wxString &aProjectFullName)
This is a threaded call that will change the map of git status icons for use in the main thread.
wxTreeItemId addItemToProjectTree(const wxString &aName, const wxTreeItemId &aParent, std::vector< wxString > *aProjectNames, bool aRecurse)
Add the file or directory aName to the project tree.
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 updateGitStatusIcons()
Updates the icons shown in the tree project to reflect the current git status.
std::future< void > m_gitStatusIconTask
PROJECT_TREE_ITEM * GetItemIdData(wxTreeItemId aId)
Return the item data corresponding to a wxTreeItemId identifier.
std::unique_ptr< KIGIT_QUERY > m_branchQuery
Owns the branch-switch preflight and suppresses callbacks when the project closes.
void reportGitSyncResult(bool aFetched, std::optional< KIGIT_FAILURE > aKind, const wxString &aSummary)
Background fetches have no window to answer, so each failure goes to the status bar's warnings once,...
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 ...
wxMenu * buildIgnoreSubmenu(const std::vector< PROJECT_TREE_ITEM * > &aSelection, bool &aUsable)
Build the Ignore submenu for a selection, and remember what its items apply to.
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