OSDN Git Service

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