KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_commit_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef GIT_COMMIT_PANE_H
21#define GIT_COMMIT_PANE_H
22
23#include <atomic>
24#include <functional>
25#include <memory>
26#include <optional>
27#include <set>
28
34
35class EDA_BASE_FRAME;
37class KIGIT_COMMON;
38enum class GitOperation;
39class wxCommandEvent;
40class wxMenuItem;
41class wxDataViewEvent;
42class wxHyperlinkCtrl;
43class wxStaticText;
44
45
52{
53public:
55
58 GIT_COMMIT_PANE( wxWindow* aParent, EDA_BASE_FRAME* aFrame );
59 ~GIT_COMMIT_PANE() override;
60
62 void OnGitTransfersChanged() override;
63
65 bool Layout() override;
66
68 void SetFileSelectedHandler( std::function<void( const wxString& )> aHandler );
69
71 wxString GetCommitMessage() const;
72 void SetCommitMessage( const wxString& aMessage );
73
75 void SetMessageChangedHandler( std::function<void()> aHandler ) { m_messageChangedHandler = aHandler; }
76
78 void RefreshFileList();
79
81 void ShowTransferProgress( const wxString& aText );
82
85
87 void ShowHistory();
88
91 void Pull();
92
95 void Push();
96
98 void BeginAmend( const wxString& aExpectedCommit = wxEmptyString );
99
101 void SetBusyChangedHandler( std::function<void( bool )> aHandler ) { m_busyChangedHandler = aHandler; }
102
104 int GetMinDockWidth() const { return m_minDockWidth; }
105
106private:
108 void onCommit( wxCommandEvent& aEvent );
109 void onCommitAndPush( wxCommandEvent& aEvent );
110 void onPull( wxCommandEvent& aEvent );
111
113 void abandonOperation( std::shared_ptr<KIGIT_COMMON> aCommon );
114 void finishAbandonOperation( std::shared_ptr<KIGIT_COMMON> aCommon, const std::vector<wxString>& aOutside );
115 void onAmendToggled( wxCommandEvent& aEvent );
116
118 void onUndoCommit( wxCommandEvent& aEvent );
119
120 void onNewBranchToggled( wxCommandEvent& aEvent );
121 void onRecentMessage( wxCommandEvent& aEvent );
122 void onShowDiff( wxCommandEvent& aEvent );
123 void onFileActivated( wxDataViewEvent& aEvent );
124 void onChecklistContextMenu( wxDataViewEvent& aEvent );
125 void discardFile( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aPath );
126 void confirmDiscardFile( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aPath, bool aTracked,
127 bool aConflicted, wxString aRoot );
128
131 void doCommit( bool aAndPush );
132
133 struct COMMIT_REQUEST;
134 void saveForCommit( std::shared_ptr<KIGIT_COMMON> aCommon, std::shared_ptr<COMMIT_REQUEST> aRequest );
135 void finishCommit( std::shared_ptr<KIGIT_COMMON> aCommon, const COMMIT_REQUEST& aRequest );
136 void onChecklistChanged( wxDataViewEvent& aEvent );
137 void onMessageChanged( wxCommandEvent& aEvent );
138 void onIdle( wxIdleEvent& aEvent );
140 void applyTheme();
141 void onThemeChanged( wxSysColourChangedEvent& aEvent );
142
144 void onSettings( wxCommandEvent& aEvent );
145 void setAuthor();
146
148 void setStatusText( const wxString& aText );
149
151 bool layoutAndWrapStatus();
152
154 void updateDockMinHeight();
155
157 void showTrustCommand( const wxString& aCommand );
158
160 bool transferCanStart();
161
164 void layoutWide();
165
168 void updateSummary();
169
170 struct STATUS;
171
173 void applyStatus( const STATUS& aStatus );
174
176 void populateBranches( const STATUS& aStatus );
177
179 void populateRecentMessages( const std::vector<wxString>& aMessages );
180
184 void setDescription( const wxString& aText );
185
187 void showDisabledState();
188
190 void setBusy( bool aBusy, const wxString& aStatus );
191
194
196 bool othersBusy() const;
197 wxString othersStatus() const;
198 bool othersCanCancel() const;
199
201 void runActionQuery( std::shared_ptr<KIGIT_COMMON> aCommon, std::function<void( KIGIT_COMMON& )> aWork,
202 std::function<void()> aDone, const wxString& aStatus );
203
206 bool deferForSecret( const std::shared_ptr<KIGIT_COMMON>& aCommon, const wxString& aStatus,
207 std::function<void()> aStart );
208 void abandonKeyringWait();
209
211 bool dropKeyringWait();
212
213 // The on*Done continuations run back on the UI thread, so credential prompts and
214 // confirmations stay there. aRetriedAfterTrust marks a transfer already rerun after a trusted host key.
215 void submitPush( std::shared_ptr<KIGIT_COMMON> aCommon, bool aRetriedAfterTrust = false );
216 void startPush( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aBranch, const wxString& aHead,
217 bool aRetriedAfterTrust );
218 void onPushDone( std::shared_ptr<KIGIT_COMMON> aCommon, int aResult, const wxString& aError,
219 const wxString& aDetails, bool aAuthFailure,
220 const std::optional<KIGIT::HOST_KEY_FAILURE>& aHostKey, bool aRetriedAfterTrust, bool aCancelled );
223 void submitPull( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush, bool aRetriedAfterTrust = false );
224 void startPull( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush, bool aRetriedAfterTrust );
225
228 void resolvePullConflicts( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush );
229 struct MERGE_PREPARATION;
230 void finishPullConflictPreparation( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush,
231 std::shared_ptr<MERGE_PREPARATION> aPreparation );
232 void onPullDone( std::shared_ptr<KIGIT_COMMON> aCommon, int aResult, const wxString& aError,
233 const wxString& aDetails, bool aAuthFailure,
234 const std::optional<KIGIT::HOST_KEY_FAILURE>& aHostKey, bool aRetriedAfterTrust, bool aThenPush,
235 bool aCancelled );
236
238 void updateMessageVisibility( bool aHasChanges );
239
241 void updateCommitButton();
242
244 void updateSummaryCount();
245
247 wxString operationNoun() const;
248
250 wxString abandonLabel() const;
251
254 void syncListener();
255
257
260
262 bool m_inAdvancedWindow = false;
263
265
267 size_t m_unpushedCount = 0;
268
270
272 bool m_hasRepo = false;
273
276
279
282
285
288
290 bool m_canAmend = false;
291
293 std::pair<wxString, wxString> m_amendHead;
294
296 std::pair<wxString, wxString> m_undoHead;
297
299 wxStaticText* m_descriptionHint = nullptr;
300
302 wxHyperlinkCtrl* m_historyLink = nullptr;
303
305 std::vector<wxString> m_recentMessageTexts;
306
308 wxMenuItem* m_commitAndPushItem = nullptr;
309
312
313
316
319
321 bool m_keyringWait = false;
322 unsigned m_keyringRequest = 0;
323
326
329
332
334 bool m_showingOthers = false;
335
336
338 std::function<void( bool )> m_busyChangedHandler;
339
341 wxString m_statusText;
342
345
348 wxWindow* m_dockParent = nullptr;
350
353 bool m_listenerAttached = false;
354
357 std::weak_ptr<KIGIT_COMMON> m_listenerSession;
358
361 std::set<wxString> m_shownPaths;
362
366
368 std::function<void()> m_messageChangedHandler;
369
372
373 std::function<void( const wxString& )> m_fileSelectedHandler;
374
375 // The summary box of the wide layout. Null in the docked panel.
376 wxStaticText* m_summaryFiles = nullptr;
377 wxStaticText* m_summaryAdded = nullptr;
378 wxStaticText* m_summaryRemoved = nullptr;
379
381 std::pair<int, int> m_lineStats;
382
386 bool m_actionPending = false;
387};
388
389#endif // GIT_COMMIT_PANE_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...
GIT_COMMIT_PANE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 360), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxString abandonLabel() const
The label the network button carries while an operation is in progress.
bool othersCanCancel() const
void updateCommitButton()
Set what the commit buttons say, and whether they are enabled, for the current state.
void onPull(wxCommandEvent &aEvent)
int m_credentialPrompts
Keyring reads and credential prompts the current request has shown, reset when it ends.
void onMessageChanged(wxCommandEvent &aEvent)
void resolvePullConflicts(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush)
Resolve a conflicted pull file by file, using the visual merge tool for design files,...
void SetBusyChangedHandler(std::function< void(bool)> aHandler)
Called when a transfer starts and when it ends, so an owning window can follow along.
unsigned m_keyringRequest
UTIL::LINK m_transferLink
Follows the transfers other windows run on this pane's repository.
void ShowTransferProgress(const wxString &aText)
Show a line of transfer progress. Called from the UI thread by a KIGIT_STATUS_REPORTER.
wxString m_transferStatus
The status m_transfer began with, shown again once other windows' transfers end before it.
void Pull()
Get changes from the remote, as the Get Changes button does.
wxString GetCommitMessage() const
The message as typed. A second form on the same project shows the same text.
void onNewBranchToggled(wxCommandEvent &aEvent)
std::pair< wxString, wxString > m_undoHead
The branch and commit the last refresh showed, so Undo takes back only the commit the user saw.
void abandonOperation(std::shared_ptr< KIGIT_COMMON > aCommon)
Drop an in-progress merge or rebase and return the project to its last commit.
void BeginAmend(const wxString &aExpectedCommit=wxEmptyString)
Prepare the amend form. A history entry supplies its hash and starts with no files selected.
void finishCommit(std::shared_ptr< KIGIT_COMMON > aCommon, const COMMIT_REQUEST &aRequest)
void onUndoCommit(wxCommandEvent &aEvent)
Take back the last commit while no remote has it, keeping its changes staged and its message.
bool m_showingOthers
The busy state shows another window's transfer, which this pane releases when the last one ends.
bool m_inAdvancedWindow
True on the advanced window's Changes page, false in the docked panel.
std::function< void(const wxString &)> m_fileSelectedHandler
void setDescription(const wxString &aText)
void submitPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, bool aRetriedAfterTrust=false)
aThenPush pushes after a successful pull, which belongs only to the rejected-push recovery flow.
void discardFile(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aPath)
KIGIT_QUERY m_refresh
Coalesce refreshes while a repository read is running, and discard stale results.
bool othersBusy() const
The transfers on it that other windows started, leaving out this pane's own.
std::pair< int, int > m_lineStats
Lines the working tree adds and removes against HEAD, read at the last refresh.
void onSettings(wxCommandEvent &aEvent)
The gear's menu: the advanced window and the author.
bool transferCanStart()
False, with a message, while a transfer is running or a merge waits to be finished.
void updateMessageVisibility(bool aHasChanges)
Show the message field whenever a commit is possible, including a message-only amend.
bool deferForSecret(const std::shared_ptr< KIGIT_COMMON > &aCommon, const wxString &aStatus, std::function< void()> aStart)
Read the keyring before a transfer, holding the pane busy as aStatus, then call aStart unless cancell...
EDA_BASE_FRAME * m_frame
void RefreshFileList()
Read the project's git status and repopulate the list.
bool m_editorsDirty
True when an open editor held unsaved changes at the last refresh.
void finishPullConflictPreparation(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, std::shared_ptr< MERGE_PREPARATION > aPreparation)
void setBusy(bool aBusy, const wxString &aStatus)
Enable or disable the controls while a network operation runs, showing a status.
wxString othersStatus() const
void ReloadAdvancedWindow()
Reload the advanced window when it is open, for a preferences change it also shows.
bool m_canAmend
Whether the current branch allows an amend. A refresh must not change an active amend into a commit.
wxString operationNoun() const
The noun for the operation in progress, for messages.
void onChecklistChanged(wxDataViewEvent &aEvent)
void populateBranches(const STATUS &aStatus)
Fill the branch dropdown from the completed snapshot.
size_t m_unpushedCount
Commits waiting to be pushed, or 0 when the branch has no upstream to count them against.
void onFileActivated(wxDataViewEvent &aEvent)
wxWindow * m_dockParent
bool Layout() override
Lay out the pane, then re-wrap the status line when the width its column got has changed.
bool m_commitButtonPushes
True while the main button reads Push, with nothing left to commit.
void ShowHistory()
Open the advanced window on its History page.
wxStaticText * m_summaryRemoved
void updateSummary()
Refresh the staged count in the changes heading, and the summary box where the wide layout has one.
void saveForCommit(std::shared_ptr< KIGIT_COMMON > aCommon, std::shared_ptr< COMMIT_REQUEST > aRequest)
void onCommit(wxCommandEvent &aEvent)
The split button's main half. It commits, or pushes when that is all there is to do.
GIT_TRANSFER_BUSY::HOLD m_ownHold
m_transfer's hold on the repository, so every other pane on it follows and can cancel it
GIT_TRANSFER_BUSY & transfers() const
The transfers on the repository this pane shows.
void showDisabledState()
Clear the list and disable every control while version control is off.
void updateDescriptionHint()
Where the platform has no hint for a multi line box, a label lies over the description box while it i...
std::function< void(bool)> m_busyChangedHandler
Told when a transfer starts and ends. Empty unless an owning window asked.
void layoutWide()
Put the file list beside the commit controls instead of above them, for a wide host,...
KIGIT_TRANSFER m_transfer
The push or pull this panel submitted last.
void OnGitTransfersChanged() override
Follow a transfer on this pane's repository beginning or ending in any window.
void onPushDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, const wxString &aDetails, bool aAuthFailure, const std::optional< KIGIT::HOST_KEY_FAILURE > &aHostKey, bool aRetriedAfterTrust, bool aCancelled)
std::pair< wxString, wxString > m_amendHead
The branch and commit chosen when amend started. Keep them fixed while editing.
void onChecklistContextMenu(wxDataViewEvent &aEvent)
void startPush(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aBranch, const wxString &aHead, bool aRetriedAfterTrust)
void setStatusText(const wxString &aText)
Set the status line text and wrap it to the width of the label's column.
std::function< void()> m_messageChangedHandler
Told when the message is edited. Empty unless an owning window asked.
bool m_headDetached
True when HEAD is a commit rather than a branch, so nothing can be committed or pushed.
wxString m_statusText
Unwrapped status text, kept so it can be re-wrapped on resize.
std::vector< wxString > m_recentMessageTexts
The full messages behind the Recent messages dropdown, in its order after the caption.
wxString m_currentBranch
The branch a commit will land on, empty when detached or before the first commit.
void populateRecentMessages(const std::vector< wxString > &aMessages)
Fill the Recent messages dropdown from the completed snapshot.
void Push()
Push the local commits, as the Push button does.
int m_statusWrapWidth
The width the status text was last wrapped to, so a layout re-wraps it only when that changes.
bool layoutAndWrapStatus()
Lay out the controls, then rewrap the status line to its column's new width.
void onShowDiff(wxCommandEvent &aEvent)
bool m_operationInProgress
True while a merge or rebase is in progress. The network button then reads Abandon.
void SetCommitMessage(const wxString &aMessage)
wxStaticText * m_summaryFiles
void onThemeChanged(wxSysColourChangedEvent &aEvent)
wxMenuItem * m_commitAndPushItem
The arrow menu's entry, relabelled with the main button.
void SetMessageChangedHandler(std::function< void()> aHandler)
Called when the user edits the message, so another form can follow along.
bool m_hasRepo
Whether the last completed status snapshot had a repository.
void SetFileSelectedHandler(std::function< void(const wxString &)> aHandler)
Called with the path of the file the user selects in the list, or empty when none is.
void onCommitAndPush(wxCommandEvent &aEvent)
GIT_COMMIT_PANE(EDA_BASE_FRAME *aParent)
int GetMinDockWidth() const
The width the panel needs so its widest row fits, for the dock that holds it.
int m_minDockWidth
The widest row's minimum width, measured before anything is hidden.
GitOperation m_operation
Which operation, so the button and the explanation can name it.
~GIT_COMMIT_PANE() override
std::set< wxString > m_shownPaths
Paths shown in the list at the last refresh, so a refresh can tell which files the user deliberately ...
void onPullDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, const wxString &aDetails, bool aAuthFailure, const std::optional< KIGIT::HOST_KEY_FAILURE > &aHostKey, bool aRetriedAfterTrust, bool aThenPush, bool aCancelled)
void onRecentMessage(wxCommandEvent &aEvent)
void runActionQuery(std::shared_ptr< KIGIT_COMMON > aCommon, std::function< void(KIGIT_COMMON &)> aWork, std::function< void()> aDone, const wxString &aStatus)
Read an action's prerequisites off the UI thread, then resume only in the same project.
void startPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, bool aRetriedAfterTrust)
bool dropKeyringWait()
Forget a keyring wait without touching the busy state. True when one was pending.
void onAmendToggled(wxCommandEvent &aEvent)
void onIdle(wxIdleEvent &aEvent)
int m_dockMinHeight
The controls' minimum height from the last layout, applied to the AUI pane at idle time.
bool m_listenerAttached
True once this panel has attached its refresh listener to a session at least once.
void syncListener()
Register a refresh listener with the project's current git session, re-registering if the session cha...
bool m_keyringWait
A push or pull waits on the keyring. The count fences off an answer from a cancelled wait.
size_t m_upstreamAhead
Commits the upstream has that this project does not, which Get Changes brings in.
void applyTheme()
Set the icons and colours that follow the light or dark theme.
void confirmDiscardFile(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aPath, bool aTracked, bool aConflicted, wxString aRoot)
KIGIT_QUERY m_actionQuery
EDITOR_SNAPSHOT m_docsBeforePull
On-disk identity of the open documents, taken before a pull so only the ones the merge rewrote are re...
wxStaticText * m_descriptionHint
The description box's hint, a label laid over it while it is empty.
void updateSummaryCount()
Show how many of the summary's 72 columns are left, once that is 10 or fewer.
void applyStatus(const STATUS &aStatus)
Apply a completed repository snapshot on the UI thread.
void submitPush(std::shared_ptr< KIGIT_COMMON > aCommon, bool aRetriedAfterTrust=false)
void finishAbandonOperation(std::shared_ptr< KIGIT_COMMON > aCommon, const std::vector< wxString > &aOutside)
std::weak_ptr< KIGIT_COMMON > m_listenerSession
The git session this panel registered a refresh listener with, weak so it does not keep the session a...
wxHyperlinkCtrl * m_historyLink
Opens the History page from the docked panel. Never shown inside the advanced window.
void updateDockMinHeight()
Give the AUI pane the controls' minimum height, so a dock never squeezes them.
void doCommit(bool aAndPush)
Commit the checked files (or amend the last commit when the amend box is ticked), then push when aAnd...
wxStaticText * m_summaryAdded
void showTrustCommand(const wxString &aCommand)
Show a command to copy under the status line, or hide the row when aCommand is empty.
One transfer's hold on its repository, released when reset, begun again or destroyed.
The transfers running on one repository, so every window can show and cancel the others'.
Told whenever a transfer on the repository it subscribed to begins or ends.
The project's git session.
Read repository state without blocking the UI.
GitOperation
What the open editors and the project settings looked like on disk before an operation that may rewri...