OSDN Git Service

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