Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.h
blobea0e1f103995973ffc9c387d52152ff6e73495dc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2023 - TortoiseGit
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 2
9 // of the License, or (at your option) any later version.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 #include "StandAloneDlg.h"
23 #include "GitStatusListCtrl.h"
24 #include "RegHistory.h"
25 #include "registry.h"
26 #include "SciEdit.h"
27 #include "SplitterControl.h"
28 #include "LinkControl.h"
29 #include "PathWatcher.h"
30 #include "BugTraqAssociations.h"
31 #include "../IBugTraqProvider/IBugTraqProvider_h.h"
32 #include "HyperLink.h"
33 #include "PatchViewDlg.h"
34 #include "MenuButton.h"
35 #include "EnableStagingTypes.h"
36 #include <regex>
37 #include "MassiveGitTask.h"
39 #define ENDDIALOGTIMER 100
40 #define REFRESHTIMER 101
41 #define FILLPATCHVTIMER 102
43 enum class Git_PostCommit_Cmd
45 Nothing,
46 ReCommit,
47 Push,
48 DCommit,
49 Pull,
50 CreateTag,
54 /**
55 * \ingroup TortoiseProc
56 * Dialog to enter log messages used in a commit.
58 class CCommitDlg : public CResizableStandAloneDialog, public CSciEditContextMenuInterface, IHasPatchView
60 DECLARE_DYNAMIC(CCommitDlg)
62 public:
63 CCommitDlg(CWnd* pParent = nullptr); // standard constructor
64 virtual ~CCommitDlg();
66 protected:
67 // CSciEditContextMenuInterface
68 void InsertMenuItems(CMenu& mPopup, int& nCmd) override;
69 bool HandleMenuItemClick(int cmd, CSciEdit* pSciEdit) override;
70 void HandleSnippet(int type, const CString& text, CSciEdit* pSciEdit) override;
72 public:
73 void ShowViewPatchText(bool b=true)
75 if(b)
76 this->m_ctrlShowPatch.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_SHOWPATCH)));
77 else
78 this->m_ctrlShowPatch.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_HIDEPATCH)));
80 m_ctrlShowPatch.Invalidate();
82 void ShowPartialStagingTextAndUpdateDisplayState(bool b = true)
84 if (b)
86 this->m_ctrlPartialStaging.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PARTIAL_STAGING)));
87 m_stagingDisplayState |= SHOW_STAGING; // set
89 else
91 this->m_ctrlPartialStaging.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_HIDE_STAGING)));
92 m_stagingDisplayState &= ~SHOW_STAGING; // unset
94 m_ctrlPartialStaging.Invalidate();
96 void ShowPartialUnstagingTextAndUpdateDisplayState(bool b = true)
98 if (b)
100 this->m_ctrlPartialUnstaging.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_PARTIAL_UNSTAGING)));
101 m_stagingDisplayState |= SHOW_UNSTAGING; // set
103 else
105 this->m_ctrlPartialUnstaging.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_COMMIT_HIDE_UNSTAGING)));
106 m_stagingDisplayState &= ~SHOW_UNSTAGING; // unset
108 m_ctrlPartialUnstaging.Invalidate();
110 void SetAuthor(CString author)
112 m_bSetAuthor = TRUE;
113 m_sAuthor = author;
115 void SetTime(CTime time)
117 m_bSetCommitDateTime = TRUE;
118 m_wantCommitTime = time;
120 private:
121 CTime m_wantCommitTime;
122 void ReloadHistoryEntries();
123 static UINT StatusThreadEntry(LPVOID pVoid);
124 UINT StatusThread();
125 void FillPatchView(bool onlySetTimer = false);
126 CWnd* GetPatchViewParentWnd() override { return this; }
127 void TogglePatchView() override;
128 void SetDlgTitle();
129 CString GetSignedOffByLine();
130 CString m_sTitle;
131 void UpdateLogMsgByBugId(bool comapreExistingBugID);
133 // Dialog Data
134 enum { IDD = IDD_COMMITDLG };
136 protected:
137 void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
139 BOOL OnInitDialog() override;
140 void OnOK() override;
141 void PrepareIndexForCommitWithoutStagingSupport(int nListItems, bool& bAddSuccess, int& nchecked, CMassiveGitTask& mgtReAddAfterCommit, CMassiveGitTask& mgtReDelAfterCommit);
142 void OnCancel() override;
143 BOOL PreTranslateMessage(MSG* pMsg) override;
144 LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) override;
145 afx_msg void OnBnClickedShowunversioned();
146 afx_msg void OnBnClickedHistory();
147 afx_msg void OnBnClickedBugtraqbutton();
148 afx_msg void OnEnChangeLogmessage();
149 afx_msg void OnFocusMessage();
150 afx_msg void OnFocusFileList();
151 afx_msg LRESULT OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM);
152 afx_msg LRESULT OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM);
153 afx_msg LRESULT OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM);
154 afx_msg LRESULT OnGitStatusListCtrlItemChanged(WPARAM, LPARAM);
156 afx_msg LRESULT OnCheck(WPARAM count, LPARAM);
157 afx_msg LRESULT OnAutoListReady(WPARAM, LPARAM);
158 afx_msg LRESULT OnUpdateOKButton(WPARAM, LPARAM);
159 afx_msg LRESULT OnUpdateDataFalse(WPARAM, LPARAM);
160 afx_msg LRESULT OnPartialStagingRefreshPatchView(WPARAM, LPARAM);
161 afx_msg LRESULT OnFileDropped(WPARAM, LPARAM lParam);
162 afx_msg void OnTimer(UINT_PTR nIDEvent);
163 afx_msg void OnSize(UINT nType, int cx, int cy);
164 void Refresh();
165 void StartStatusThread();
166 void StopStatusThread();
167 void GetAutocompletionList(std::map<CString, int>& autolist);
168 void ScanFile(std::map<CString, int>& autolist, const CString& sFilePath, const CString& sRegex, const CString& sExt);
169 void DoSize(int delta);
170 void SetSplitterRange();
171 void SaveSplitterPos();
172 void UpdateCheckLinks();
173 void ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex);
174 void ParseSnippetFile(const CString& sFile, std::map<CString, CString>& mapSnippet);
175 bool RunStartCommitHook();
176 void CreatePatchViewDlg();
177 void DestroyPatchViewDlgIfOpen();
178 void PrepareStagingSupport();
180 DECLARE_MESSAGE_MAP()
182 public:
183 CString m_sLogMessage;
184 BOOL m_bDoNotAutoselectSubmodules;
185 bool m_bForceCommitAmend = false;
186 BOOL m_bCommitAmend;
187 bool m_bNoPostActions = false;
188 bool m_bSelectFilesForCommit = true;
189 bool m_bAutoClose = false;
190 CString m_AmendStr;
191 CString m_sBugID;
192 BOOL m_bWholeProject;
193 BOOL m_bWholeProject2;
194 CTGitPathList m_pathList;
195 Git_PostCommit_Cmd m_PostCmd = Git_PostCommit_Cmd::Nothing;
196 BOOL m_bAmendDiffToLastCommit;
197 BOOL m_bCommitMessageOnly;
198 bool m_bWarnDetachedHead = true;
200 protected:
201 CTGitPathList m_selectedPathList;
202 CSciEdit m_cLogMessage;
203 INT_PTR m_itemsCount = 0;
204 CComPtr<IBugTraqProvider> m_BugTraqProvider;
205 CString m_NoAmendStr;
206 BOOL m_bCreateNewBranch;
207 BOOL m_bSetAuthor;
208 CString m_sAuthor;
209 volatile bool m_bDoNotStoreLastSelectedLine = true; // true on first start of commit dialog and set on recommit
210 BOOL m_bStagingSupport;
211 volatile LONG m_nBlockItemChangeHandler = FALSE; // used to make sure FillPatch is called only once after a partial staging
213 int CheckHeadDetach();
215 private:
216 CWinThread* m_pThread = nullptr;
217 std::map<CString, CString> m_snippet;
218 CGitStatusListCtrl m_ListCtrl;
219 BOOL m_bShowUnversioned;
220 volatile LONG m_bBlock = FALSE;
221 volatile LONG m_bThreadRunning = FALSE;
222 volatile LONG m_bRunThread = FALSE;
223 CRegDWORD m_regAddBeforeCommit;
224 CRegDWORD m_regDoNotAutoselectSubmodules;
225 CRegDWORD m_regShowWholeProject;
226 ProjectProperties m_ProjectProperties;
227 CString m_sWindowTitle;
228 static UINT WM_AUTOLISTREADY;
229 static UINT WM_UPDATEOKBUTTON;
230 static UINT WM_UPDATEDATAFALSE;
231 static UINT WM_PARTIALSTAGINGREFRESHPATCHVIEW;
232 int m_nPopupPickCommitHash = 0;
233 int m_nPopupPickCommitMessage = 0;
234 int m_nPopupPasteListCmd = 0;
235 int m_nPopupPasteLastMessage = 0;
236 int m_nPopupRecentMessage = 0;
237 CRegHistory m_History;
238 bool m_bCancelled = false;
239 CSplitterControl m_wndSplitter;
240 CRect m_DlgOrigRect;
241 CRect m_LogMsgOrigRect;
242 CPathWatcher m_pathwatcher;
243 CHyperLink m_ctrlShowPatch;
244 CHyperLink m_ctrlPartialStaging;
245 CHyperLink m_ctrlPartialUnstaging;
246 CPatchViewDlg m_patchViewdlg;
247 BOOL m_bSetCommitDateTime;
248 CDateTimeCtrl m_CommitDate;
249 CDateTimeCtrl m_CommitTime;
250 CButton m_AsCommitDateCtrl;
251 CLinkControl m_linkControl;
252 CString m_sLogTemplate;
253 CMenuButton m_ctrlOkButton;
254 CRegDWORD m_regLastAction;
255 void PrepareOkButton();
256 struct ACCELLERATOR
258 int id;
259 int cnt;
260 int wmid;
262 std::map<wchar_t, ACCELLERATOR> m_accellerators;
263 HACCEL m_hAccelOkButton = nullptr;
265 CBugTraqAssociation m_bugtraq_association;
266 HACCEL m_hAccel = nullptr;
267 bool RestoreFiles(bool doNotAsk = false, bool allowCancel = true);
269 // State of the links "Partial Staging>>" and "Partial Unstaging>>" shown on the commit window
270 enum PartialStagingDisplayState : unsigned char
272 // both unset should never happen
273 SHOW_STAGING = 0x00000001, // unset when "Hide Staging"
274 SHOW_UNSTAGING = 0x00000002, // unset when "Hide Unstaging"
276 unsigned char m_stagingDisplayState = SHOW_STAGING | SHOW_UNSTAGING;
278 protected:
279 afx_msg void OnBnClickedSignOff();
280 afx_msg void OnBnClickedCommitAmend();
281 afx_msg void OnBnClickedCommitMessageOnly();
282 afx_msg void OnBnClickedWholeProject();
283 afx_msg void OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult);
284 afx_msg void OnStnClickedViewPatch();
285 afx_msg void OnStnClickedPartialUnstaging();
286 afx_msg void OnStnClickedPartialStaging();
287 afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
288 afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
289 afx_msg void OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult);
290 afx_msg void OnBnClickedCommitAmenddiff();
291 afx_msg void OnBnClickedNoautoselectsubmodules();
292 afx_msg void OnBnClickedCommitSetDateTime();
293 afx_msg void OnBnClickedCommitAsCommitDate();
294 afx_msg void OnBnClickedCheckNewBranch();
295 afx_msg void OnBnClickedCommitSetauthor();
296 afx_msg void OnBnClickedStagingSupport();
298 CLinkControl m_CheckAll;
299 CLinkControl m_CheckNone;
300 CLinkControl m_CheckUnversioned;
301 CLinkControl m_CheckVersioned;
302 CLinkControl m_CheckAdded;
303 CLinkControl m_CheckDeleted;
304 CLinkControl m_CheckModified;
305 CLinkControl m_CheckFiles;
306 CLinkControl m_CheckSubmodules;