OSDN Git Service

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