OSDN Git Service

Fix when nothing commit, message box will show ask user enable "show unversion files"
[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.UpdateFileList(CGitStatusListCtrl::FILELIST_UNVER);\r
711                         m_ListCtrl.Show(dwShow);\r
712                 }\r
713         }\r
714 \r
715         CTGitPath commonDir = m_ListCtrl.GetCommonDirectory(false);\r
716         SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
717 \r
718         m_autolist.clear();\r
719         // we don't have to block the commit dialog while we fetch the\r
720         // auto completion list.\r
721         m_pathwatcher.ClearChangedPaths();\r
722         InterlockedExchange(&m_bBlock, FALSE);\r
723         if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\Autocompletion"), TRUE)==TRUE)\r
724         {\r
725                 m_ListCtrl.Block(TRUE, TRUE);\r
726                 GetAutocompletionList();\r
727                 m_ListCtrl.Block(FALSE, FALSE);\r
728         }\r
729         if (m_bRunThread)\r
730         {\r
731                 DialogEnableWindow(IDC_SHOWUNVERSIONED, true);\r
732                 DialogEnableWindow(IDC_SELECTALL, true);\r
733                 if (m_ListCtrl.HasChangeLists())\r
734                         DialogEnableWindow(IDC_KEEPLISTS, true);\r
735                 if (m_ListCtrl.HasLocks())\r
736                         DialogEnableWindow(IDC_KEEPLOCK, true);\r
737                 // we have the list, now signal the main thread about it\r
738                 SendMessage(WM_AUTOLISTREADY);  // only send the message if the thread wasn't told to quit!\r
739         }\r
740 \r
741         InterlockedExchange(&m_bRunThread, FALSE);\r
742         InterlockedExchange(&m_bThreadRunning, FALSE);\r
743         // force the cursor to normal\r
744         RefreshCursor();\r
745 \r
746         return 0;\r
747 }\r
748 \r
749 void CCommitDlg::OnCancel()\r
750 {\r
751         m_bCancelled = true;\r
752         if (m_bBlock)\r
753                 return;\r
754         m_pathwatcher.Stop();\r
755         if (m_bThreadRunning)\r
756         {\r
757                 InterlockedExchange(&m_bRunThread, FALSE);\r
758                 WaitForSingleObject(m_pThread->m_hThread, 1000);\r
759                 if (m_bThreadRunning)\r
760                 {\r
761                         // we gave the thread a chance to quit. Since the thread didn't\r
762                         // listen to us we have to kill it.\r
763                         TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
764                         InterlockedExchange(&m_bThreadRunning, FALSE);\r
765                 }\r
766         }\r
767         UpdateData();\r
768         m_sBugID.Trim();\r
769         m_sLogMessage = m_cLogMessage.GetText();\r
770         if (!m_sBugID.IsEmpty())\r
771         {\r
772                 m_sBugID.Replace(_T(", "), _T(","));\r
773                 m_sBugID.Replace(_T(" ,"), _T(","));\r
774                 CString sBugID = m_ProjectProperties.sMessage;\r
775                 sBugID.Replace(_T("%BUGID%"), m_sBugID);\r
776                 if (m_ProjectProperties.bAppend)\r
777                         m_sLogMessage += _T("\n") + sBugID + _T("\n");\r
778                 else\r
779                         m_sLogMessage = sBugID + _T("\n") + m_sLogMessage;\r
780         }\r
781         if (m_ProjectProperties.sLogTemplate.Compare(m_sLogMessage) != 0)\r
782                 m_History.AddEntry(m_sLogMessage);\r
783         m_History.Save();\r
784         SaveSplitterPos();\r
785         CResizableStandAloneDialog::OnCancel();\r
786 }\r
787 \r
788 void CCommitDlg::OnBnClickedSelectall()\r
789 {\r
790         m_tooltips.Pop();       // hide the tooltips\r
791         UINT state = (m_SelectAll.GetState() & 0x0003);\r
792         if (state == BST_INDETERMINATE)\r
793         {\r
794                 // It is not at all useful to manually place the checkbox into the indeterminate state...\r
795                 // We will force this on to the unchecked state\r
796                 state = BST_UNCHECKED;\r
797                 m_SelectAll.SetCheck(state);\r
798         }\r
799         m_ListCtrl.SelectAll(state == BST_CHECKED);\r
800 }\r
801 \r
802 BOOL CCommitDlg::PreTranslateMessage(MSG* pMsg)\r
803 {\r
804         if (!m_bBlock)\r
805                 m_tooltips.RelayEvent(pMsg);\r
806         if (pMsg->message == WM_KEYDOWN)\r
807         {\r
808                 switch (pMsg->wParam)\r
809                 {\r
810                 case VK_F5:\r
811                         {\r
812                                 if (m_bBlock)\r
813                                         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
814                                 Refresh();\r
815                         }\r
816                         break;\r
817                 case VK_RETURN:\r
818                         {\r
819                                 if (GetAsyncKeyState(VK_CONTROL)&0x8000)\r
820                                 {\r
821                                         if ( GetDlgItem(IDOK)->IsWindowEnabled() )\r
822                                         {\r
823                                                 PostMessage(WM_COMMAND, IDOK);\r
824                                         }\r
825                                         return TRUE;\r
826                                 }\r
827                                 if ( GetFocus()==GetDlgItem(IDC_BUGID) )\r
828                                 {\r
829                                         // Pressing RETURN in the bug id control\r
830                                         // moves the focus to the message\r
831                                         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
832                                         return TRUE;\r
833                                 }\r
834                         }\r
835                         break;\r
836                 }\r
837         }\r
838 \r
839         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
840 }\r
841 \r
842 void CCommitDlg::Refresh()\r
843 {\r
844         if (m_bThreadRunning)\r
845                 return;\r
846 \r
847         InterlockedExchange(&m_bBlock, TRUE);\r
848         m_pThread = AfxBeginThread(StatusThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
849         if (m_pThread==NULL)\r
850         {\r
851                 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
852                 InterlockedExchange(&m_bBlock, FALSE);\r
853         }\r
854         else\r
855         {\r
856                 m_pThread->m_bAutoDelete = FALSE;\r
857                 m_pThread->ResumeThread();\r
858         }\r
859 }\r
860 \r
861 void CCommitDlg::OnBnClickedHelp()\r
862 {\r
863         OnHelp();\r
864 }\r
865 \r
866 void CCommitDlg::OnBnClickedShowunversioned()\r
867 {\r
868         m_tooltips.Pop();       // hide the tooltips\r
869         UpdateData();\r
870         m_regAddBeforeCommit = m_bShowUnversioned;\r
871         if (!m_bBlock)\r
872         {\r
873                 DWORD dwShow = m_ListCtrl.GetShowFlags();\r
874                 if (DWORD(m_regAddBeforeCommit))\r
875                         dwShow |= SVNSLC_SHOWUNVERSIONED;\r
876                 else\r
877                         dwShow &= ~SVNSLC_SHOWUNVERSIONED;\r
878                 if(dwShow & SVNSLC_SHOWUNVERSIONED)\r
879                 {\r
880                         m_ListCtrl.GetStatus(this->m_pathList,false,false,true);\r
881                 }\r
882                 m_ListCtrl.Show(dwShow);\r
883         }\r
884 }\r
885 \r
886 void CCommitDlg::OnStnClickedExternalwarning()\r
887 {\r
888         m_tooltips.Popup();\r
889 }\r
890 \r
891 void CCommitDlg::OnEnChangeLogmessage()\r
892 {\r
893         UpdateOKButton();\r
894 }\r
895 \r
896 LRESULT CCommitDlg::OnGitStatusListCtrlItemCountChanged(WPARAM, LPARAM)\r
897 {\r
898 #if 0\r
899         if ((m_ListCtrl.GetItemCount() == 0)&&(m_ListCtrl.HasUnversionedItems())&&(!m_bShowUnversioned))\r
900         {\r
901                 if (CMessageBox::Show(*this, IDS_COMMITDLG_NOTHINGTOCOMMITUNVERSIONED, IDS_APPNAME, MB_ICONINFORMATION | MB_YESNO)==IDYES)\r
902                 {\r
903                         m_bShowUnversioned = TRUE;\r
904                         DWORD dwShow = GitSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | GitSLC_SHOWUNVERSIONED | GitSLC_SHOWLOCKS;\r
905                         m_ListCtrl.Show(dwShow);\r
906                         UpdateData(FALSE);\r
907                 }\r
908         }\r
909 #endif\r
910         return 0;\r
911 }\r
912 \r
913 LRESULT CCommitDlg::OnGitStatusListCtrlNeedsRefresh(WPARAM, LPARAM)\r
914 {\r
915         Refresh();\r
916         return 0;\r
917 }\r
918 \r
919 LRESULT CCommitDlg::OnFileDropped(WPARAM, LPARAM lParam)\r
920 {\r
921 #if 0\r
922         BringWindowToTop();\r
923         SetForegroundWindow();\r
924         SetActiveWindow();\r
925         // if multiple files/folders are dropped\r
926         // this handler is called for every single item\r
927         // separately.\r
928         // To avoid creating multiple refresh threads and\r
929         // causing crashes, we only add the items to the\r
930         // list control and start a timer.\r
931         // When the timer expires, we start the refresh thread,\r
932         // but only if it isn't already running - otherwise we\r
933         // restart the timer.\r
934         CTGitPath path;\r
935         path.SetFromWin((LPCTSTR)lParam);\r
936 \r
937         // just add all the items we get here.\r
938         // if the item is versioned, the add will fail but nothing\r
939         // more will happen.\r
940         Git Git;\r
941         Git.Add(CTGitPathList(path), &m_ProjectProperties, Git_depth_empty, false, true, true);\r
942 \r
943         if (!m_ListCtrl.HasPath(path))\r
944         {\r
945                 if (m_pathList.AreAllPathsFiles())\r
946                 {\r
947                         m_pathList.AddPath(path);\r
948                         m_pathList.RemoveDuplicates();\r
949                         m_updatedPathList.AddPath(path);\r
950                         m_updatedPathList.RemoveDuplicates();\r
951                 }\r
952                 else\r
953                 {\r
954                         // if the path list contains folders, we have to check whether\r
955                         // our just (maybe) added path is a child of one of those. If it is\r
956                         // a child of a folder already in the list, we must not add it. Otherwise\r
957                         // that path could show up twice in the list.\r
958                         bool bHasParentInList = false;\r
959                         for (int i=0; i<m_pathList.GetCount(); ++i)\r
960                         {\r
961                                 if (m_pathList[i].IsAncestorOf(path))\r
962                                 {\r
963                                         bHasParentInList = true;\r
964                                         break;\r
965                                 }\r
966                         }\r
967                         if (!bHasParentInList)\r
968                         {\r
969                                 m_pathList.AddPath(path);\r
970                                 m_pathList.RemoveDuplicates();\r
971                                 m_updatedPathList.AddPath(path);\r
972                                 m_updatedPathList.RemoveDuplicates();\r
973                         }\r
974                 }\r
975         }\r
976         \r
977         // Always start the timer, since the status of an existing item might have changed\r
978         SetTimer(REFRESHTIMER, 200, NULL);\r
979         ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());\r
980 #endif\r
981         return 0;\r
982 }\r
983 \r
984 LRESULT CCommitDlg::OnAutoListReady(WPARAM, LPARAM)\r
985 {\r
986         m_cLogMessage.SetAutoCompletionList(m_autolist, '*');\r
987         return 0;\r
988 }\r
989 \r
990 //////////////////////////////////////////////////////////////////////////\r
991 // functions which run in the status thread\r
992 //////////////////////////////////////////////////////////////////////////\r
993 \r
994 void CCommitDlg::ParseRegexFile(const CString& sFile, std::map<CString, CString>& mapRegex)\r
995 {\r
996         CString strLine;\r
997         try\r
998         {\r
999                 CStdioFile file(sFile, CFile::typeText | CFile::modeRead | CFile::shareDenyWrite);\r
1000                 while (m_bRunThread && file.ReadString(strLine))\r
1001                 {\r
1002                         int eqpos = strLine.Find('=');\r
1003                         CString rgx;\r
1004                         rgx = strLine.Mid(eqpos+1).Trim();\r
1005 \r
1006                         int pos = -1;\r
1007                         while (((pos = strLine.Find(','))>=0)&&(pos < eqpos))\r
1008                         {\r
1009                                 mapRegex[strLine.Left(pos)] = rgx;\r
1010                                 strLine = strLine.Mid(pos+1).Trim();\r
1011                         }\r
1012                         mapRegex[strLine.Left(strLine.Find('=')).Trim()] = rgx;\r
1013                 }\r
1014                 file.Close();\r
1015         }\r
1016         catch (CFileException* pE)\r
1017         {\r
1018                 TRACE("CFileException loading auto list regex file\n");\r
1019                 pE->Delete();\r
1020                 return;\r
1021         }\r
1022 }\r
1023 void CCommitDlg::GetAutocompletionList()\r
1024 {\r
1025         // the auto completion list is made of strings from each selected files.\r
1026         // the strings used are extracted from the files with regexes found\r
1027         // in the file "autolist.txt".\r
1028         // the format of that file is:\r
1029         // file extensions separated with commas '=' regular expression to use\r
1030         // example:\r
1031         // .h, .hpp = (?<=class[\s])\b\w+\b|(\b\w+(?=[\s ]?\(\);))\r
1032         // .cpp = (?<=[^\s]::)\b\w+\b\r
1033         \r
1034         std::map<CString, CString> mapRegex;\r
1035         CString sRegexFile = CPathUtils::GetAppDirectory();\r
1036         CRegDWORD regtimeout = CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteParseTimeout"), 5);\r
1037         DWORD timeoutvalue = regtimeout*1000;\r
1038         sRegexFile += _T("autolist.txt");\r
1039         if (!m_bRunThread)\r
1040                 return;\r
1041         ParseRegexFile(sRegexFile, mapRegex);\r
1042         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, sRegexFile.GetBuffer(MAX_PATH+1));\r
1043         sRegexFile.ReleaseBuffer();\r
1044         sRegexFile += _T("\\TortoiseGit\\autolist.txt");\r
1045         if (PathFileExists(sRegexFile))\r
1046         {\r
1047                 ParseRegexFile(sRegexFile, mapRegex);\r
1048         }\r
1049         DWORD starttime = GetTickCount();\r
1050 \r
1051         // now we have two arrays of strings, where the first array contains all\r
1052         // file extensions we can use and the second the corresponding regex strings\r
1053         // to apply to those files.\r
1054 \r
1055         // the next step is to go over all files shown in the commit dialog\r
1056         // and scan them for strings we can use\r
1057         int nListItems = m_ListCtrl.GetItemCount();\r
1058 \r
1059         for (int i=0; i<nListItems && m_bRunThread; ++i)\r
1060         {\r
1061                 // stop parsing after timeout\r
1062                 if ((!m_bRunThread) || (GetTickCount() - starttime > timeoutvalue))\r
1063                         return;\r
1064 \r
1065                 CTGitPath *path = (CTGitPath*)m_ListCtrl.GetItemData(i);\r
1066 \r
1067                 if(path == NULL)\r
1068                         continue;\r
1069 \r
1070                 CString sPartPath =path->GetGitPathString();\r
1071                 m_autolist.insert(sPartPath);\r
1072 \r
1073 //              const CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1074 //              if (!entry)\r
1075 //                      continue;\r
1076                 \r
1077                 // add the path parts to the auto completion list too\r
1078 //              CString sPartPath = entry->GetRelativeGitPath();\r
1079 //              m_autolist.insert(sPartPath);\r
1080 \r
1081 \r
1082                 int pos = 0;\r
1083                 int lastPos = 0;\r
1084                 while ((pos = sPartPath.Find('/', pos)) >= 0)\r
1085                 {\r
1086                         pos++;\r
1087                         lastPos = pos;\r
1088                         m_autolist.insert(sPartPath.Mid(pos));\r
1089                 }\r
1090 \r
1091                 // Last inserted entry is a file name.\r
1092                 // Some users prefer to also list file name without extension.\r
1093                 if (CRegDWORD(_T("Software\\TortoiseGit\\AutocompleteRemovesExtensions"), FALSE))\r
1094                 {\r
1095                         int dotPos = sPartPath.ReverseFind('.');\r
1096                         if ((dotPos >= 0) && (dotPos > lastPos))\r
1097                                 m_autolist.insert(sPartPath.Mid(lastPos, dotPos - lastPos));\r
1098                 }\r
1099 #if 0\r
1100                 if ((entry->status <= Git_wc_status_normal)||(entry->status == Git_wc_status_ignored))\r
1101                         continue;\r
1102 \r
1103                 CString sExt = entry->GetPath().GetFileExtension();\r
1104                 sExt.MakeLower();\r
1105                 // find the regex string which corresponds to the file extension\r
1106                 CString rdata = mapRegex[sExt];\r
1107                 if (rdata.IsEmpty())\r
1108                         continue;\r
1109 \r
1110                 ScanFile(entry->GetPath().GetWinPathString(), rdata);\r
1111                 if ((entry->textstatus != Git_wc_status_unversioned) &&\r
1112                         (entry->textstatus != Git_wc_status_none) &&\r
1113                         (entry->textstatus != Git_wc_status_ignored) &&\r
1114                         (entry->textstatus != Git_wc_status_added) &&\r
1115                         (entry->textstatus != Git_wc_status_normal))\r
1116                 {\r
1117                         CTGitPath basePath = Git::GetPristinePath(entry->GetPath());\r
1118                         if (!basePath.IsEmpty())\r
1119                                 ScanFile(basePath.GetWinPathString(), rdata);\r
1120                 }\r
1121 #endif\r
1122         }\r
1123         ATLTRACE(_T("Auto completion list loaded in %d msec\n"), GetTickCount() - starttime);\r
1124 }\r
1125 \r
1126 void CCommitDlg::ScanFile(const CString& sFilePath, const CString& sRegex)\r
1127 {\r
1128         wstring sFileContent;\r
1129         HANDLE hFile = CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);\r
1130         if (hFile != INVALID_HANDLE_VALUE)\r
1131         {\r
1132                 DWORD size = GetFileSize(hFile, NULL);\r
1133                 if (size > 1000000L)\r
1134                 {\r
1135                         // no files bigger than 1 Meg\r
1136                         CloseHandle(hFile);\r
1137                         return;\r
1138                 }\r
1139                 // allocate memory to hold file contents\r
1140                 char * buffer = new char[size];\r
1141                 DWORD readbytes;\r
1142                 ReadFile(hFile, buffer, size, &readbytes, NULL);\r
1143                 CloseHandle(hFile);\r
1144                 int opts = 0;\r
1145                 IsTextUnicode(buffer, readbytes, &opts);\r
1146                 if (opts & IS_TEXT_UNICODE_NULL_BYTES)\r
1147                 {\r
1148                         delete [] buffer;\r
1149                         return;\r
1150                 }\r
1151                 if (opts & IS_TEXT_UNICODE_UNICODE_MASK)\r
1152                 {\r
1153                         sFileContent = wstring((wchar_t*)buffer, readbytes/sizeof(WCHAR));\r
1154                 }\r
1155                 if ((opts & IS_TEXT_UNICODE_NOT_UNICODE_MASK)||(opts == 0))\r
1156                 {\r
1157                         int ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, NULL, 0);\r
1158                         wchar_t * pWideBuf = new wchar_t[ret];\r
1159                         int ret2 = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, readbytes, pWideBuf, ret);\r
1160                         if (ret2 == ret)\r
1161                                 sFileContent = wstring(pWideBuf, ret);\r
1162                         delete [] pWideBuf;\r
1163                 }\r
1164                 delete [] buffer;\r
1165         }\r
1166         if (sFileContent.empty()|| !m_bRunThread)\r
1167         {\r
1168                 return;\r
1169         }\r
1170 \r
1171         try\r
1172         {\r
1173                 const tr1::wregex regCheck(sRegex, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
1174                 const tr1::wsregex_iterator end;\r
1175                 wstring s = sFileContent;\r
1176                 for (tr1::wsregex_iterator it(s.begin(), s.end(), regCheck); it != end; ++it)\r
1177                 {\r
1178                         const tr1::wsmatch match = *it;\r
1179                         for (size_t i=1; i<match.size(); ++i)\r
1180                         {\r
1181                                 if (match[i].second-match[i].first)\r
1182                                 {\r
1183                                         ATLTRACE(_T("matched keyword : %s\n"), wstring(match[i]).c_str());\r
1184                                         m_autolist.insert(wstring(match[i]).c_str());\r
1185                                 }\r
1186                         }\r
1187                 }\r
1188         }\r
1189         catch (exception) {}\r
1190 }\r
1191 \r
1192 // CSciEditContextMenuInterface\r
1193 void CCommitDlg::InsertMenuItems(CMenu& mPopup, int& nCmd)\r
1194 {\r
1195         CString sMenuItemText(MAKEINTRESOURCE(IDS_COMMITDLG_POPUP_PASTEFILELIST));\r
1196         m_nPopupPasteListCmd = nCmd++;\r
1197         mPopup.AppendMenu(MF_STRING | MF_ENABLED, m_nPopupPasteListCmd, sMenuItemText);\r
1198 }\r
1199 \r
1200 bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit)\r
1201 {\r
1202 #if 0\r
1203         if (m_bBlock)\r
1204                 return false;\r
1205         if (cmd == m_nPopupPasteListCmd)\r
1206         {\r
1207                 CString logmsg;\r
1208                 TCHAR buf[MAX_STATUS_STRING_LENGTH];\r
1209                 int nListItems = m_ListCtrl.GetItemCount();\r
1210                 for (int i=0; i<nListItems; ++i)\r
1211                 {\r
1212                         CGitStatusListCtrl::FileEntry * entry = m_ListCtrl.GetListEntry(i);\r
1213                         if (entry->IsChecked())\r
1214                         {\r
1215                                 CString line;\r
1216                                 Git_wc_status_kind status = entry->status;\r
1217                                 if (status == Git_wc_status_unversioned)\r
1218                                         status = Git_wc_status_added;\r
1219                                 if (status == Git_wc_status_missing)\r
1220                                         status = Git_wc_status_deleted;\r
1221                                 WORD langID = (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), GetUserDefaultLangID());\r
1222                                 if (m_ProjectProperties.bFileListInEnglish)\r
1223                                         langID = 1033;\r
1224                                 GitStatus::GetStatusString(AfxGetResourceHandle(), status, buf, sizeof(buf)/sizeof(TCHAR), langID);\r
1225                                 line.Format(_T("%-10s %s\r\n"), buf, (LPCTSTR)m_ListCtrl.GetItemText(i,0));\r
1226                                 logmsg += line;\r
1227                         }\r
1228                 }\r
1229                 pSciEdit->InsertText(logmsg);\r
1230                 return true;\r
1231         }\r
1232 #endif\r
1233         return false;\r
1234 }\r
1235 \r
1236 void CCommitDlg::OnTimer(UINT_PTR nIDEvent)\r
1237 {\r
1238         switch (nIDEvent)\r
1239         {\r
1240         case ENDDIALOGTIMER:\r
1241                 KillTimer(ENDDIALOGTIMER);\r
1242                 EndDialog(0);\r
1243                 break;\r
1244         case REFRESHTIMER:\r
1245                 if (m_bThreadRunning)\r
1246                 {\r
1247                         SetTimer(REFRESHTIMER, 200, NULL);\r
1248                         ATLTRACE("Wait some more before refreshing\n");\r
1249                 }\r
1250                 else\r
1251                 {\r
1252                         KillTimer(REFRESHTIMER);\r
1253                         ATLTRACE("Refreshing after items dropped\n");\r
1254                         Refresh();\r
1255                 }\r
1256                 break;\r
1257         }\r
1258         __super::OnTimer(nIDEvent);\r
1259 }\r
1260 \r
1261 void CCommitDlg::OnBnClickedHistory()\r
1262 {\r
1263         m_tooltips.Pop();       // hide the tooltips\r
1264         if (m_pathList.GetCount() == 0)\r
1265                 return;\r
1266 #if 0\r
1267         CHistoryDlg historyDlg;\r
1268         historyDlg.SetHistory(m_History);\r
1269         if (historyDlg.DoModal() != IDOK)\r
1270                 return;\r
1271 \r
1272         CString sMsg = historyDlg.GetSelectedText();\r
1273         if (sMsg != m_cLogMessage.GetText().Left(sMsg.GetLength()))\r
1274         {\r
1275                 CString sBugID = m_ProjectProperties.GetBugIDFromLog(sMsg);\r
1276                 if (!sBugID.IsEmpty())\r
1277                 {\r
1278                         SetDlgItemText(IDC_BUGID, sBugID);\r
1279                 }\r
1280                 if (m_ProjectProperties.sLogTemplate.Compare(m_cLogMessage.GetText())!=0)\r
1281                         m_cLogMessage.InsertText(sMsg, !m_cLogMessage.GetText().IsEmpty());\r
1282                 else\r
1283                         m_cLogMessage.SetText(sMsg);\r
1284         }\r
1285 \r
1286         UpdateOKButton();\r
1287         GetDlgItem(IDC_LOGMESSAGE)->SetFocus();\r
1288 #endif\r
1289 }\r
1290 \r
1291 void CCommitDlg::OnBnClickedBugtraqbutton()\r
1292 {\r
1293 #if 0\r
1294         m_tooltips.Pop();       // hide the tooltips\r
1295         CString sMsg = m_cLogMessage.GetText();\r
1296 \r
1297         if (m_BugTraqProvider == NULL)\r
1298                 return;\r
1299 \r
1300         BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
1301         BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());\r
1302         SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());\r
1303 \r
1304         for (LONG index = 0; index < m_pathList.GetCount(); ++index)\r
1305                 SafeArrayPutElement(pathList, &index, m_pathList[index].GetGitPathString().AllocSysString());\r
1306 \r
1307         BSTR originalMessage = sMsg.AllocSysString();\r
1308         BSTR temp = NULL;\r
1309 \r
1310         // first try the IBugTraqProvider2 interface\r
1311         CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
1312         HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
1313         if (SUCCEEDED(hr))\r
1314         {\r
1315                 CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
1316                 BSTR repositoryRoot = common.AllocSysString();\r
1317                 if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, &temp)))\r
1318                 {\r
1319                         CString sErr;\r
1320                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1321                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1322                 }\r
1323                 else\r
1324                         m_cLogMessage.SetText(temp);\r
1325         }\r
1326         else\r
1327         {\r
1328                 // if IBugTraqProvider2 failed, try IBugTraqProvider\r
1329                 CComPtr<IBugTraqProvider> pProvider = NULL;\r
1330                 HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
1331                 if (FAILED(hr))\r
1332                 {\r
1333                         CString sErr;\r
1334                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, (LPCTSTR)m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1335                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1336                         return;\r
1337                 }\r
1338 \r
1339                 if (FAILED(hr = pProvider->GetCommitMessage(GetSafeHwnd(), parameters, commonRoot, pathList, originalMessage, &temp)))\r
1340                 {\r
1341                         CString sErr;\r
1342                         sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
1343                         CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
1344                 }\r
1345                 else\r
1346                         m_cLogMessage.SetText(temp);\r
1347         }\r
1348 \r
1349         m_cLogMessage.SetFocus();\r
1350 \r
1351         SysFreeString(temp);\r
1352 #endif\r
1353 }\r
1354 \r
1355 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)\r
1356 {\r
1357         UpdateOKButton();\r
1358         return 0;\r
1359 }\r
1360 \r
1361 void CCommitDlg::UpdateOKButton()\r
1362 {\r
1363 #if 0\r
1364         BOOL bValidLogSize = FALSE;\r
1365 \r
1366     if (m_cLogMessage.GetText().GetLength() >= m_ProjectProperties.nMinLogSize)\r
1367                 bValidLogSize = !m_bBlock;\r
1368 \r
1369         LONG nSelectedItems = m_ListCtrl.GetSelected();\r
1370         DialogEnableWindow(IDOK, bValidLogSize && nSelectedItems>0);\r
1371 #endif\r
1372 }\r
1373 \r
1374 \r
1375 LRESULT CCommitDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)\r
1376 {\r
1377         switch (message) {\r
1378         case WM_NOTIFY:\r
1379                 if (wParam == IDC_SPLITTER)\r
1380                 { \r
1381                         SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;\r
1382                         DoSize(pHdr->delta);\r
1383                 }\r
1384                 break;\r
1385         }\r
1386 \r
1387         return __super::DefWindowProc(message, wParam, lParam);\r
1388 }\r
1389 \r
1390 void CCommitDlg::SetSplitterRange()\r
1391 {\r
1392         if ((m_ListCtrl)&&(m_cLogMessage))\r
1393         {\r
1394                 CRect rcTop;\r
1395                 m_cLogMessage.GetWindowRect(rcTop);\r
1396                 ScreenToClient(rcTop);\r
1397                 CRect rcMiddle;\r
1398                 m_ListCtrl.GetWindowRect(rcMiddle);\r
1399                 ScreenToClient(rcMiddle);\r
1400                 if (rcMiddle.Height() && rcMiddle.Width())\r
1401                         m_wndSplitter.SetRange(rcTop.top+60, rcMiddle.bottom-80);\r
1402         }\r
1403 }\r
1404 \r
1405 void CCommitDlg::DoSize(int delta)\r
1406 {\r
1407         RemoveAnchor(IDC_MESSAGEGROUP);\r
1408         RemoveAnchor(IDC_LOGMESSAGE);\r
1409         RemoveAnchor(IDC_SPLITTER);\r
1410         RemoveAnchor(IDC_SIGNOFF);\r
1411         RemoveAnchor(IDC_COMMIT_AMEND);\r
1412         RemoveAnchor(IDC_LISTGROUP);\r
1413         RemoveAnchor(IDC_FILELIST);\r
1414         CSplitterControl::ChangeHeight(&m_cLogMessage, delta, CW_TOPALIGN);\r
1415         CSplitterControl::ChangeHeight(GetDlgItem(IDC_MESSAGEGROUP), delta, CW_TOPALIGN);\r
1416         CSplitterControl::ChangeHeight(&m_ListCtrl, -delta, CW_BOTTOMALIGN);\r
1417         CSplitterControl::ChangeHeight(GetDlgItem(IDC_LISTGROUP), -delta, CW_BOTTOMALIGN);\r
1418         CSplitterControl::ChangePos(GetDlgItem(IDC_SIGNOFF),0,delta);\r
1419         CSplitterControl::ChangePos(GetDlgItem(IDC_COMMIT_AMEND),0,delta);\r
1420         AddAnchor(IDC_MESSAGEGROUP, TOP_LEFT, TOP_RIGHT);\r
1421         AddAnchor(IDC_LOGMESSAGE, TOP_LEFT, TOP_RIGHT);\r
1422         AddAnchor(IDC_SPLITTER, TOP_LEFT, TOP_RIGHT);\r
1423         AddAnchor(IDC_LISTGROUP, TOP_LEFT, BOTTOM_RIGHT);\r
1424         AddAnchor(IDC_FILELIST, TOP_LEFT, BOTTOM_RIGHT);\r
1425         AddAnchor(IDC_SIGNOFF,TOP_RIGHT);\r
1426         AddAnchor(IDC_COMMIT_AMEND,TOP_LEFT);\r
1427         ArrangeLayout();\r
1428         // adjust the minimum size of the dialog to prevent the resizing from\r
1429         // moving the list control too far down.\r
1430         CRect rcLogMsg;\r
1431         m_cLogMessage.GetClientRect(rcLogMsg);\r
1432         SetMinTrackSize(CSize(m_DlgOrigRect.Width(), m_DlgOrigRect.Height()-m_LogMsgOrigRect.Height()+rcLogMsg.Height()));\r
1433 \r
1434         SetSplitterRange();\r
1435         m_cLogMessage.Invalidate();\r
1436         GetDlgItem(IDC_LOGMESSAGE)->Invalidate();\r
1437 }\r
1438 \r
1439 void CCommitDlg::OnSize(UINT nType, int cx, int cy)\r
1440 {\r
1441     // first, let the resizing take place\r
1442     __super::OnSize(nType, cx, cy);\r
1443 \r
1444     //set range\r
1445     SetSplitterRange();\r
1446 }\r
1447 \r
1448 \r
1449 void CCommitDlg::OnBnClickedSignOff()\r
1450 {\r
1451         // TODO: Add your control notification handler code here\r
1452         CString str;\r
1453         CString username;\r
1454         CString email;\r
1455         username=g_Git.GetUserName();\r
1456         email=g_Git.GetUserEmail();\r
1457         username.Remove(_T('\n'));\r
1458         email.Remove(_T('\n'));\r
1459         str.Format(_T("Signed-off-by: %s <%s>\n"),username,email);\r
1460 \r
1461         m_cLogMessage.SetText(m_cLogMessage.GetText()+_T("\r\n\r\n")+str);\r
1462 }\r
1463 \r
1464 void CCommitDlg::OnStnClickedCommitlabel()\r
1465 {\r
1466         // TODO: Add your control notification handler code here\r
1467 }\r
1468 \r
1469 void CCommitDlg::OnBnClickedCommitAmend()\r
1470 {\r
1471     // TODO: Add your control notification handler code here\r
1472         this->UpdateData();\r
1473         if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())\r
1474         {\r
1475                 GitRev rev;\r
1476                 BYTE_VECTOR vector;\r
1477                 CString head(_T("HEAD"));\r
1478                 g_Git.GetLog(vector,head,NULL,1);\r
1479                 rev.ParserFromLog(vector);\r
1480                 m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;\r
1481         }\r
1482 \r
1483         if(this->m_bCommitAmend)\r
1484         {\r
1485                 this->m_NoAmendStr=this->m_cLogMessage.GetText();\r
1486                 m_cLogMessage.SetText(m_AmendStr);\r
1487 \r
1488         }else\r
1489         {\r
1490                 this->m_AmendStr=this->m_cLogMessage.GetText();\r
1491                 m_cLogMessage.SetText(m_NoAmendStr);\r
1492 \r
1493         }\r
1494 \r
1495 }\r