Use correct length for buffer
[TortoiseGit.git] / src / TortoiseProc / CommitDlg.h
bloba91d68891b659594d8acf8327ec3eefab34e8674
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2016 - 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 "Git.h"
33 #include "HyperLink.h"
34 #include "PatchViewDlg.h"
35 #include "MenuButton.h"
37 #include <regex>
39 #define ENDDIALOGTIMER 100
40 #define REFRESHTIMER 101
41 #define FILLPATCHVTIMER 102
43 typedef enum
45 GIT_POSTCOMMIT_CMD_NOTHING,
46 GIT_POSTCOMMIT_CMD_RECOMMIT,
47 GIT_POSTCOMMIT_CMD_PUSH,
48 GIT_POSTCOMMIT_CMD_DCOMMIT,
49 GIT_POSTCOMMIT_CMD_PULL,
50 GIT_POSTCOMMIT_CMD_CREATETAG,
51 } GIT_POSTCOMMIT_CMD;
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 virtual void InsertMenuItems(CMenu& mPopup, int& nCmd);
69 virtual bool HandleMenuItemClick(int cmd, CSciEdit * pSciEdit);
70 virtual void HandleSnippet(int type, const CString &text, CSciEdit *pSciEdit);
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 SetAuthor(CString author)
84 m_bSetAuthor = TRUE;
85 m_sAuthor = author;
87 void SetTime(CTime time)
89 m_bSetCommitDateTime = TRUE;
90 m_wantCommitTime = time;
92 private:
93 CTime m_wantCommitTime;
94 void ReloadHistoryEntries();
95 static UINT StatusThreadEntry(LPVOID pVoid);
96 UINT StatusThread();
97 void FillPatchView(bool onlySetTimer = false);
98 CWnd * GetPatchViewParentWnd() { return this; }
99 virtual void TogglePatchView();
100 void SetDlgTitle();
101 CString GetSignedOffByLine();
102 CString m_sTitle;
104 // Dialog Data
105 enum { IDD = IDD_COMMITDLG };
107 protected:
108 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
110 virtual BOOL OnInitDialog();
111 virtual void OnOK();
112 virtual void OnCancel();
113 virtual BOOL PreTranslateMessage(MSG* pMsg);
114 virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
115 afx_msg void OnBnClickedShowunversioned();
116 afx_msg void OnBnClickedHistory();
117 afx_msg void OnBnClickedBugtraqbutton();
118 afx_msg void OnEnChangeLogmessage();
119 afx_msg void OnStnClickedExternalwarning();
120 afx_msg void OnFocusMessage();
121 afx_msg void OnFocusFileList();
122 afx_msg LRESULT OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM);
123 afx_msg LRESULT OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM);
124 afx_msg LRESULT OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM);
125 afx_msg LRESULT OnGitStatusListCtrlItemChanged(WPARAM, LPARAM);
127 afx_msg LRESULT OnCheck(WPARAM count, LPARAM);
128 afx_msg LRESULT OnAutoListReady(WPARAM, LPARAM);
129 afx_msg LRESULT OnUpdateOKButton(WPARAM, LPARAM);
130 afx_msg LRESULT OnUpdateDataFalse(WPARAM, LPARAM);
131 afx_msg LRESULT OnFileDropped(WPARAM, LPARAM lParam);
132 afx_msg void OnTimer(UINT_PTR nIDEvent);
133 afx_msg void OnSize(UINT nType, int cx, int cy);
134 void Refresh();
135 void StartStatusThread();
136 void StopStatusThread();
137 void GetAutocompletionList();
138 void ScanFile(const CString& sFilePath, const CString& sRegex, const CString& sExt);
139 void DoSize(int delta);
140 void SetSplitterRange();
141 void SaveSplitterPos();
142 void UpdateCheckLinks();
143 void ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex);
144 void ParseSnippetFile(const CString& sFile, std::map<CString, CString>& mapSnippet);
145 void RunStartCommitHook();
147 DECLARE_MESSAGE_MAP()
149 public:
150 CString m_sLogMessage;
151 BOOL m_bKeepChangeList;
152 BOOL m_bDoNotAutoselectSubmodules;
153 bool m_bForceCommitAmend;
154 BOOL m_bCommitAmend;
155 BOOL m_bNoPostActions;
156 bool m_bSelectFilesForCommit;
157 bool m_bAutoClose;
158 CString m_AmendStr;
159 CString m_sBugID;
160 BOOL m_bWholeProject;
161 BOOL m_bWholeProject2;
162 CTGitPathList m_pathList;
163 CTGitPathList m_checkedPathList;
164 CTGitPathList m_updatedPathList;
165 GIT_POSTCOMMIT_CMD m_PostCmd;
166 BOOL m_bAmendDiffToLastCommit;
167 BOOL m_bCommitMessageOnly;
168 bool m_bWarnDetachedHead;
170 protected:
171 CTGitPathList m_selectedPathList;
172 CSciEdit m_cLogMessage;
173 INT_PTR m_itemsCount;
174 CComPtr<IBugTraqProvider> m_BugTraqProvider;
175 CString m_NoAmendStr;
176 BOOL m_bCreateNewBranch;
177 CString m_sCreateNewBranch;
178 BOOL m_bSetAuthor;
179 CString m_sAuthor;
181 int CheckHeadDetach();
183 private:
184 CWinThread* m_pThread;
185 std::map<CString, int> m_autolist;
186 std::map<CString, CString> m_snippet;
187 CGitStatusListCtrl m_ListCtrl;
188 BOOL m_bShowUnversioned;
189 volatile LONG m_bBlock;
190 volatile LONG m_bThreadRunning;
191 volatile LONG m_bRunThread;
192 CRegDWORD m_regAddBeforeCommit;
193 CRegDWORD m_regKeepChangelists;
194 CRegDWORD m_regDoNotAutoselectSubmodules;
195 CRegDWORD m_regShowWholeProject;
196 ProjectProperties m_ProjectProperties;
197 CString m_sWindowTitle;
198 static UINT WM_AUTOLISTREADY;
199 static UINT WM_UPDATEOKBUTTON;
200 static UINT WM_UPDATEDATAFALSE;
201 int m_nPopupPickCommitHash;
202 int m_nPopupPickCommitMessage;
203 int m_nPopupPasteListCmd;
204 int m_nPopupPasteLastMessage;
205 int m_nPopupRecentMessage;
206 CRegHistory m_History;
207 bool m_bCancelled;
208 CSplitterControl m_wndSplitter;
209 CRect m_DlgOrigRect;
210 CRect m_LogMsgOrigRect;
211 CPathWatcher m_pathwatcher;
212 CHyperLink m_ctrlShowPatch;
213 CPatchViewDlg m_patchViewdlg;
214 BOOL m_bSetCommitDateTime;
215 CDateTimeCtrl m_CommitDate;
216 CDateTimeCtrl m_CommitTime;
217 CButton m_AsCommitDateCtrl;
218 CLinkControl m_linkControl;
219 CString m_sLogTemplate;
220 CMenuButton m_ctrlOkButton;
221 CRegDWORD m_regLastAction;
222 void PrepareOkButton();
223 typedef struct
225 int id;
226 int cnt;
227 int wmid;
228 } ACCELLERATOR;
229 std::map<TCHAR, ACCELLERATOR> m_accellerators;
230 HACCEL m_hAccelOkButton;
232 CBugTraqAssociation m_bugtraq_association;
233 HACCEL m_hAccel;
234 bool RestoreFiles(bool doNotAsk = false, bool allowCancel = true);
236 protected:
237 afx_msg void OnBnClickedSignOff();
238 afx_msg void OnBnClickedCommitAmend();
239 afx_msg void OnBnClickedCommitMessageOnly();
240 afx_msg void OnBnClickedWholeProject();
241 afx_msg void OnScnUpdateUI(NMHDR *pNMHDR, LRESULT *pResult);
242 afx_msg void OnStnClickedViewPatch();
243 afx_msg void OnMoving(UINT fwSide, LPRECT pRect);
244 afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
245 afx_msg void OnHdnItemchangedFilelist(NMHDR *pNMHDR, LRESULT *pResult);
246 afx_msg void OnBnClickedCommitAmenddiff();
247 afx_msg void OnBnClickedNoautoselectsubmodules();
248 afx_msg void OnBnClickedCommitSetDateTime();
249 afx_msg void OnBnClickedCommitAsCommitDate();
250 afx_msg void OnBnClickedCheckNewBranch();
251 afx_msg void OnBnClickedCommitSetauthor();
253 CLinkControl m_CheckAll;
254 CLinkControl m_CheckNone;
255 CLinkControl m_CheckUnversioned;
256 CLinkControl m_CheckVersioned;
257 CLinkControl m_CheckAdded;
258 CLinkControl m_CheckDeleted;
259 CLinkControl m_CheckModified;
260 CLinkControl m_CheckFiles;
261 CLinkControl m_CheckSubmodules;