KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_git_history.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PANEL_GIT_HISTORY_H
21#define PANEL_GIT_HISTORY_H
22
23#include <map>
24#include <set>
25#include <string>
26#include <atomic>
27#include <thread>
28#include <vector>
29
30#include <wx/bitmap.h>
31#include <wx/timer.h>
32
36
37class EDA_BASE_FRAME;
44namespace KIGIT
45{
46struct GIT_IDENTITY;
47}
48
49
55{
56public:
57 PANEL_GIT_HISTORY( wxWindow* aParent, GIT_ADVANCED_DIALOG* aDialog, EDA_BASE_FRAME* aFrame );
58 ~PANEL_GIT_HISTORY() override;
59
61 void Populate();
62
64 void SetBranches( const std::vector<KIGIT_BRANCH_INFO>& aBranches );
65
68 void ShowHistoryForFile( const wxString& aPath );
69
70private:
72 void reloadHistory();
73
75 void fillHistory( const std::vector<KIGIT_COMMIT_INFO>& aCommits, size_t aLimit );
76
79
81 void showCommitDetail( const wxString& aHash );
82 void fillCommitDetail( const KIGIT_COMMIT_DETAIL& aDetail );
83 void clearCommitDetail();
84
86 void showFileDiff( const wxString& aPath );
87 void hideFileDiff();
88
91 void appendHistoryRows( const std::vector<KIGIT_COMMIT_INFO>& aCommits, size_t aFrom );
92
95
98 void requestAvatar( const wxString& aEmail, int aDiameter );
99
102 void applyAvatar( const wxString& aEmail, int aDiameter, const std::string& aBytes );
103
106 void onRestoreVersion( const wxString& aCommitHash );
107 void restoreVersion( const wxString& aCommitHash, const KIGIT::GIT_IDENTITY& aIdentity );
108
111
112 wxDataViewColumn* m_historyRefsColumn;
114
117 std::atomic<bool> m_avatarCancel{ false };
118
120 std::vector<std::thread> m_avatarWorkers;
121
123 std::vector<wxString> m_historyEmails;
124
127 std::vector<bool> m_historyAtHead;
128
130 std::map<wxString, wxBitmap> m_avatarCache;
131
133 std::set<wxString> m_avatarRequested;
134
138
141
144
148
150 size_t m_historyLimit = 50;
151
154
157
159 wxString m_detailHash;
160
163
166
169
172
174 bool m_historyComplete = false;
175
177 bool m_fillingHistory = false;
178};
179
180#endif // PANEL_GIT_HISTORY_H
The base frame for deriving all KiCad main window classes.
The advanced Git window: a non-modal dialog with a top bar naming the repository and branch and a sid...
Shows what changed in one file: the old and new drawing side by side for a schematic or board,...
Read repository state without blocking the UI.
PANEL_GIT_HISTORY_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
WX_DEBOUNCED_ACTION m_historySearchDebounce
Waits for the user to pause typing in the search box before walking the history again.
PANEL_GIT_HISTORY(wxWindow *aParent, GIT_ADVANCED_DIALOG *aDialog, EDA_BASE_FRAME *aFrame)
void onHistoryScrollTick()
Grow the history window when the user has scrolled near its end.
bool m_fillingHistory
True while the list is being refilled, when its selection events are its own.
wxString m_detailEmail
Its author's email, so a web avatar that arrives later lands on the pane too.
wxDataViewColumn * m_historyRefsColumn
void Populate()
Load the repository's recent commits in the background, up to the current window.
wxTimer m_historyScrollTimer
Polls whether the user scrolled near the end of the history, which is the one portable way to notice ...
void requestAvatar(const wxString &aEmail, int aDiameter)
Start a background fetch of the contributor's web avatar for aEmail, if opted in and not already cach...
std::atomic< bool > m_avatarCancel
Set when the page goes, so a fetch still waiting on the network gives up rather than holding the clos...
size_t m_historyLimit
How many commits the page currently shows at most. Grows as the user scrolls.
bool m_historyComplete
True once a load returned fewer commits than asked for, meaning everything is shown.
KIGIT_QUERY m_historyQuery
Listing and selection have separate requests so choosing a commit does not cancel paging.
int m_historySashPos
Where the user left the sash, so the pane comes back at the same width.
std::set< wxString > m_avatarRequested
Emails whose avatar fetch was already started, so each is fetched at most once.
KIGIT_QUERY m_actionQuery
Read action preconditions without delaying history selection or scrolling.
void showFileDiff(const wxString &aPath)
Show what the selected commit did to aPath under the file list, or hide that area.
std::vector< wxString > m_historyEmails
Author email for each history row, so a fetched avatar can find its rows.
void SetBranches(const std::vector< KIGIT_BRANCH_INFO > &aBranches)
Offer every branch in the branch filter, keeping the current choice.
std::vector< std::thread > m_avatarWorkers
The avatar fetches this page started, joined before it goes.
void showCommitDetail(const wxString &aHash)
Fill the detail pane with aHash, or clear it when the hash is empty or gone.
void ShowHistoryForFile(const wxString &aPath)
Narrow the list to the commits that changed aPath, a file or folder relative to the repository root.
GIT_ADVANCED_DIALOG * m_dialog
void onRestoreVersion(const wxString &aCommitHash)
Restore the project as it was at the given commit, recorded as a new commit on top of the current hea...
void applyAvatar(const wxString &aEmail, int aDiameter, const std::string &aBytes)
On the UI thread, decode the fetched avatar bytes and place the photo on every history row for aEmail...
GIT_FILE_DIFF_AREA * m_fileDiff
std::vector< bool > m_historyAtHead
Whether each row's commit is the one HEAD points at.
EDA_BASE_FRAME * m_frame
void restoreVersion(const wxString &aCommitHash, const KIGIT::GIT_IDENTITY &aIdentity)
void fillCommitDetail(const KIGIT_COMMIT_DETAIL &aDetail)
wxString m_detailParent
The first parent of the shown commit, which the diff area's before side names.
void fillHistory(const std::vector< KIGIT_COMMIT_INFO > &aCommits, size_t aLimit)
Apply a loaded history window, keeping the currently selected commit when possible.
void appendHistoryRows(const std::vector< KIGIT_COMMIT_INFO > &aCommits, size_t aFrom)
Append rows for aCommits starting at aFrom, without clearing, so growing the history window keeps the...
std::map< wxString, wxBitmap > m_avatarCache
Fetched web avatars, keyed by author email.
void reloadHistory()
Restart the history at the first window after the search or branch filter changed.
KIGIT_HISTORY_FILTER historyFilter() const
The search text and branch the page is narrowed to.
wxString m_historyPath
The file or folder the history is narrowed to, or empty for all of it.
wxString m_historyBranchName
The branch the list is narrowed to, or empty for every branch.
int m_detailSashPos
Where the user left the sash between the file list and the diff area.
wxString m_detailHash
The commit the detail pane shows, so a refresh can put the selection back on it.
Debounces an action: runs it only after a quiet period following the last trigger.
Repository values and whether Git can use them to record a commit.