OSDN Git Service

a193f78be326be57dba9d9809897d3852d1c9699
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / CommitDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "CommitDlg.h"\r
22 #include "DirFileEnum.h"\r
23 //#include "GitConfig.h"\r
24 //#include "GitProperties.h"\r
25 #include "MessageBox.h"\r
26 #include "AppUtils.h"\r
27 #include "PathUtils.h"\r
28 #include "Git.h"\r
29 #include "Registry.h"\r
30 #include "GitStatus.h"\r
31 #include "HistoryDlg.h"\r
32 #include "Hooks.h"\r
33 #include "CommonResource.h"\r
34 #include "UnicodeUtils.h"\r
35 \r
36 #ifdef _DEBUG\r
37 #define new DEBUG_NEW\r
38 #undef THIS_FILE\r
39 static char THIS_FILE[] = __FILE__;\r
40 #endif\r
41 \r
42 UINT CCommitDlg::WM_AUTOLISTREADY = RegisterWindowMessage(_T("TORTOISEGIT_AUTOLISTREADY_MSG"));\r
43 \r
44 IMPLEMENT_DYNAMIC(CCommitDlg, CResizableStandAloneDialog)\r
45 CCommitDlg::CCommitDlg(CWnd* pParent /*=NULL*/)\r
46         : CResizableStandAloneDialog(CCommitDlg::IDD, pParent)\r
47         , m_bRecursive(FALSE)\r
48         , m_bShowUnversioned(FALSE)\r
49         , m_bBlock(FALSE)\r
50         , m_bThreadRunning(FALSE)\r
51         , m_bRunThread(FALSE)\r
52         , m_pThread(NULL)\r
53         , m_bKeepLocks(FALSE)\r
54         , m_bKeepChangeList(TRUE)\r
55         , m_itemsCount(0)\r
56         , m_bSelectFilesForCommit(TRUE)\r
57 {\r
58 }\r
59 \r
60 CCommitDlg::~CCommitDlg()\r
61 {\r
62         if(m_pThread != NULL)\r
63         {\r
64                 delete m_pThread;\r
65         }\r
66 }\r
67 \r
68 void CCommitDlg::DoDataExchange(CDataExchange* pDX)\r
69 {\r
70         CResizableStandAloneDialog::DoDataExchange(pDX);\r
71         DDX_Control(pDX, IDC_FILELIST, m_ListCtrl);\r
72         DDX_Control(pDX, IDC_LOGMESSAGE, m_cLogMessage);\r
73         DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);\r
74         DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);\r
75         DDX_Text(pDX, IDC_BUGID, m_sBugID);\r
76         DDX_Check(pDX, IDC_KEEPLOCK, m_bKeepLocks);\r
77         DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);\r
78         DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);\r
79         DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);\r
80 }\r
81 \r
82 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)\r
83         ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)\r
84         ON_BN_CLICKED(IDHELP, OnBnClickedHelp)\r
85         ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)\r
86 //      ON_BN_CLICKED(IDC_HISTORY, OnBnClickedHistory)\r
87         ON_BN_CLICKED(IDC_BUGTRAQBUTTON, OnBnClickedBugtraqbutton)\r
88         ON_EN_CHANGE(IDC_LOGMESSAGE, OnEnChangeLogmessage)\r
89         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnGitStatusListCtrlItemCountChanged)\r
90         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnGitStatusListCtrlNeedsRefresh)\r
91         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)\r
92         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_CHECKCHANGED, &CCommitDlg::OnGitStatusListCtrlCheckChanged)\r
93         ON_REGISTERED_MESSAGE(WM_AUTOLISTREADY, OnAutoListReady) \r
94         ON_WM_TIMER()\r
95     ON_WM_SIZE()\r
96         ON_STN_CLICKED(IDC_EXTERNALWARNING, &CCommitDlg::OnStnClickedExternalwarning)\r
97         ON_BN_CLICKED(IDC_SIGNOFF, &CCommitDlg::OnBnClickedSignOff)\r
98         ON_STN_CLICKED(IDC_COMMITLABEL, &CCommitDlg::OnStnClickedCommitlabel)\r
99     ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)\r
100 END_MESSAGE_MAP()\r
101 \r
102 BOOL CCommitDlg::OnInitDialog()\r
103 {\r
104         CResizableStandAloneDialog::OnInitDialog();\r
105         \r
106         m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);\r
107         m_bShowUnversioned = m_regAddBeforeCommit;\r
108 \r
109         m_History.SetMaxHistoryItems((LONG)CRegDWORD(_T("Software\\TortoiseGit\\MaxHistoryItems"), 25));\r
110 \r
111         m_regKeepChangelists = CRegDWORD(_T("Software\\TortoiseGit\\KeepChangeLists"), FALSE);\r
112         m_bKeepChangeList = m_regKeepChangelists;\r
113 \r
114 //      GitConfig config;\r
115 //      m_bKeepLocks = config.KeepLocks();\r
116 \r
117         UpdateData(FALSE);\r
118         \r
119         m_ListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS , _T("CommitDlg"));\r
120         m_ListCtrl.SetSelectButton(&m_SelectAll);\r
121         m_ListCtrl.SetStatLabel(GetDlgItem(IDC_STATISTICS));\r
122         m_ListCtrl.SetCancelBool(&m_bCancelled);\r
123         m_ListCtrl.SetEmptyString(IDS_COMMITDLG_NOTHINGTOCOMMIT);\r
124         m_ListCtrl.EnableFileDrop();\r
125         m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);\r
126         \r
127         //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);\r
128 //      m_ProjectProperties.ReadPropsPathList(m_pathList);\r
129         m_cLogMessage.Init(m_ProjectProperties);\r
130         m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));\r
131         m_cLogMessage.RegisterContextMenuHandler(this);\r
132 \r
133         OnEnChangeLogmessage();\r
134 \r
135         m_tooltips.Create(this);\r
136         m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);\r
137         m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);\r
138 //      m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);\r
139         \r
140         m_SelectAll.SetCheck(BST_INDETERMINATE);\r
141 \r
142 #if 0\r
143         CBugTraqAssociations bugtraq_associations;\r
144         bugtraq_associations.Load();\r
145 \r
146         if (bugtraq_associations.FindProvider(m_pathList, &m_bugtraq_association))\r
147         {\r
148                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
149                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
150 \r
151                 CComPtr<IBugTraqProvider> pProvider;\r
152                 HRESULT hr = pProvider.CoCreateInstance(m_bugtraq_association.GetProviderClass());\r
153                 if (SUCCEEDED(hr))\r
154                 {\r
155                         m_BugTraqProvider = pProvider;\r
156                         BSTR temp = NULL;\r
157                         if (SUCCEEDED(hr = pProvider->GetLinkText(GetSafeHwnd(), m_bugtraq_association.GetParameters().AllocSysString(), &temp)))\r
158                         {\r
159                                 SetDlgItemText(IDC_BUGTRAQBUTTON, temp);\r
160                                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(TRUE);\r
161                                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_SHOW);\r
162                         }\r
163 \r
164                         SysFreeString(temp);\r
165                 }\r
166 \r
167                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
168         }\r
169         else if (!m_ProjectProperties.sMessage.IsEmpty())\r
170         {\r
171                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_SHOW);\r
172                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_SHOW);\r
173                 if (!m_ProjectProperties.sLabel.IsEmpty())\r
174                         SetDlgItemText(IDC_BUGIDLABEL, m_ProjectProperties.sLabel);\r
175                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
176                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
177                 GetDlgItem(IDC_BUGID)->SetFocus();\r
178                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(m_sLogMessage);\r
179                 if (!sBugID.IsEmpty())\r
180                 {\r
181                         SetDlgItemText(IDC_BUGID, sBugID);\r
182                 }\r
183         }\r
184         else\r
185 #endif\r
186         {\r
187                 GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
188                 GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
189                 GetDlgItem(IDC_BUGTRAQBUTTON)->ShowWindow(SW_HIDE);\r
190                 GetDlgItem(IDC_BUGTRAQBUTTON)->EnableWindow(FALSE);\r
191                 GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
192         }\r
193 \r
194         if (!m_sLogMessage.IsEmpty())\r
195                 m_cLogMessage.SetText(m_sLogMessage);\r
196                 \r
197         GetWindowText(m_sWindowTitle);\r
198         \r
199         AdjustControlSize(IDC_SHOWUNVERSIONED);\r
200         AdjustControlSize(IDC_SELECTALL);\r
201         AdjustControlSize(IDC_KEEPLOCK);\r
202 \r
203         GetClientRect(m_DlgOrigRect);\r
204         m_cLogMessage.GetClientRect(m_LogMsgOrigRect);\r
205 \r
206         AddAnchor(IDC_COMMITLABEL, TOP_LEFT, TOP_RIGHT);\r
207         AddAnchor(IDC_BUGIDLABEL, TOP_RIGHT);\r
208         AddAnchor(IDC_BUGID, TOP_RIGHT);\r
209         AddAnchor(IDC_BUGTRAQBUTTON, TOP_RIGHT);\r
210         AddAnchor(IDC_COMMIT_TO, TOP_LEFT, TOP_RIGHT);\r
211         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
212 //      AddAnchor(IDC_HISTORY, TOP_LEFT);\r
213         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
214         AddAnchor(IDC_SIGNOFF,   TOP_RIGHT);\r
215         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
216         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
217         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
218         AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);\r
219         AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);\r
220         AddAnchor(IDC_EXTERNALWARNING, BOTTOM_RIGHT);\r
221         AddAnchor(IDC_STATISTICS, BOTTOM_LEFT, BOTTOM_RIGHT);\r
222         AddAnchor(IDC_KEEPLOCK, BOTTOM_LEFT);\r
223         AddAnchor(IDC_KEEPLISTS, BOTTOM_LEFT);\r
224         AddAnchor(IDOK, BOTTOM_RIGHT);\r
225         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
226         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
227         AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);\r
228         \r
229         if (hWndExplorer)\r
230                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
231         EnableSaveRestore(_T("CommitDlg"));\r
232         DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
233         RECT rcDlg, rcLogMsg, rcFileList;\r
234         GetClientRect(&rcDlg);\r
235         m_cLogMessage.GetWindowRect(&rcLogMsg);\r
236         ScreenToClient(&rcLogMsg);\r
237         m_ListCtrl.GetWindowRect(&rcFileList);\r
238         ScreenToClient(&rcFileList);\r
239         if (yPos)\r
240         {\r
241                 RECT rectSplitter;\r
242                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
243                 ScreenToClient(&rectSplitter);\r
244                 int delta = yPos - rectSplitter.top;\r
245                 if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30))\r
246                 {\r
247                         m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE);\r
248                         DoSize(delta);\r
249                 }\r
250         }\r
251 \r
252         // add all directories to the watcher\r
253         for (int i=0; i<m_pathList.GetCount(); ++i)\r
254         {\r
255                 if (m_pathList[i].IsDirectory())\r
256                         m_pathwatcher.AddPath(m_pathList[i]);\r
257         }\r
258 \r
259         m_updatedPathList = m_pathList;\r
260 \r
261         //first start a thread to obtain the file list with the status without\r
262         //blocking the dialog\r
263         InterlockedExchange(&m_bBlock, TRUE);\r
264         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
265         if (m_pThread==NULL)\r
266         {\r
267                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
268                 InterlockedExchange(&m_bBlock, FALSE);\r
269         }\r
270         else\r
271         {\r
272                 m_pThread->m_bAutoDelete = FALSE;\r
273                 m_pThread->ResumeThread();\r
274         }\r
275         CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);\r
276         CRegDWORD historyhint = CRegDWORD(_T("Software\\TortoiseGit\\HistoryHintShown"), FALSE);\r
277         if ((((DWORD)err)!=FALSE)&&((((DWORD)historyhint)==FALSE)))\r
278         {\r
279                 historyhint = TRUE;\r
280 //              ShowBalloon(IDC_HISTORY, IDS_COMMITDLG_HISTORYHINT_TT, IDI_INFORMATION);\r
281         }\r
282         err = FALSE;\r
283 \r
284         this->UpdateData(TRUE);\r
285         this->m_bCommitAmend=FALSE;\r
286         this->UpdateData(FALSE);\r
287 \r
288         return FALSE;  // return TRUE unless you set the focus to a control\r
289         // EXCEPTION: OCX Property Pages should return FALSE\r
290 }\r
291 \r
292 void CCommitDlg::OnOK()\r
293 {\r
294         if (m_bBlock)\r
295                 return;\r
296         if (m_bThreadRunning)\r
297         {\r
298                 m_bCancelled = true;\r
299                 InterlockedExchange(&m_bRunThread, FALSE);\r
300                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
301                 if (m_bThreadRunning)\r
302                 {\r
303                         // we gave the thread a chance to quit. Since the thread didn't\r
304                         // listen to us we have to kill it.\r
305                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
306                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
307                 }\r
308         }\r
309         this->UpdateData();\r
310 \r
311         CString id;\r
312         GetDlgItemText(IDC_BUGID, id);\r
313         if (!m_ProjectProperties.CheckBugID(id))\r
314         {\r
315                 ShowBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDI_EXCLAMATION);\r
316                 return;\r
317         }\r
318         m_sLogMessage = m_cLogMessage.GetText();\r
319         if ( m_sLogMessage.IsEmpty() )\r
320         {\r
321                 // no message entered, go round again\r
322                 CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
323                 return;\r
324         }\r
325         if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage)))\r
326         {\r
327                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_NOISSUEWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
328                         return;\r
329         }\r
330 \r
331 #if 0\r
332         CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);\r
333         if (!(DWORD)regUnversionedRecurse)\r
334         {\r
335                 // Find unversioned directories which are marked for commit. The user might expect them\r
336                 // to be added recursively since he cannot the the files. Let's ask the user if he knows\r
337                 // what he is doing.\r
338                 int nListItems = m_ListCtrl.GetItemCount();\r
339                 for (int j=0; j<nListItems; j++)\r
340                 {\r
341                         const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
342                         if (entry->IsChecked() && (entry->status == Git_wc_status_unversioned) && entry->IsFolder() )\r
343                         {\r
344                                 if (CMessageBox::Show(this->m_hWnd, IDS_COMMITDLG_UNVERSIONEDFOLDERWARNING, IDS_APPNAME, MB_YESNO | MB_ICONWARNING)!=IDYES)\r
345                                         return;\r
346                         }\r
347                 }\r
348         }\r
349 #endif\r
350         m_pathwatcher.Stop();\r
351         InterlockedExchange(&m_bBlock, TRUE);\r
352         CDWordArray arDeleted;\r
353         //first add all the unversioned files the user selected\r
354         //and check if all versioned files are selected\r
355         int nchecked = 0;\r
356         m_bRecursive = true;\r
357         int nListItems = m_ListCtrl.GetItemCount();\r
358 \r
359         CTGitPathList itemsToAdd;\r
360         CTGitPathList itemsToRemove;\r
361         //std::set<CString> checkedLists;\r
362         //std::set<CString> uncheckedLists;\r
363 \r
364         //CString checkedfiles;\r
365         //CString uncheckedfiles;\r
366 \r
367         CString cmd;\r
368         CString out;\r
369 \r
370         for (int j=0; j<nListItems; j++)\r
371         {\r
372                 //const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(j);\r
373                 CTGitPath *entry = (CTGitPath*)m_ListCtrl.GetItemData(j);\r
374                 if (entry->m_Checked)\r
375                 {\r
376 #if 0\r
377                         if (entry->status == Git_wc_status_unversioned)\r
378                         {\r
379                                 itemsToAdd.AddPath(entry->GetPath());\r
380                         }\r
381                         if (entry->status == Git_wc_status_conflicted)\r
382                         {\r
383                                 bHasConflicted = true;\r
384                         }\r
385                         if (entry->status == Git_wc_status_missing)\r
386                         {\r
387                                 itemsToRemove.AddPath(entry->GetPath());\r
388                         }\r
389                         if (entry->status == Git_wc_status_deleted)\r
390                         {\r
391                                 arDeleted.Add(j);\r
392                         }\r
393                         if (entry->IsInExternal())\r
394                         {\r
395                                 bCheckedInExternal = true;\r
396                         }\r
397 #endif\r
398                         cmd.Format(_T("git.exe update-index --add -- \"%s\""),entry->GetGitPathString());\r
399                         g_Git.Run(cmd,&out,CP_OEMCP);\r
400                         nchecked++;\r
401                         //checkedLists.insert(entry->GetGitPathString());\r
402 //                      checkedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
403                 }\r
404                 else\r
405                 {\r
406                         //uncheckedLists.insert(entry->GetGitPathString());\r
407                         if(entry->m_Action & CTGitPath::LOGACTIONS_ADDED)\r
408                         {       //To init git repository, there are not HEAD, so we can use git reset command\r
409                                 cmd.Format(_T("git.exe rm --cache -- \"%s\""),entry->GetGitPathString());\r
410                                 g_Git.Run(cmd,&out,CP_OEMCP);   \r
411                         }\r
412                         else\r
413                         {\r
414                                 cmd.Format(_T("git.exe reset -- %s"),entry->GetGitPathString());\r
415                                 g_Git.Run(cmd,&out,CP_OEMCP);\r
416                         }\r
417 \r
418                 //      uncheckedfiles += _T("\"")+entry->GetGitPathString()+_T("\" ");\r
419 #if 0\r
420                         if ((entry->status != Git_wc_status_unversioned)        &&\r
421                                 (entry->status != Git_wc_status_ignored))\r
422                         {\r
423                                 nUnchecked++;\r
424                                 uncheckedLists.insert(entry->GetChangeList());\r
425                                 if (m_bRecursive)\r
426                                 {\r
427                                         // This algorithm is for the sake of simplicity of the complexity O(N?\r
428                                         for (int k=0; k<nListItems; k++)\r
429                                         {\r
430                                                 const CGitStatusListCtrl::FileEntry * entryK = m_ListCtrl.GetListEntry(k);\r
431                                                 if (entryK->IsChecked() && entryK->GetPath().IsAncestorOf(entry->GetPath())  )\r
432                                                 {\r
433                                                         // Fall back to a non-recursive commit to prevent items being\r
434                                                         // committed which aren't checked although its parent is checked\r
435                                                         // (property change, directory deletion, ... )\r
436                                                         m_bRecursive = false;\r
437                                                         break;\r
438                                                 }\r
439                                         }\r
440                                 }\r
441                         }\r
442 #endif\r
443                 }\r
444         }\r
445 \r
446         //if(uncheckedfiles.GetLength()>0)\r
447         //{\r
448         //      cmd.Format(_T("git.exe reset -- %s"),uncheckedfiles);\r
449         //      g_Git.Run(cmd,&out);\r
450         //}\r
451 \r
452         //if(checkedfiles.GetLength()>0)\r
453         if(nchecked||m_bCommitAmend)\r
454         {\r
455         //      cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);\r
456         //      g_Git.Run(cmd,&out);\r
457 \r
458                 CString tempfile=::GetTempFile();\r
459                 CFile file(tempfile,CFile::modeReadWrite|CFile::modeCreate );\r
460                 CStringA log=CUnicodeUtils::GetUTF8( m_sLogMessage);\r
461                 file.Write(log,log.GetLength());\r
462                 //file.WriteString(m_sLogMessage);\r
463                 file.Close();\r
464         \r
465                 out =_T("");\r
466                 CString amend;\r
467                 if(this->m_bCommitAmend)\r
468                 {\r
469                         amend=_T("--amend");\r
470                 }\r
471                 cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);\r
472                 g_Git.Run(cmd,&out,CP_OEMCP);\r
473         \r
474                 CFile::Remove(tempfile);\r
475 \r
476                 CMessageBox::Show(this->m_hWnd, out, _T("Commit Finish"), MB_OK | MB_ICONINFORMATION);\r
477         }else\r
478                 CMessageBox::Show(this->m_hWnd, _T("Nothing Commit"), _T("Commit Finish"), MB_OK | MB_ICONINFORMATION);\r
479 #if 0\r
480         if (m_pathwatcher.GetNumberOfChangedPaths() && m_bRecursive)\r
481         {\r
482                 // There are paths which got changed (touched at least).\r
483                 // We have to find out if this affects the selection in the commit dialog\r
484                 // If it could affect the selection, revert back to a non-recursive commit\r
485                 CTGitPathList changedList = m_pathwatcher.GetChangedPaths();\r
486                 changedList.RemoveDuplicates();\r
487                 for (int i=0; i<changedList.GetCount(); ++i)\r
488                 {\r
489                         if (changedList[i].IsAdminDir())\r
490                         {\r
491                                 // something inside an admin dir was changed.\r
492                                 // if it's the entries file, then we have to fully refresh because\r
493                                 // files may have been added/removed from version control\r
494                                 if ((changedList[i].GetWinPathString().Right(7).CompareNoCase(_T("entries")) == 0) &&\r
495                                         (changedList[i].GetWinPathString().Find(_T("\\tmp\\"))<0))\r
496                                 {\r
497                                         m_bRecursive = false;\r
498                                         break;\r
499                                 }\r
500                         }\r
501                         else if (!m_ListCtrl.IsPathShown(changedList[i]))\r
502                         {\r
503                                 // a path which is not shown in the list has changed\r
504                                 CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(changedList[i]);\r
505                                 if (entry)\r
506                                 {\r
507                                         // check if the changed path would get committed by a recursive commit\r
508                                         if ((!entry->IsFromDifferentRepository()) &&\r
509                                                 (!entry->IsInExternal()) &&\r
510                                                 (!entry->IsNested()) && \r
511                                                 (!entry->IsChecked()))\r
512                                         {\r
513                                                 m_bRecursive = false;\r
514                                                 break;\r
515                                         }\r
516                                 }\r
517                         }\r
518                 }\r
519         }\r
520 \r
521 \r
522         // Now, do all the adds - make sure that the list is sorted so that parents \r
523         // are added before their children\r
524         itemsToAdd.SortByPathname();\r
525         Git Git;\r
526         if (!Git.Add(itemsToAdd, &m_ProjectProperties, Git_depth_empty, FALSE, FALSE, TRUE))\r
527         {\r
528                 CMessageBox::Show(m_hWnd, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
529                 InterlockedExchange(&m_bBlock, FALSE);\r
530                 Refresh();\r
531                 return;\r
532         }\r
533 \r
534         // Remove any missing items\r
535         // Not sure that this sort is really necessary - indeed, it might be better to do a reverse sort at this point\r
536         itemsToRemove.SortByPathname();\r
537         Git.Remove(itemsToRemove, TRUE);\r
538 \r
539         //the next step: find all deleted files and check if they're \r
540         //inside a deleted folder. If that's the case, then remove those\r
541         //files from the list since they'll get deleted by the parent\r
542         //folder automatically.\r
543         m_ListCtrl.Block(TRUE, FALSE);\r
544         INT_PTR nDeleted = arDeleted.GetCount();\r
545         for (INT_PTR i=0; i<arDeleted.GetCount(); i++)\r
546         {\r
547                 if (m_ListCtrl.GetCheck(arDeleted.GetAt(i)))\r
548                 {\r
549                         const CTGitPath& path = m_ListCtrl.GetListEntry(arDeleted.GetAt(i))->GetPath();\r
550                         if (path.IsDirectory())\r
551                         {\r
552                                 //now find all children of this directory\r
553                                 for (int j=0; j<arDeleted.GetCount(); j++)\r
554                                 {\r
555                                         if (i!=j)\r
556                                         {\r
557                                                 CGitStatusListCtrl::FileEntry* childEntry = m_ListCtrl.GetListEntry(arDeleted.GetAt(j));\r
558                                                 if (childEntry->IsChecked())\r
559                                                 {\r
560                                                         if (path.IsAncestorOf(childEntry->GetPath()))\r
561                                                         {\r
562                                                                 m_ListCtrl.SetEntryCheck(childEntry, arDeleted.GetAt(j), false);\r
563                                                                 nDeleted--;\r
564                                                         }\r
565                                                 }\r
566                                         }\r
567                                 }\r
568                         }\r
569                 }\r
570         } \r
571         m_ListCtrl.Block(FALSE, FALSE);\r
572 \r
573         if ((nUnchecked != 0)||(bCheckedInExternal)||(bHasConflicted)||(!m_bRecursive))\r
574         {\r
575                 //save only the files the user has checked into the temporary file\r
576                 m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);\r
577         }\r
578         m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);\r
579         // the item count is used in the progress dialog to show the overall commit\r
580         // progress.\r
581         // deleted items only send one notification event, all others send two\r
582         m_itemsCount = ((m_selectedPathList.GetCount() - nDeleted - itemsToRemove.GetCount()) * 2) + nDeleted + itemsToRemove.GetCount();\r
583 \r
584         if ((m_bRecursive)&&(checkedLists.size() == 1))\r
585         {\r
586                 // all checked items belong to the same changelist\r
587                 // find out if there are any unchecked items which belong to that changelist\r
588                 if (uncheckedLists.find(*checkedLists.begin()) == uncheckedLists.end())\r
589                         m_sChangeList = *checkedLists.begin();\r
590         }\r
591 #endif\r
592         UpdateData();\r
593         m_regAddBeforeCommit = m_bShowUnversioned;\r
594         if (!GetDlgItem(IDC_KEEPLOCK)->IsWindowEnabled())\r
595                 m_bKeepLocks = FALSE;\r
596         m_regKeepChangelists = m_bKeepChangeList;\r
597         if (!GetDlgItem(IDC_KEEPLISTS)->IsWindowEnabled())\r
598                 m_bKeepChangeList = FALSE;\r
599         InterlockedExchange(&m_bBlock, FALSE);\r
600         m_sBugID.Trim();\r
601         if (!m_sBugID.IsEmpty())\r
602         {\r
603                 m_sBugID.Replace(_T(", "), _T(","));\r
604                 m_sBugID.Replace(_T(" ,"), _T(","));\r
605                 CString sBugID = m_ProjectProperties.sMessage;\r
606                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
607                 if (m_ProjectProperties.bAppend)\r
608                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
609                 else\r
610                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
611         }\r
612         m_History.AddEntry(m_sLogMessage);\r
613         m_History.Save();\r
614 \r
615         SaveSplitterPos();\r
616 \r
617         CResizableStandAloneDialog::OnOK();\r
618 }\r
619 \r
620 void CCommitDlg::SaveSplitterPos()\r
621 {\r
622         if (!IsIconic())\r
623         {\r
624                 CRegDWORD regPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\CommitDlgSizer"));\r
625                 RECT rectSplitter;\r
626                 m_wndSplitter.GetWindowRect(&rectSplitter);\r
627                 ScreenToClient(&rectSplitter);\r
628                 regPos = rectSplitter.top;\r
629         }\r
630 }\r
631 \r
632 UINT CCommitDlg::StatusThreadEntry(LPVOID pVoid)\r
633 {\r
634         return ((CCommitDlg*)pVoid)->StatusThread();\r
635 }\r
636 \r
637 UINT CCommitDlg::StatusThread()\r
638 {\r
639         //get the status of all selected file/folders recursively\r
640         //and show the ones which have to be committed to the user\r
641         //in a list control. \r
642         InterlockedExchange(&m_bBlock, TRUE);\r
643         InterlockedExchange(&m_bThreadRunning, TRUE);// so the main thread knows that this thread is still running\r
644         InterlockedExchange(&m_bRunThread, TRUE);       // if this is set to FALSE, the thread should stop\r
645         m_bCancelled = false;\r
646 \r
647         DialogEnableWindow(IDOK, false);\r
648         DialogEnableWindow(IDC_SHOWUNVERSIONED, false);\r
649         DialogEnableWindow(IDC_SELECTALL, false);\r
650         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_HIDE);\r
651         DialogEnableWindow(IDC_EXTERNALWARNING, false);\r
652     // read the list of recent log entries before querying the WC for status\r
653     // -> the user may select one and modify / update it while we are crawling the WC\r
654 #if 0\r
655         if (m_History.GetCount()==0)\r
656         {\r
657                 CString reg;\r
658                 if (m_ListCtrl.m_sUUID.IsEmpty() && m_pathList.GetCount()>0)\r
659                 {\r
660                         Git Git;\r
661                         reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)Git.GetUUIDFromPath(m_pathList[0]));\r
662                 }\r
663                 else\r
664                         reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_ListCtrl.m_sUUID);\r
665                 m_History.Load(reg, _T("logmsgs"));\r
666         }\r
667 #endif\r
668     // Initialise the list control with the status of the files/folders below us\r
669         m_ListCtrl.Clear();\r
670         BOOL success = m_ListCtrl.GetStatus(m_pathList);\r
671 \r
672         //m_ListCtrl.UpdateFileList(git_revnum_t(GIT_REV_ZERO));\r
673         if(this->m_bShowUnversioned)\r
674                 m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);\r
675         \r
676         m_ListCtrl.CheckIfChangelistsArePresent(false);\r
677 \r
678         DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWINCHANGELIST;\r
679         dwShow |= DWORD(m_regAddBeforeCommit) ? SVNSLC_SHOWUNVERSIONED : 0;\r
680         if (success)\r
681         {\r
682                 if (m_checkedPathList.GetCount())\r
683                         m_ListCtrl.Show(dwShow, m_checkedPathList);\r
684                 else\r
685                 {\r
686                         DWORD dwCheck = m_bSelectFilesForCommit ? dwShow : 0;\r
687                         m_ListCtrl.Show(dwShow, dwCheck);\r
688                         m_bSelectFilesForCommit = true;\r
689                 }\r
690 \r
691                 if (m_ListCtrl.HasExternalsFromDifferentRepos())\r
692                 {\r
693                         GetDlgItem(IDC_EXTERNALWARNING)->ShowWindow(SW_SHOW);\r
694                         DialogEnableWindow(IDC_EXTERNALWARNING, TRUE);\r
695                 }\r
696                 \r
697                 SetDlgItemText(IDC_COMMIT_TO, g_Git.GetCurrentBranch());\r
698                 m_tooltips.AddTool(GetDlgItem(IDC_STATISTICS), m_ListCtrl.GetStatisticsString());\r
699         }\r
700         CString logmsg;\r
701         GetDlgItemText(IDC_LOGMESSAGE, logmsg);\r
702         DialogEnableWindow(IDOK, logmsg.GetLength() >= m_ProjectProperties.nMinLogSize);\r
703         if (!success)\r
704         {\r
705                 if (!m_ListCtrl.GetLastErrorMessage().IsEmpty())\r
706                         m_ListCtrl.SetEmptyString(m_ListCtrl.GetLastErrorMessage());\r
707                 m_ListCtrl.Show(dwShow);\r
708         }\r
709         if ((m_ListCtrl.GetItemCount()==0)&&(m_ListCtrl.HasUnversionedItems()))\r
710         {\r
711                 if (CMessageBox::Show(m_hWnd, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
712                 {\r
713                         m_bShowUnversioned = TRUE;\r
714                         GetDlgItem(IDC_SHOWUNVERSIONED)->SendMessage(BM_SETCHECK, BST_CHECKED);\r
715                         DWORD dwShow = (DWORD)(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWLOCKS);\r
716                         m_ListCtrl.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);\r
717                         m_ListCtrl.Show(dwShow);\r
718                 }\r
719         }\r
720 \r
721         CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);\r
722         SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
723 \r
724         m_autolist.clear();\r
725         // we don't have to block the commit dialog while we fetch the\r
726         // auto completion list.\r
727         m_pathwatcher.ClearChangedPaths();\r
728         InterlockedExchange(&m_bBlock, FALSE);\r
729         if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)\r
730         {\r
731                 m_ListCtrl.Block(TRUE, TRUE);\r
732                 GetAutocompletionList();\r
733                 m_ListCtrl.Block(FALSE, FALSE);\r
734         }\r
735         if (m_bRunThread)\r
736         {\r
737                 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);\r
738                 DialogEnableWindow(IDC_SELECTALL, true);\r
739                 if (m_ListCtrl.HasChangeLists())\r
740                         DialogEnableWindow(IDC_KEEPLISTS, true);\r
741                 if (m_ListCtrl.HasLocks())\r
742                         DialogEnableWindow(IDC_KEEPLOCK, true);\r
743                 // we have the list, now signal the main thread about it\r
744                 SendMessage(WM_AUTOLISTREADY);  // only send the message if the thread wasn't told to quit!\r
745         }\r
746 \r
747         InterlockedExchange(&m_bRunThread, FALSE);\r
748         InterlockedExchange(&m_bThreadRunning, FALSE);\r
749         // force the cursor to normal\r
750         RefreshCursor();\r
751 \r
752         return 0;\r
753 }\r
754 \r
755 void CCommitDlg::OnCancel()\r
756 {\r
757         m_bCancelled = true;\r
758         if (m_bBlock)\r
759                 return;\r
760         m_pathwatcher.Stop();\r
761         if (m_bThreadRunning)\r
762         {\r
763                 InterlockedExchange(&m_bRunThread, FALSE);\r
764                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
765                 if (m_bThreadRunning)\r
766                 {\r
767                         // we gave the thread a chance to quit. Since the thread didn't\r
768                         // listen to us we have to kill it.\r
769                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
770                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
771                 }\r
772         }\r
773         UpdateData();\r
774         m_sBugID.Trim();\r
775         m_sLogMessage = m_cLogMessage.GetText();\r
776         if (!m_sBugID.IsEmpty())\r
777         {\r
778                 m_sBugID.Replace(_T(", "), _T(","));\r
779                 m_sBugID.Replace(_T(" ,"), _T(","));\r
780                 CString sBugID = m_ProjectProperties.sMessage;\r
781                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
782                 if (m_ProjectProperties.bAppend)\r
783                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
784                 else\r
785                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
786         }\r
787         if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)\r
788                 m_History.AddEntry(m_sLogMessage);\r
789         m_History.Save();\r
790         SaveSplitterPos();\r
791         CResizableStandAloneDialog::OnCancel();\r
792 }\r
793 \r
794 void CCommitDlg::OnBnClickedSelectall()\r
795 {\r
796         m_tooltips.Pop();       // hide the tooltips\r
797         UINT state = (m_SelectAll.GetState() & 0x0003);\r
798         if (state == BST_INDETERMINATE)\r
799         {\r
800                 // It is not at all useful to manually place the checkbox into the indeterminate state...\r
801                 // We will force this on to the unchecked state\r
802                 state = BST_UNCHECKED;\r
803                 m_SelectAll.SetCheck(state);\r
804         }\r
805         m_ListCtrl.SelectAll(state == BST_CHECKED);\r
806 }\r
807 \r
808 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)\r
809 {\r
810         if (!m_bBlock)\r
811                 m_tooltips.RelayEvent(pMsg);\r
812         if (pMsg->message == WM_KEYDOWN)\r
813         {\r
814                 switch (pMsg->wParam)\r
815                 {\r
816                 case VK_F5:\r
817                         {\r
818                                 if (m_bBlock)\r
819                                         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
820                                 Refresh();\r
821                         }\r
822                         break;\r
823                 case VK_RETURN:\r
824                         {\r
825                                 if (GetAsyncKeyState(VK_CONTROL)&0x8000)\r
826                                 {\r
827                                         if ( GetDlgItem(IDOK)->IsWindowEnabled() )\r
828                                         {\r
829                                                 PostMessage(WM_COMMAND, IDOK);\r
830                                         }\r
831                                         return TRUE;\r
832                                 }\r
833                                 if ( GetFocus()==GetDlgItem(IDC_BUGID) )\r
834                                 {\r
835                                         // Pressing RETURN in the bug id control\r
836                                         // moves the focus to the message\r
837                                         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
838                                         return TRUE;\r
839                                 }\r
840                         }\r
841                         break;\r
842                 }\r
843         }\r
844 \r
845         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
846 }\r
847 \r
848 void CCommitDlg::Refresh()\r
849 {\r
850         if (m_bThreadRunning)\r
851                 return;\r
852 \r
853         InterlockedExchange(&m_bBlock, TRUE);\r
854         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
855         if (m_pThread==NULL)\r
856         {\r
857                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
858                 InterlockedExchange(&m_bBlock, FALSE);\r
859         }\r
860         else\r
861         {\r
862                 m_pThread->m_bAutoDelete = FALSE;\r
863                 m_pThread->ResumeThread();\r
864         }\r
865 }\r
866 \r
867 void CCommitDlg::OnBnClickedHelp()\r
868 {\r
869         OnHelp();\r
870 }\r
871 \r
872 void CCommitDlg::OnBnClickedShowunversioned()\r
873 {\r
874         m_tooltips.Pop();       // hide the tooltips\r
875         UpdateData();\r
876         m_regAddBeforeCommit = m_bShowUnversioned;\r
877         if (!m_bBlock)\r
878         {\r
879                 DWORD dwShow = m_ListCtrl.GetShowFlags();\r
880                 if (DWORD(m_regAddBeforeCommit))\r
881                         dwShow |= SVNSLC_SHOWUNVERSIONED;\r
882                 else\r
883                         dwShow &= ~SVNSLC_SHOWUNVERSIONED;\r
884                 if(dwShow & SVNSLC_SHOWUNVERSIONED)\r
885                 {\r
886                         m_ListCtrl.GetStatus(this->m_pathList,false,false,true);\r
887                 }\r
888                 m_ListCtrl.Show(dwShow);\r
889         }\r
890 }\r
891 \r
892 void CCommitDlg::OnStnClickedExternalwarning()\r
893 {\r
894         m_tooltips.Popup();\r
895 }\r
896 \r
897 void CCommitDlg::OnEnChangeLogmessage()\r
898 {\r
899         UpdateOKButton();\r
900 }\r
901 \r
902 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)\r
903 {\r
904 #if 0\r
905         if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))\r
906         {\r
907                 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
908                 {\r
909                         m_bShowUnversioned = TRUE;\r
910                         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;\r
911                         m_ListCtrl.Show(dwShow);\r
912                         UpdateData(FALSE);\r
913                 }\r
914         }\r
915 #endif\r
916         return 0;\r
917 }\r
918 \r
919 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)\r
920 {\r
921         Refresh();\r
922         return 0;\r
923 }\r
924 \r
925 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM /*lParam*/)\r
926 {\r
927 #if 0\r
928         BringWindowToTop();\r
929         SetForegroundWindow();\r
930         SetActiveWindow();\r
931         // if multiple files/folders are dropped\r
932         // this handler is called for every single item\r
933         // separately.\r
934         // To avoid creating multiple refresh threads and\r
935         // causing crashes, we only add the items to the\r
936         // list control and start a timer.\r
937         // When the timer expires, we start the refresh thread,\r
938         // but only if it isn't already running - otherwise we\r
939         // restart the timer.\r
940         CTGitPath path;\r
941         path.SetFromWin((LPCTSTR)lParam);\r
942 \r
943         // just add all the items we get here.\r
944         // if the item is versioned, the add will fail but nothing\r
945         // more will happen.\r
946         Git Git;\r
947         Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);\r
948 \r
949         if (!m_ListCtrl.HasPath(path))\r
950         {\r
951                 if (m_pathList.AreAllPathsFiles())\r
952                 {\r
953                         m_pathList.AddPath(path);\r
954                         m_pathList.RemoveDuplicates();\r
955                         m_updatedPathList.AddPath(path);\r
956                         m_updatedPathList.RemoveDuplicates();\r
957                 }\r
958                 else\r
959                 {\r
960                         // if the path list contains folders, we have to check whether\r
961                         // our just (maybe) added path is a child of one of those. If it is\r
962                         // a child of a folder already in the list, we must not add it. Otherwise\r
963                         // that path could show up twice in the list.\r
964                         bool bHasParentInList = false;\r
965                         for (int i=0; i<m_pathList.GetCount(); ++i)\r
966                         {\r
967                                 if (m_pathList[i].IsAncestorOf(path))\r
968                                 {\r
969                                         bHasParentInList = true;\r
970                                         break;\r
971                                 }\r
972                         }\r
973                         if (!bHasParentInList)\r
974                         {\r
975                                 m_pathList.AddPath(path);\r
976                                 m_pathList.RemoveDuplicates();\r
977                                 m_updatedPathList.AddPath(path);\r
978                                 m_updatedPathList.RemoveDuplicates();\r
979                         }\r
980                 }\r
981         }\r
982         \r
983         // Always start the timer, since the status of an existing item might have changed\r
984         SetTimer(REFRESHTIMER, 200, NULL);\r
985         ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());\r
986 #endif\r
987         return 0;\r
988 }\r
989 \r
990 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)\r
991 {\r
992         m_cLogMessage.SetAutoCompletionList(m_autolist, '*');\r
993         return 0;\r
994 }\r
995 \r
996 //////////////////////////////////////////////////////////////////////////\r
997 // functions which run in the status thread\r
998 //////////////////////////////////////////////////////////////////////////\r
999 \r
1000 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)\r
1001 {\r
1002         CString strLine;\r
1003         try\r
1004         {\r
1005                 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);\r
1006                 while (m_bRunThread && file.ReadString(strLine))\r
1007                 {\r
1008                         int eqpos = strLine.Find('=');\r
1009                         CString rgx;\r
1010                         rgx = strLine.Mid(eqpos+1).Trim();\r
1011 \r
1012                         int pos = -1;\r
1013                         while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))\r
1014                         {\r
1015                                 mapRegex[strLine.Left(pos)] = rgx;\r
1016                                 strLine = strLine.Mid(pos+1).Trim();\r
1017                         }\r
1018                         mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;\r
1019                 }\r
1020                 file.Close();\r
1021         }\r
1022         catch (CFileException* pE)\r
1023         {\r
1024                 TRACE("CFileException loading auto list regex file\n");\r
1025                 pE->Delete();\r
1026                 return;\r
1027         }\r
1028 }\r
1029 void CCommitDlg::GetAutocompletionList()\r
1030 {\r
1031         // the auto completion list is made of strings from each selected files.\r
1032         // the strings used are extracted from the files with regexes found\r
1033         // in the file "autolist.txt".\r
1034         // the format of that file is:\r
1035         // file extensions separated with commas '=' regular expression to use\r
1036         // example:\r
1037         // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))\r
1038         // .cpp = (?<=[^\s]::)\b\w+\b\r
1039         \r
1040         std::map<CString, CString> mapRegex;\r
1041         CString sRegexFile = CPathUtils::GetAppDirectory();\r
1042         CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);\r
1043         DWORD timeoutvalue = regtimeout*1000;\r
1044         sRegexFile += _T("autolist.txt");\r
1045         if (!m_bRunThread)\r
1046                 return;\r
1047         ParseRegexFile(sRegexFile, mapRegex);\r
1048         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));\r
1049         sRegexFile.ReleaseBuffer();\r
1050         sRegexFile += _T("\\TortoiseGit\\autolist.txt");\r
1051         if (PathFileExists(sRegexFile))\r
1052         {\r
1053                 ParseRegexFile(sRegexFile, mapRegex);\r
1054         }\r
1055         DWORD starttime = GetTickCount();\r
1056 \r
1057         // now we have two arrays of strings, where the first array contains all\r
1058         // file extensions we can use and the second the corresponding regex strings\r
1059         // to apply to those files.\r
1060 \r
1061         // the next step is to go over all files shown in the commit dialog\r
1062         // and scan them for strings we can use\r
1063         int nListItems = m_ListCtrl.GetItemCount();\r
1064 \r
1065         for (int i=0; i<nListItems && m_bRunThread; ++i)\r
1066         {\r
1067                 // stop parsing after timeout\r
1068                 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))\r
1069                         return;\r
1070 \r
1071                 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
1072 \r
1073                 if(path == NULL)\r
1074                         continue;\r
1075 \r
1076                 CString sPartPath =path->GetGitPathString();\r
1077                 m_autolist.insert(sPartPath);\r
1078 \r
1079 //              const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1080 //              if (!entry)\r
1081 //                      continue;\r
1082                 \r
1083                 // add the path parts to the auto completion list too\r
1084 //              CString sPartPath = entry->GetRelativeGitPath();\r
1085 //              m_autolist.insert(sPartPath);\r
1086 \r
1087 \r
1088                 int pos = 0;\r
1089                 int lastPos = 0;\r
1090                 while ((pos = sPartPath.Find('/', pos)) >= 0)\r
1091                 {\r
1092                         pos++;\r
1093                         lastPos = pos;\r
1094                         m_autolist.insert(sPartPath.Mid(pos));\r
1095                 }\r
1096 \r
1097                 // Last inserted entry is a file name.\r
1098                 // Some users prefer to also list file name without extension.\r
1099                 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))\r
1100                 {\r
1101                         int dotPos = sPartPath.ReverseFind('.');\r
1102                         if ((dotPos >= 0) && (dotPos > lastPos))\r
1103                                 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));\r
1104                 }\r
1105 #if 0\r
1106                 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))\r
1107                         continue;\r
1108 \r
1109                 CString sExt = entry->GetPath().GetFileExtension();\r
1110                 sExt.MakeLower();\r
1111                 // find the regex string which corresponds to the file extension\r
1112                 CString rdata = mapRegex[sExt];\r
1113                 if (rdata.IsEmpty())\r
1114                         continue;\r
1115 \r
1116                 ScanFile(entry->GetPath().GetWinPathString(), rdata);\r
1117                 if ((entry->textstatus != Git_wc_status_unversioned) &&\r
1118                         (entry->textstatus != Git_wc_status_none) &&\r
1119                         (entry->textstatus != Git_wc_status_ignored) &&\r
1120                         (entry->textstatus != Git_wc_status_added) &&\r
1121                         (entry->textstatus != Git_wc_status_normal))\r
1122                 {\r
1123                         CTGitPath basePath = Git::GetPristinePath(entry->GetPath());\r
1124                         if (!basePath.IsEmpty())\r
1125                                 ScanFile(basePath.GetWinPathString(), rdata);\r
1126                 }\r
1127 #endif\r
1128         }\r
1129         ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);\r
1130 }\r
1131 \r
1132 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)\r
1133 {\r
1134         wstring sFileContent;\r
1135         HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);\r
1136         if (hFile != INVALID_HANDLE_VALUE)\r
1137         {\r
1138                 DWORD size = GetFileSize(hFile, NULL);\r
1139                 if (size > 1000000L)\r
1140                 {\r
1141                         // no files bigger than 1 Meg\r
1142                         CloseHandle(hFile);\r
1143                         return;\r
1144                 }\r
1145                 // allocate memory to hold file contents\r
1146                 char * buffer = new char[size];\r
1147                 DWORD readbytes;\r
1148                 ReadFile(hFile, buffer, size, &readbytes, NULL);\r
1149                 CloseHandle(hFile);\r
1150                 int opts = 0;\r
1151                 IsTextUnicode(buffer, readbytes, &opts);\r
1152                 if (opts & IS_TEXT_UNICODE_NULL_BYTES)\r
1153                 {\r
1154                         delete [] buffer;\r
1155                         return;\r
1156                 }\r
1157                 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)\r
1158                 {\r
1159                         sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));\r
1160                 }\r
1161                 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))\r
1162                 {\r
1163                         int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);\r
1164                         wchar_t * pWideBuf = new wchar_t[ret];\r
1165                         int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);\r
1166                         if (ret2 == ret)\r
1167                                 sFileContent = wstring(pWideBuf, ret);\r
1168                         delete [] pWideBuf;\r
1169                 }\r
1170                 delete [] buffer;\r
1171         }\r
1172         if (sFileContent.empty()|| !m_bRunThread)\r
1173         {\r
1174                 return;\r
1175         }\r
1176 \r
1177         try\r
1178         {\r
1179                 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
1180                 const tr1::wsregex_iterator end;\r
1181                 wstring s = sFileContent;\r
1182                 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)\r
1183                 {\r
1184                         const tr1::wsmatch match = *it;\r
1185                         for (size_t i=1; i<match.size(); ++i)\r
1186                         {\r
1187                                 if (match[i].second-match[i].first)\r
1188                                 {\r
1189                                         ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());\r
1190                                         m_autolist.insert(wstring(match[i]).c_str());\r
1191                                 }\r
1192                         }\r
1193                 }\r
1194         }\r
1195         catch (exception) {}\r
1196 }\r
1197 \r
1198 // CSciEditContextMenuInterface\r
1199 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)\r
1200 {\r
1201         CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));\r
1202         m_nPopupPasteListCmd = nCmd++;\r
1203         mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);\r
1204 }\r
1205 \r
1206 bool CCommitDlg::HandleMenuItemClick(int /*cmd*/, CSciEdit * /*pSciEdit*/)\r
1207 {\r
1208 #if 0\r
1209         if (m_bBlock)\r
1210                 return false;\r
1211         if (cmd == m_nPopupPasteListCmd)\r
1212         {\r
1213                 CString logmsg;\r
1214                 TCHAR buf[MAX_STATUS_STRING_LENGTH];\r
1215                 int nListItems = m_ListCtrl.GetItemCount();\r
1216                 for (int i=0; i<nListItems; ++i)\r
1217                 {\r
1218                         CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1219                         if (entry->IsChecked())\r
1220                         {\r
1221                                 CString line;\r
1222                                 Git_wc_status_kind status = entry->status;\r
1223                                 if (status == Git_wc_status_unversioned)\r
1224                                         status = Git_wc_status_added;\r
1225                                 if (status == Git_wc_status_missing)\r
1226                                         status = Git_wc_status_deleted;\r
1227                                 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());\r
1228                                 if (m_ProjectProperties.bFileListInEnglish)\r
1229                                         langID = 1033;\r
1230                                 GitStatus::GetStatusString(AfxGetResourceHandle(), status, buf, sizeof(buf)/sizeof(TCHAR), langID);\r
1231                                 line.Format(_T("%-10s %s\r\n"), buf, (LPCTSTR)m_ListCtrl.GetItemText(i,0));\r
1232                                 logmsg += line;\r
1233                         }\r
1234                 }\r
1235                 pSciEdit->InsertText(logmsg);\r
1236                 return true;\r
1237         }\r
1238 #endif\r
1239         return false;\r
1240 }\r
1241 \r
1242 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)\r
1243 {\r
1244         switch (nIDEvent)\r
1245         {\r
1246         case ENDDIALOGTIMER:\r
1247                 KillTimer(ENDDIALOGTIMER);\r
1248                 EndDialog(0);\r
1249                 break;\r
1250         case REFRESHTIMER:\r
1251                 if (m_bThreadRunning)\r
1252                 {\r
1253                         SetTimer(REFRESHTIMER, 200, NULL);\r
1254                         ATLTRACE("Wait some more before refreshing\n");\r
1255                 }\r
1256                 else\r
1257                 {\r
1258                         KillTimer(REFRESHTIMER);\r
1259                         ATLTRACE("Refreshing after items dropped\n");\r
1260                         Refresh();\r
1261                 }\r
1262                 break;\r
1263         }\r
1264         __super::OnTimer(nIDEvent);\r
1265 }\r
1266 \r
1267 void CCommitDlg::OnBnClickedHistory()\r
1268 {\r
1269         m_tooltips.Pop();       // hide the tooltips\r
1270         if (m_pathList.GetCount() == 0)\r
1271                 return;\r
1272 #if 0\r
1273         CHistoryDlg historyDlg;\r
1274         historyDlg.SetHistory(m_History);\r
1275         if (historyDlg.DoModal() != IDOK)\r
1276                 return;\r
1277 \r
1278         CString sMsg = historyDlg.GetSelectedText();\r
1279         if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))\r
1280         {\r
1281                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);\r
1282                 if (!sBugID.IsEmpty())\r
1283                 {\r
1284                         SetDlgItemText(IDC_BUGID, sBugID);\r
1285                 }\r
1286                 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)\r
1287                         m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());\r
1288                 else\r
1289                         m_cLogMessage.SetText(sMsg);\r
1290         }\r
1291 \r
1292         UpdateOKButton();\r
1293         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
1294 #endif\r
1295 }\r
1296 \r
1297 void CCommitDlg::OnBnClickedBugtraqbutton()\r
1298 {\r
1299 #if 0\r
1300         m_tooltips.Pop();       // hide the tooltips\r
1301         CString sMsg = m_cLogMessage.GetText();\r
1302 \r
1303         if (m_BugTraqProvider == NULL)\r
1304                 return;\r
1305 \r
1306         BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
1307         BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());\r
1308         SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());\r
1309 \r
1310         for (LONG index = 0; index < m_pathList.GetCount(); ++index)\r
1311                 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());\r
1312 \r
1313         BSTR originalMessage = sMsg.AllocSysString();\r
1314         BSTR temp = NULL;\r
1315 \r
1316         // first try the IBugTraqProvider2 interface\r
1317         CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
1318         HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
1319         if (SUCCEEDED(hr))\r
1320         {\r
1321                 CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
1322                 BSTR repositoryRoot = common.AllocSysString();\r
1323                 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, &temp)))\r
1324                 {\r
1325                         CString sErr;\r
1326                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1327                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1328                 }\r
1329                 else\r
1330                         m_cLogMessage.SetText(temp);\r
1331         }\r
1332         else\r
1333         {\r
1334                 // if IBugTraqProvider2 failed, try IBugTraqProvider\r
1335                 CComPtr<IBugTraqProvider> pProvider = NULL;\r
1336                 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
1337                 if (FAILED(hr))\r
1338                 {\r
1339                         CString sErr;\r
1340                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1341                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1342                         return;\r
1343                 }\r
1344 \r
1345                 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))\r
1346                 {\r
1347                         CString sErr;\r
1348                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1349                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1350                 }\r
1351                 else\r
1352                         m_cLogMessage.SetText(temp);\r
1353         }\r
1354 \r
1355         m_cLogMessage.SetFocus();\r
1356 \r
1357         SysFreeString(temp);\r
1358 #endif\r
1359 }\r
1360 \r
1361 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)\r
1362 {\r
1363         UpdateOKButton();\r
1364         return 0;\r
1365 }\r
1366 \r
1367 void CCommitDlg::UpdateOKButton()\r
1368 {\r
1369 #if 0\r
1370         BOOL bValidLogSize = FALSE;\r
1371 \r
1372     if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)\r
1373                 bValidLogSize = !m_bBlock;\r
1374 \r
1375         LONG nSelectedItems = m_ListCtrl.GetSelected();\r
1376         DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);\r
1377 #endif\r
1378 }\r
1379 \r
1380 \r
1381 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
1382 {\r
1383         switch (message) {\r
1384         case WM_NOTIFY:\r
1385                 if (wParam == IDC_SPLITTER)\r
1386                 { \r
1387                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
1388                         DoSize(pHdr->delta);\r
1389                 }\r
1390                 break;\r
1391         }\r
1392 \r
1393         return __super::DefWindowProc(message, wParam, lParam);\r
1394 }\r
1395 \r
1396 void CCommitDlg::SetSplitterRange()\r
1397 {\r
1398         if ((m_ListCtrl)&&(m_cLogMessage))\r
1399         {\r
1400                 CRect rcTop;\r
1401                 m_cLogMessage.GetWindowRect(rcTop);\r
1402                 ScreenToClient(rcTop);\r
1403                 CRect rcMiddle;\r
1404                 m_ListCtrl.GetWindowRect(rcMiddle);\r
1405                 ScreenToClient(rcMiddle);\r
1406                 if (rcMiddle.Height() && rcMiddle.Width())\r
1407                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
1408         }\r
1409 }\r
1410 \r
1411 void CCommitDlg::DoSize(int delta)\r
1412 {\r
1413         RemoveAnchor(IDC_MESSAGEGROUP);\r
1414         RemoveAnchor(IDC_LOGMESSAGE);\r
1415         RemoveAnchor(IDC_SPLITTER);\r
1416         RemoveAnchor(IDC_SIGNOFF);\r
1417         RemoveAnchor(IDC_COMMIT_AMEND);\r
1418         RemoveAnchor(IDC_LISTGROUP);\r
1419         RemoveAnchor(IDC_FILELIST);\r
1420         CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);\r
1421         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);\r
1422         CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);\r
1423         CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);\r
1424         CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);\r
1425         CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);\r
1426         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
1427         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
1428         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
1429         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
1430         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
1431         AddAnchor(IDC_SIGNOFF,TOP_RIGHT);\r
1432         AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);\r
1433         ArrangeLayout();\r
1434         // adjust the minimum size of the dialog to prevent the resizing from\r
1435         // moving the list control too far down.\r
1436         CRect rcLogMsg;\r
1437         m_cLogMessage.GetClientRect(rcLogMsg);\r
1438         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));\r
1439 \r
1440         SetSplitterRange();\r
1441         m_cLogMessage.Invalidate();\r
1442         GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
1443 }\r
1444 \r
1445 void CCommitDlg::OnSize(UINT nType, int cx, int cy)\r
1446 {\r
1447     // first, let the resizing take place\r
1448     __super::OnSize(nType, cx, cy);\r
1449 \r
1450     //set range\r
1451     SetSplitterRange();\r
1452 }\r
1453 \r
1454 \r
1455 void CCommitDlg::OnBnClickedSignOff()\r
1456 {\r
1457         // TODO: Add your control notification handler code here\r
1458         CString str;\r
1459         CString username;\r
1460         CString email;\r
1461         username=g_Git.GetUserName();\r
1462         email=g_Git.GetUserEmail();\r
1463         username.Remove(_T('\n'));\r
1464         email.Remove(_T('\n'));\r
1465         str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);\r
1466 \r
1467         m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);\r
1468 }\r
1469 \r
1470 void CCommitDlg::OnStnClickedCommitlabel()\r
1471 {\r
1472         // TODO: Add your control notification handler code here\r
1473 }\r
1474 \r
1475 void CCommitDlg::OnBnClickedCommitAmend()\r
1476 {\r
1477     // TODO: Add your control notification handler code here\r
1478         this->UpdateData();\r
1479         if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())\r
1480         {\r
1481                 GitRev rev;\r
1482                 BYTE_VECTOR vector;\r
1483                 CString head(_T("HEAD"));\r
1484                 g_Git.GetLog(vector,head,NULL,1);\r
1485                 rev.ParserFromLog(vector);\r
1486                 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;\r
1487         }\r
1488 \r
1489         if(this->m_bCommitAmend)\r
1490         {\r
1491                 this->m_NoAmendStr=this->m_cLogMessage.GetText();\r
1492                 m_cLogMessage.SetText(m_AmendStr);\r
1493 \r
1494         }else\r
1495         {\r
1496                 this->m_AmendStr=this->m_cLogMessage.GetText();\r
1497                 m_cLogMessage.SetText(m_NoAmendStr);\r
1498 \r
1499         }\r
1500 \r
1501 }\r