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 <set>
27
31
32class EDA_BASE_FRAME;
34class KIGIT_COMMON;
35enum class GitOperation;
36class wxCommandEvent;
37class wxMenuItem;
38class wxDataViewEvent;
39class wxStaticText;
40
41
48{
49public:
51
54 GIT_COMMIT_PANE( wxWindow* aParent, EDA_BASE_FRAME* aFrame );
55 ~GIT_COMMIT_PANE() override;
56
58 void SetFileSelectedHandler( std::function<void( const wxString& )> aHandler );
59
61 wxString GetCommitMessage() const;
62 void SetCommitMessage( const wxString& aMessage );
63
65 void SetMessageChangedHandler( std::function<void()> aHandler ) { m_messageChangedHandler = aHandler; }
66
68 void RefreshFileList();
69
73 void SetTransferBusy( bool aBusy, const wxString& aStatus = wxEmptyString );
74
76 void ShowTransferProgress( const wxString& aText );
77
80
83 void Pull();
84
87 void Push();
88
90 void BeginAmend( const wxString& aExpectedCommit = wxEmptyString );
91
93 void SetBusyChangedHandler( std::function<void( bool )> aHandler ) { m_busyChangedHandler = aHandler; }
94
96 int GetMinDockWidth() const { return m_minDockWidth; }
97
98private:
100 void onCommit( wxCommandEvent& aEvent );
101 void onCommitAndPush( wxCommandEvent& aEvent );
102 void onPull( wxCommandEvent& aEvent );
103
105 void abandonOperation( std::shared_ptr<KIGIT_COMMON> aCommon );
106 void finishAbandonOperation( std::shared_ptr<KIGIT_COMMON> aCommon, const std::vector<wxString>& aOutside );
107 void onAmendToggled( wxCommandEvent& aEvent );
108 void onNewBranchToggled( wxCommandEvent& aEvent );
109 void onRecentMessage( wxCommandEvent& aEvent );
110 void onShowDiff( wxCommandEvent& aEvent );
111 void onFileActivated( wxDataViewEvent& aEvent );
112 void onChecklistContextMenu( wxDataViewEvent& aEvent );
113 void discardFile( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aPath );
114 void confirmDiscardFile( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aPath, bool aTracked,
115 bool aConflicted, wxString aRoot );
116
119 void doCommit( bool aAndPush );
120
121 struct COMMIT_REQUEST;
122 void saveForCommit( std::shared_ptr<KIGIT_COMMON> aCommon, std::shared_ptr<COMMIT_REQUEST> aRequest );
123 void finishCommit( std::shared_ptr<KIGIT_COMMON> aCommon, const COMMIT_REQUEST& aRequest );
124 void onChecklistChanged( wxDataViewEvent& aEvent );
125 void onMessageChanged( wxCommandEvent& aEvent );
126 void onIdle( wxIdleEvent& aEvent );
127 void onSize( wxSizeEvent& aEvent );
128
130 void onSettings( wxCommandEvent& aEvent );
131 void setAuthor();
132
134 void setStatusText( const wxString& aText );
135
137 bool transferCanStart();
138
141 void layoutWide();
142
145 void updateSummary();
146
147 struct STATUS;
148
150 void applyStatus( const STATUS& aStatus );
151
153 void populateBranches( const STATUS& aStatus );
154
156 void populateRecentMessages( const std::vector<wxString>& aMessages );
157
161 void setDescription( const wxString& aText );
162
164 void showDisabledState();
165
167 void setBusy( bool aBusy, const wxString& aStatus );
168
170 void runActionQuery( std::shared_ptr<KIGIT_COMMON> aCommon, std::function<void( KIGIT_COMMON& )> aWork,
171 std::function<void()> aDone, const wxString& aStatus );
172
173 // The on*Done continuations run back on the UI thread, so credential prompts and
174 // confirmations stay there.
175 void submitPush( std::shared_ptr<KIGIT_COMMON> aCommon );
176 void startPush( std::shared_ptr<KIGIT_COMMON> aCommon, const wxString& aBranch, const wxString& aHead );
177 void onPushDone( std::shared_ptr<KIGIT_COMMON> aCommon, int aResult, const wxString& aError, bool aAuthFailure,
178 bool aCancelled );
181 void submitPull( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush );
182 void startPull( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush );
183
186 void resolvePullConflicts( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush );
187 struct MERGE_PREPARATION;
188 void finishPullConflictPreparation( std::shared_ptr<KIGIT_COMMON> aCommon, bool aThenPush,
189 std::shared_ptr<MERGE_PREPARATION> aPreparation );
190 void onPullDone( std::shared_ptr<KIGIT_COMMON> aCommon, int aResult, const wxString& aError, bool aAuthFailure,
191 bool aThenPush, bool aCancelled );
192
194 void updateMessageVisibility( bool aHasChanges );
195
197 void updateCommitButton();
198
200 void updateSummaryCount();
201
203 wxString operationNoun() const;
204
206 wxString abandonLabel() const;
207
210 void syncListener();
211
213
216
218 bool m_inAdvancedWindow = false;
219
221
223
225 bool m_hasRepo = false;
226
229
232
235
238
241
243 bool m_canAmend = false;
244
246 std::pair<wxString, wxString> m_amendHead;
247
250 wxStaticText* m_descriptionHint = nullptr;
251
253 std::vector<wxString> m_recentMessageTexts;
254
256 wxMenuItem* m_commitAndPushItem = nullptr;
257
260
261
264
265
267 std::function<void( bool )> m_busyChangedHandler;
268
270 wxString m_statusText;
271
274 bool m_listenerAttached = false;
275
278 std::weak_ptr<KIGIT_COMMON> m_listenerSession;
279
282 std::set<wxString> m_shownPaths;
283
287
289 std::function<void()> m_messageChangedHandler;
290
293
294 std::function<void( const wxString& )> m_fileSelectedHandler;
295
296 // The summary box of the wide layout. Null in the docked panel.
297 wxStaticText* m_summaryFiles = nullptr;
298 wxStaticText* m_summaryAdded = nullptr;
299 wxStaticText* m_summaryRemoved = nullptr;
300
302 std::pair<int, int> m_lineStats;
303
307 bool m_actionPending = false;
308};
309
310#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.
void submitPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush)
aThenPush pushes after a successful pull, which belongs only to the rejected-push recovery flow.
void updateCommitButton()
Set what the commit buttons say, and whether they are enabled, for the current state.
void onPull(wxCommandEvent &aEvent)
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.
void ShowTransferProgress(const wxString &aText)
Show a line of transfer progress. Called from the UI thread by a KIGIT_STATUS_REPORTER.
void SetTransferBusy(bool aBusy, const wxString &aStatus=wxEmptyString)
Put the panel into the state it uses while a transfer runs, for one started elsewhere.
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)
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)
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 startPush(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aBranch, const wxString &aHead)
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.
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.
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.
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.
void onFileActivated(wxDataViewEvent &aEvent)
bool m_upstreamAhead
True when the upstream has commits this project does not, so Get Changes has work to do.
void onPullDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, bool aAuthFailure, bool aThenPush, bool aCancelled)
bool m_commitButtonPushes
True while the main button reads Push, with nothing left to commit.
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.
void showDisabledState()
Clear the list and disable every control while version control is off.
void submitPush(std::shared_ptr< KIGIT_COMMON > aCommon)
void updateDescriptionHint()
Where the platform has no hint for a multi line box, a label lies over the description box while it i...
void onPushDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, bool aAuthFailure, bool aCancelled)
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.
std::pair< wxString, wxString > m_amendHead
The branch and commit chosen when amend started. Keep them fixed while editing.
void onChecklistContextMenu(wxDataViewEvent &aEvent)
void setStatusText(const wxString &aText)
Set the status line text and wrap it to the current panel width.
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.
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
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.
void startPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush)
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 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 onAmendToggled(wxCommandEvent &aEvent)
void onIdle(wxIdleEvent &aEvent)
bool m_listenerAttached
True once this panel has attached its refresh listener to a session at least once.
void onSize(wxSizeEvent &aEvent)
void syncListener()
Register a refresh listener with the project's current git session, re-registering if the session cha...
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.
void applyStatus(const STATUS &aStatus)
Apply a completed repository snapshot on the UI thread.
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...
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
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...